Start of command-line arguments
This commit is contained in:
parent
9904e20f61
commit
1b42eae8d8
@ -27,6 +27,8 @@ public:
|
||||
*/
|
||||
bool OnInit()
|
||||
{
|
||||
if ( ! wxApp::OnInit()) return false;
|
||||
|
||||
this->SetAppName(APP_NAME);
|
||||
this->SetVendorName(APP_VENDOR);
|
||||
|
||||
@ -36,13 +38,13 @@ public:
|
||||
Glob_menu_bar = new TyroMenu();
|
||||
Glob_main_frame = new MainFrame(0L, APP_NAME);
|
||||
|
||||
SetTopWindow(Glob_main_frame);
|
||||
|
||||
// Setup Main Window
|
||||
Glob_main_frame->Layout();
|
||||
Glob_main_frame->CenterOnScreen();
|
||||
Glob_main_frame->Show(true);
|
||||
|
||||
SetTopWindow(Glob_main_frame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,6 +60,49 @@ public:
|
||||
|
||||
return close(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Command Line options
|
||||
*
|
||||
* @param wxCmdLineParser& parser
|
||||
* @return void
|
||||
*/
|
||||
void OnInitCmdLine(wxCmdLineParser &parser)
|
||||
{
|
||||
parser.SetDesc(Glob_cmdLineDesc);
|
||||
|
||||
// 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
|
||||
wxArrayString files;
|
||||
int i;
|
||||
int param_count = parser.GetParamCount();
|
||||
|
||||
wxLogDebug("%i Parameters", param_count);
|
||||
|
||||
for (i = 0; i < param_count; i++)
|
||||
{
|
||||
files.Add(parser.GetParam(i));
|
||||
}
|
||||
|
||||
// Open files in editor, if any are passed
|
||||
if (param_count > 0)
|
||||
{
|
||||
Glob_main_frame->OpenFiles(files);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* Set up mapping for lexers
|
||||
|
@ -8,9 +8,22 @@
|
||||
// Application config
|
||||
const wxString APP_NAME = "Tyro";
|
||||
const wxString APP_VENDOR = "Aviat Ion";
|
||||
const wxString APP_VERSION = "0.1.0";
|
||||
const wxString APP_VERSION = "0.5.0";
|
||||
const wxString APP_VERSION_MORE = "Pre-release";
|
||||
|
||||
// Command-line arguments
|
||||
const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
|
||||
{
|
||||
wxCMD_LINE_PARAM,
|
||||
NULL,
|
||||
NULL,
|
||||
"input file(s)",
|
||||
wxCMD_LINE_VAL_STRING,
|
||||
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE
|
||||
},
|
||||
{wxCMD_LINE_NONE}
|
||||
};
|
||||
|
||||
// Some boilerplate text
|
||||
const wxString TYRO_SAVE_ERROR = "Failed to save the file. Maybe you lack the permissions.";
|
||||
const wxString TYRO_SAVE_ERROR_CAPTION = "Saving Failed";
|
||||
|
@ -15,6 +15,9 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
|
||||
{
|
||||
findReplaceData = new wxFindReplaceData(wxFR_DOWN);
|
||||
|
||||
// Create the tab container
|
||||
notebook = new TabContainer(this);
|
||||
|
||||
// Set the frame icon
|
||||
#include "../../resources/xpm/tyro.xpm"
|
||||
wxIcon app_icon(tyro_icon);
|
||||
@ -35,7 +38,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
|
||||
MainFrame::~MainFrame()
|
||||
{
|
||||
wxLogDebug("Main Frame Destructor Called.");
|
||||
delete notebook;
|
||||
//delete notebook;
|
||||
delete toolBar;
|
||||
manager->UnInit();
|
||||
}
|
||||
@ -47,9 +50,6 @@ MainFrame::~MainFrame()
|
||||
*/
|
||||
void MainFrame::DoLayout()
|
||||
{
|
||||
// Create the tab container
|
||||
notebook = new TabContainer(this);
|
||||
|
||||
this->manager = new wxAuiManager(this);
|
||||
this->SetupToolbar();
|
||||
|
||||
@ -188,14 +188,13 @@ void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event))
|
||||
}
|
||||
|
||||
/**
|
||||
* Open existing document(s)
|
||||
* Display a file open dialog, and open the selected files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
|
||||
{
|
||||
wxArrayString filelist;
|
||||
int listcount;
|
||||
|
||||
wxFileDialog dlg (this, "Open file(s)", wxEmptyString, wxEmptyString,
|
||||
TYRO_FILE_OPEN_WILDCARDS, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | wxFD_MULTIPLE);
|
||||
@ -203,15 +202,29 @@ void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
|
||||
if (dlg.ShowModal() != wxID_OK) return;
|
||||
|
||||
dlg.GetPaths(filelist);
|
||||
listcount = filelist.GetCount();
|
||||
|
||||
this->OpenFiles(filelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open tabs containing the files passed
|
||||
*
|
||||
* @param wxArrayString& filelist
|
||||
* @return void
|
||||
*/
|
||||
void MainFrame::OpenFiles(wxArrayString filelist)
|
||||
{
|
||||
int listcount = filelist.GetCount();
|
||||
|
||||
if (listcount < 1) return;
|
||||
|
||||
// Open a new tab for each file
|
||||
notebook->Hide();
|
||||
//notebook->Freeze();
|
||||
for (int i = 0; i < listcount; i++)
|
||||
{
|
||||
notebook->AddTab(filelist[i]);
|
||||
}
|
||||
notebook->Show();
|
||||
//notebook->Thaw();
|
||||
|
||||
this->EnableEditControls(true);
|
||||
}
|
||||
@ -225,7 +238,7 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
|
||||
{
|
||||
int current_tab = notebook->GetSelection();
|
||||
|
||||
notebook->Hide();
|
||||
notebook->Freeze();
|
||||
notebook->DeletePage(current_tab);
|
||||
|
||||
if (notebook->GetPageCount() == 0)
|
||||
@ -233,7 +246,7 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
|
||||
this->EnableEditControls(false);
|
||||
}
|
||||
|
||||
notebook->Show();
|
||||
notebook->Thaw();
|
||||
this->manager->Update();
|
||||
}
|
||||
|
||||
@ -244,10 +257,10 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
|
||||
*/
|
||||
void MainFrame::OnCloseAll(wxCommandEvent &WXUNUSED(event))
|
||||
{
|
||||
notebook->Hide();
|
||||
notebook->Freeze();
|
||||
notebook->DeleteAllPages();
|
||||
this->EnableEditControls(false);
|
||||
notebook->Show();
|
||||
notebook->Thaw();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ class MainFrame: public wxFrame
|
||||
MainFrame(wxFrame *frame, const wxString &title);
|
||||
~MainFrame();
|
||||
void EnableEditControls(bool enable=true);
|
||||
void OpenFiles(wxArrayString filelist);
|
||||
private:
|
||||
wxAuiManager *manager;
|
||||
wxAuiToolBar *toolBar;
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "widget.h"
|
||||
|
||||
extern MainFrame *Glob_main_frame;
|
||||
extern TyroMenu *Glob_menu_bar;
|
||||
static unsigned long untitled_document_count = 0;
|
||||
|
||||
@ -25,6 +24,8 @@ TabContainer::TabContainer(
|
||||
long style
|
||||
) : wxAuiNotebook(parent, id, pos, size, style)
|
||||
{
|
||||
this->parent = (MainFrame *) parent;
|
||||
|
||||
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &TabContainer::OnClose, this, wxID_ANY);
|
||||
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY);
|
||||
Bind(wxEVT_AUINOTEBOOK_TAB_RIGHT_DOWN, &TabContainer::OnTabContextMenu, this, wxID_ANY);
|
||||
@ -52,7 +53,7 @@ void TabContainer::AddTab()
|
||||
|
||||
caption.Printf("Untitled %lu", untitled_document_count);
|
||||
|
||||
EditPane *editor = new EditPane(this, wxID_ANY);
|
||||
EditPane *editor = new EditPane(this);
|
||||
|
||||
this->AddPage(editor, caption, true);
|
||||
}
|
||||
@ -67,8 +68,14 @@ void TabContainer::AddTab(wxString filePath)
|
||||
{
|
||||
wxFileName fileName(filePath);
|
||||
|
||||
if ( ! (fileName.IsOk() && fileName.FileExists()))
|
||||
{
|
||||
wxLogDebug("Invalid file name.");
|
||||
return;
|
||||
}
|
||||
|
||||
wxString caption= fileName.GetFullName();
|
||||
EditPane *editor = new EditPane(this, wxID_ANY);
|
||||
EditPane *editor = new EditPane(this);
|
||||
|
||||
if (editor->Load(filePath))
|
||||
{
|
||||
@ -155,7 +162,7 @@ void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
|
||||
{
|
||||
if (this->GetPageCount() == 0)
|
||||
{
|
||||
Glob_main_frame->EnableEditControls(false);
|
||||
this->parent->EnableEditControls(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +189,7 @@ void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
|
||||
void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event))
|
||||
{
|
||||
this->DeleteAllPages();
|
||||
Glob_main_frame->EnableEditControls(false);
|
||||
this->parent->EnableEditControls(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
EditPane *GetEditor(size_t page_idx);
|
||||
void OnCloseAll(wxCommandEvent &event);
|
||||
private:
|
||||
MainFrame *parent;
|
||||
void OnTabSwitch(wxAuiNotebookEvent &event);
|
||||
void OnClose(wxAuiNotebookEvent &event);
|
||||
void OnClosed(wxAuiNotebookEvent &event);
|
||||
|
Loading…
Reference in New Issue
Block a user