1 #ifndef FILEEXPLORER_H 2 #define FILEEXPLORER_H 3 4 #include <wx/wx.h> 5 #include <wx/treectrl.h> 6 #include <wx/combobox.h> 7 #include <wx/dynarray.h> 8 9 #include <memory> 10 #include <vector> 11 #include "FileExplorerSettings.h" 12 #include "FileExplorerUpdater.h" 13 #include "directorymonitor.h" 14 15 class UpdateQueue; 16 17 class Expansion; 18 19 typedef std::vector<Expansion*> ExpList; 20 21 class VCSstate 22 { 23 public: 24 int state; 25 wxString path; 26 }; 27 28 WX_DECLARE_OBJARRAY(VCSstate, VCSstatearray); 29 30 class Expansion 31 { 32 public: Expansion()33 Expansion() { name = _T("");} ~Expansion()34 ~Expansion() {for(size_t i=0;i<children.size();i++) delete children[i];} 35 wxString name; 36 ExpList children; 37 }; 38 39 class wxFEDropTarget; 40 41 42 class FileTreeCtrl: public wxTreeCtrl 43 { 44 public: //wxTR_HIDE_ROOT| 45 FileTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, 46 const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS|wxTR_MULTIPLE|wxTR_NO_LINES, 47 const wxValidator& validator = wxDefaultValidator, 48 const wxString& name = _T("treeCtrl")); 49 FileTreeCtrl(); 50 FileTreeCtrl(wxWindow *parent); 51 void OnKeyDown(wxKeyEvent &e); 52 // void OnActivate(wxTreeEvent &event); 53 virtual ~FileTreeCtrl(); 54 // void SortChildren(const wxTreeItemId& ti); 55 protected: 56 virtual int OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2); 57 DECLARE_DYNAMIC_CLASS(FileTreeCtrl) 58 DECLARE_EVENT_TABLE() 59 }; 60 61 class FileExplorer: public wxPanel 62 { 63 friend class FileExplorerUpdater; 64 friend class VCSFileLoader; 65 friend class wxFEDropTarget; 66 public: 67 FileExplorer(wxWindow *parent,wxWindowID id = wxID_ANY, 68 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, 69 long style = wxTAB_TRAVERSAL|wxTE_PROCESS_ENTER, const wxString& name = _T("Files")); 70 ~FileExplorer(); 71 bool SetRootFolder(wxString root); GetRootFolder()72 wxString GetRootFolder() {return m_root;} FindFile(const wxString &)73 void FindFile(const wxString &/*file*/) {} 74 void MoveFiles(const wxString &destination, const wxArrayString &selectedfiles); 75 void CopyFiles(const wxString &destination, const wxArrayString &selectedfiles); 76 77 private: 78 // User initiated events 79 bool IsBrowsingVCSTree(); 80 bool IsBrowsingWorkingCopy(); 81 void OnRightClick(wxTreeEvent &event); 82 void OnActivate(wxTreeEvent &event); 83 void OnExpand(wxTreeEvent &event); 84 void OnEnterLoc(wxCommandEvent &event); 85 void OnEnterWild(wxCommandEvent &event); 86 void OnVCSControl(wxCommandEvent &event); 87 void OnVCSChangesCheck(wxCommandEvent &event); 88 void OnChooseLoc(wxCommandEvent &event); 89 void OnChooseWild(wxCommandEvent &event); 90 void OnSetLoc(wxCommandEvent &event); 91 void OnNewFile(wxCommandEvent &event); 92 void OnOpenInEditor(wxCommandEvent &event); 93 void DoOpenInEditor(const wxString &filename); 94 void OnVCSFileLoaderComplete(wxCommandEvent &event); 95 void OnNewFolder(wxCommandEvent &event); 96 void OnAddFavorite(wxCommandEvent &event); 97 void OnCopy(wxCommandEvent &event); 98 void OnDuplicate(wxCommandEvent &event); 99 void OnMove(wxCommandEvent &event); 100 void OnDelete(wxCommandEvent &event); 101 void OnRename(wxCommandEvent &event); 102 void OnExpandAll(wxCommandEvent &event); 103 void OnCollapseAll(wxCommandEvent &event); 104 void OnSettings(wxCommandEvent &event); 105 void OnShowHidden(wxCommandEvent &event); 106 void OnParseCVS(wxCommandEvent &event); 107 void OnParseSVN(wxCommandEvent &event); 108 void OnParseHG(wxCommandEvent &event); 109 void OnParseBZR(wxCommandEvent &event); 110 void OnParseGIT(wxCommandEvent &event); 111 void OnUpButton(wxCommandEvent &event); 112 void OnRefresh(wxCommandEvent &event); 113 void OnVCSDiff(wxCommandEvent &event); 114 void OnBeginDragTreeItem(wxTreeEvent &event); 115 void OnEndDragTreeItem(wxTreeEvent &event); 116 void OnKeyDown(wxKeyEvent &event); 117 118 void OnAddToProject(wxCommandEvent &event); 119 120 // Events related to updating the Tree 121 void OnDirMonitor(wxDirectoryMonitorEvent &e); 122 void OnUpdateTreeItems(wxCommandEvent &event); 123 void OnTimerCheckUpdates(wxTimerEvent &event); 124 125 void UpdateAbort(); 126 void ResetDirMonitor(); 127 128 void WriteConfig(); 129 void ReadConfig(); 130 131 wxArrayString GetSelectedPaths(); 132 bool IsFilesOnly(wxArrayTreeItemIds tis); 133 void FindFile(const wxString &findfilename, const wxTreeItemId &ti); 134 void FocusFile(const wxTreeItemId &ti); 135 bool IsInSelection(const wxTreeItemId &ti); 136 wxString GetFullPath(const wxTreeItemId &ti); 137 bool GetItemFromPath(const wxString &path, wxTreeItemId &ti); 138 void GetExpandedNodes(wxTreeItemId ti, Expansion *exp); 139 void GetExpandedPaths(wxTreeItemId ti, wxArrayString &paths); 140 wxTreeItemId GetNextExpandedNode(wxTreeItemId ti); 141 bool ValidateRoot(); 142 void Refresh(wxTreeItemId ti); 143 void RefreshExpanded(wxTreeItemId ti); 144 wxString m_root; 145 wxString m_commit; 146 FileTreeCtrl *m_Tree; //the widget display the file tree from root defined by m_Loc 147 std::unique_ptr<wxImageList> m_TreeImages; 148 wxComboBox *m_Loc; // the combo box maintaining a list of useful locations and the current location 149 wxComboBox *m_WildCards; // the combo box maintaining a list of wildcard filters for files 150 wxButton *m_UpButton; 151 wxBoxSizer *m_Box_VCS_Control; 152 wxChoice *m_VCS_Control; 153 wxStaticText *m_VCS_Type; 154 wxCheckBox *m_VCS_ChangesOnly; 155 bool m_show_hidden; 156 wxArrayTreeItemIds m_selectti; //contains selections after context menu is called up 157 FavoriteDirs m_favdirs; 158 159 //State information required for updating the Tree in a background thread 160 wxTimer *m_updatetimer; 161 FileExplorerUpdater *m_updater; 162 bool m_updater_cancel; 163 bool m_update_expand; 164 wxTreeItemId m_updating_node; 165 wxTreeItemId m_updated_node; 166 bool m_update_active; 167 UpdateQueue *m_update_queue; 168 wxDirectoryMonitor *m_dir_monitor; 169 wxFEDropTarget *m_droptarget; 170 171 int m_ticount; //number of selections 172 wxString m_dragtest; 173 size_t m_findmatchcount; 174 wxArrayString m_findmatch; 175 176 LoaderQueue m_vcs_file_loader_queue; 177 VCSFileLoader *m_vcs_file_loader; 178 179 bool m_parse_cvs; 180 bool m_parse_svn; 181 bool m_parse_hg; 182 bool m_parse_bzr; 183 bool m_parse_git; 184 bool m_kill; 185 DECLARE_EVENT_TABLE() 186 }; 187 188 //wxPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = "panel") 189 190 //wxTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS, const wxValidator& validator = wxDefaultValidator, const wxString& name = "treeCtrl") 191 192 #endif // FILEEXPLORER_H 193 194