Slow progress on File pane
This commit is contained in:
parent
f2dc0a9eae
commit
9a2f12f06b
@ -1,3 +1,4 @@
|
|||||||
|
#include <libgen.h>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "src/widgets/FilePane.h"
|
#include "src/widgets/FilePane.h"
|
||||||
@ -55,7 +56,7 @@ void FilePane::OpenFolder(wxTreeListEvent& event)
|
|||||||
wxTreeListItem item = event.GetItem();
|
wxTreeListItem item = event.GetItem();
|
||||||
const wxString path = this->GetItemText(item, 0);
|
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)
|
void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
|
||||||
{
|
{
|
||||||
auto *files = new wxArrayString();
|
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)
|
for (const wxString &file: *files)
|
||||||
{
|
{
|
||||||
wxFileName fileName(file);
|
wxFileName fileName(file);
|
||||||
|
|
||||||
if (fileName.DirExists("."))
|
|
||||||
{
|
|
||||||
fileName.RemoveDir(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the file is at the root, add it to the tree
|
// 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);
|
this->AddDirFiles(path, root);
|
||||||
}
|
}
|
||||||
@ -92,8 +95,8 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
|
|||||||
|
|
||||||
// Append the folder to the tree
|
// Append the folder to the tree
|
||||||
wxString wdir = wxString(dir);
|
wxString wdir = wxString(dir);
|
||||||
wxLogDebug("Creating Dir Tree: %s", wdir);
|
// wxLogDebug("Creating Dir Tree: %s", wdir);
|
||||||
this->DirToTree(wdir, root, wxString("."));
|
this->AddDirToTree(this->BaseName(wdir), root, wxString(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,34 +105,48 @@ void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
|
|||||||
*
|
*
|
||||||
* @access private
|
* @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 pathBase = this->BaseName(path);
|
||||||
|
auto fullPath = this->base_path;
|
||||||
|
|
||||||
|
if ( ! parent.empty())
|
||||||
{
|
{
|
||||||
auto fullPath = parent.Clone();
|
|
||||||
fullPath += "/";
|
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();
|
auto *files = new wxArrayString();
|
||||||
wxDir::GetAllFiles(path, files);
|
wxDir::GetAllFiles(fullPath, files);
|
||||||
|
|
||||||
for (const wxString &item: *files)
|
for (const wxString &item: *files)
|
||||||
{
|
{
|
||||||
wxFileName fileName(item);
|
wxFileName fileName(item);
|
||||||
|
|
||||||
// Remove the directory component closest to the root
|
auto dir = std::string(fileName.GetPath());
|
||||||
if (fileName.GetDirCount() > 1 || fileName.DirExists("."))
|
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
|
// Stop early if folder exists
|
||||||
auto it = this->dir_set.find(std::string(dir));
|
auto it = this->dir_set.find(std::string(dir));
|
||||||
if (it != this->dir_set.end())
|
if (it != this->dir_set.end())
|
||||||
@ -140,14 +157,15 @@ void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxStr
|
|||||||
auto fileData = new wxStringClientData();
|
auto fileData = new wxStringClientData();
|
||||||
fileData->SetData(dir);
|
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->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();
|
auto *files = new wxArrayString();
|
||||||
wxDir::GetAllFiles(path, files);
|
wxDir::GetAllFiles(path, files);
|
||||||
|
|
||||||
wxLogDebug("Redering files in : %s", path);
|
wxFileName rootPath(path);
|
||||||
|
rootPath.MakeAbsolute();
|
||||||
|
|
||||||
for (const wxString &item: *files)
|
for (const wxString &item: *files)
|
||||||
{
|
{
|
||||||
wxFileName fileName(item);
|
wxFileName fileName(item);
|
||||||
fileName.MakeAbsolute();
|
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()));
|
auto it = this->file_set.find(std::string(fileName.GetFullPath()));
|
||||||
if (it != this->file_set.end())
|
if (it != this->file_set.end())
|
||||||
{
|
{
|
||||||
@ -172,7 +197,9 @@ void FilePane::AddDirFiles(const wxString &path, wxTreeListItem &root)
|
|||||||
auto fileData = new wxStringClientData();
|
auto fileData = new wxStringClientData();
|
||||||
fileData->SetData(fileName.GetFullPath());
|
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()));
|
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;
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
);
|
);
|
||||||
~FilePane() override;
|
~FilePane() override;
|
||||||
private:
|
private:
|
||||||
wxString curr_path = "";
|
wxString base_path = "";
|
||||||
wxImageList *img_list = nullptr;
|
wxImageList *img_list = nullptr;
|
||||||
unordered_set<std::string> file_set;
|
unordered_set<std::string> file_set;
|
||||||
unordered_set<std::string> dir_set;
|
unordered_set<std::string> dir_set;
|
||||||
@ -24,7 +24,8 @@ private:
|
|||||||
void OpenFileInEditor(wxTreeListEvent& event);
|
void OpenFileInEditor(wxTreeListEvent& event);
|
||||||
void InitImageList();
|
void InitImageList();
|
||||||
void CreateTree(const wxString &path, wxTreeListItem &root);
|
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);
|
void AddDirFiles(const wxString &path, wxTreeListItem &root);
|
||||||
|
wxString BaseName(wxString path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ MainFrame::~MainFrame()
|
|||||||
wxDELETE(this->findData);
|
wxDELETE(this->findData);
|
||||||
wxDELETE(this->replaceDlg);
|
wxDELETE(this->replaceDlg);
|
||||||
wxDELETE(this->findReplaceData);
|
wxDELETE(this->findReplaceData);
|
||||||
|
wxDELETE(this->toolBar);
|
||||||
|
|
||||||
Glob_status_bar->Destroy();
|
Glob_status_bar->Destroy();
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ MainFrame::~MainFrame()
|
|||||||
void MainFrame::DoLayout()
|
void MainFrame::DoLayout()
|
||||||
{
|
{
|
||||||
this->manager = new wxAuiManager(this);
|
this->manager = new wxAuiManager(this);
|
||||||
this->SetupToolbar();
|
this->toolBar = this->SetupToolbar();
|
||||||
|
|
||||||
// Setup properties for each AUI pane
|
// Setup properties for each AUI pane
|
||||||
wxAuiPaneInfo toolBarPaneInfo;
|
wxAuiPaneInfo toolBarPaneInfo;
|
||||||
@ -123,7 +124,7 @@ void MainFrame::SetupStatusBar()
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void MainFrame::SetupToolbar()
|
wxAuiToolBar* MainFrame::SetupToolbar()
|
||||||
{
|
{
|
||||||
// Icon files
|
// Icon files
|
||||||
#ifndef __WXGTK__
|
#ifndef __WXGTK__
|
||||||
@ -163,6 +164,8 @@ void MainFrame::SetupToolbar()
|
|||||||
toolBar->AddStretchSpacer();
|
toolBar->AddStretchSpacer();
|
||||||
|
|
||||||
toolBar->Realize();
|
toolBar->Realize();
|
||||||
|
|
||||||
|
return toolBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@ class MainFrame: public wxFrame
|
|||||||
wxFindReplaceData *findData = nullptr;
|
wxFindReplaceData *findData = nullptr;
|
||||||
wxFindReplaceDialog *findDlg = nullptr;
|
wxFindReplaceDialog *findDlg = nullptr;
|
||||||
wxFindReplaceDialog *replaceDlg = nullptr;
|
wxFindReplaceDialog *replaceDlg = nullptr;
|
||||||
void SetupToolbar();
|
wxAuiToolBar* SetupToolbar();
|
||||||
void SetupStatusBar();
|
void SetupStatusBar();
|
||||||
void BindEvents();
|
void BindEvents();
|
||||||
void DoLayout();
|
void DoLayout();
|
||||||
|
Loading…
Reference in New Issue
Block a user