Reduce use of globals, tweak about dialog

This commit is contained in:
Timothy Warren 2019-06-13 12:14:48 -04:00
parent b927dad749
commit e43ccaf9a3
5 changed files with 37 additions and 26 deletions

View File

@ -138,7 +138,12 @@ private:
Glob_lexer_map["properties"] = wxSTC_LEX_PROPERTIES;
Glob_lexer_map["python"] = wxSTC_LEX_PYTHON;
Glob_lexer_map["ruby"] = wxSTC_LEX_RUBY;
#ifdef wxSTC_LEX_RUST
Glob_lexer_map["rust"] = wxSTC_LEX_RUST;
#endif
#ifndef wxSTC_LEX_RUST
Glob_lexer_map["rust"] = wxSTC_LEX_CPP;
#endif
Glob_lexer_map["scheme"] = wxSTC_LEX_LISP;
Glob_lexer_map["shell"] = wxSTC_LEX_BASH;
Glob_lexer_map["sql"] = wxSTC_LEX_SQL;
@ -155,8 +160,8 @@ private:
wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1);
#endif
#ifdef __WXMSW_
wxSystemOptions::SetOption("msw.remap", 0);_
#ifdef __WXMSW__
wxSystemOptions::SetOption("msw.remap", 0);
wxSystemOptions::SetOption("msw.display.directdraw", 1);
#endif
}

View File

@ -3,8 +3,6 @@
#include "src/widgets/FilePane.h"
#include "src/widgets/MainFrame.h"
extern MainFrame *Glob_main_frame;
auto DIR_SEP = wxFileName::GetPathSeparator();
enum
@ -253,7 +251,10 @@ void FilePane::OpenFileInEditor(wxTreeListEvent& event)
wxString path_arr [1] = { path };
auto files = wxArrayString(1, *path_arr);
Glob_main_frame->OpenFiles(files);
// Use the parent accessor to get the main frame
auto parent = (MainFrame *)this->GetParent();
parent->OpenFiles(files);
}
/**

View File

@ -12,7 +12,7 @@ static FilePane *filePane = nullptr;
extern PrefPane *Glob_pref_pane;
// Frame icon
// Frame icon (const static char *tyro_icon[])
#include "resources/xpm/tyro.xpm"
/**
@ -48,9 +48,6 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title, const wxSize &size)
MainFrame::~MainFrame()
{
wxLogDebug("Main Frame Destructor Called.");
//delete notebook;
//delete toolBar;
//delete filePane;
wxDELETE(this->findDlg);
wxDELETE(this->findData);
@ -311,6 +308,7 @@ void MainFrame::OnOpenFolder(wxCommandEvent &event)
*/
void MainFrame::OpenFiles(wxArrayString filelist)
{
// @TODO skip duplicated files
int listcount = filelist.GetCount();
if (listcount < 1) return;
@ -447,7 +445,7 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
info.SetName(APP_NAME);
info.SetVersion(APP_VERSION, APP_VERSION_MORE);
info.AddDeveloper("Tim Warren");
info.AddDeveloper("Timothy J. Warren");
info.AddArtist("Brian Smith: Main icon");
#ifndef __WXGTK__
@ -457,15 +455,15 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
wxString desc = "Tyro, a text editor for all development\n\n"
"System info: \n";
desc += wxString::Format("\tArchitecture: %s\n",
desc += wxString::Format("%s\n",
wxPlatformInfo::GetArchName(plat_info.GetArchitecture()));
desc += wxString::Format("\tOperating System:\n\t\t%s %i.%i\n",
desc += wxString::Format("%s %i.%i\n",
wxPlatformInfo::GetOperatingSystemIdName(plat_info.GetOperatingSystemId()),
plat_info.GetOSMajorVersion(),
plat_info.GetOSMinorVersion());
desc += wxString::Format("\nwxWidgets version: %s %i.%i.%i\n",
desc += wxString::Format("%s %i.%i.%i\n",
plat_info.GetPortIdName(),
wxMAJOR_VERSION,
wxMINOR_VERSION,
@ -477,10 +475,9 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
wxString desk = plat_info.GetDesktopEnvironment();
if (desk != "")
{
desc += wxString::Format("\tDesktop Environment:%s\n", desk);
desc += wxString::Format("%s\n", desk);
}
desc += "\tDistro: ";
desc += dist_info.Description;
if (dist_info.CodeName != "")
@ -489,6 +486,12 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
}
#endif
if ( ! info.HasIcon())
{
wxIcon appIcon = wxIcon(tyro_icon);
info.SetIcon(appIcon);
}
info.SetDescription(desc);
info.SetCopyright(" (C) 2015-2019");
@ -704,7 +707,13 @@ void MainFrame::OnLangSelect(wxCommandEvent &event)
{
auto *selectedMenu = (wxMenu *) event.GetEventObject();
auto *langMenu = Glob_menu_bar->GetMenu(myLANG_MENU);
if (langMenu == nullptr) wxLogDebug("Couldn't get lang menu");
if (langMenu == nullptr)
{
wxLogDebug("Couldn't get lang menu");
// Go to the more specific event handlers
event.Skip(true);
return;
}
if (selectedMenu == langMenu)
{

View File

@ -8,11 +8,6 @@
extern TyroMenu *Glob_menu_bar;
extern wxStatusBar *Glob_status_bar;
static MainFrame *parentFrame = nullptr;
static vector<EditPane *> editors;
static unsigned long untitled_document_count = 0;
/**
* Constructor
*
@ -30,8 +25,6 @@ TabContainer::TabContainer(
long style
) : wxAuiNotebook(parent, id, pos, size, style)
{
parentFrame = (MainFrame *) parent;
this->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &TabContainer::OnClose, this, wxID_ANY);
this->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY);
this->Bind(wxEVT_AUINOTEBOOK_TAB_RIGHT_DOWN, &TabContainer::OnTabContextMenu, this, wxID_ANY);
@ -63,11 +56,11 @@ EditPane* TabContainer::NewEditor()
*/
void TabContainer::AddTab()
{
untitled_document_count++;
this->untitled_document_count++;
wxString caption;
caption.Printf("Untitled %lu", untitled_document_count);
caption.Printf("Untitled %lu", this->untitled_document_count);
this->AddPage(this->NewEditor(), caption, true);
}
@ -176,6 +169,7 @@ void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{
if (this->GetPageCount() == 0)
{
auto parentFrame = (MainFrame *)this->GetParent();
parentFrame->EnableEditControls(false);
Glob_status_bar->SetStatusText("", STATUS_CURSOR_LOCATION);
Glob_status_bar->SetStatusText("", STATUS_CURRENT_LANGUAGE);
@ -206,6 +200,7 @@ void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event))
{
this->DeleteAllPages();
auto parentFrame = (MainFrame *)this->GetParent();
parentFrame->EnableEditControls(false);
}

View File

@ -28,6 +28,7 @@ public:
void OnCloseAll(wxCommandEvent &event);
void OnCloseAllButThis(wxCommandEvent &event);
private:
unsigned long untitled_document_count = 0;
EditPane *NewEditor();
void OnTabSwitch(wxAuiNotebookEvent &event);
void OnClose(wxAuiNotebookEvent &event);