fix #2200 (add context-menu in resolve window)

Showing 1-4 of 4 messages
fix #2200 (add context-menu in resolve window) ike 10/21/12 12:42 PM
Hi,

Warning: this is my first python and qt code.

Regards,
Ike

# HG changeset patch
# User i...@compufit.be
# Date 1350848004 -7200
# Node ID 40f1d75ee003736a1fc52fd828a8abfb6f191cb3
# Parent  e4e99bb369d9faf9c46a1c04c86a0f0245c4e5bc
fixes #2200

add context-menu in resolve window

diff --git a/tortoisehg/hgqt/resolve.py b/tortoisehg/hgqt/resolve.py
--- a/tortoisehg/hgqt/resolve.py
+++ b/tortoisehg/hgqt/resolve.py
@@ -71,6 +71,14 @@
 
             return hbox
 
+        def utreeMenu(self, event):
+            self.utreecmenu.exec_(event.globalPos(), self.umenuitems[0])
+            return
+
+        def rtreeMenu(self, event):
+            self.rtreecmenu.exec_(event.globalPos(), self.rmenuitems[0])
+            return
+
         if len(self.repo[None].parents()) > 1:
             self.layout().addLayout(revisionInfoLayout(self.repo))
 
@@ -82,7 +90,7 @@
         hbox.setContentsMargins(*MARGINS)
         self.layout().addLayout(hbox)
 
-        self.utree = PathsTree(self.repo, self)
+        self.utree = PathsTree(self.repo, self, utreeMenu)
         hbox.addWidget(self.utree)
 
         vbox = QVBoxLayout()
@@ -111,6 +119,19 @@
         vbox.addStretch(1)
         self.ubuttons = (auto, manual, local, other, res)
 
+        self.utreecmenu = QMenu(self)
+        cmauto = self.utreecmenu.addAction(_('Mercurial Resolve'))
+        cmauto.triggered.connect(lambda: self.merge('internal:merge'))
+        cmmanual = self.utreecmenu.addAction(_('Tool Resolve'))
+        cmmanual.triggered.connect(self.merge)
+        cmlocal = self.utreecmenu.addAction(_('Take Local'))
+        cmlocal.triggered.connect(lambda: self.merge('internal:local'))
+        cmother = self.utreecmenu.addAction(_('Take Other'))
+        cmother.triggered.connect(lambda: self.merge('internal:other'))
+        cmres = self.utreecmenu.addAction(_('Mark as Resolved'))
+        cmres.triggered.connect(self.markresolved)
+        self.umenuitems = (cmauto, cmmanual, cmlocal, cmother, cmres)
+
         res = qtlib.LabeledSeparator(_('Resolved conflicts'))
         self.layout().addWidget(res)
 
@@ -119,7 +140,7 @@
         hbox.setSpacing(0)
         self.layout().addLayout(hbox)
 
-        self.rtree = PathsTree(self.repo, self)
+        self.rtree = PathsTree(self.repo, self, rtreeMenu)
         hbox.addWidget(self.rtree)
 
         vbox = QVBoxLayout()
@@ -149,6 +170,20 @@
         self.rbuttons = (edit, vp0, ures)
         self.rmbuttons = (vp1, v3way)
 
+        self.rtreecmenu = QMenu(self)
+        cmedit = self.rtreecmenu.addAction(_('Edit File'))
+        cmedit.triggered.connect(self.edit)
+        cmv3way = self.rtreecmenu.addAction(_('3-Way Diff'))
+        cmv3way.triggered.connect(self.v3way)
+        cmvp0 = self.rtreecmenu.addAction(_('Diff to Local'))
+        cmvp0.triggered.connect(self.vp0)
+        cmvp1 = self.rtreecmenu.addAction(_('Diff to Other'))
+        cmvp1.triggered.connect(self.vp1)
+        cmures = self.rtreecmenu.addAction(_('Mark as Unresolved'))
+        cmures.triggered.connect(self.markunresolved)
+        self.rmenuitems = (cmedit, cmvp0, cmures)
+        self.rmmenuitems = (cmvp1, cmv3way)
+
         hbox = QHBoxLayout()
         hbox.setContentsMargins(*MARGINS)
         hbox.setSpacing(4)
@@ -311,6 +346,8 @@
             enable = self.utree.selectionModel().hasSelection()
             for b in self.ubuttons:
                 b.setEnabled(enable)
+            for c in self.umenuitems:
+                c.setEnabled(enable)
         smodel.selectionChanged.connect(uchanged)
         uchanged(None, None)
 
