Skip to content

Commit

Permalink
Add ability to load workspace folder into the explorer pane
Browse files Browse the repository at this point in the history
  • Loading branch information
kosude committed May 4, 2024
1 parent 706ebc7 commit 9f9aed2
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 19 deletions.
4 changes: 3 additions & 1 deletion texedit/gui/command_ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace te::gui::cmds {
enum {
Menu_URLSourcePage = 101,
Menu_URLSourcePage = 501,
Menu_URLFeatureRequest,
Menu_URLBugReport,
Menu_URLUserManual,
Menu_PaneExplorer,
Menu_PaneOutput,
Menu_PanePreview,
Menu_OpenFolder,
Button_OpenFolder,
};
}

Expand Down
2 changes: 1 addition & 1 deletion texedit/gui/layout/panes/editor_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "editor_pane.hpp"

namespace te::gui {
EditorPane::EditorPane(wxWindow *parent) : PaneBase(parent) {
EditorPane::EditorPane(wxWindow *parent) : PaneBase{parent} {
_stc = new wxStyledTextCtrl(this, wxID_ANY);

_sizer = new wxBoxSizer(wxVERTICAL);
Expand Down
39 changes: 36 additions & 3 deletions texedit/gui/layout/panes/explorer_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,45 @@

#include "explorer_pane.hpp"

#include "gui/command_ids.hpp"

namespace te::gui {
ExplorerPane::ExplorerPane(wxWindow *parent) : PaneBase(parent) {
_dirctl = new wxGenericDirCtrl(this, wxID_ANY);
LocalDirCtrl::LocalDirCtrl(wxWindow *parent, const wxString &root, wxWindowID id) : _root{root} {
Init();
Create(parent, id);
}

void LocalDirCtrl::SetupSections() {
AddSection(_root, wxFileNameFromPath(_root), wxFileIconsTable::folder_open);

ExpandPath(_root);
}

ExplorerPane::ExplorerPane(wxWindow *parent) : PaneBase(parent) {
_sizer = new wxBoxSizer(wxVERTICAL);
_sizer->Add(_dirctl, 1, wxEXPAND);
SetSizer(_sizer);

AddEmptyTreeButton();
}

void ExplorerPane::ChangeRootDir(const wxString &path) {
_sizer->Clear();

// destroy and recreate the dirctrl
if (_dirctrl) {
_sizer->Detach(_dirctrl);
_dirctrl->Destroy();
}
_dirctrl = new LocalDirCtrl(this, path, wxID_ANY);
_sizer->Add(_dirctrl, 1, wxEXPAND);
}

void ExplorerPane::AddEmptyTreeButton() {
_sizer->Clear();

_empty_tree_btn = new wxButton(this, cmds::Button_OpenFolder, "Open a folder");
_empty_tree_stretch_spacer[0] = _sizer->AddStretchSpacer();
_sizer->Add(_empty_tree_btn, 0, wxALIGN_CENTER);
_empty_tree_stretch_spacer[1] = _sizer->AddStretchSpacer();
}
}
21 changes: 20 additions & 1 deletion texedit/gui/layout/panes/explorer_pane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,32 @@
#include "pane_base.hpp"

namespace te::gui {
// An implementation of wxGenericDirCtrl that is local to a specified directory, as opposed to listing the entire filesystem
class LocalDirCtrl : public wxGenericDirCtrl {
public:
LocalDirCtrl(wxWindow *parent, const wxString &root, wxWindowID id = wxID_ANY);

void SetupSections() override;

private:
wxString _root;
};

class ExplorerPane : public PaneBase {
public:
ExplorerPane(wxWindow *parent);

inline LocalDirCtrl *GetDirCtrl() const { return _dirctrl; }

void ChangeRootDir(const wxString &path);

private:
wxSizerItem *_empty_tree_stretch_spacer[2];
wxButton *_empty_tree_btn;
void AddEmptyTreeButton();

wxBoxSizer *_sizer;
wxGenericDirCtrl *_dirctl;
LocalDirCtrl *_dirctrl{nullptr};
};
}

Expand Down
2 changes: 1 addition & 1 deletion texedit/gui/layout/panes/output_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "output_pane.hpp"

namespace te::gui {
OutputPane::OutputPane(wxWindow *parent) : PaneBase(parent) {
OutputPane::OutputPane(wxWindow *parent) : PaneBase{parent} {
_listbox = new wxListBox(this, wxID_ANY);

_sizer = new wxBoxSizer(wxVERTICAL);
Expand Down
2 changes: 1 addition & 1 deletion texedit/gui/layout/panes/preview_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "preview_pane.hpp"

namespace te::gui {
PreviewPane::PreviewPane(wxWindow *parent) : PaneBase(parent) {
PreviewPane::PreviewPane(wxWindow *parent) : PaneBase{parent} {
wxString pdf;
_webView = wxWebView::New(this, wxID_ANY);

Expand Down
30 changes: 27 additions & 3 deletions texedit/gui/main_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "main_frame.hpp"

#include "layout/panes/explorer_pane.hpp"
#include "layout/panes/output_pane.hpp"
#include "layout/panes/preview_pane.hpp"
#include "process/services/compiler_process.hpp"
Expand All @@ -16,6 +17,7 @@
#include "prog_info.hpp"

#include <wx/aboutdlg.h>
#include <wx/generic/dirctrlg.h>
#include <wx/splitter.h>

namespace te::gui {
Expand Down Expand Up @@ -43,6 +45,7 @@ namespace te::gui {
wxMenuBar *menuBar = new wxMenuBar();

wxMenu *fileMenu = new wxMenu();
fileMenu->Append(cmds::Menu_OpenFolder, "O&pen Folder...");
fileMenu->Append(wxID_EXIT, "&Quit");
menuBar->Append(fileMenu, "&File");

Expand All @@ -65,6 +68,12 @@ namespace te::gui {
SetMenuBar(menuBar);
}

void MainFrame::ShowURL(const wxString &url) {
if (!wxLaunchDefaultBrowser(url)) {
wxLogError("Failed to open URL \"%s\"", url);
}
}

void MainFrame::OnIdle(wxIdleEvent &ev) {
wxString sc = _compiler_proc->ReadLineStdout();
if (!sc.IsEmpty()) {
Expand All @@ -77,10 +86,20 @@ namespace te::gui {
}
}

void MainFrame::ShowURL(const wxString &url) {
if (!wxLaunchDefaultBrowser(url)) {
wxLogError("Failed to open URL \"%s\"", url);
void MainFrame::OnDirCtrlFileActivated(wxTreeEvent &event) {
wxGenericDirCtrl dirctrl = _layout.GetExplorerPane()->GetDirCtrl();

wxLogMessage("%s", dirctrl.GetPath(event.GetItem()));
}

void MainFrame::OnButtonOpenFolder(wxCommandEvent &event) {
wxDirDialog dlg(this, "Choose a workspace directory", "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);

if (dlg.ShowModal() == wxID_CANCEL) {
return;
}

_layout.GetExplorerPane()->ChangeRootDir(dlg.GetPath());
}

void MainFrame::OnMenuAbout(wxCommandEvent &event) {
Expand Down Expand Up @@ -120,6 +139,11 @@ namespace te::gui {

wxBEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_IDLE(MainFrame::OnIdle)

EVT_DIRCTRL_FILEACTIVATED(wxID_ANY, MainFrame::OnDirCtrlFileActivated)
EVT_BUTTON(cmds::Button_OpenFolder, MainFrame::OnButtonOpenFolder)
EVT_MENU(cmds::Menu_OpenFolder, MainFrame::OnButtonOpenFolder)

EVT_MENU(wxID_EXIT, MainFrame::OnMenuQuit)
EVT_MENU(wxID_ABOUT, MainFrame::OnMenuAbout)
EVT_MENU(cmds::Menu_URLSourcePage, MainFrame::OnMenuURLSourcePage)
Expand Down
7 changes: 5 additions & 2 deletions texedit/gui/main_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define __texedit__root_frame_hpp__

#include <wx/wx.h>
#include <wx/treebase.h>

#include "process/process_manager.hpp"
#include "process/services/compiler_process.hpp"
Expand All @@ -33,10 +34,12 @@ namespace te::gui {

void BuildMenuBar();

void OnIdle(wxIdleEvent &ev);

void ShowURL(const wxString &url);

void OnIdle(wxIdleEvent &ev);
void OnDirCtrlFileActivated(wxTreeEvent &event);
void OnButtonOpenFolder(wxCommandEvent &event);

void OnMenuAbout(wxCommandEvent &event);
void OnMenuQuit(wxCommandEvent &event);
void OnMenuURLSourcePage(wxCommandEvent &event);
Expand Down
7 changes: 4 additions & 3 deletions texedit/util/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "resources.hpp"

#include <wx/filename.h>
#include <wx/dir.h>
#include <wx/stdpaths.h>

namespace te::util {
Expand All @@ -16,7 +17,7 @@ namespace te::util {
return f.GetPath();
}

wxString RelToExec(std::vector<wxString> dirs, wxString filename) {
wxString RelToExec(const std::vector<wxString> &dirs, const wxString &filename) {
wxFileName f = wxFileName::DirName(GetTexeditDir());
for (auto d : dirs) {
f.AppendDir(d);
Expand All @@ -27,11 +28,11 @@ namespace te::util {
filename;
}

wxString RelToExec(wxString filename) {
wxString RelToExec(const wxString &filename) {
return RelToExec({}, filename);
}

bool ValidateExecutable(wxString path) {
bool ValidateExecutable(const wxString &path) {
wxFileName f{path};
return f.FileExists() && f.IsFileExecutable();
}
Expand Down
6 changes: 3 additions & 3 deletions texedit/util/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
namespace te::util {
wxString GetTexeditDir();

wxString RelToExec(std::vector<wxString> dirs, wxString filename);
wxString RelToExec(wxString filename);
wxString RelToExec(const std::vector<wxString> &dirs, const wxString &filename);
wxString RelToExec(const wxString &filename);

bool ValidateExecutable(wxString path);
bool ValidateExecutable(const wxString &path);
}

#endif

0 comments on commit 9f9aed2

Please sign in to comment.