Start of command-line arguments

This commit is contained in:
Tim Warren 2015-05-15 16:55:18 -04:00
parent 9904e20f61
commit 1b42eae8d8
6 changed files with 118 additions and 38 deletions

View File

@ -27,6 +27,8 @@ public:
*/ */
bool OnInit() bool OnInit()
{ {
if ( ! wxApp::OnInit()) return false;
this->SetAppName(APP_NAME); this->SetAppName(APP_NAME);
this->SetVendorName(APP_VENDOR); this->SetVendorName(APP_VENDOR);
@ -36,13 +38,13 @@ public:
Glob_menu_bar = new TyroMenu(); Glob_menu_bar = new TyroMenu();
Glob_main_frame = new MainFrame(0L, APP_NAME); Glob_main_frame = new MainFrame(0L, APP_NAME);
SetTopWindow(Glob_main_frame);
// Setup Main Window // Setup Main Window
Glob_main_frame->Layout(); Glob_main_frame->Layout();
Glob_main_frame->CenterOnScreen(); Glob_main_frame->CenterOnScreen();
Glob_main_frame->Show(true); Glob_main_frame->Show(true);
SetTopWindow(Glob_main_frame);
return true; return true;
} }
@ -58,6 +60,49 @@ public:
return close(true); 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: private:
/** /**
* Set up mapping for lexers * Set up mapping for lexers

View File

@ -8,9 +8,22 @@
// Application config // Application config
const wxString APP_NAME = "Tyro"; const wxString APP_NAME = "Tyro";
const wxString APP_VENDOR = "Aviat Ion"; 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"; 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 // Some boilerplate text
const wxString TYRO_SAVE_ERROR = "Failed to save the file. Maybe you lack the permissions."; const wxString TYRO_SAVE_ERROR = "Failed to save the file. Maybe you lack the permissions.";
const wxString TYRO_SAVE_ERROR_CAPTION = "Saving Failed"; const wxString TYRO_SAVE_ERROR_CAPTION = "Saving Failed";

View File

@ -15,6 +15,9 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
{ {
findReplaceData = new wxFindReplaceData(wxFR_DOWN); findReplaceData = new wxFindReplaceData(wxFR_DOWN);
// Create the tab container
notebook = new TabContainer(this);
// Set the frame icon // Set the frame icon
#include "../../resources/xpm/tyro.xpm" #include "../../resources/xpm/tyro.xpm"
wxIcon app_icon(tyro_icon); wxIcon app_icon(tyro_icon);
@ -35,7 +38,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
MainFrame::~MainFrame() MainFrame::~MainFrame()
{ {
wxLogDebug("Main Frame Destructor Called."); wxLogDebug("Main Frame Destructor Called.");
delete notebook; //delete notebook;
delete toolBar; delete toolBar;
manager->UnInit(); manager->UnInit();
} }
@ -47,9 +50,6 @@ MainFrame::~MainFrame()
*/ */
void MainFrame::DoLayout() void MainFrame::DoLayout()
{ {
// Create the tab container
notebook = new TabContainer(this);
this->manager = new wxAuiManager(this); this->manager = new wxAuiManager(this);
this->SetupToolbar(); 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 * @return void
*/ */
void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
{ {
wxArrayString filelist; wxArrayString filelist;
int listcount;
wxFileDialog dlg (this, "Open file(s)", wxEmptyString, wxEmptyString, wxFileDialog dlg (this, "Open file(s)", wxEmptyString, wxEmptyString,
TYRO_FILE_OPEN_WILDCARDS, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | wxFD_MULTIPLE); 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; if (dlg.ShowModal() != wxID_OK) return;
dlg.GetPaths(filelist); 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 // Open a new tab for each file
notebook->Hide(); //notebook->Freeze();
for (int i = 0; i < listcount; i++) for (int i = 0; i < listcount; i++)
{ {
notebook->AddTab(filelist[i]); notebook->AddTab(filelist[i]);
} }
notebook->Show(); //notebook->Thaw();
this->EnableEditControls(true); this->EnableEditControls(true);
} }
@ -225,7 +238,7 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
{ {
int current_tab = notebook->GetSelection(); int current_tab = notebook->GetSelection();
notebook->Hide(); notebook->Freeze();
notebook->DeletePage(current_tab); notebook->DeletePage(current_tab);
if (notebook->GetPageCount() == 0) if (notebook->GetPageCount() == 0)
@ -233,7 +246,7 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
this->EnableEditControls(false); this->EnableEditControls(false);
} }
notebook->Show(); notebook->Thaw();
this->manager->Update(); this->manager->Update();
} }
@ -244,10 +257,10 @@ void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
*/ */
void MainFrame::OnCloseAll(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnCloseAll(wxCommandEvent &WXUNUSED(event))
{ {
notebook->Hide(); notebook->Freeze();
notebook->DeleteAllPages(); notebook->DeleteAllPages();
this->EnableEditControls(false); this->EnableEditControls(false);
notebook->Show(); notebook->Thaw();
} }
/** /**

View File

@ -13,6 +13,7 @@ class MainFrame: public wxFrame
MainFrame(wxFrame *frame, const wxString &title); MainFrame(wxFrame *frame, const wxString &title);
~MainFrame(); ~MainFrame();
void EnableEditControls(bool enable=true); void EnableEditControls(bool enable=true);
void OpenFiles(wxArrayString filelist);
private: private:
wxAuiManager *manager; wxAuiManager *manager;
wxAuiToolBar *toolBar; wxAuiToolBar *toolBar;

View File

@ -4,7 +4,6 @@
#include "widget.h" #include "widget.h"
extern MainFrame *Glob_main_frame;
extern TyroMenu *Glob_menu_bar; extern TyroMenu *Glob_menu_bar;
static unsigned long untitled_document_count = 0; static unsigned long untitled_document_count = 0;
@ -25,6 +24,8 @@ TabContainer::TabContainer(
long style long style
) : wxAuiNotebook(parent, id, pos, size, 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_CLOSE, &TabContainer::OnClose, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY); Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_TAB_RIGHT_DOWN, &TabContainer::OnTabContextMenu, 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); caption.Printf("Untitled %lu", untitled_document_count);
EditPane *editor = new EditPane(this, wxID_ANY); EditPane *editor = new EditPane(this);
this->AddPage(editor, caption, true); this->AddPage(editor, caption, true);
} }
@ -67,8 +68,14 @@ void TabContainer::AddTab(wxString filePath)
{ {
wxFileName fileName(filePath); wxFileName fileName(filePath);
if ( ! (fileName.IsOk() && fileName.FileExists()))
{
wxLogDebug("Invalid file name.");
return;
}
wxString caption= fileName.GetFullName(); wxString caption= fileName.GetFullName();
EditPane *editor = new EditPane(this, wxID_ANY); EditPane *editor = new EditPane(this);
if (editor->Load(filePath)) if (editor->Load(filePath))
{ {
@ -155,7 +162,7 @@ void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{ {
if (this->GetPageCount() == 0) 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)) void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event))
{ {
this->DeleteAllPages(); this->DeleteAllPages();
Glob_main_frame->EnableEditControls(false); this->parent->EnableEditControls(false);
} }
/** /**

View File

@ -29,6 +29,7 @@ public:
EditPane *GetEditor(size_t page_idx); EditPane *GetEditor(size_t page_idx);
void OnCloseAll(wxCommandEvent &event); void OnCloseAll(wxCommandEvent &event);
private: private:
MainFrame *parent;
void OnTabSwitch(wxAuiNotebookEvent &event); void OnTabSwitch(wxAuiNotebookEvent &event);
void OnClose(wxAuiNotebookEvent &event); void OnClose(wxAuiNotebookEvent &event);
void OnClosed(wxAuiNotebookEvent &event); void OnClosed(wxAuiNotebookEvent &event);