1 /* 2 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3 3 * http://www.gnu.org/licenses/gpl-3.0.html 4 */ 5 6 #ifndef TODOLISTVIEW_H 7 #define TODOLISTVIEW_H 8 9 #include <wx/dynarray.h> // WX_DECLARE_OBJARRAY 10 #include <wx/string.h> 11 12 #include <vector> 13 #include <map> 14 15 #include "loggers.h" 16 17 class cbEditor; 18 class wxArrayString; 19 class wxCommandEvent; 20 class wxListEvent; 21 class wxComboBox; 22 class wxButton; 23 class wxPanel; 24 class wxStaticText; 25 26 // an item is one record in the file, such as a fixme, it can have several properties, such as 27 // the type (todo, note, fixme..), the user (who wrote the item) and the date, all its properties 28 // are wrappered in the ToDoItem struct 29 struct ToDoItem 30 { 31 wxString type; 32 wxString text; 33 wxString user; 34 wxString filename; 35 wxString lineStr; 36 wxString priorityStr; 37 wxString date; 38 int line; 39 int priority; 40 }; 41 // each source file can have several ToDoItems, so we use a Map structure to record all the items 42 typedef std::map<wxString,std::vector<ToDoItem> > TodoItemsMap; 43 WX_DECLARE_OBJARRAY(ToDoItem, ToDoItems); 44 45 // when user click the "Types" button on the Todo list control panel, it will show a dialog, the 46 // dialog can let user to filter which types will be shown in the Todo list. 47 class CheckListDialog : public wxDialog 48 { 49 public: 50 CheckListDialog( wxWindow* parent, 51 wxWindowID id = wxID_ANY, 52 const wxString& title = wxEmptyString, 53 const wxPoint& pos = wxDefaultPosition, 54 const wxSize& size = wxSize(150,180), 55 long style = 0 ); 56 ~CheckListDialog(); 57 58 virtual void OkOnButtonClick( wxCommandEvent& event ); 59 AddItem(const wxArrayString & items)60 void AddItem(const wxArrayString& items) { m_checkList->InsertItems(items, 0); } Clear()61 void Clear() { m_checkList->Clear(); } 62 63 bool IsChecked(const wxString& item) const; 64 wxArrayString GetChecked() const; 65 void SetChecked(const wxArrayString& items); 66 67 protected: 68 wxCheckListBox* m_checkList; 69 wxButton* m_okBtn; 70 71 private: 72 }; 73 74 // the list control to show all the todo items 75 class ToDoListView : public wxEvtHandler, public ListCtrlLogger 76 { 77 public: 78 ToDoListView(const wxArrayString& titles, const wxArrayInt& widths, const wxArrayString& types); 79 ~ToDoListView(); 80 virtual wxWindow* CreateControl(wxWindow* parent); 81 void DestroyControls(bool control); 82 83 // parse all the sources 84 void Parse(); 85 // if forced == true, we need to reparse the editor, otherwise, if the same editor, we do 86 // not rebuild the list 87 void ParseCurrent(bool forced); GetWindow()88 wxWindow* GetWindow() { return m_pPanel; } 89 90 CheckListDialog * m_pAllowedTypesDlg; 91 private: 92 93 // reset the user selection list 94 void LoadUsers(); 95 // Fill the list control by using the data in m_ItemsMap 96 void FillList(); 97 // sort the items (m_Items) 98 void SortList(); 99 // will only be called by FillList() 100 void FillListControl(); 101 102 103 // parse the specified editor 104 void ParseEditor(cbEditor* pEditor); 105 // parse the file on hard disk, if the file is opened in editor, then we should call ParseEditor 106 void ParseFile(const wxString& filename); 107 // this actually parse the buffer, and fill the items map 108 void ParseBuffer(const wxString& buffer, const wxString& filename); 109 // ensure the ith element of the list control is shown 110 void FocusEntry(size_t index); 111 112 113 // GUI event handler 114 // either source or user selection changed 115 void OnComboChange(wxCommandEvent& event); 116 // when a list item is selected (single click) 117 void OnListItemSelected(wxCommandEvent& event); 118 // refresh the list 119 void OnButtonRefresh(wxCommandEvent& event); 120 // select which types need to show 121 void OnButtonTypes(wxCommandEvent& event); 122 // user double click on the entry, or hit the Enter key on the keyboard 123 void OnDoubleClick( wxCommandEvent& event ); 124 // sort the column 125 void OnColClick( wxListEvent& event ); 126 127 wxWindow* m_pPanel; 128 // a map file->vector<Items> 129 TodoItemsMap m_ItemsMap; 130 // this is all the todo items need to show on the list control 131 ToDoItems m_Items; 132 133 // GUI 134 // show item's source, whether it show the current file's items, or current target's items 135 // or current project's items. 136 wxComboBox* m_pSource; 137 // user filter, we can show only the specified todo items belongs to a single user 138 wxComboBox* m_pUser; 139 wxStaticText* m_pTotal; 140 141 // type string array: such as todo, readme, note, fixme, and so on 142 const wxArrayString& m_Types; 143 144 wxString m_LastFile; 145 // if this variable is true, we don't actually do the parse (this avoid recursive parsing 146 // files) 147 bool m_Ignore; 148 bool m_SortAscending; 149 int m_SortColumn; 150 151 DECLARE_EVENT_TABLE() 152 }; 153 154 #endif // TODOLISTVIEW_H 155 156