From 72be1d808f8f1e16258ac926b08c8115d5244624 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 15 May 2019 16:34:01 -0400 Subject: [PATCH] Another ugly progress commit --- src/widgets/FilePane.cpp | 77 ++++++++++++++++++++++++--------------- src/widgets/FilePane.h | 1 + src/widgets/MainFrame.cpp | 13 +++---- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/widgets/FilePane.cpp b/src/widgets/FilePane.cpp index 1a68643..2c74758 100644 --- a/src/widgets/FilePane.cpp +++ b/src/widgets/FilePane.cpp @@ -68,8 +68,6 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) auto *files = new wxArrayString(); wxDir::GetAllFiles(path, files); - // std::unordered_set dirs; - for (const wxString &file: *files) { wxFileName fileName(file); @@ -79,6 +77,12 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) fileName.RemoveDir(0); } + // If the file is at the root, add it to the tree + if (fileName.GetDirCount() == 1) + { + this->AddDirFiles(path, root); + } + auto dir = std::string(fileName.GetPath()); if (dir.empty()) @@ -86,11 +90,7 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) continue; } - this->dir_set.insert(dir); - } - - for (auto& dir: this->dir_set) - { + // Append the folder to the tree wxString wdir = wxString(dir); wxLogDebug("Creating Dir Tree: %s", wdir); this->DirToTree(wdir, root, wxString(".")); @@ -104,33 +104,37 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) */ void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent) { - auto fullPath = parent.Clone(); + auto fullPath = parent.Clone(); fullPath += "/"; fullPath += path; + this->dir_set.insert("."); + + wxLogDebug("Rendering Dir Tree for %s", fullPath); + auto *files = new wxArrayString(); wxDir::GetAllFiles(path, files); for (const wxString &item: *files) { - wxFileName filename(item); + wxFileName fileName(item); // Remove the directory component closest to the root - if (filename.GetDirCount() > 1) + if (fileName.GetDirCount() > 1 || fileName.DirExists(".")) { - filename.RemoveDir(0); + fileName.RemoveDir(0); } - const wxArrayString dirs = filename.GetDirs(); + const wxArrayString dirs = fileName.GetDirs(); // See if the path already exists on the tree - /* for (const wxString &dir: dirs) + for (const wxString &dir: dirs) { - this->dir_it = find(this->examined.begin(), this->examined.end(), dir); - - if (dir_it != this->examined.end()) + // Stop early if folder exists + auto it = this->dir_set.find(std::string(dir)); + if (it != this->dir_set.end()) { - break; + continue; } auto fileData = new wxStringClientData(); @@ -138,23 +142,38 @@ void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxStr auto dir_node = this->AppendItem(root, dir, Icon_FolderClosed, Icon_FolderOpened, fileData); - this->examined.push_back(dir); + this->dir_set.insert(std::string(dir)); - this->CreateTree(dir, dir_node); - break; - }*/ + this->DirToTree(dir, dir_node, fullPath); - // If the file is at the root, add it to the tree - if (filename.GetDirCount() == 1) + // break; + } + } +} + +void FilePane::AddDirFiles(const wxString &path, wxTreeListItem &root) +{ + auto *files = new wxArrayString(); + wxDir::GetAllFiles(path, files); + + wxLogDebug("Redering files in : %s", path); + + for (const wxString &item: *files) + { + wxFileName fileName(item); + fileName.MakeAbsolute(); + + auto it = this->file_set.find(std::string(fileName.GetFullPath())); + if (it != this->file_set.end()) { - filename.MakeAbsolute(); - - auto fileData = new wxStringClientData(); - fileData->SetData(filename.GetFullPath()); - - this->AppendItem(root, filename.GetFullName(), Icon_File, Icon_File, fileData); continue; } + + auto fileData = new wxStringClientData(); + fileData->SetData(fileName.GetFullPath()); + + this->AppendItem(root, fileName.GetFullName(), Icon_File, Icon_File, fileData); + this->file_set.insert(std::string(fileName.GetFullPath())); } } diff --git a/src/widgets/FilePane.h b/src/widgets/FilePane.h index 0725cc9..311e8fd 100644 --- a/src/widgets/FilePane.h +++ b/src/widgets/FilePane.h @@ -25,5 +25,6 @@ private: void InitImageList(); void CreateTree(const wxString &path, wxTreeListItem &root); void DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent); + void AddDirFiles(const wxString &path, wxTreeListItem &root); }; diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index e79f52a..48a84c3 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -393,11 +393,10 @@ void MainFrame::OnSaveAs(wxCommandEvent &WXUNUSED(event)) if(editor->SaveFile(filePath)) { wxFileName fileName(filePath); - const wxString fullPath = filePath; - const wxString caption= fileName.GetFullName(); + const wxString caption = fileName.GetFullName(); // Update the name of the tab - notebook->SetPageToolTip(notebook->GetSelection(), fullPath); + notebook->SetPageToolTip(notebook->GetSelection(), filePath); notebook->SetPageText(notebook->GetSelection(), caption); // Update the editor highlighting @@ -541,8 +540,8 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) EditPane *editor = notebook->GetCurrentEditor(); // Parse flags - int stc_flags = 0; - int fr_flags = event.GetFlags(); + uint stc_flags = 0; + uint fr_flags = event.GetFlags(); if (fr_flags & wxFR_WHOLEWORD) stc_flags |= wxSTC_FIND_WHOLEWORD; if (fr_flags & wxFR_MATCHCASE) stc_flags |= wxSTC_FIND_MATCHCASE; @@ -686,8 +685,8 @@ void MainFrame::EnableEditControls(bool enable) */ void MainFrame::OnLangSelect(wxCommandEvent &event) { - wxMenu *selectedMenu = (wxMenu *) event.GetEventObject(); - wxMenu *langMenu = Glob_menu_bar->GetMenu(myLANG_MENU); + auto *selectedMenu = (wxMenu *) event.GetEventObject(); + auto *langMenu = Glob_menu_bar->GetMenu(myLANG_MENU); if (langMenu == NULL) wxLogDebug("Couldn't get lang menu"); if (selectedMenu == langMenu)