2015-04-23 16:40:59 -04:00
|
|
|
/**
|
|
|
|
* Main application file
|
|
|
|
*/
|
2015-03-30 14:50:10 -04:00
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
#include "src/wx_common.h"
|
|
|
|
#include "src/widgets/widget.h"
|
2015-04-22 10:09:43 -04:00
|
|
|
|
|
|
|
#include <wx/app.h>
|
2015-06-12 16:50:27 -04:00
|
|
|
#include <wx/sysopt.h>
|
2015-06-18 13:34:54 -04:00
|
|
|
#include <wx/vidmode.h>
|
2015-05-12 16:30:22 -04:00
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
#include "src/widgets/MainFrame.h"
|
|
|
|
|
2015-05-07 17:05:27 -04:00
|
|
|
// Some global stuff
|
2015-06-03 17:06:55 -04:00
|
|
|
wxConfigBase *Glob_config = nullptr;
|
|
|
|
TyroMenu *Glob_menu_bar = nullptr;
|
|
|
|
wxStatusBar *Glob_status_bar = nullptr;
|
|
|
|
MainFrame *Glob_main_frame = nullptr;
|
2015-05-13 16:55:44 -04:00
|
|
|
StringConstMap Glob_lexer_map;
|
2015-05-07 17:05:27 -04:00
|
|
|
|
2015-06-18 13:34:54 -04:00
|
|
|
#ifndef TRAVIS
|
|
|
|
PrefPane *Glob_pref_pane = nullptr;
|
|
|
|
#endif
|
|
|
|
|
2015-04-23 16:40:59 -04:00
|
|
|
/**
|
2015-05-12 14:09:40 -04:00
|
|
|
* Class with main method
|
2015-04-23 16:40:59 -04:00
|
|
|
*/
|
2015-05-12 14:09:40 -04:00
|
|
|
class TyroApp : public wxApp
|
2015-03-30 14:50:10 -04:00
|
|
|
{
|
2015-05-12 14:09:40 -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-12 14:09:40 -04:00
|
|
|
|
2019-05-14 16:23:47 -04:00
|
|
|
TyroApp::SetSystemOptions();
|
2015-05-15 16:55:18 -04:00
|
|
|
this->SetAppName(APP_NAME);
|
|
|
|
this->SetVendorName(APP_VENDOR);
|
2015-05-12 14:09:40 -04:00
|
|
|
|
2015-05-15 16:55:18 -04:00
|
|
|
// Initialize globals
|
2019-05-17 16:19:42 -04:00
|
|
|
TyroApp::InitLexerMap();
|
2015-05-15 16:55:18 -04:00
|
|
|
Glob_config = wxConfigBase::Get();
|
|
|
|
Glob_menu_bar = new TyroMenu();
|
2019-05-16 15:21:32 -04:00
|
|
|
Glob_main_frame = new MainFrame(nullptr, APP_NAME, CalculateWindowSize());
|
2015-05-26 15:46:55 -04:00
|
|
|
Glob_pref_pane = new PrefPane();
|
2015-05-12 14:09:40 -04:00
|
|
|
|
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
|
2019-05-31 14:17:30 -04:00
|
|
|
if (this->param_count > 0)
|
2015-05-19 12:12:12 -04:00
|
|
|
{
|
|
|
|
Glob_main_frame->OpenFiles(files);
|
|
|
|
}
|
2015-05-12 14:09:40 -04:00
|
|
|
|
2015-05-15 16:55:18 -04:00
|
|
|
SetTopWindow(Glob_main_frame);
|
|
|
|
|
|
|
|
return true;
|
2015-05-12 14:09:40 -04:00
|
|
|
}
|
2015-04-16 17:03:27 -04:00
|
|
|
|
2015-05-12 14:09:40 -04:00
|
|
|
/**
|
|
|
|
* Exit handler
|
2019-03-20 16:49:25 -04:00
|
|
|
*
|
2015-05-12 14:09:40 -04:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
int OnExit()
|
|
|
|
{
|
2015-05-15 16:55:18 -04:00
|
|
|
// Deallocate config object
|
2019-03-20 16:49:25 -04:00
|
|
|
delete wxConfigBase::Set((wxConfigBase *) nullptr);
|
2015-06-03 17:06:55 -04:00
|
|
|
|
2015-05-15 16:55:18 -04:00
|
|
|
return close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up Command Line options
|
|
|
|
*
|
|
|
|
* @param wxCmdLineParser& parser
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
void OnInitCmdLine(wxCmdLineParser &parser)
|
|
|
|
{
|
|
|
|
parser.SetDesc(Glob_cmdLineDesc);
|
2015-05-12 14:09:40 -04:00
|
|
|
|
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;
|
2019-05-31 14:17:30 -04:00
|
|
|
this->param_count = parser.GetParamCount();
|
2015-05-15 16:55:18 -04:00
|
|
|
|
2019-05-31 14:17:30 -04:00
|
|
|
wxLogDebug("%i Parameters", this->param_count);
|
2015-05-15 16:55:18 -04:00
|
|
|
|
2019-05-31 14:17:30 -04:00
|
|
|
for (i = 0; i < this->param_count; i++)
|
2015-05-15 16:55:18 -04:00
|
|
|
{
|
2019-05-31 14:17:30 -04:00
|
|
|
this->files.Add(parser.GetParam(i));
|
2015-05-15 16:55:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-05-12 14:09:40 -04:00
|
|
|
}
|
2015-05-13 16:55:44 -04:00
|
|
|
private:
|
2019-05-31 14:17:30 -04:00
|
|
|
// app loading variables
|
|
|
|
wxArrayString files;
|
|
|
|
int param_count = 0;
|
|
|
|
|
2015-05-13 16:55:44 -04:00
|
|
|
/**
|
|
|
|
* Set up mapping for lexers
|
2015-05-15 16:55:18 -04:00
|
|
|
*/
|
2019-05-17 16:19:42 -04:00
|
|
|
void static InitLexerMap()
|
2015-05-13 16:55:44 -04:00
|
|
|
{
|
|
|
|
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["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;
|
2019-05-30 15:09:42 -04:00
|
|
|
Glob_lexer_map["scheme"] = wxSTC_LEX_LISP;
|
2015-05-13 16:55:44 -04:00
|
|
|
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-06-12 16:50:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Toolkit-specific settings
|
2019-05-16 15:21:32 -04:00
|
|
|
*/
|
2019-05-14 16:23:47 -04:00
|
|
|
void static SetSystemOptions()
|
2015-06-12 16:50:27 -04:00
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1);
|
|
|
|
#endif
|
|
|
|
|
2019-05-14 16:23:47 -04:00
|
|
|
#ifdef __WXMSW_
|
|
|
|
wxSystemOptions::SetOption("msw.remap", 0);_
|
2015-06-12 16:50:27 -04:00
|
|
|
wxSystemOptions::SetOption("msw.display.directdraw", 1);
|
|
|
|
#endif
|
|
|
|
}
|
2015-05-12 14:09:40 -04:00
|
|
|
};
|
2015-03-30 16:01:24 -04:00
|
|
|
|
2015-06-03 14:32:19 -04:00
|
|
|
// Set up the main method and event loop
|
2019-05-17 16:19:42 -04:00
|
|
|
wxIMPLEMENT_APP(TyroApp);
|