From 45cc064ec8e0cda1b83ea44e6fb9ff6003a28d14 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 20 Mar 2019 16:49:25 -0400 Subject: [PATCH] Ugly progress commit --- config/languages.json | 2 +- src/TyroApp.cpp | 6 +-- src/widgets/EditPane.cpp | 24 ++++++------ src/widgets/FilePane.cpp | 82 ++++++++++++++++++++++++++++----------- src/widgets/FilePane.h | 7 ++-- src/widgets/MainFrame.cpp | 2 +- src/widgets/TyroMenu.cpp | 2 +- 7 files changed, 82 insertions(+), 43 deletions(-) diff --git a/config/languages.json b/config/languages.json index 510c6a1..baaee1c 100644 --- a/config/languages.json +++ b/config/languages.json @@ -141,7 +141,7 @@ }, "lisp": { "name": "Lisp", - "file_pattern": "*.lsp;*.lisp", + "file_pattern": "*.lsp;*.lisp;*.scm", "keywords": [ "not defun + - * / = < > <= >= princ eval apply funcall quote identity function complement backquote lambda set setq setf defun defmacro gensym make symbol intern symbol name symbol value symbol plist get getf putprop remprop hash make array aref car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr cons list append reverse last nth nthcdr member assoc subst sublis nsubst nsublis remove length list length mapc mapcar mapl maplist mapcan mapcon rplaca rplacd nconc delete atom symbolp numberp boundp null listp consp minusp zerop plusp evenp oddp eq eql equal cond case and or let l if prog prog1 prog2 progn go return do dolist dotimes catch throw error cerror break continue errset baktrace evalhook truncate float rem min max abs sin cos tan expt exp sqrt random logand logior logxor lognot bignums logeqv lognand lognor logorc2 logtest logbitp logcount integer length nil" ], diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 866940e..08b8618 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -51,7 +51,7 @@ public: this->InitLexerMap(); Glob_config = wxConfigBase::Get(); Glob_menu_bar = new TyroMenu(); - Glob_main_frame = new MainFrame(0L, APP_NAME, this->CalculateWindowSize()); + Glob_main_frame = new MainFrame(nullptr, APP_NAME, this->CalculateWindowSize()); #ifndef TRAVIS Glob_pref_pane = new PrefPane(); #endif @@ -74,13 +74,13 @@ public: /** * Exit handler - * + * * @return int */ int OnExit() { // Deallocate config object - delete wxConfigBase::Set((wxConfigBase *) NULL); + delete wxConfigBase::Set((wxConfigBase *) nullptr); return close(true); } diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index 291d4bd..2a7175d 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -97,7 +97,7 @@ void EditPane::ApplyTheme(string lang, string theme) this->SetLexer(wxSTC_LEX_NULL); } - if (theme != "") + if ( ! theme.empty()) { theme_config->SetTheme(theme); } @@ -115,7 +115,7 @@ void EditPane::ApplyTheme(string lang, string theme) } else { - if (lang != "") + if ( ! lang.empty()) { string typeMap[] = {"null", "int", "unsigned int", "double", "string", "boolean", "array", "object"}; stringstream output; @@ -272,7 +272,7 @@ void EditPane::BindEvents() } }, wxID_ANY); - this->Bind(wxEVT_STC_CHARADDED, &EditPane::OnCharAdded, this, wxID_ANY); + // this->Bind(wxEVT_STC_CHARADDED, &EditPane::OnCharAdded, this, wxID_ANY); } /** @@ -316,14 +316,14 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map) wxFONTFLAG_ANTIALIASED ); - static const wxColor default_background = theme_config->GetThemeColor("background", "default"); - static const wxColor default_foreground = theme_config->GetThemeColor("foreground", "default"); - wxColor line_number_background = ( ! theme_config->GetThemeValue("line_numbers", "background").isNull()) - ? (theme_config->GetThemeColor("line_numbers", "background")) + static const wxColor default_background = this->theme_config->GetThemeColor("background", "default"); + static const wxColor default_foreground = this->theme_config->GetThemeColor("foreground", "default"); + wxColor line_number_background = ( ! this->theme_config->GetThemeValue("line_numbers", "background").isNull()) + ? (this->theme_config->GetThemeColor("line_numbers", "background")) : default_background; - wxColor line_number_foreground = ( ! theme_config->GetThemeValue("line_numbers", "foreground").isNull()) - ? (theme_config->GetThemeColor("line_numbers", "foreground")) + wxColor line_number_foreground = ( ! this->theme_config->GetThemeValue("line_numbers", "foreground").isNull()) + ? (this->theme_config->GetThemeColor("line_numbers", "foreground")) : default_foreground; // Set default colors/ fonts @@ -452,7 +452,7 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map) */ string EditPane::GetCurrentLang() { - return lang_config->GetCurrentLangName(); + return this->lang_config->GetCurrentLangName(); } /** @@ -464,8 +464,8 @@ string EditPane::GetCurrentLang() void EditPane::SetCurrentLang(string name) { // Update the current lang in the config - string langKey = lang_config->GetLangByName(name); - lang_config->SetLang(langKey); + string langKey = this->lang_config->GetLangByName(name); + this->lang_config->SetLang(langKey); // Re-highlight the page with the new langauge this->ApplyTheme(langKey); diff --git a/src/widgets/FilePane.cpp b/src/widgets/FilePane.cpp index 5f1727a..ba8ee07 100644 --- a/src/widgets/FilePane.cpp +++ b/src/widgets/FilePane.cpp @@ -20,8 +20,8 @@ FilePane::FilePane( this->SetImageList(this->img_list); wxString defaultPath("."); - wxFileName fname(defaultPath); - fname.MakeAbsolute(defaultPath); + wxFileName filename(defaultPath); + filename.MakeAbsolute(defaultPath); wxTreeListItem root = this->GetRootItem(); this->CreateTree(defaultPath, root); @@ -41,6 +41,7 @@ FilePane::~FilePane() void FilePane::BindEvents() { this->Bind(wxEVT_TREELIST_ITEM_EXPANDING, &FilePane::OpenFolder, this, wxID_ANY); + this->Bind(wxEVT_TREELIST_ITEM_ACTIVATED, &FilePane::OpenFileInEditor, this, wxID_ANY); } void FilePane::OpenFolder(wxTreeListEvent& event) @@ -59,39 +60,68 @@ void FilePane::OpenFolder(wxTreeListEvent& event) * @param wxString &path * @param wxTreeListItem &root */ -void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) +void FilePane::CreateTree(const wxString &path, wxTreeListItem &root, int level) { - wxArrayString *files = new wxArrayString(); + // So yeah, this doesn't really work right. + // It seems I need to create a tree from the list of file paths, + // after which this should be much simpler. + // @TODO Fix + + auto *files = new wxArrayString(); wxDir::GetAllFiles(path, files); vector examined; vector::iterator it; - for (wxString filename : *files) + for (const wxString &item : *files) { - wxFileName fname(filename); + wxFileName filename(item); // For loose files, just add directly to the tree - if (fname.GetDirCount() == 1) + if (filename.GetDirCount() == 1) { - this->AppendItem(root, fname.GetFullName(), Icon_File, Icon_File); + auto fullFileName = filename.GetFullPath(); + + auto fileData = new wxStringClientData(); + fileData->SetData(fullFileName); + + examined.push_back(fullFileName); + + this->AppendItem(root, filename.GetFullName(), Icon_File, Icon_File, fileData); + continue; } - else + + // Remove the directory component closest to the root + filename.RemoveDir(0); + + wxArrayString folders = filename.GetDirs(); + + wxLogDebug(item); + + wxTreeListItem newRootNode = root; + + for (const wxString &curr_folder: folders) { - fname.RemoveDir(0); - wxArrayString folders = fname.GetDirs(); - wxString curr_folder = folders[0]; - + // Check if directory has already been created it = find(examined.begin(), examined.end(), curr_folder); - - // If the directory already exists, continue; + if (it != examined.end()) continue; - - wxTreeListItem current = this->AppendItem(root, curr_folder, Icon_FolderClosed, Icon_FolderOpened); + + // Create the directory node if it doesn't exist + auto fileData = new wxStringClientData(); + fileData->SetData(curr_folder); + + wxTreeListItem current = this->AppendItem( + newRootNode, + curr_folder, + Icon_FolderClosed, + Icon_FolderOpened, + fileData); examined.push_back(curr_folder); - - // Recurse to create sub dirs - this->CreateTree(fname.GetPath(), current); + + newRootNode = current; + + this->CreateTree(curr_folder, root); } } } @@ -101,6 +131,14 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) }*/ +void FilePane::OpenFileInEditor(wxTreeListEvent& event) +{ + wxTreeListItem item = event.GetItem(); + auto path = this->GetItemText(item, 0); + + wxLogMessage(path); +} + /** * Create the image list object for the file pane widget */ @@ -122,10 +160,10 @@ void FilePane::InitImageList() wxART_FOLDER_OPEN }; - for (unsigned n = 0; n < WXSIZEOF(icons); n++) + for (auto icon : icons) { this->img_list->Add( - wxArtProvider::GetIcon(icons[n], wxART_LIST, iconSize) + wxArtProvider::GetIcon(icon, wxART_LIST, iconSize) ); } } \ No newline at end of file diff --git a/src/widgets/FilePane.h b/src/widgets/FilePane.h index e82a169..3b4ebca 100644 --- a/src/widgets/FilePane.h +++ b/src/widgets/FilePane.h @@ -4,7 +4,7 @@ class FilePane : public wxTreeListCtrl { public: - FilePane( + explicit FilePane( wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, @@ -12,13 +12,14 @@ public: long style=wxTL_DEFAULT_STYLE, const wxString &name=wxTreeListCtrlNameStr ); - ~FilePane(); + ~FilePane() override; private: wxString curr_path = ""; wxImageList *img_list = nullptr; void BindEvents(); void OpenFolder(wxTreeListEvent& event); + void OpenFileInEditor(wxTreeListEvent& event); void InitImageList(); - void CreateTree(const wxString &path, wxTreeListItem &root); + void CreateTree(const wxString &path, wxTreeListItem &root, int level = 0); }; diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 548dd0a..e79f52a 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -475,7 +475,7 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) info.SetDescription(desc); - info.SetCopyright(" (C) 2015"); + info.SetCopyright(" (C) 2015-2019"); wxAboutBox(info); } diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index 4d83062..6e2b19e 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -88,7 +88,7 @@ void TyroMenu::SetupLangMenu() { StringMap languages = lang_config->GetLangList(); - for (auto lang: languages) + for (const auto lang: languages) { langMenu->Append(wxID_ANY, lang.second, "Highlight file as " + lang.second, wxITEM_RADIO); }