Tyro/src/TyroApp.cpp

146 lines
3.1 KiB
C++
Raw Normal View History

/**
* Main application file
*/
2015-03-30 14:50:10 -04:00
2015-04-22 10:09:43 -04:00
#include "wx_common.h"
2015-05-08 16:01:36 -04:00
#include "widgets/widget.h"
2015-04-22 10:09:43 -04:00
#include <wx/app.h>
2015-04-22 10:09:43 -04:00
// Some global stuff
wxConfigBase *Glob_config;
TyroMenu *Glob_menu_bar;
MainFrame *Glob_main_frame;
StringConstMap Glob_lexer_map;
PrefPane *Glob_pref_pane;
2015-05-19 12:12:12 -04:00
// Static app loading variables
static wxArrayString files;
static int param_count;
/**
* Class with main method
*/
class TyroApp : public wxApp
2015-03-30 14:50:10 -04:00
{
public:
/**
* Start the event loop and create the main window
*
* @return bool
*/
bool OnInit()
{
2015-05-15 16:55:18 -04:00
if ( ! wxApp::OnInit()) return false;
2015-05-15 16:55:18 -04:00
this->SetAppName(APP_NAME);
this->SetVendorName(APP_VENDOR);
2015-05-15 16:55:18 -04:00
// Initialize globals
this->InitLexerMap();
Glob_config = wxConfigBase::Get();
Glob_menu_bar = new TyroMenu();
Glob_main_frame = new MainFrame(0L, APP_NAME);
Glob_pref_pane = new PrefPane();
2015-05-15 16:55:18 -04:00
// Setup Main Window
Glob_main_frame->Layout();
Glob_main_frame->CenterOnScreen();
Glob_main_frame->Show(true);
2015-05-19 12:12:12 -04:00
// Open passed files
if (param_count > 0)
{
Glob_main_frame->OpenFiles(files);
}
2015-05-15 16:55:18 -04:00
SetTopWindow(Glob_main_frame);
return true;
}
/**
* Exit handler
*
* @return int
*/
int OnExit()
{
2015-05-15 16:55:18 -04:00
// Deallocate config object
delete wxConfigBase::Set((wxConfigBase *) NULL);
return close(true);
}
/**
* Set up Command Line options
*
* @param wxCmdLineParser& parser
* @return void
*/
void OnInitCmdLine(wxCmdLineParser &parser)
{
parser.SetDesc(Glob_cmdLineDesc);
2015-05-15 16:55:18 -04:00
// Set - as parameter delimeter, so raw file paths can be used
parser.SetSwitchChars("-");
}
/**
* Handler for command line options
*
* @param wxCmdLineParser& parser
* @return bool
*/
bool OnCmdLineParsed(wxCmdLineParser &parser)
{
// Get un-named parameters
int i;
2015-05-19 12:12:12 -04:00
param_count = parser.GetParamCount();
2015-05-15 16:55:18 -04:00
wxLogDebug("%i Parameters", param_count);
for (i = 0; i < param_count; i++)
{
2015-05-20 08:39:33 -04:00
files.Add(parser.GetParam(i));
2015-05-15 16:55:18 -04:00
}
return true;
}
private:
/**
* Set up mapping for lexers
2015-05-15 16:55:18 -04:00
*/
void InitLexerMap()
{
Glob_lexer_map[""] = wxSTC_LEX_NULL;
Glob_lexer_map["batch"] = wxSTC_LEX_BATCH;
Glob_lexer_map["caml"] = wxSTC_LEX_CAML;
Glob_lexer_map["cmake"] = wxSTC_LEX_CMAKE;
Glob_lexer_map["coffeescript"] = wxSTC_LEX_COFFEESCRIPT;
Glob_lexer_map["cpp"] = wxSTC_LEX_CPP;
Glob_lexer_map["css"] = wxSTC_LEX_CSS;
Glob_lexer_map["fortran"] = wxSTC_LEX_FORTRAN;
Glob_lexer_map["haskell"] = wxSTC_LEX_HASKELL;
Glob_lexer_map["html"] = wxSTC_LEX_HTML;
Glob_lexer_map["java"] = wxSTC_LEX_CPP;
Glob_lexer_map["js"] = wxSTC_LEX_CPP;
Glob_lexer_map["lisp"] = wxSTC_LEX_LISP;
Glob_lexer_map["lua"] = wxSTC_LEX_LUA;
Glob_lexer_map["makefile"] = wxSTC_LEX_MAKEFILE;
Glob_lexer_map["markdown"] = wxSTC_LEX_MARKDOWN;
Glob_lexer_map["php"] = wxSTC_LEX_HTML;
Glob_lexer_map["perl"] = wxSTC_LEX_PERL;
Glob_lexer_map["python"] = wxSTC_LEX_PYTHON;
Glob_lexer_map["ruby"] = wxSTC_LEX_RUBY;
Glob_lexer_map["rust"] = wxSTC_LEX_CPP;
Glob_lexer_map["shell"] = wxSTC_LEX_BASH;
Glob_lexer_map["sql"] = wxSTC_LEX_SQL;
Glob_lexer_map["xml"] = wxSTC_LEX_XML;
Glob_lexer_map["yaml"] = wxSTC_LEX_YAML;
}
};
2015-03-30 16:01:24 -04:00
IMPLEMENT_APP(TyroApp);