Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

fileview: improve selected text "search" context menus

1 - actually do something when these menus are triggered
2 - allow selection menus in diff or file mode
3 - do not check the line < 0 until after selection menus are added

Changeset 92ebeab5ac70

Parent 2654a95c0653

by Steve Borho

Changes to one file · Browse files at 92ebeab5ac70 Showing diff from parent 2654a95c0653 Diff from another changeset...

 
34
35
36
37
38
39
40
41
42
 
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
 
531
532
533
 
 
 
 
 
 
 
 
534
535
536
537
538
539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
541
542
543
544
545
546
 
 
547
548
549
550
551
552
 
553
554
555
556
 
 
557
558
559
 
566
567
568
 
 
 
 
 
 
 
 
569
570
571
 
34
35
36
 
 
 
37
38
39
 
429
430
431
 
 
 
 
 
 
 
 
 
432
433
434
 
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
 
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
 
 
 
 
 
554
555
556
557
 
 
 
 
558
559
560
561
 
562
563
564
565
566
 
573
574
575
576
577
578
579
580
581
582
583
584
585
586
@@ -34,9 +34,6 @@
  revisionSelected = pyqtSignal(int)   shelveToolExited = pyqtSignal()   - searchRequested = pyqtSignal(unicode) - """Emitted (pattern) when user request to search content""" -   grepRequested = pyqtSignal(unicode, dict)   """Emitted (pattern, opts) when user request to search changelog"""   @@ -432,15 +429,6 @@
  x, y = self.sci.getCursorPosition()   self.sci.setCursorPosition(x, y-1)   - @pyqtSlot(unicode, object, int) - def editSelected(self, path, rev, line): - """Open editor to show the specified file""" - path = hglib.fromunicode(path) - base = visdiff.snapshot(self.repo, [path], self.repo[rev])[0] - files = [os.path.join(base, path)] - pattern = hglib.fromunicode(self._lastSearch[0]) - qtlib.editfiles(self.repo, files, line, pattern, self) -   @pyqtSlot(unicode, bool, bool, bool)   def find(self, exp, icase=True, wrap=False, forward=True):   self.sci.find(exp, icase, wrap, forward) @@ -531,29 +519,48 @@
  def nDiffs(self):   return len(self._diffs)   + def editSelected(self, path, rev, line): + """Open editor to show the specified file""" + path = hglib.fromunicode(path) + base = visdiff.snapshot(self.repo, [path], self.repo[rev])[0] + files = [os.path.join(base, path)] + pattern = hglib.fromunicode(self._lastSearch[0]) + qtlib.editfiles(self.repo, files, line, pattern, self) +   @pyqtSlot(QPoint)   def menuRequest(self, point):   menu = self.sci.createStandardContextMenu()   line = self.sci.lineAt(point)   point = self.sci.mapToGlobal(point) - if line < 0 or self._mode != AnnMode: + + selection = self.sci.selectedText() + def sreq(**opts): + return lambda: self.grepRequested.emit(selection, opts) + def sann(): + self.searchbar.search(selection) + self.searchbar.show() + + if self._mode != AnnMode: + if selection: + menu.addSeparator() + for name, func in [(_('Search in current file'), sann), + (_('Search in history'), sreq(all=True))]: + def add(name, func): + action = menu.addAction(name) + action.triggered.connect(func) + add(name, func)   return menu.exec_(point)   - def setSource(path, rev, line): - self.revisionSelected.emit(rev) - self.setContext(self.repo[rev]) - self.displayFile(path, None) - self.showLine(line) + if line < 0: + return menu.exec_(point)     fctx, line = self.sci._links[line] - data = [hglib.tounicode(fctx.path()), fctx.rev(), line] - - if self.sci.hasSelectedText(): - selection = self.sci.selectedText() + if selection:   def sreq(**opts):   return lambda: self.grepRequested.emit(selection, opts)   def sann(): - self.searchRequested.emit(selection) + self.searchbar.search(selection) + self.searchbar.show()   menu.addSeparator()   for name, func in [(_('Search in original revision'),   sreq(rev=fctx.rev())), @@ -566,6 +573,14 @@
  action.triggered.connect(func)   add(name, func)   + def setSource(path, rev, line): + self.revisionSelected.emit(rev) + self.setContext(self.repo[rev]) + self.displayFile(path, None) + self.showLine(line) + + data = [hglib.tounicode(fctx.path()), fctx.rev(), line] +   def annorig():   setSource(*data)   def editorig():