@@ -332,9 +369,13 @@
             enable = self.rtree.selectionModel().hasSelection()
             for b in self.rbuttons:
                 b.setEnabled(enable)
+            for b in self.rmenuitems:
+                b.setEnabled(enable)
             merge = len(self.repo.parents()) > 1
             for b in self.rmbuttons:
                 b.setEnabled(enable and merge)
+            for b in self.rmmenuitems:
+                b.setEnabled(enable and merge)
         smodel.selectionChanged.connect(rchanged)
         rchanged(None, None)
 
@@ -360,11 +401,13 @@
         super(ResolveDialog, self).reject()
 
 class PathsTree(QTreeView):
-    def __init__(self, repo, parent):
+    def __init__(self, repo, parent, method):
         QTreeView.__init__(self, parent)
         self.repo = repo
         self.setSelectionMode(QTreeView.ExtendedSelection)
         self.setSortingEnabled(True)
+        self.cmenu = method
+        self.parent = parent
 
     def dragObject(self):
         urls = []
@@ -393,6 +436,9 @@
         self.dragObject()
         return QTreeView.mouseMoveEvent(self, event)
 
+    def contextMenuEvent (self, event):
+        self.cmenu(self.parent, event)
+
 class PathsModel(QAbstractTableModel):
     def __init__(self, pathlist, parent):
         QAbstractTableModel.__init__(self, parent)

Re: [thg-dev] fix #2200 (add context-menu in resolve window) Yuya Nishihara 10/31/12 8:31 AM
Hi,

thanks for the improvements, and sorry for late response...

On Sun, 21 Oct 2012 21:42:28 +0200, Ike Casteleyn wrote:
> # HG changeset patch
> # User i...@compufit.be
> # Date 1350848004 -7200
> # Node ID 40f1d75ee003736a1fc52fd828a8abfb6f191cb3
> # Parent  e4e99bb369d9faf9c46a1c04c86a0f0245c4e5bc
> fixes #2200
>
> add context-menu in resolve window

Please follow our style [1], for example,
"resolve: add context menu (fixes #2200)"

 [1]: http://mercurial.selenic.com/wiki/ContributingChanges#Patch_descriptions

> diff --git a/tortoisehg/hgqt/resolve.py b/tortoisehg/hgqt/resolve.py
> --- a/tortoisehg/hgqt/resolve.py
> +++ b/tortoisehg/hgqt/resolve.py
> @@ -71,6 +71,14 @@
>
>              return hbox
>
> +        def utreeMenu(self, event):
> +            self.utreecmenu.exec_(event.globalPos(), self.umenuitems[0])
> +            return
> +
> +        def rtreeMenu(self, event):
> +            self.rtreecmenu.exec_(event.globalPos(), self.rmenuitems[0])
> +            return
> +
>          if len(self.repo[None].parents()) > 1:
>              self.layout().addLayout(revisionInfoLayout(self.repo))
>
> @@ -82,7 +90,7 @@
>          hbox.setContentsMargins(*MARGINS)
>          self.layout().addLayout(hbox)
>
> -        self.utree = PathsTree(self.repo, self)
> +        self.utree = PathsTree(self.repo, self, utreeMenu)
>          hbox.addWidget(self.utree)

You can avoid this reverse dependency from utree to utreeMenu by using
customContextMenuRequested signal [2].

 [2]: http://qt-project.org/doc/qt-4.8/qwidget.html#customContextMenuRequested

Also refer setContextMenuPolicy(Qt.CustomContextMenu) and mapToGlobal().

The other part looks good to me.

Regards,
Re: fix #2200 (add context-menu in resolve window) ike 10/31/12 4:00 PM
Hi,

I've implemented the changes as requested.

Best regards

Ike

# HG changeset patch
# User i...@gmail.com
# Date 1351724102 -3600
# Node ID 1d3c549cda6e20a347a2f6b7c7776ce650e6ede8
# Parent  dc20de4094117c2ef67bc21d500c464a465ad392
resolve: add context-menu in resolve window (fixes #2200)


diff --git a/tortoisehg/hgqt/resolve.py b/tortoisehg/hgqt/resolve.py
--- a/tortoisehg/hgqt/resolve.py
+++ b/tortoisehg/hgqt/resolve.py
@@ -111,6 +111,21 @@

         vbox.addStretch(1)
         self.ubuttons = (auto, manual, local, other, res)
 
+        self.utree.setContextMenuPolicy(Qt.CustomContextMenu)

+        self.utreecmenu = QMenu(self)
+        cmauto = self.utreecmenu.addAction(_('Mercurial Resolve'))
+        cmauto.triggered.connect(lambda: self.merge('internal:merge'))
+        cmmanual = self.utreecmenu.addAction(_('Tool Resolve'))
+        cmmanual.triggered.connect(self.merge)
+        cmlocal = self.utreecmenu.addAction(_('Take Local'))
+        cmlocal.triggered.connect(lambda: self.merge('internal:local'))
+        cmother = self.utreecmenu.addAction(_('Take Other'))
+        cmother.triggered.connect(lambda: self.merge('internal:other'))
+        cmres = self.utreecmenu.addAction(_('Mark as Resolved'))
+        cmres.triggered.connect(self.markresolved)
+        self.umenuitems = (cmauto, cmmanual, cmlocal, cmother, cmres)
+        self.utree.customContextMenuRequested.connect(self.utreeMenuRequested)

+
         res = qtlib.LabeledSeparator(_('Resolved conflicts'))
         self.layout().addWidget(res)
 
@@ -149,6 +164,22 @@

         self.rbuttons = (edit, vp0, ures)
         self.rmbuttons = (vp1, v3way)
 
+        self.rtree.setContextMenuPolicy(Qt.CustomContextMenu)

+        self.rtreecmenu = QMenu(self)
+        cmedit = self.rtreecmenu.addAction(_('Edit File'))
+        cmedit.triggered.connect(self.edit)
+        cmv3way = self.rtreecmenu.addAction(_('3-Way Diff'))
+        cmv3way.triggered.connect(self.v3way)
+        cmvp0 = self.rtreecmenu.addAction(_('Diff to Local'))
+        cmvp0.triggered.connect(self.vp0)
+        cmvp1 = self.rtreecmenu.addAction(_('Diff to Other'))
+        cmvp1.triggered.connect(self.vp1)
+        cmures = self.rtreecmenu.addAction(_('Mark as Unresolved'))
+        cmures.triggered.connect(self.markunresolved)
+        self.rmenuitems = (cmedit, cmvp0, cmures)
+        self.rmmenuitems = (cmvp1, cmv3way)
+        self.rtree.customContextMenuRequested.connect(self.rtreeMenuRequested)

+
         hbox = QHBoxLayout()
         hbox.setContentsMargins(*MARGINS)
         hbox.setSpacing(4)
@@ -311,6 +342,8 @@

             enable = self.utree.selectionModel().hasSelection()
             for b in self.ubuttons:
                 b.setEnabled(enable)
+            for c in self.umenuitems:
+                c.setEnabled(enable)
         smodel.selectionChanged.connect(uchanged)
         uchanged(None, None)
 
@@ -332,9 +365,13 @@

             enable = self.rtree.selectionModel().hasSelection()
             for b in self.rbuttons:
                 b.setEnabled(enable)
+            for c in self.rmenuitems:
+                c.setEnabled(enable)
             merge = len(self.repo.parents()) > 1
             for b in self.rmbuttons:
                 b.setEnabled(enable and merge)
+            for c in self.rmmenuitems:
+                c.setEnabled(enable and merge)
         smodel.selectionChanged.connect(rchanged)
         rchanged(None, None)
 
@@ -359,6 +396,14 @@
                 return
         super(ResolveDialog, self).reject()
 
+    @pyqtSlot(QPoint)
+    def utreeMenuRequested(self, point):
+        self.utreecmenu.exec_(self.utree.mapToGlobal(point), self.umenuitems[0])
+
+    @pyqtSlot(QPoint)
+    def rtreeMenuRequested(self, point):
+        self.rtreecmenu.exec_(self.rtree.mapToGlobal(point), self.rmenuitems[0])
+
 class PathsTree(QTreeView):
     def __init__(self, repo, parent):
         QTreeView.__init__(self, parent)

Re: [thg-dev] Re: fix #2200 (add context-menu in resolve window) Yuya Nishihara 11/1/12 7:30 AM
On Wed, 31 Oct 2012 16:00:00 -0700 (PDT), ike wrote:
> # HG changeset patch
> # User i...@gmail.com
> # Date 1351724102 -3600
> # Node ID 1d3c549cda6e20a347a2f6b7c7776ce650e6ede8
> # Parent  dc20de4094117c2ef67bc21d500c464a465ad392
> resolve: add context-menu in resolve window (fixes #2200)

Thanks!
Pushed to default branch.

Regards,