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

annotate: give special context menu for selected text

offer to search for the selected text in...
* originating revision
* working parent revision
* all history
* current annotation text

All but the last should open a new grep window, but grep is
not yet ready to receive arguments like these.

Changeset 6f1f4cabfa33

Parent df51f9db28fa

by Steve Borho

Changes to one file · Browse files at 6f1f4cabfa33 Showing diff from parent df51f9db28fa Diff from another changeset...

 
91
92
93
 
 
94
95
96
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101
102
 
132
133
134
 
 
 
 
 
 
 
 
135
136
137
 
248
249
250
251
 
252
253
254
255
256
257
258
 
259
260
261
262
263
264
 
265
266
267
 
316
317
318
 
 
 
 
 
319
320
321
 
360
361
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
364
365
366
367
368
369
 
370
371
372
373
 
 
 
 
 
 
 
374
375
376
 
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
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
283
284
285
 
286
287
288
289
290
291
292
 
293
294
295
296
297
298
 
299
300
301
302
 
351
352
353
354
355
356
357
358
359
360
361
 
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
 
 
427
428
429
430
 
431
432
433
434
435
436
437
438
439
440
@@ -91,12 +91,39 @@
    def customContextMenuRequested(self, point):   cursor = self.cursorForPosition(point) + point = self.mapToGlobal(point) +   line = cursor.block()   if not line.isValid() or line.blockNumber() >= len(self.revs):   return - point = self.mapToGlobal(point)   fctx, line = self.links[line.blockNumber()]   data = [fctx.path(), fctx.linkrev(), line] + + # check if the user has opened a menu on a text selection + c = self.textCursor() + if cursor.position() >= c.selectionStart() and \ + cursor.position() <= c.selectionEnd(): + selection = c.selection().toPlainText() + def sorig(): + sdata = [selection, fctx.linkrev()] + self.emit(SIGNAL('searchAtRev'), sdata) + def sctx(): + self.emit(SIGNAL('searchAtParent'), selection) + def searchall(): + self.emit(SIGNAL('searchAll'), selection) + def sann(): + self.emit(SIGNAL('searchAnnotation'), selection) + menu = QMenu(self) + menu = QMenu(self) + for name, func in [(_('Search in original revision'), sorig), + (_('Search in working revision'), sctx), + (_('Search in current annotation'), sann), + (_('Search in history'), searchall)]: + action = menu.addAction(name) + action.wrapper = lambda f=func: f() + self.connect(action, SIGNAL('triggered()'), action.wrapper) + return menu.exec_(point) +   def annorig():   self.emit(SIGNAL('revSelected'), data)   def editorig(): @@ -132,6 +159,14 @@
  lambda data: self.emit(SIGNAL('revSelected'), data))   self.connect(self.edit, SIGNAL('editSelected'),   lambda data: self.emit(SIGNAL('editSelected'), data)) + self.connect(self.edit, SIGNAL('searchAtRev'), + lambda data: self.emit(SIGNAL('searchAtRev'), data)) + self.connect(self.edit, SIGNAL('searchAtParent'), + lambda pattern: self.emit(SIGNAL('searchAtParent'), pattern)) + self.connect(self.edit, SIGNAL('searchAll'), + lambda pattern: self.emit(SIGNAL('searchAll'), pattern)) + self.connect(self.edit, SIGNAL('searchAnnotation'), + lambda pattern: self.emit(SIGNAL('searchAnnotation'), pattern))     hbox = QHBoxLayout(self)   hbox.setSpacing(10) @@ -248,20 +283,20 @@
  self.curmatch -= 1   self.edit.setTextCursor(self.matches[self.curmatch].cursor)   - def searchText(self, regexp, icase): + def searchText(self, match, icase):   matches = []   color = QColor(Qt.yellow)   flags = QTextDocument.FindFlags()   if not icase:   flags |= QTextDocument.FindCaseSensitively   doc = self.edit.document() - cursor = doc.find(regexp, 0, flags) + cursor = doc.find(match, 0, flags)   while not cursor.isNull():   selection = QTextEdit.ExtraSelection()   selection.format.setBackground(color)   selection.cursor = cursor   matches.append(selection) - cursor = doc.find(regexp, cursor) + cursor = doc.find(match, cursor)   self.matches = matches   self.curmatch = 0   if matches: @@ -316,6 +351,11 @@
  av.revisionHint.connect(status.setText)   self.connect(av, SIGNAL('revSelected'), self.revSelected)   self.connect(av, SIGNAL('editSelected'), self.editSelected) + self.connect(av, SIGNAL('searchAtRev'), self.searchAtRev) + self.connect(av, SIGNAL('searchAtParent'), self.searchAtParent) + self.connect(av, SIGNAL('searchAll'), self.searchAll) + self.connect(av, SIGNAL('searchAnnotation'), self.searchAnnotation) +   self.status = status     self.opts = opts @@ -360,17 +400,41 @@
  files = [os.path.join(base, wfile)]   wctxactions.edit(self, repo.ui, repo, files, line, pattern)   + def searchAtRev(self, args): + # grep widget needs to support argument passing via **opts + # search repo[args[1]] + raise NotImplementedError() + + def searchAtParent(self, pattern): + # grep widget needs to support argument passing via **opts + # search repo['.'] + raise NotImplementedError() + + def searchAll(self, pattern): + # grep widget needs to support argument passing via **opts + # search all history + raise NotImplementedError() + + def searchAnnotation(self, pattern): + self.le.setText(pattern) + self.av.searchText(pattern, False) +   def searchText(self):   pattern = hglib.fromunicode(self.le.text())   if not pattern:   return   try: - icase = self.chk.isChecked() - regexp = re.compile(pattern, icase and re.I or 0) + regexp = re.compile(pattern)   except Exception, inst:   msg = _('grep: invalid match pattern: %s\n') % inst   self.status.setText(hglib.tounicode(msg)) - self.av.searchText(QRegExp(pattern), icase) + if self.chk.isChecked(): + regexp = QRegExp(pattern) + icase = True + else: + icase = False + regexp = QRegExp(pattern, Qt.CaseSensitive) + self.av.searchText(regexp, icase)     def wheelEvent(self, event):   if self.childAt(event.pos()) != self.le: