|
22 | 22 | from core.gcmd import GError, GException
|
23 | 23 | from gui_core.forms import GUI
|
24 | 24 | from gui_core.treeview import CTreeView
|
| 25 | +from gui_core.wrap import SearchCtrl |
25 | 26 | from history.tree import HistoryBrowserTree
|
26 | 27 |
|
27 | 28 | from grass.pydispatch.signal import Signal
|
@@ -57,11 +58,23 @@ def __init__(
|
57 | 58 | lambda cmd: self.UpdateHistoryModelByCommand(cmd)
|
58 | 59 | )
|
59 | 60 |
|
| 61 | + self.search = SearchCtrl(self) |
| 62 | + self.search.SetDescriptiveText(_("Search")) |
| 63 | + self.search.ShowCancelButton(True) |
| 64 | + self.search.Bind(wx.EVT_TEXT, lambda evt: self.Filter(evt.GetString())) |
| 65 | + self.search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.Filter("")) |
| 66 | + |
60 | 67 | self._layout()
|
61 | 68 |
|
62 | 69 | def _layout(self):
|
63 | 70 | """Dialog layout"""
|
64 | 71 | sizer = wx.BoxSizer(wx.VERTICAL)
|
| 72 | + sizer.Add( |
| 73 | + self.search, |
| 74 | + proportion=0, |
| 75 | + flag=wx.ALL | wx.EXPAND, |
| 76 | + border=5, |
| 77 | + ) |
65 | 78 | sizer.Add(
|
66 | 79 | self._tree, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5
|
67 | 80 | )
|
@@ -90,6 +103,19 @@ def _getSelectedNode(self):
|
90 | 103 | def _refreshTree(self):
|
91 | 104 | self._tree.SetModel(self._model.GetModel())
|
92 | 105 |
|
| 106 | + def Filter(self, text): |
| 107 | + """Filter history |
| 108 | +
|
| 109 | + :param str text: text string |
| 110 | + """ |
| 111 | + model = self._model.GetModel() |
| 112 | + if text: |
| 113 | + model = self._model.model.Filtered(key=["command"], value=text) |
| 114 | + self._tree.SetModel(model) |
| 115 | + self._tree.ExpandAll() |
| 116 | + else: |
| 117 | + self._tree.SetModel(model) |
| 118 | + |
93 | 119 | def UpdateHistoryModelFromScratch(self):
|
94 | 120 | """Update the model from scratch and refresh the tree"""
|
95 | 121 | self._model.CreateModel()
|
|
0 commit comments