← Back to team overview

kicad-developers team mailing list archive

[Patch] Bug 1584977: Open project folder in host OS

 

Hi,

Tiny patch to fullfil feature request in bug 1584977
<https://bugs.launchpad.net/kicad/+bug/1584977>.

Regards,
Ashutosh Gangwar
From 7adbb4ac56810251588afc7ab8d8e85f4648aaf1 Mon Sep 17 00:00:00 2001
From: Ashutosh Gangwar <ashutoshgngwr@xxxxxxxxx>
Date: Mon, 11 Jun 2018 15:40:00 +0530
Subject: [PATCH] kicad: Open project folder in host OS
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.17.1"

This is a multi-part message in MIME format.
--------------2.17.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


NEW: Adds support to browse project directory in default file manager in the host OS

CHANGED: Main frame's Browse menu now contains third option to Browse Project Files

Fixes: lp:1584977
https://bugs.launchpad.net/kicad/+bug/1584977
---
 kicad/kicad.h       |  2 ++
 kicad/mainframe.cpp | 18 ++++++++++++++++++
 kicad/menubar.cpp   |  8 ++++++++
 3 files changed, 28 insertions(+)


--------------2.17.1
Content-Type: text/x-patch; name="0001-kicad-Open-project-folder-in-host-OS.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-kicad-Open-project-folder-in-host-OS.patch"

diff --git a/kicad/kicad.h b/kicad/kicad.h
index 06c198e7f..21852e106 100644
--- a/kicad/kicad.h
+++ b/kicad/kicad.h
@@ -116,6 +116,7 @@ enum id_kicad_frm {
 
     ID_TO_TEXT_EDITOR,
     ID_BROWSE_AN_SELECT_FILE,
+    ID_BROWSE_IN_FILE_EXPLORER,
     ID_SELECT_PREFERED_EDITOR,
     ID_SELECT_PREFERED_PDF_BROWSER_NAME,
     ID_SELECT_PREFERED_PDF_BROWSER,
@@ -184,6 +185,7 @@ public:
     void OnConfigurePaths( wxCommandEvent& aEvent );
     void OnOpenTextEditor( wxCommandEvent& event );
     void OnOpenFileInTextEditor( wxCommandEvent& event );
+    void OnBrowseInFileExplorer( wxCommandEvent& event );
     void OnOpenFileInEditor( wxCommandEvent& event );
 
     void OnFileHistory( wxCommandEvent& event );
diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp
index 899815b38..9fc0129bf 100644
--- a/kicad/mainframe.cpp
+++ b/kicad/mainframe.cpp
@@ -512,6 +512,24 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
         Execute( this, Pgm().GetEditorName(), filename );
 }
 
+void KICAD_MANAGER_FRAME::OnBrowseInFileExplorer( wxCommandEvent& event )
+{
+    // open project directory in host OS's file explorer
+    wxString project_dir = Prj().GetProjectPath();
+
+    #if defined(__linux__) || defined(__FreeBSD__)
+        #define OPEN_FM_CMD_BASE "xdg-open"
+    #elif defined(__WXMAC__)
+        #define OPEN_FM_CMD_BASE "open"
+    #elif defined(_WIN32)
+        #define OPEN_FM_CMD_BASE "explorer"
+    #else
+        #error "Unsupported platform!"
+    #endif
+
+    wxExecute( wxT(OPEN_FM_CMD_BASE " " + project_dir ), wxEXEC_ASYNC, NULL );
+}
+
 
 void KICAD_MANAGER_FRAME::OnRefresh( wxCommandEvent& event )
 {
diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp
index 7411452b8..96dc1e8c5 100644
--- a/kicad/menubar.cpp
+++ b/kicad/menubar.cpp
@@ -53,6 +53,7 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
     EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
     EVT_MENU( ID_TO_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenTextEditor )
     EVT_MENU( ID_BROWSE_AN_SELECT_FILE, KICAD_MANAGER_FRAME::OnOpenFileInTextEditor )
+    EVT_MENU( ID_BROWSE_IN_FILE_EXPLORER, KICAD_MANAGER_FRAME::OnBrowseInFileExplorer )
     EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, KICAD_MANAGER_FRAME::OnConfigurePaths )
     EVT_MENU( ID_SELECT_PREFERED_EDITOR, EDA_BASE_FRAME::OnSelectPreferredEditor )
     EVT_MENU( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser )
@@ -328,6 +329,13 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
                  _( "Edit local file" ),
                  KiBitmap( browse_files_xpm ) );
 
+    // Browse in file explorer
+    AddMenuItem( browseMenu,
+                ID_BROWSE_IN_FILE_EXPLORER,
+                _( "&Browse project files..." ),
+                _( "Open project directory in file explorer" ),
+                KiBitmap( open_project_xpm ) );
+
     // Menu Preferences:
     wxMenu* preferencesMenu = new wxMenu;
 

--------------2.17.1--



Follow ups