Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

grep: semi-functional for working directory scans

Changeset f34584e97aea

Parent c201d802f489

by Steve Borho

Changes to one file · Browse files at f34584e97aea Showing diff from parent c201d802f489 Diff from another changeset...

 
10
11
12
13
 
14
15
16
 
63
64
65
 
 
66
67
68
 
87
88
89
 
 
90
91
92
93
94
95
 
 
96
97
98
99
100
101
102
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
105
106
107
108
 
 
109
110
111
112
113
114
 
115
116
117
 
209
210
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
213
 
10
11
12
 
13
14
15
16
 
63
64
65
66
67
68
69
70
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
 
 
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
 
127
128
129
130
131
132
133
134
135
136
137
138
 
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
@@ -10,7 +10,7 @@
   from mercurial import ui, hg, error   -from tortoisehg.hgqt import htmlui, visdiff +from tortoisehg.hgqt import htmlui, visdiff, qtlib  from tortoisehg.util import paths, hglib  from tortoisehg.util.i18n import _   @@ -63,6 +63,8 @@
  tv.setRootIsDecorated(False)   tm = MatchModel()   tv.setModel(tm) + tv.setColumnHidden(COL_REVISION, True) + tv.setColumnHidden(COL_USER, True)   layout.addWidget(tv)   le.returnPressed.connect(self.searchActivated)   self.repo = repo @@ -87,31 +89,50 @@
  if not regexp:   return   self.le.selectAll() + searchre = re.compile(regexp, icase and re.I or 0) +   mode = self.cb.currentIndex()   if mode == 0:   ctx = self.repo[None]   elif mode == 1:   ctx = self.repo['.']   else: + self.tv.setColumnHidden(COL_REVISION, False) + self.tv.setColumnHidden(COL_USER, False)   # Full blown 'hg grep' call   # show revision, user columns   # hg grep [-i] -afn regexp   return   - # hide revision, user columns - # walk ctx.manifest, load file data, perform regexp, fill model - model.appendRow('path', 'line', 'rev', 'user', 'text') + self.tv.setColumnHidden(COL_REVISION, True) + self.tv.setColumnHidden(COL_USER, True) + hu = htmlui.htmlui() + # searching len(ctx.manifest()) files + for wfile in ctx: # walk manifest + data = ctx[wfile].data() # load file data + if '\0' in data: + continue + for i, line in enumerate(data.splitlines()): + pos = 0 + for m in searchre.finditer(line): # perform regexp + hu.write(line[pos:m.start()]) + hu.write(line[m.start():m.end()], label='grep.match') + pos = m.end() + if pos: + hu.write(line[pos:]) + model.appendRow(wfile, i, None, None, hu.getdata()[0])    COL_PATH = 0  COL_LINE = 1 -COL_REVISION = 2 # Hidden if wctx -COL_USER = 3 # Hidden if wctx +COL_REVISION = 2 # Hidden if ctx +COL_USER = 3 # Hidden if ctx  COL_TEXT = 4    class MatchTree(QTreeView):   def __init__(self, repo, parent=None):   QTreeView.__init__(self, parent)   self.repo = repo + self.setItemDelegate(HTMLDelegate(self))   self.setSelectionMode(QTreeView.ExtendedSelection)   self.setContextMenuPolicy(Qt.CustomContextMenu)   self.connect(self, SIGNAL('customContextMenuRequested(const QPoint &)'), @@ -209,5 +230,38 @@
  self.rows = []   self.endRemoveRows()   +class HTMLDelegate(QStyledItemDelegate): + def __init__(self, parent=0): + QStyledItemDelegate.__init__(self, parent) + + def paint(self, painter, option, index): + if index.column() != COL_TEXT: + return QStyledItemDelegate.paint(self, painter, option, index) + text = index.model().data(index, Qt.DisplayRole).toString() + palette = QApplication.palette() + doc = QTextDocument() + doc.setDefaultFont(option.font) + doc.setDefaultStyleSheet(qtlib.thgstylesheet) + painter.save() + if option.state & QStyle.State_Selected: + doc.setHtml('<font color=%s>%s</font>' % ( + palette.highlightedText().color().name(), text)) + bgcolor = palette.highlight().color() + painter.fillRect(option.rect, bgcolor) + else: + doc.setHtml(text) + painter.translate(option.rect.left(), option.rect.top()) + doc.drawContents(painter) + painter.restore() + + def sizeHint(self, option, index): + text = index.model().data(index, Qt.DisplayRole).toString() + doc = QTextDocument() + doc.setDefaultStyleSheet(qtlib.thgstylesheet) + doc.setDefaultFont(option.font) + doc.setHtml(text) + doc.setTextWidth(option.rect.width()) + return QSize(doc.idealWidth() + 5, doc.size().height()) +  def run(ui, *pats, **opts):   return SearchWidget()