Anonymous avatar Anonymous committed 935f86a

filedialogs: add multi-selection menu (fixes #1871)

This change backs out bcf0854d848c6534 and adds a new menu which is shown when
more than one item is selected. The menu shows two options:

- Diff selected changesets...
- Diff selected file revisions...

Ideally it should not be possible to select more than two revisions. However,
for now if more than two revisions are selected and the user right clicks the
context menu will not be shown and insted a message will be shown on the status
bar indicating that you cannot select more than two revisions.

The code to generate the menus could be improved a lot, but that should be left
for another revision.

Comments (0)

Files changed (1)

tortoisehg/hgqt/filedialogs.py

         super(FileLogDialog, self).__init__(repo, filename, repoviewer)
         self._readSettings()
         self.menu = None
+        self.dualmenu = None
 
     def closeEvent(self, event):
         self._writeSettings()
         self.setCentralWidget(self.splitter)
         cs = ('fileLogDialog', _('File History Log Columns'))
         self.repoview = repoview.HgRepoView(self.repo, cs[0], cs, self.splitter)
-        self.repoview.setSelectionMode(QAbstractItemView.SingleSelection)
+
         self.contentframe = QFrame(self.splitter)
 
         vbox = QVBoxLayout()
         'User requested a context menu in repo view widget'
         if not selection:
             return
-        if self.menu is None:
+        if len(selection) > 2:
+            self.textView.showMessage.emit(_('Too many rows selected for menu'))
+            return
+        elif len(selection) == 2:
+            if self.dualmenu is None:
+                self.dualmenu = menu = QMenu(self)
+                a = menu.addAction(_('Diff selected changesets...'))
+                a.triggered.connect(self.onVisualDiffRevs)
+                a = menu.addAction(_('Diff selected file revisions...'))
+                a.setIcon(qtlib.getmenuicon('visualdiff'))
+                a.triggered.connect(self.onVisualDiffFileRevs)
+            else:
+                menu = self.dualmenu
+        elif self.menu is None:
             self.menu = menu = QMenu(self)
             a = menu.addAction(_('Diff changeset to parent...'))
             a.setIcon(qtlib.getmenuicon('visualdiff'))
             a = menu.addAction(_('Revert to revision...'))
             a.setIcon(qtlib.getmenuicon('hg-revert'))
             a.triggered.connect(self.onRevertFileToRevision)
+        else:
+            menu = self.menu
         self.selection = selection
-        self.menu.exec_(point)
+        menu.exec_(point)
 
     def onVisualDiff(self):
         opts = dict(change=self.selection[0])
             dlg.exec_()
             dlg.deleteLater()
 
+    def onVisualDiffRevs(self):
+        revs = self.selection
+        if len(revs) != 2:
+            self.textView.showMessage.emit(_('You must select two revisions to diff'))
+            return
+        opts = dict(rev=revs)
+        dlg = visdiff.visualdiff(self.repo.ui, self.repo, [], opts)
+        if dlg:
+            dlg.exec_()
+            dlg.deleteLater()
+
     def onVisualDiffFile(self):
         rev = self.selection[0]
         paths = [self.filerevmodel.graph.filename(rev)]
             dlg.exec_()
             dlg.deleteLater()
 
+    def onVisualDiffFileRevs(self):
+        revs = self.selection
+        if len(revs) != 2:
+            self.textView.showMessage.emit(_('You must select two revisions to diff'))
+            return
+        paths = [self.filerevmodel.graph.filename(revs[0])]
+        opts = dict(rev=['rev(%d)' % rev for rev in revs])
+        dlg = visdiff.visualdiff(self.repo.ui, self.repo, paths, opts)
+        if dlg:
+            dlg.exec_()
+            dlg.deleteLater()
+
     def onEditLocal(self):
         filenames = [self.filename]
         if not filenames:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.