1 /*************************************************************** 2 * Name: ThreadSearch 3 * Purpose: ThreadSearch Code::Blocks plugin 4 * Most of the interactions with C::B are handled here. 5 * Author: Jerome ANTOINE 6 * Created: 2007-10-08 7 * Copyright: Jerome ANTOINE 8 * License: GPL 9 **************************************************************/ 10 11 #ifndef THREAD_SEARCH_H 12 #define THREAD_SEARCH_H 13 14 #include <wx/string.h> 15 #include <wx/splitter.h> 16 17 #include <cbplugin.h> // for "class cbPlugin" 18 #include <globals.h> // for "ModuleType" 19 20 #include "ThreadSearchFindData.h" 21 #include "ThreadSearchViewManagerBase.h" 22 #include "ThreadSearchLoggerBase.h" 23 #include "InsertIndexManager.h" 24 25 class wxWindow; 26 class wxMenu; 27 class wxMenuBar; 28 class wxToolBar; 29 class wxLogWindow; 30 class wxComboBox; 31 class FileTreeData; 32 class wxCommandEvent; 33 class wxUpdateUIEvent; 34 35 class cbConfigurationPanel; 36 class cbProject; 37 38 class ThreadSearchView; 39 40 41 class ThreadSearch : public cbPlugin 42 { 43 public: 44 /** Constructor. */ 45 ThreadSearch(); 46 47 /** Destructor. */ 48 virtual ~ThreadSearch(); 49 50 /** Return the plugin's configuration priority. 51 * This is a number (default is 50) that is used to sort plugins 52 * in configuration dialogs. Lower numbers mean the plugin's 53 * configuration is put higher in the list. 54 */ GetConfigurationPriority()55 virtual int GetConfigurationPriority() const { return 50; } 56 57 /** Return the configuration group for this plugin. Default is cgUnknown. 58 * Notice that you can logically OR more than one configuration groups, 59 * so you could set it, for example, as "cgCompiler | cgContribPlugin". 60 */ GetConfigurationGroup()61 virtual int GetConfigurationGroup() const { return cgContribPlugin; } 62 63 /** Return plugin's configuration panel. 64 * @param parent The parent window. 65 * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller. 66 */ 67 virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent); 68 69 /** Return plugin's configuration panel for projects. 70 * The panel returned from this function will be added in the project's 71 * configuration dialog. 72 * @param parent The parent window. 73 * @param project The project that is being edited. 74 * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller. 75 */ GetProjectConfigurationPanel(wxWindow * WXUNUSED (parent),cbProject * WXUNUSED (project))76 virtual cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* WXUNUSED(parent), cbProject* WXUNUSED(project)){ return 0; } 77 78 /** This method is called by Code::Blocks and is used by the plugin 79 * to add any menu items it needs on Code::Blocks's menu bar.\n 80 * It is a pure virtual method that needs to be implemented by all 81 * plugins. If the plugin does not need to add items on the menu, 82 * just do nothing ;) 83 * @param menuBar the wxMenuBar to create items in 84 */ 85 virtual void BuildMenu(wxMenuBar* menuBar); 86 87 /** This method is called by Code::Blocks core modules (EditorManager, 88 * ProjectManager etc) and is used by the plugin to add any menu 89 * items it needs in the module's popup menu. For example, when 90 * the user right-clicks on a project file in the project tree, 91 * ProjectManager prepares a popup menu to display with context 92 * sensitive options for that file. Before it displays this popup 93 * menu, it asks all attached plugins (by asking PluginManager to call 94 * this method), if they need to add any entries 95 * in that menu. This method is called.\n 96 * If the plugin does not need to add items in the menu, 97 * just do nothing ;) 98 * @param type the module that's preparing a popup menu 99 * @param pMenu pointer to the popup menu 100 * @param data pointer to FileTreeData object (to access/modify the file tree) 101 */ 102 virtual void BuildModuleMenu(const ModuleType type, wxMenu* pMenu, const FileTreeData* data = 0); 103 104 /** This method is called by Code::Blocks and is used by the plugin 105 * to add any toolbar items it needs on Code::Blocks's toolbar.\n 106 * It is a pure virtual method that needs to be implemented by all 107 * plugins. If the plugin does not need to add items on the toolbar, 108 * just do nothing ;) 109 * @param toolBar the wxToolBar to create items on 110 * @return The plugin should return true if it needed the toolbar, false if not 111 */ 112 virtual bool BuildToolBar(wxToolBar* toolBar); 113 114 /** This method is called to update observers. 115 * The pattern has not been implemented as there is only one observer 116 * (the ThreadSearchView) that already holds a reference on the plugin. 117 */ 118 void Notify(); 119 120 // Setters SetCtxMenuIntegration(bool ctxMenuIntegration)121 void SetCtxMenuIntegration(bool ctxMenuIntegration) {m_CtxMenuIntegration = ctxMenuIntegration;} SetUseDefValsForThreadSearch(bool useDefVals)122 void SetUseDefValsForThreadSearch(bool useDefVals) {m_UseDefValsForThreadSearch = useDefVals;} SetShowSearchControls(bool showSearchControls)123 void SetShowSearchControls(bool showSearchControls) {m_ShowSearchControls = showSearchControls;} SetShowDirControls(bool showDirControls)124 void SetShowDirControls(bool showDirControls) {m_ShowDirControls = showDirControls;} SetShowCodePreview(bool showCodePreview)125 void SetShowCodePreview(bool showCodePreview) {m_ShowCodePreview = showCodePreview;} SetDeletePreviousResults(bool deletePreviousResults)126 void SetDeletePreviousResults(bool deletePreviousResults) {m_DeletePreviousResults = deletePreviousResults;} SetDisplayLogHeaders(bool displayLogHeaders)127 void SetDisplayLogHeaders(bool displayLogHeaders) {m_DisplayLogHeaders = displayLogHeaders;} SetDrawLogLines(bool drawLogLines)128 void SetDrawLogLines(bool drawLogLines) {m_DrawLogLines = drawLogLines;} SetAutosizeLogColumns(bool autosizeLogColumns)129 void SetAutosizeLogColumns(bool autosizeLogColumns) {m_AutosizeLogColumns = autosizeLogColumns;} SetFindData(const ThreadSearchFindData & findData)130 void SetFindData(const ThreadSearchFindData& findData) {m_FindData = findData;} 131 132 void SetManagerType (ThreadSearchViewManagerBase::eManagerTypes mgrType); SetLoggerType(ThreadSearchLoggerBase::eLoggerTypes lgrType)133 void SetLoggerType (ThreadSearchLoggerBase::eLoggerTypes lgrType) {m_LoggerType = lgrType;} SetSplitterMode(wxSplitMode splitterMode)134 void SetSplitterMode(wxSplitMode splitterMode) {m_SplitterMode = splitterMode;} SetFileSorting(InsertIndexManager::eFileSorting fileSorting)135 void SetFileSorting (InsertIndexManager::eFileSorting fileSorting) {m_FileSorting = fileSorting;} 136 137 // Getters GetCtxMenuIntegration()138 bool GetCtxMenuIntegration() const {return m_CtxMenuIntegration;} GetUseDefValsForThreadSearch()139 bool GetUseDefValsForThreadSearch() const {return m_UseDefValsForThreadSearch;} GetShowSearchControls()140 bool GetShowSearchControls() const {return m_ShowSearchControls;} GetShowDirControls()141 bool GetShowDirControls() const {return m_ShowDirControls;} GetShowCodePreview()142 bool GetShowCodePreview() const {return m_ShowCodePreview;} GetDeletePreviousResults()143 bool GetDeletePreviousResults() const {return m_DeletePreviousResults;} GetDisplayLogHeaders()144 bool GetDisplayLogHeaders() const {return m_DisplayLogHeaders;} GetDrawLogLines()145 bool GetDrawLogLines() const {return m_DrawLogLines;} GetAutosizeLogColumns()146 bool GetAutosizeLogColumns() const {return m_AutosizeLogColumns;} GetFindData(ThreadSearchFindData & findData)147 void GetFindData(ThreadSearchFindData& findData) const {findData = m_FindData;} GetFindData()148 ThreadSearchFindData& GetFindData() {return m_FindData;} GetManagerType()149 ThreadSearchViewManagerBase::eManagerTypes GetManagerType() const {return m_pViewManager->GetManagerType();} GetLoggerType()150 ThreadSearchLoggerBase::eLoggerTypes GetLoggerType() const {return m_LoggerType;} GetSplitterMode()151 long GetSplitterMode() const {return m_SplitterMode;} GetFileSorting()152 InsertIndexManager::eFileSorting GetFileSorting() const {return m_FileSorting;} 153 154 /** This method runs a threaded search for text param. 155 * @param text : text to look after 156 * @param isCtxSearch : bool that tells if it is a ctx search 157 * to set, if necessary, the default ctx search options 158 */ 159 void RunThreadSearch(const wxString& text, bool isCtxSearch = false); 160 161 /** This method is a callback called by ThreadSearchView destructor. 162 * Either view is destroyed by C::B InfoPane if plugin is used in 163 * the Messages Notebook or by plugin instance if view is not displayed 164 * or used in the layout. 165 */ 166 void OnThreadSearchViewDestruction(); 167 168 /** This method shows/hide the ThreadSearch toolbar. 169 * @param show : show = true/hide = false toolbar 170 */ 171 void ShowToolBar(bool show); 172 173 /** Method used to know is toolbar is visible. */ 174 bool IsToolbarVisible(); 175 176 wxLogWindow* m_pLog; //(pecan 2007/7/26) 177 178 protected: 179 /** Any descendent plugin should override this virtual method and 180 * perform any necessary initialization. This method is called by 181 * Code::Blocks (PluginManager actually) when the plugin has been 182 * loaded and should attach in Code::Blocks. When Code::Blocks 183 * starts up, it finds and <em>loads</em> all plugins but <em>does 184 * not</em> activate (attaches) them. It then activates all plugins 185 * that the user has selected to be activated on start-up.\n 186 * This means that a plugin might be loaded but <b>not</b> activated...\n 187 * Think of this method as the actual constructor... 188 */ 189 virtual void OnAttach(); 190 191 /** Any descendent plugin should override this virtual method and 192 * perform any necessary de-initialization. This method is called by 193 * Code::Blocks (PluginManager actually) when the plugin has been 194 * loaded, attached and should de-attach from Code::Blocks.\n 195 * Think of this method as the actual destructor... 196 * @param appShutDown If true, the application is shutting down. In this 197 * case *don't* use Manager::Get()->Get...() functions or the 198 * behaviour is undefined... 199 */ 200 virtual void OnRelease(bool appShutDown); 201 202 /** This method loads the plugin configuration from default.conf using 203 * the standard ConfigManager 204 * @param showPanel : reference that will be true after the call if 205 * the panel is managed by the MessageManager during last save. 206 * @param sashPosition : position of the splitter window. 207 * @param mgrType : type of view manager (Messages notebook, layout) 208 * @param searchPatterns : - undocumented - 209 * @param searchDirs : - undocumented - 210 * @param searchMasks : - undocumented - 211 */ 212 virtual void LoadConfig(bool &showPanel, int &sashPosition, 213 ThreadSearchViewManagerBase::eManagerTypes& mgrType, 214 wxArrayString& searchPatterns, wxArrayString& searchDirs, 215 wxArrayString& searchMasks); 216 217 /** This method saves the plugin configuration to default.conf using 218 * the standard ConfigManager 219 * @param showPanel : boolean telling if ThreadSearch panel is managed 220 * by the MessageManager. 221 * @param sashPosition : position of the splitter window. 222 * @param searchPatterns : - undocumented - 223 * @param searchDirs : - undocumented - 224 * @param searchMasks : - undocumented - 225 */ 226 virtual void SaveConfig(bool showPanel, int sashPosition, 227 ThreadSearchViewManagerBase::eManagerTypes mgrType, 228 const wxArrayString& searchPatterns, const wxArrayString& searchDirs, 229 const wxArrayString& searchMasks); 230 231 private: 232 /** Event handler called when user clicks on the 'Thread search' 233 * item of the 'View' menu. 234 */ 235 void OnMnuViewThreadSearch(wxCommandEvent& event); 236 237 /** Event handler called when user clicks on the 'Thread Search' 238 * item of the 'Search' menu. 239 */ 240 void OnMnuSearchThreadSearch(wxCommandEvent& event); 241 242 /** Event handler called when user clicks on the 'Focus Thread Search' 243 * item of the 'View' menu. 244 */ 245 void OnMnuViewFocusThreadSearch(wxCommandEvent& event); 246 247 /** Event handler called when user clicks on the 'Find occurrences of' 248 * item of the contextual menu. 249 */ 250 void OnCtxThreadSearch(wxCommandEvent& event); 251 252 /** Event handler called to update the 'Thread search' 253 * item of the View menu. Checked if 'Thread search' panel 254 * is present in the message notebook. 255 */ 256 void OnMnuViewThreadSearchUpdateUI(wxUpdateUIEvent& event); 257 258 /** Event handler called to update the 'Thread search' 259 * item of the 'Search' menu. 260 */ 261 void OnMnuSearchThreadSearchUpdateUI(wxUpdateUIEvent& event); 262 263 void OnMnuViewFocusThreadSearchUpdateUI(wxUpdateUIEvent& event); 264 265 // Toolbar controls events management 266 void OnBtnOptionsClick(wxCommandEvent& event); 267 void OnBtnSearchClick (wxCommandEvent& event); 268 void OnCboSearchExprEnter(wxCommandEvent &event); 269 270 /** Removes the 'Thread search' item added in BuildMenu method. 271 */ 272 void RemoveMenuItems(); 273 274 /** Internal Method refactored from BuildMenu 275 */ 276 static bool GetCursorWord(wxString& sWord); 277 278 /** Adds the 'Find occurrences of' at the right place, ie just after 279 * the 'Find implementation' item if possible 280 */ 281 int GetInsertionMenuIndex(const wxMenu* const pCtxMenu); 282 283 // The following method are there to make it possible to copy 284 // and paste from and to view graphical widgets. 285 void OnMnuEditCopy(wxCommandEvent& event); 286 void OnMnuEditCopyUpdateUI(wxUpdateUIEvent& event); 287 void OnMnuEditPaste(wxCommandEvent& event); 288 289 290 // Member variables 291 wxString m_SearchedWord; // Word under cursor on right click 292 ThreadSearchFindData m_FindData; // Search structure containing all useful inforamtions 293 ThreadSearchView* m_pThreadSearchView; // Panel added to Messages notebook 294 ThreadSearchViewManagerBase* m_pViewManager; // View manager. Used to add, remove, show and hide view. 295 // Used on a derived class (message notebook or layout manager). 296 wxToolBar* m_pToolbar; // Panel added to Messages notebook 297 bool m_CtxMenuIntegration; // Tells if 'Find occurrences' item must be present in contextual menu 298 bool m_UseDefValsForThreadSearch; // Tells if default values (whole word = true, match case = true) 299 // are used for 'Find occurrences' ctx menu command 300 bool m_ShowSearchControls; // True if user wants to use message tab controls 301 bool m_ShowDirControls; // True if user wants to display directory specific controls 302 bool m_ShowCodePreview; // True if user wants to benefit from code preview 303 bool m_DeletePreviousResults; // True if logger contents is deleted at search begin 304 ThreadSearchLoggerBase::eLoggerTypes m_LoggerType; // Logger type, can be a list or a tree 305 bool m_DisplayLogHeaders; // Show/Hide column headers in wxListCtrl logger 306 bool m_DrawLogLines; // Draw lines between columns in wxListCtrl logger 307 /// Automatically resize columns in wxListCtrl logger after search is finished. 308 bool m_AutosizeLogColumns; 309 bool m_OnReleased; // For multiple simultaneous calls of OnRelease 310 wxComboBox* m_pCboSearchExpr; 311 wxSplitMode m_SplitterMode; // Sets vertical or horizontal display for code 312 // preview and search results (logger) 313 InsertIndexManager::eFileSorting m_FileSorting; // Sorts file by name or by path 314 315 DECLARE_EVENT_TABLE(); 316 }; 317 318 #endif // THREAD_SEARCH_H 319