Skip to content

Commit

Permalink
NodeJS workspace: added an option to close the workspace from the wor…
Browse files Browse the repository at this point in the history
…kspace view context menu
  • Loading branch information
eranif committed Jul 28, 2015
1 parent c2ac0f9 commit 39295b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
41 changes: 25 additions & 16 deletions WebTools/NodeJSWorkspaceView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,45 @@ NodeJSWorkspaceView::NodeJSWorkspaceView(wxWindow* parent, const wxString& viewN
{
SetNewFileTemplate("Untitled.js", wxStrlen("Untitled"));
SetViewName(viewName);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &NodeJSWorkspaceView::OnContenxtMenu, this);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &NodeJSWorkspaceView::OnContextMenu, this);
}

NodeJSWorkspaceView::~NodeJSWorkspaceView()
{
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &NodeJSWorkspaceView::OnContenxtMenu, this);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &NodeJSWorkspaceView::OnContextMenu, this);
}

void NodeJSWorkspaceView::OnContenxtMenu(clContextMenuEvent& event)
void NodeJSWorkspaceView::OnContextMenu(clContextMenuEvent& event)
{
event.Skip();
if(event.GetEventObject() == this) {
wxMenu* menu = event.GetMenu();
// Remove the 'Close folder' option
wxMenuItem* item = menu->FindItem(XRCID("tree_ctrl_close_folder"));
if(item) {
menu->Remove(item);
wxMenuItem* sepItem = menu->FindItemByPosition(0);
if(sepItem) {
menu->Remove(sepItem);
}
}

// Locate the "Close" menu entry
int pos = wxNOT_FOUND;
wxMenuItem* closeItem = NULL;
for(size_t i = 0; i < menu->GetMenuItemCount(); ++i) {
wxMenuItem* mi = menu->FindItemByPosition(i);
if(mi && mi->GetId() == wxID_REFRESH) {
if(mi && mi->GetId() == XRCID("tree_ctrl_close_folder")) {
pos = i;
closeItem = mi;
break;
}
}

if(pos != wxNOT_FOUND) {
if((pos != wxNOT_FOUND) && closeItem) {
wxMenuItem* showHiddenItem =
menu->Insert(pos + 2, XRCID("nodejs_show_hidden_files"), _("Show hidden files"), "", wxITEM_CHECK);
menu->Insert(pos, XRCID("nodejs_show_hidden_files"), _("Show hidden files"), "", wxITEM_CHECK);
NodeJSWorkspaceConfiguration conf;
showHiddenItem->Check(conf.Load(NodeJSWorkspace::Get()->GetFilename()).IsShowHiddenFiles());
menu->InsertSeparator(pos + 3);
menu->Bind(wxEVT_MENU, &NodeJSWorkspaceView::OnShowHiddenFiles, this, XRCID("nodejs_show_hidden_files"));

menu->InsertSeparator(pos);
menu->Insert(pos, XRCID("nodejs_close_workspace"), _("Close Workspace"));
menu->Bind(wxEVT_MENU, &NodeJSWorkspaceView::OnCloseWorkspace, this, XRCID("nodejs_close_workspace"));

// Remove the 'close' menu item
menu->Remove(closeItem);
}
}
}
Expand Down Expand Up @@ -134,3 +134,12 @@ void NodeJSWorkspaceView::OnShowHiddenFiles(wxCommandEvent& event)
ShowHiddenFiles(event.IsChecked());
RebuildTree();
}

void NodeJSWorkspaceView::OnCloseWorkspace(wxCommandEvent& event)
{
// Simulate the menu event "Close Workspace"
wxUnusedVar(event);
wxCommandEvent eventCloseWorkspace(wxEVT_MENU, XRCID("close_workspace"));
eventCloseWorkspace.SetEventObject(EventNotifier::Get()->TopFrame());
EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent(eventCloseWorkspace);
}
3 changes: 2 additions & 1 deletion WebTools/NodeJSWorkspaceView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
class NodeJSWorkspaceView : public clTreeCtrlPanel
{
protected:
void OnContenxtMenu(clContextMenuEvent& event);
void OnContextMenu(clContextMenuEvent& event);
void OnFolderDropped(clCommandEvent& event);
void OnShowHiddenFiles(wxCommandEvent& event);
void OnCloseWorkspace(wxCommandEvent& event);

public:
NodeJSWorkspaceView(wxWindow* parent, const wxString& viewName);
Expand Down

0 comments on commit 39295b6

Please sign in to comment.