Skip to content

Commit

Permalink
Initial work: File System Workspace view should now be using the nati…
Browse files Browse the repository at this point in the history
…ve wxTreeCtrl

Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Nov 13, 2024
1 parent 789f1aa commit 2aff47d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Interfaces/imanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class IManager
* @param type the type of tree
* @sa TreeType
*/
virtual clTreeCtrl* GetFileExplorerTree() = 0;
virtual wxTreeCtrl* GetFileExplorerTree() = 0;
virtual clTreeCtrl* GetWorkspaceTree() = 0;

/**
Expand Down
12 changes: 2 additions & 10 deletions LiteEditor/fileexplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,13 @@
//////////////////////////////////////////////////////////////////////////////
#include "fileexplorer.h"

#include "OpenFolderDlg.h"
#include "SideBar.hpp"
#include "clFileOrFolderDropTarget.h"
#include "clToolBarButton.h"
#include "clTreeCtrlPanel.h"
#include "clWorkspaceView.h"
#include "cl_config.h"
#include "codelite_events.h"
#include "editor_config.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "frame.h"
#include "globals.h"
#include "macros.h"
#include "manager.h"
#include "plugin.h"

#include <wx/arrstr.h>
Expand Down Expand Up @@ -77,7 +69,7 @@ void FileExplorer::CreateGUIControls()
void FileExplorer::OnFolderDropped(clCommandEvent& event)
{
const wxArrayString& folders = event.GetStrings();
for(size_t i = 0; i < folders.size(); ++i) {
for (size_t i = 0; i < folders.size(); ++i) {
m_view->AddFolder(folders.Item(i));
}
clGetManager()->BookSelectPage(PaneId::SIDE_BAR, _("Explorer"));
Expand All @@ -88,7 +80,7 @@ void FileExplorer::OpenFolder(const wxString& path) { m_view->AddFolder(path); }
void FileExplorer::OnOpenFolder(wxCommandEvent& event)
{
wxString path = ::wxDirSelector(_("Select folder to open"));
if(path.IsEmpty()) {
if (path.IsEmpty()) {
return;
}
OpenFolder(path);
Expand Down
2 changes: 1 addition & 1 deletion LiteEditor/fileexplorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FileExplorer : public wxPanel
virtual ~FileExplorer();
const wxString& GetCaption() const { return m_caption; }
TreeItemInfo GetItemInfo() { return m_view->GetSelectedItemInfo(); }
clTreeCtrl* GetTree() { return m_view->GetTreeCtrl(); }
auto GetTree() { return m_view->GetTreeCtrl(); }
void OpenFolder(const wxString& path);
};

Expand Down
2 changes: 1 addition & 1 deletion LiteEditor/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ TreeItemInfo PluginManager::GetSelectedTreeItemInfo(TreeType type)

clTreeCtrl* PluginManager::GetWorkspaceTree() { return clMainFrame::Get()->GetWorkspaceTab()->GetFileView(); }

clTreeCtrl* PluginManager::GetFileExplorerTree() { return clMainFrame::Get()->GetFileExplorer()->GetTree(); }
wxTreeCtrl* PluginManager::GetFileExplorerTree() { return clMainFrame::Get()->GetFileExplorer()->GetTree(); }

MainNotebook* PluginManager::GetMainNotebook() { return clMainFrame::Get()->GetMainBook()->GetNotebook(); }

Expand Down
2 changes: 1 addition & 1 deletion LiteEditor/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PluginManager : public IManager
wxMenuBar* GetMenuBar() override;
IConfigTool* GetConfigTool() override;
TreeItemInfo GetSelectedTreeItemInfo(TreeType type) override;
clTreeCtrl* GetFileExplorerTree() override;
wxTreeCtrl* GetFileExplorerTree() override;
clTreeCtrl* GetWorkspaceTree() override;
MainNotebook* GetMainNotebook() override;
IEditor* OpenFile(const wxString& fileName, const wxString& projectName = wxEmptyString, int lineno = wxNOT_FOUND,
Expand Down
10 changes: 7 additions & 3 deletions Plugin/clFileViwerTreeCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

clFileViewerTreeCtrl::clFileViewerTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style)
: clThemedTreeCtrl(parent, id, pos, size, (style & ~wxTR_FULL_ROW_HIGHLIGHT))
: wxTreeCtrl(parent, id, pos, size, (style | wxTR_FULL_ROW_HIGHLIGHT))
{
#if 0
std::function<bool(const wxTreeItemId&, const wxTreeItemId&)> SortFunc = [&](const wxTreeItemId& itemA,
const wxTreeItemId& itemB) {
clTreeCtrlData* a = static_cast<clTreeCtrlData*>(GetItemData(itemA));
Expand All @@ -16,19 +17,22 @@ clFileViewerTreeCtrl::clFileViewerTreeCtrl(wxWindow* parent, wxWindowID id, cons
return (a->GetName().CmpNoCase(b->GetName()) < 0);
};
SetSortFunction(SortFunc);
#endif
}

clFileViewerTreeCtrl::~clFileViewerTreeCtrl() {}

void clFileViewerTreeCtrl::SetBitmaps(BitmapLoader::Vec_t* bitmaps) { m_bitmaps = bitmaps; }

wxTreeItemId clTreeNodeIndex::Find(const wxString& path)
{
#ifdef __WXMSW__
wxString lcpath = path.Lower();
if(m_children.count(lcpath)) {
if (m_children.count(lcpath)) {
return m_children.find(lcpath)->second;
}
#else
if(m_children.count(path)) {
if (m_children.count(path)) {
return m_children.find(path)->second;
}
#endif
Expand Down
20 changes: 13 additions & 7 deletions Plugin/clFileViwerTreeCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#define CLFILEVIWERTREECTRL_H

#include "clThemedTreeCtrl.h"
#include "clTreeCtrl.h"
#include "codelite_exports.h"
#include "wxStringHash.h"

#include <map>
#include <wx/dataview.h>
#include <wx/filename.h>
#include <wx/treectrl.h>

Expand Down Expand Up @@ -78,7 +78,7 @@ class WXDLLIMPEXP_SDK clTreeCtrlData : public wxTreeItemData
: m_kind(kind)
, m_index(NULL)
{
if(IsFolder()) {
if (IsFolder()) {
m_index = new clTreeNodeIndex();
}
}
Expand All @@ -95,14 +95,14 @@ class WXDLLIMPEXP_SDK clTreeCtrlData : public wxTreeItemData
void SetPath(const wxString& path)
{
this->m_path = path;
if(IsFolder()) {
if (IsFolder()) {
wxFileName fn(m_path, "");
if(fn.GetDirCount()) {
if (fn.GetDirCount()) {
m_name = fn.GetDirs().Last();
} else {
m_name = m_path;
}
} else if(IsFile()) {
} else if (IsFile()) {
wxFileName fn(m_path);
m_name = fn.GetFullName();
} else {
Expand All @@ -127,13 +127,19 @@ class WXDLLIMPEXP_SDK clTreeCtrlData : public wxTreeItemData
bool IsDummy() const { return m_kind == kDummy; }
};

class WXDLLIMPEXP_SDK clFileViewerTreeCtrl : public clThemedTreeCtrl
#include "bitmap_loader.h"
class WXDLLIMPEXP_SDK clFileViewerTreeCtrl : public wxTreeCtrl
{
public:
clFileViewerTreeCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTR_DEFAULT_STYLE | wxTR_MULTIPLE | wxTR_HIDE_ROOT | wxBORDER_STATIC);
long style = wxTR_DEFAULT_STYLE | wxTR_MULTIPLE | wxTR_HIDE_ROOT | wxBORDER_NONE);
virtual ~clFileViewerTreeCtrl();

void SetBitmaps(BitmapLoader::Vec_t* bitmaps);

private:
BitmapLoader::Vec_t* m_bitmaps = nullptr;
};

#endif // CLFILEVIWERTREECTRL_H
6 changes: 3 additions & 3 deletions Plugin/clTreeCtrlPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ wxTreeItemId clTreeCtrlPanel::DoAddFile(const wxTreeItemId& parent, const wxStri
// use gray text for hidden items
if (isHidden) {
// a hidden item, use a disabled colour
GetTreeCtrl()->SetItemTextColour(fileItem, GetTreeCtrl()->GetColours().GetGrayText());
GetTreeCtrl()->SetItemTextColour(fileItem, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
}

return fileItem;
Expand Down Expand Up @@ -421,7 +421,7 @@ wxTreeItemId clTreeCtrlPanel::DoAddFolder(const wxTreeItemId& parent, const wxSt
// use gray text for hidden items
if (isHiddenFolder) {
// a hidden item, use a disabled colour
GetTreeCtrl()->SetItemTextColour(itemFolder, GetTreeCtrl()->GetColours().GetGrayText());
GetTreeCtrl()->SetItemTextColour(itemFolder, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
}

// Add this entry to the index
Expand Down Expand Up @@ -823,7 +823,7 @@ bool clTreeCtrlPanel::ExpandToFile(const wxFileName& file_to_search)
void clTreeCtrlPanel::GetTopLevelFolders(wxArrayString& paths, wxArrayTreeItemIds& items) const
{
wxTreeItemIdValue cookie;
const clTreeCtrl* tree = m_treeCtrl;
const auto tree = m_treeCtrl;
wxTreeItemId child = tree->GetFirstChild(tree->GetRootItem(), cookie);
while (child.IsOk()) {
clTreeCtrlData* clientData = GetItemData(child);
Expand Down
Loading

0 comments on commit 2aff47d

Please sign in to comment.