2010-02-19 15:01:32 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-02-19 15:01:32 +00:00
|
|
|
*
|
2012-12-31 08:12:29 +00:00
|
|
|
* Copyright (C) 1992-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-01-08 16:40:29 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2010-02-19 15:01:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-02-24 21:36:52 +00:00
|
|
|
/**
|
2020-12-02 12:35:19 +00:00
|
|
|
* @file PROJECT_TREE_PANE.h
|
2016-02-24 21:36:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
#ifndef TREEPRJ_FRAME_H
|
|
|
|
#define TREEPRJ_FRAME_H
|
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
#include <vector>
|
2012-12-31 08:12:29 +00:00
|
|
|
#include <wx/fswatcher.h>
|
2016-02-24 21:36:52 +00:00
|
|
|
#include <wx/laywin.h>
|
|
|
|
#include <wx/treebase.h>
|
|
|
|
|
2020-10-12 22:40:17 +00:00
|
|
|
#include "tree_file_type.h"
|
2015-07-29 18:06:45 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2016-02-24 21:36:52 +00:00
|
|
|
class KICAD_MANAGER_FRAME;
|
2020-12-02 12:35:19 +00:00
|
|
|
class PROJECT_TREE_ITEM;
|
|
|
|
class PROJECT_TREE;
|
2010-02-20 13:20:55 +00:00
|
|
|
|
2020-12-02 12:35:19 +00:00
|
|
|
/** PROJECT_TREE_PANE
|
2010-02-19 15:01:32 +00:00
|
|
|
* Window to display the tree files
|
|
|
|
*/
|
2020-12-02 12:35:19 +00:00
|
|
|
class PROJECT_TREE_PANE : public wxSashLayoutWindow
|
2010-02-19 15:01:32 +00:00
|
|
|
{
|
2020-12-02 12:35:19 +00:00
|
|
|
friend class PROJECT_TREE_ITEM;
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
public:
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_PANE( KICAD_MANAGER_FRAME* parent );
|
|
|
|
~PROJECT_TREE_PANE();
|
2014-07-07 19:49:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create or modify the tree showing project file names
|
|
|
|
*/
|
2013-01-01 14:06:49 +00:00
|
|
|
void ReCreateTreePrj();
|
2014-07-07 19:49:14 +00:00
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
/**
|
|
|
|
* Reinit the watched paths
|
|
|
|
* Should be called after opening a new project to
|
|
|
|
* rebuild the list of watched paths.
|
2021-01-08 16:40:29 +00:00
|
|
|
* Should be called *after* the main loop event handler is started
|
2013-01-01 14:06:49 +00:00
|
|
|
*/
|
|
|
|
void FileWatcherReset();
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2020-08-08 18:52:14 +00:00
|
|
|
/**
|
|
|
|
* Delete all @ref m_TreeProject entries
|
|
|
|
*/
|
|
|
|
void EmptyTreePrj();
|
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
protected:
|
2020-10-12 22:40:17 +00:00
|
|
|
static wxString GetFileExt( TREE_FILE_TYPE type );
|
2012-04-16 12:56:01 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetSelectedData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data from item currently selected (highlighted)
|
|
|
|
* Note this is not necessary the "clicked" item,
|
|
|
|
* because when expanding, collapsing an item this item is not selected
|
|
|
|
*/
|
2020-12-02 12:35:19 +00:00
|
|
|
std::vector<PROJECT_TREE_ITEM*> GetSelectedData();
|
2012-12-31 08:12:29 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetItemIdData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data corresponding to a wxTreeItemId identifier
|
|
|
|
* @param aId = the wxTreeItemId identifier.
|
2020-12-02 12:35:19 +00:00
|
|
|
* @return a PROJECT_TREE_ITEM pointer corresponding to item id aId
|
2010-02-20 13:20:55 +00:00
|
|
|
*/
|
2020-12-02 12:35:19 +00:00
|
|
|
PROJECT_TREE_ITEM* GetItemIdData( wxTreeItemId aId );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
private:
|
2013-01-03 19:25:12 +00:00
|
|
|
/**
|
|
|
|
* Called on a double click on an item
|
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onSelect( wxTreeEvent& Event );
|
2013-01-03 19:25:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on a click on the + or - button of an item with children
|
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onExpand( wxTreeEvent& Event );
|
2013-01-03 19:25:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on a right click on an item
|
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onRight( wxTreeEvent& Event );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function onOpenSelectedFileWithTextEditor
|
2019-07-17 10:57:12 +00:00
|
|
|
* Call the text editor to open the selected file in the tree project
|
2012-12-31 08:12:29 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onOpenSelectedFileWithTextEditor( wxCommandEvent& event );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function onDeleteFile
|
2019-08-28 16:01:06 +00:00
|
|
|
* Delete the selected file or directory in the tree project
|
2012-12-31 08:12:29 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onDeleteFile( wxCommandEvent& event );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function onRenameFile
|
2019-08-28 16:01:06 +00:00
|
|
|
* Rename the selected file or directory in the tree project
|
2012-12-31 08:12:29 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onRenameFile( wxCommandEvent& event );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2019-06-17 13:25:49 +00:00
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function onOpenDirectory
|
2019-07-17 10:57:12 +00:00
|
|
|
* Handles the right-click menu for opening a directory in the current system file browser
|
2019-06-17 13:25:49 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onOpenDirectory( wxCommandEvent& event );
|
2019-06-17 13:25:49 +00:00
|
|
|
|
2012-04-16 12:56:01 +00:00
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function onCreateNewDirectory
|
2019-07-17 10:57:12 +00:00
|
|
|
* Creates a new subdirectory inside the current kicad project directory the user is
|
|
|
|
* prompted to enter a directory name
|
2012-04-16 12:56:01 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onCreateNewDirectory( wxCommandEvent& event );
|
2010-02-19 15:01:32 +00:00
|
|
|
|
2018-06-21 15:05:08 +00:00
|
|
|
/**
|
2019-07-17 10:57:12 +00:00
|
|
|
* Switch to a other project selected from the tree project (by selecting an other .pro
|
|
|
|
* file inside the current project folder)
|
2018-06-21 15:05:08 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onSwitchToSelectedProject( wxCommandEvent& event );
|
2018-06-21 15:05:08 +00:00
|
|
|
|
2020-10-17 03:40:27 +00:00
|
|
|
/**
|
|
|
|
* Idle event handler, used process the selected items at a point in time
|
|
|
|
* when all other events have been consumed
|
|
|
|
*/
|
2021-11-14 15:01:00 +00:00
|
|
|
void onIdle( wxIdleEvent& aEvent );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We don't have uniform borders so we have to draw them ourselves.
|
|
|
|
*/
|
|
|
|
void onPaint( wxPaintEvent& aEvent );
|
2020-10-17 03:40:27 +00:00
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
/**
|
2021-05-20 15:52:49 +00:00
|
|
|
* Shutdown the file watcher. Used when closing to prevent post-free access into the project
|
|
|
|
* tree. (Using the destructor doesn't work as wxWidgets defers destruction in some cases.)
|
|
|
|
*/
|
|
|
|
void shutdownFileWatcher();
|
|
|
|
|
|
|
|
/**
|
2020-12-18 15:06:59 +00:00
|
|
|
* Function addItemToProjectTree
|
2012-04-16 12:56:01 +00:00
|
|
|
* @brief Add the file or directory aName to the project tree
|
|
|
|
* @param aName = the filename or the directory name to add in tree
|
2021-01-07 20:53:28 +00:00
|
|
|
* @param aParent = the wxTreeItemId item where to add sub tree items
|
2012-12-31 08:12:29 +00:00
|
|
|
* @param aRecurse = true to add file or subdir names to the current tree item
|
2010-02-20 13:20:55 +00:00
|
|
|
* false to stop file add.
|
2019-11-17 00:52:43 +00:00
|
|
|
* @return the Id for the new tree item
|
2010-02-20 13:20:55 +00:00
|
|
|
*/
|
2021-01-07 20:53:28 +00:00
|
|
|
wxTreeItemId addItemToProjectTree( const wxString& aName, const wxTreeItemId& aParent,
|
2020-12-22 13:51:32 +00:00
|
|
|
std::vector<wxString>* aProjectNames, bool aRecurse );
|
2012-12-31 08:12:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-07 19:49:14 +00:00
|
|
|
* Function findSubdirTreeItem
|
2019-07-17 10:57:12 +00:00
|
|
|
* searches for the item in tree project which is the node of the subdirectory aSubDir
|
2012-12-31 08:12:29 +00:00
|
|
|
* @param aSubDir = the directory to find in tree
|
2019-07-17 10:57:12 +00:00
|
|
|
* @return the opaque reference to the tree item; if not found, return an invalid tree item
|
|
|
|
* so that wxTreeItemId::IsOk() can be used to test the returned value
|
2012-12-31 08:12:29 +00:00
|
|
|
*/
|
|
|
|
wxTreeItemId findSubdirTreeItem( const wxString& aSubDir );
|
|
|
|
|
2013-01-01 14:06:49 +00:00
|
|
|
/**
|
|
|
|
* called when a file or directory is modified/created/deleted
|
2019-07-17 10:57:12 +00:00
|
|
|
* The tree project is modified when a file or directory is created/deleted/renamed to
|
|
|
|
* reflect the file change
|
2013-01-01 14:06:49 +00:00
|
|
|
*/
|
2020-12-18 15:06:59 +00:00
|
|
|
void onFileSystemEvent( wxFileSystemWatcherEvent& event );
|
|
|
|
|
2021-09-13 22:30:22 +00:00
|
|
|
void onThemeChanged( wxSysColourChangedEvent &aEvent );
|
|
|
|
|
2020-12-18 15:06:59 +00:00
|
|
|
public:
|
|
|
|
KICAD_MANAGER_FRAME* m_Parent;
|
|
|
|
PROJECT_TREE* m_TreeProject;
|
|
|
|
|
|
|
|
private:
|
2021-01-08 16:40:29 +00:00
|
|
|
bool m_isRenaming; // Are we in the process of renaming a file
|
2020-12-18 15:06:59 +00:00
|
|
|
wxTreeItemId m_root;
|
|
|
|
std::vector<wxString> m_filters;
|
2021-01-08 16:40:29 +00:00
|
|
|
wxFileSystemWatcher* m_watcher; // file system watcher
|
2020-12-18 15:06:59 +00:00
|
|
|
PROJECT_TREE_ITEM* m_selectedItem;
|
2021-01-08 16:40:29 +00:00
|
|
|
bool m_watcherNeedReset; // true if FileWatcherReset() must be called
|
|
|
|
// (during an idle time for instance) after
|
|
|
|
// the main loop event handler is started
|
2010-02-19 15:01:32 +00:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2012-12-31 08:12:29 +00:00
|
|
|
#endif // TREEPRJ_FRAME_H
|