# HG changeset patch
# User ike@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)
