Patch #3038 2010-07-24 20:01

codeman

Editor's right-click menu can open file's containing folder.
Download
3038-Editor_s_right.patch (5.0 KB)
Category
Application::FeatureAdd
Status
Accepted
Close date
2010-11-04 13:27
Assigned to
mortenmacfly
Index: src/include/editormanager.h
===================================================================
--- src/include/editormanager.h    (revision 6416)
+++ src/include/editormanager.h    (working copy)
@@ -115,6 +115,7 @@
 
         bool UpdateProjectFiles(cbProject* project);
         bool SwapActiveHeaderSource();
+        bool OpenContainingFolder();
         bool CloseActive(bool dontsave = false);
         bool Close(const wxString& filename, bool dontsave = false);
         bool Close(EditorBase* editor, bool dontsave = false);
@@ -155,6 +156,7 @@
         void OnSave(wxCommandEvent& event);
         void OnSaveAll(wxCommandEvent& event);
         void OnSwapHeaderSource(wxCommandEvent& event);
+        void OnOpenContainingFolder(wxCommandEvent& event);
         void OnTabPosition(wxCommandEvent& event);
         void OnProperties(wxCommandEvent& event);
         void OnAddFileToProject(wxCommandEvent& event);
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 6416)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -633,6 +633,7 @@
 const int idLowerCase = wxNewId();
 const int idSelectAll = wxNewId();
 const int idSwapHeaderSource = wxNewId();
+const int idOpenContainingFolder = wxNewId();
 const int idBookmarks = wxNewId();
 const int idBookmarksToggle = wxNewId();
 const int idBookmarksPrevious = wxNewId();
@@ -676,6 +677,7 @@
     EVT_MENU(idLowerCase, cbEditor::OnContextMenuEntry)
     EVT_MENU(idSelectAll, cbEditor::OnContextMenuEntry)
     EVT_MENU(idSwapHeaderSource, cbEditor::OnContextMenuEntry)
+    EVT_MENU(idOpenContainingFolder, cbEditor::OnContextMenuEntry)
     EVT_MENU(idBookmarksToggle, cbEditor::OnContextMenuEntry)
     EVT_MENU(idBookmarksPrevious, cbEditor::OnContextMenuEntry)
     EVT_MENU(idBookmarksNext, cbEditor::OnContextMenuEntry)
@@ -2650,6 +2652,7 @@
             popup->AppendSeparator();
         }
         popup->Append(idSwapHeaderSource, _("Swap header/source"));
+        popup->Append(idOpenContainingFolder, _("Open containing folder"));
         if(!noeditor)
             popup->AppendSeparator();
 
@@ -2885,6 +2888,8 @@
         control->SelectAll();
     else if (id == idSwapHeaderSource)
         Manager::Get()->GetEditorManager()->SwapActiveHeaderSource();
+    else if (id == idOpenContainingFolder)
+        Manager::Get()->GetEditorManager()->OpenContainingFolder();
     else if (id == idBookmarkAdd)
         control->MarkerAdd(m_pData->m_LastMarginMenuLine, BOOKMARK_MARKER);
     else if (id == idBookmarkRemove)
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp    (revision 6416)
+++ src/sdk/editormanager.cpp    (working copy)
@@ -146,6 +146,7 @@
 static const int idNBTabSave = wxNewId();
 static const int idNBTabSaveAll = wxNewId();
 static const int idNBSwapHeaderSource = wxNewId();
+static const int idNBTabOpenContainingFolder = wxNewId();
 static const int idNBTabTop = wxNewId();
 static const int idNBTabBottom = wxNewId();
 static const int idNBProperties = wxNewId();
@@ -190,6 +191,7 @@
     EVT_MENU(idNBTabClose, EditorManager::OnClose)
     EVT_MENU(idNBTabCloseAll, EditorManager::OnCloseAll)
     EVT_MENU(idNBTabCloseAllOthers, EditorManager::OnCloseAllOthers)
+    EVT_MENU(idNBTabOpenContainingFolder, EditorManager::OnOpenContainingFolder)
     EVT_MENU(idNBTabSave, EditorManager::OnSave)
     EVT_MENU(idNBTabSaveAll, EditorManager::OnSaveAll)
     EVT_MENU(idNBSwapHeaderSource, EditorManager::OnSwapHeaderSource)
@@ -1119,6 +1121,35 @@
     return candidateFile;
 }
 
+bool EditorManager::OpenContainingFolder()
+{
+    cbEditor* ed = GetBuiltinEditor(GetActiveEditor());
+    if (!ed)
+        return false;
+
+    const wxString& fullpath = ed->GetFilename();
+
+    wxString cmd;
+
+#ifdef __WXMSW__
+    cmd = _("explorer /select,") + fullpath;    //Open folder with the file selected
+#else
+#ifdef __WXMAC__
+    cmd = _("open -R ") + fullpath;                //Open folder with the file selected
+#else
+    //Cant select the file on Linux, so just extract the folder name
+    wxFileName::SplitPath(fullpath, &cmd, NULL, NULL);
+
+    //Use the xdg-open command
+    cmd = _("xdg-open ") + cmd;
+#endif
+#endif
+
+    wxExecute(cmd);
+
+    return true;
+}
+
 bool EditorManager::SwapActiveHeaderSource()
 {
     cbEditor* ed = GetBuiltinEditor(GetActiveEditor());
@@ -2777,6 +2808,7 @@
     pop->Append(idNBTabSaveAll, _("Save all"));
     pop->AppendSeparator();
     pop->Append(idNBSwapHeaderSource, _("Swap header/source"));
+    pop->Append(idNBTabOpenContainingFolder, _("Open containing folder"));
     pop->AppendSeparator();
     pop->Append(idNBTabTop, _("Tabs at top"));
     pop->Append(idNBTabBottom, _("Tabs at bottom"));
@@ -2859,6 +2891,11 @@
     Manager::Get()->GetEditorManager()->SwapActiveHeaderSource();
 }
 
+void EditorManager::OnOpenContainingFolder(wxCommandEvent& event)
+{
+    Manager::Get()->GetEditorManager()->OpenContainingFolder();
+}
+
 void EditorManager::OnTabPosition(wxCommandEvent& event)
 {
     long style = m_pNotebook->GetWindowStyleFlag();
codeman 2010-07-24 20:34

Editor's right-click context menu now has an option to open the containing folder of the file.

This is only implemented on WIN32 at the moment.

codeman 2010-07-26 00:38

Editor's right-click context menu now has an option to open the containing folder of the file.

Now works on all 3 platforms.