1
/***************************************************************
2
* Name: ThreadSearchView
3
* Purpose: This class implements the panel that is added to
4
* Code::Blocks Message notebook or layout.
5
* It runs the search worker thread and receives
6
* ThreadSearchEvent from it to update the list log.
7
* Author: Jerome ANTOINE
9
* Copyright: Jerome ANTOINE
11
**************************************************************/
13
#ifndef THREAD_SEARCH_VIEW_H
14
#define THREAD_SEARCH_VIEW_H
16
#include <wx/string.h>
17
#include <wx/thread.h>
19
#include <wx/dynarray.h>
20
#include <wx/datetime.h>
22
#include <wx/arrstr.h>
24
#include "editormanager.h"
25
#include "cbproject.h"
26
#include "projectmanager.h"
28
#include "ThreadSearchLoggerBase.h"
35
class cbStyledTextCtrl;
39
class wxSplitterEvent;
40
class wxScintillaEvent;
41
class wxContextMenuEvent;
42
class wxSplitterWindow;
43
class wxStaticBoxSizer;
47
class ThreadSearchEvent;
48
class ThreadSearchThread;
49
class ThreadSearchFindData;
51
class DirectoryParamsPanel;
54
class ThreadSearchView: public wxPanel {
56
friend class ThreadSearch;
58
// begin wxGlade: ThreadSearchView::ids
62
ThreadSearchView( ThreadSearch& threadSearchPlugin);
69
/** Runs the worker thread search.
70
* @param aFindData : structure containing all search parameters :
71
* text, whole word, case, directory...
73
void ThreadedSearch(const ThreadSearchFindData& aFindData);
76
* @return true if a search is running, false otherwise
78
bool IsSearchRunning();
80
/** This function is called from ThreadSearchThread::OnExit.
81
* This must not be called directly.
85
/** Makes instance update its graphical widgets.
86
* Should be called by ThreadSearch instance after m_ThreadSearchPlugin modification
90
/** Loads file in code preview and makes line visible.
91
* @param file : file path
92
* @param line : line to display in the preview editor
93
* @return true if success
95
bool UpdatePreview(const wxString& file, long line);
97
/** Sets/gets the splitter window sash position. */
98
void SetSashPosition(int position, const bool redraw = true);
99
int GetSashPosition() const;
101
/** Sets/gets the search history */
102
void SetSearchHistory(const wxArrayString& searchPatterns);
103
wxArrayString GetSearchHistory() const;
106
* Sets the logger type. If value is different from current one,
107
* m_pLogger is destroyed and rebuilt on the fly.
108
* @param lgrType : type of logger, can be a wxListCtrl or a wxTreeCtrl
110
void SetLoggerType(ThreadSearchLoggerBase::eLoggerTypes lgrType);
112
/** PostThreadSearchEvent
113
* @param event : event sent by the worker thread (ThreadSearchThread)
114
* Thread safe mechanism. Clone the worker thread event to the mutex protected events array.
116
void PostThreadSearchEvent(const ThreadSearchEvent& event);
119
* C::B plugins manager provides a toolbar instance to ThreadSearch instance
120
* during init. This instance is referenced in ThreadSearchView by m_pToolBar.
122
void SetToolBar(wxToolBar* pToolBar) {m_pToolBar = pToolBar;}
124
/** This method shows/hide the search graphical controls.
125
* @param show : show = true/hide = false toolbar
127
void ShowSearchControls(bool show);
129
/** This method applies splitter settings
130
* @param showCodePreview : show = true/hide = false preview editor (=~ splitted or not)
131
* @param splitterMode : wxSPLIT_HORIZONTAL or wxSPLIT_VERTICAL
133
void ApplySplitterSettings(bool showCodePreview, long splitterMode);
134
ThreadSearch* GetThreadSearchPlugin(){return &m_ThreadSearchPlugin;} //(pecan 2008/4/11)
137
// begin wxGlade: ThreadSearchView::methods
138
void set_properties();
142
/** ClearThreadSearchEventsArray
143
* Removes all events sent by the worker thread and stored in the array.
144
* Thread safe method.
145
@return true if clear successful. Not successful if Mutex is not caught.
147
bool ClearThreadSearchEventsArray();
150
* Called to stop the thread and manage all required operations.
151
* @return true if successful.
155
// BEGIN Duplicated from cbeditor.cpp to apply folding options
156
void SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back);
157
void UnderlineFoldedLines(bool underline);
158
void SetFoldingIndicator(int id);
159
// END Duplicated from cbeditor.cpp to apply folding options
161
ThreadSearchThread* m_pFindThread; // Worker thread pointer. Must be allocated on the heap.
162
ThreadSearch& m_ThreadSearchPlugin; // Thread search plugin reference. 'Subject' in the observer pattern.
163
wxString m_PreviewFilePath; // File currently previewed path. Used to avoid reloading files.
164
wxDateTime m_PreviewFileDate; // File currently previewed modification time. Used to avoid reloading files.
166
wxMutex m_MutexSearchEventsArray; // Mutex used for multi thread access to m_ThreadSearchEventsArray
167
wxArrayPtrVoid m_ThreadSearchEventsArray; // Used to store events sent by the worker thread.
168
wxTimer m_Timer; // Used for events update
169
long m_StoppingThread; // Used not to do more than one thread termination.
171
bool m_bNotebookSizerSet; // sizer added for wxAuiNotebook
172
wxWindow* m_pParent; // parent window/frame //(pecan 2008/4/03)
173
wxFrame* m_pTSFrame; // ThreadSearchFrame pointer
176
// Graphical widgets managed by wxGlade
177
// begin wxGlade: ThreadSearchView::attributes
178
wxStaticBox* m_pSizerSearchDirItems_staticbox;
179
wxComboBox* m_pCboSearchExpr;
180
wxButton* m_pBtnSearch;
181
wxButton* m_pBtnOptions;
182
//?wxStaticText* m_pStaTxtSearchIn;
183
//?SearchInPanel* m_pPnlSearchIn;
184
wxButton* m_pBtnShowDirItems;
185
DirectoryParamsPanel* m_pPnlDirParams;
186
cbStyledTextCtrl* m_pSearchPreview;
187
wxPanel* m_pPnlPreview;
188
ThreadSearchLoggerBase* m_pLogger;
189
wxPanel* m_pPnlListLog;
190
wxSplitterWindow* m_pSplitter;
192
wxStaticBoxSizer* m_pSizerSearchDirItems;
193
wxBoxSizer* m_pSizerSearchItems;
194
wxToolBar* m_pToolBar;
196
DECLARE_EVENT_TABLE()
198
/** AddExpressionToSearchCombos
199
* Inserts expression to search combo in first position.
200
* If expression is already listed, it is removed before insertion.
201
* Used to keep the search history in the combo box.
202
* @param expression : searched text.
204
void AddExpressionToSearchCombos(const wxString& expression);
206
/// enum defining the possible labels to update Search buttons (view and toolbars)
207
/// Undefined can be used to skip label update
208
enum eSearchButtonLabel {
214
/** UpdateSearchButtons
215
* Updates wxButtons and wxBitmap buttons according to new label.
216
* @param enable : true : enable; false : disable
217
* @param label : see eSearchButtonLabel declaration
219
void UpdateSearchButtons(bool enable, eSearchButtonLabel label = skip);
221
/** Method used to enable/disable the graphical widgets related
222
* to search parameters. Disabled when thread is running.
223
* @param enable : true : enable; false : disable
225
void EnableControls(bool enable);
228
void OnThreadSearchErrorEvent(const ThreadSearchEvent& event);
229
void OnCboSearchExprEnter(wxCommandEvent &event); // wxGlade: <event_handler>
230
void OnBtnSearchClick(wxCommandEvent &event); // wxGlade: <event_handler>
231
void OnBtnOptionsClick(wxCommandEvent &event); // wxGlade: <event_handler>
232
void OnBtnShowDirItemsClick(wxCommandEvent &event); // wxGlade: <event_handler>
233
void OnSplitterDoubleClick(wxSplitterEvent &event); // wxGlade: <event_handler>
235
void OnMarginClick(wxScintillaEvent& event);
236
void OnContextMenu(wxContextMenuEvent& event);
237
void OnLoggerClick (const wxString& file, long line); // Called by ThreadSearchLoggerBase derived instance
238
// when user clicks on a search result
239
void OnLoggerDoubleClick(const wxString& file, long line); // Called by ThreadSearchLoggerBase derived instance
240
// when user double clicks on a search result
242
void OnChkSearchOpenFiles(wxCommandEvent &event);
243
void OnChkSearchSnippetFiles(wxCommandEvent &event);
244
void OnChkSearchWorkspaceFiles(wxCommandEvent &event);
245
void OnChkSearchDirectoryFiles(wxCommandEvent &event);
246
void OnChkSearchDirRecurse(wxCommandEvent &event);
247
void OnChkSearchDirHidden(wxCommandEvent &event);
249
void OnTxtSearchMaskTextEvent(wxCommandEvent &event);
250
void OnTxtSearchDirPathTextEvent(wxCommandEvent &event);
252
void OnTmrListCtrlUpdate(wxTimerEvent& event);
254
}; // wxGlade: end class
257
#endif // THREAD_SEARCH_VIEW_H