Slow progress on File pane

This commit is contained in:
Timothy Warren 2019-05-23 16:22:49 -04:00
parent f2dc0a9eae
commit 9a2f12f06b
4 changed files with 122 additions and 83 deletions

View File

@ -1,3 +1,4 @@
#include <libgen.h>
#include <unordered_set>
#include "src/widgets/FilePane.h"
@ -55,7 +56,7 @@ void FilePane::OpenFolder(wxTreeListEvent& event)
wxTreeListItem item = event.GetItem();
const wxString path = this->GetItemText(item, 0);
wxLogDebug(path);
wxLogDebug("Opening sidebar dir: %s", path);
}
/**
@ -66,19 +67,21 @@ void FilePane::OpenFolder(wxTreeListEvent& event)
void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
{
auto *files = new wxArrayString();
wxDir::GetAllFiles(path, files);
wxFileName rootPath(path);
rootPath.MakeAbsolute();
this->base_path = rootPath.GetPath();
wxLogDebug("Base Path for Sidebar: %s", this->base_path);
wxDir::GetAllFiles(this->base_path, files);
for (const wxString &file: *files)
{
wxFileName fileName(file);
if (fileName.DirExists("."))
{
fileName.RemoveDir(0);
}
// If the file is at the root, add it to the tree
if (fileName.GetDirCount() == 1)
if (fileName.GetDirCount() == rootPath.GetDirCount())
{
this->AddDirFiles(path, root);
}
@ -92,8 +95,8 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
// Append the folder to the tree
wxString wdir = wxString(dir);
wxLogDebug("Creating Dir Tree: %s", wdir);
this->DirToTree(wdir, root, wxString("."));
// wxLogDebug("Creating Dir Tree: %s", wdir);
this->AddDirToTree(this->BaseName(wdir), root, wxString(""));
}
}
@ -102,34 +105,48 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
*
* @access private
*/
void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent)
void FilePane::AddDirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent)
{
auto fullPath = parent.Clone();
auto pathBase = this->BaseName(path);
auto fullPath = this->base_path;
if ( ! parent.empty())
{
fullPath += "/";
fullPath += path;
this->dir_set.insert(".");
wxString par = parent.Clone();
par.Replace((wxString)this->base_path, "");
wxLogDebug("Rendering Dir Tree for %s", fullPath);
fullPath += par.ToStdString();
}
if ( ! fullPath.Contains(pathBase))
{
fullPath += "/";
fullPath += pathBase;
}
wxFileName parentDir(fullPath);
parentDir.MakeAbsolute();
wxLogDebug("Rendering Dir Tree for %s, full path: %s", path, fullPath);
auto *files = new wxArrayString();
wxDir::GetAllFiles(path, files);
wxDir::GetAllFiles(fullPath, files);
for (const wxString &item: *files)
{
wxFileName fileName(item);
// Remove the directory component closest to the root
if (fileName.GetDirCount() > 1 || fileName.DirExists("."))
auto dir = std::string(fileName.GetPath());
wxString wdir(dir);
wxFileName dirName(dir);
if ( ! (wdir.Contains(pathBase) || dirName.GetDirCount() != (parentDir.GetDirCount() + 1)))
{
fileName.RemoveDir(0);
continue;
}
const wxArrayString dirs = fileName.GetDirs();
// See if the path already exists on the tree
for (const wxString &dir: dirs)
{
// Stop early if folder exists
auto it = this->dir_set.find(std::string(dir));
if (it != this->dir_set.end())
@ -140,14 +157,15 @@ void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxStr
auto fileData = new wxStringClientData();
fileData->SetData(dir);
auto dir_node = this->AppendItem(root, dir, Icon_FolderClosed, Icon_FolderOpened, fileData);
auto dir_label = this->BaseName(dir);
auto dir_node = this->AppendItem(root, dir_label, Icon_FolderClosed, Icon_FolderOpened, fileData);
this->dir_set.insert(std::string(dir));
this->DirToTree(dir, dir_node, fullPath);
wxLogDebug("Recursing for dir %s, from parent %s", dir_label, fullPath);
// break;
}
this->AddDirFiles(fullPath, dir_node);
this->AddDirToTree(dir_label, dir_node, fullPath);
}
}
@ -156,13 +174,20 @@ void FilePane::AddDirFiles(const wxString &path, wxTreeListItem &root)
auto *files = new wxArrayString();
wxDir::GetAllFiles(path, files);
wxLogDebug("Redering files in : %s", path);
wxFileName rootPath(path);
rootPath.MakeAbsolute();
for (const wxString &item: *files)
{
wxFileName fileName(item);
fileName.MakeAbsolute();
// If the file is in another folder, don't add it here!
if (fileName.GetDirCount() != rootPath.GetDirCount())
{
continue;
}
auto it = this->file_set.find(std::string(fileName.GetFullPath()));
if (it != this->file_set.end())
{
@ -172,7 +197,9 @@ void FilePane::AddDirFiles(const wxString &path, wxTreeListItem &root)
auto fileData = new wxStringClientData();
fileData->SetData(fileName.GetFullPath());
this->AppendItem(root, fileName.GetFullName(), Icon_File, Icon_File, fileData);
auto fileLabel = this->BaseName(fileName.GetFullName());
this->AppendItem(root, fileLabel, Icon_File, Icon_File, fileData);
this->file_set.insert(std::string(fileName.GetFullPath()));
}
}
@ -221,3 +248,11 @@ void FilePane::InitImageList()
);
}
}
wxString FilePane::BaseName(wxString path)
{
auto fullPath = path.char_str();
auto base = basename(fullPath);
return (wxString) base;
}

View File

@ -15,7 +15,7 @@ public:
);
~FilePane() override;
private:
wxString curr_path = "";
wxString base_path = "";
wxImageList *img_list = nullptr;
unordered_set<std::string> file_set;
unordered_set<std::string> dir_set;
@ -24,7 +24,8 @@ private:
void OpenFileInEditor(wxTreeListEvent& event);
void InitImageList();
void CreateTree(const wxString &path, wxTreeListItem &root);
void DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent);
void AddDirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent);
void AddDirFiles(const wxString &path, wxTreeListItem &root);
wxString BaseName(wxString path);
};

View File

@ -58,6 +58,7 @@ MainFrame::~MainFrame()
wxDELETE(this->findData);
wxDELETE(this->replaceDlg);
wxDELETE(this->findReplaceData);
wxDELETE(this->toolBar);
Glob_status_bar->Destroy();
@ -72,7 +73,7 @@ MainFrame::~MainFrame()
void MainFrame::DoLayout()
{
this->manager = new wxAuiManager(this);
this->SetupToolbar();
this->toolBar = this->SetupToolbar();
// Setup properties for each AUI pane
wxAuiPaneInfo toolBarPaneInfo;
@ -123,7 +124,7 @@ void MainFrame::SetupStatusBar()
*
* @return void
*/
void MainFrame::SetupToolbar()
wxAuiToolBar* MainFrame::SetupToolbar()
{
// Icon files
#ifndef __WXGTK__
@ -163,6 +164,8 @@ void MainFrame::SetupToolbar()
toolBar->AddStretchSpacer();
toolBar->Realize();
return toolBar;
}
/**

View File

@ -26,7 +26,7 @@ class MainFrame: public wxFrame
wxFindReplaceData *findData = nullptr;
wxFindReplaceDialog *findDlg = nullptr;
wxFindReplaceDialog *replaceDlg = nullptr;
void SetupToolbar();
wxAuiToolBar* SetupToolbar();
void SetupStatusBar();
void BindEvents();
void DoLayout();