/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to conflicts.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-11 17:14:12 UTC
  • Revision ID: jelmer@samba.org-20111211171412-cgcn0yas3zlcahzg
StartĀ onĀ 0.104.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import subprocess
 
18
 
 
19
from gi.repository import Gtk
 
20
from gi.repository import GObject
 
21
 
 
22
from bzrlib.config import GlobalConfig
 
23
from bzrlib.plugins.gtk.i18n import _i18n
 
24
from bzrlib.plugins.gtk.dialog import (
 
25
    error_dialog,
 
26
    warning_dialog,
 
27
    )
 
28
 
 
29
 
 
30
class ConflictsDialog(Gtk.Dialog):
 
31
    """ This dialog displays the list of conflicts. """
 
32
 
 
33
    def __init__(self, wt, parent=None):
 
34
        """ Initialize the Conflicts dialog. """
 
35
        super(ConflictsDialog, self).__init__(
 
36
            title="Conflicts - Olive", parent=parent, flags=0,
 
37
            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CANCEL))
 
38
 
 
39
        # Get arguments
 
40
        self.wt = wt
 
41
 
 
42
        # Create the widgets
 
43
        self._scrolledwindow = Gtk.ScrolledWindow()
 
44
        self._treeview = Gtk.TreeView()
 
45
        self._label_diff3 = Gtk.Label(label=_i18n("External utility:"))
 
46
        self._entry_diff3 = Gtk.Entry()
 
47
        self._image_diff3 = Gtk.Image()
 
48
        self._button_diff3 = Gtk.Button()
 
49
        self._hbox_diff3 = Gtk.HBox()
 
50
 
 
51
        # Set callbacks
 
52
        self._button_diff3.connect('clicked', self._on_diff3_clicked)
 
53
 
 
54
        # Set properties
 
55
        self._scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
 
56
                                        Gtk.PolicyType.AUTOMATIC)
 
57
        self._image_diff3.set_from_stock(Gtk.STOCK_APPLY, Gtk.IconSize.BUTTON)
 
58
        self._button_diff3.set_image(self._image_diff3)
 
59
        self._entry_diff3.set_text(self._get_diff3())
 
60
        self._hbox_diff3.set_spacing(3)
 
61
        content_area = self.get_content_area()
 
62
        content_area.set_spacing(3)
 
63
        self.set_default_size(400, 300)
 
64
 
 
65
        # Construct dialog
 
66
        self._hbox_diff3.pack_start(self._label_diff3, False, False, 0)
 
67
        self._hbox_diff3.pack_start(self._entry_diff3, True, True, 0)
 
68
        self._hbox_diff3.pack_start(self._button_diff3, False, False, 0)
 
69
        self._scrolledwindow.add(self._treeview)
 
70
        content_area.pack_start(self._scrolledwindow, True, True, 0)
 
71
        content_area.pack_start(self._hbox_diff3, False, False, 0)
 
72
 
 
73
        # Create the conflict list
 
74
        self._create_conflicts()
 
75
 
 
76
        # Show the dialog
 
77
        content_area.show_all()
 
78
 
 
79
    def _get_diff3(self):
 
80
        """ Get the specified diff3 utility. Default is meld. """
 
81
        config = GlobalConfig()
 
82
        diff3 = config.get_user_option('gconflicts_diff3')
 
83
        if diff3 is None:
 
84
            diff3 = 'meld'
 
85
        return diff3
 
86
 
 
87
    def _set_diff3(self, cmd):
 
88
        """ Set the default diff3 utility to cmd. """
 
89
        config = GlobalConfig()
 
90
        config.set_user_option('gconflicts_diff3', cmd)
 
91
 
 
92
    def _create_conflicts(self):
 
93
        """ Construct the list of conflicts. """
 
94
        if len(self.wt.conflicts()) == 0:
 
95
            self.model = Gtk.ListStore(GObject.TYPE_STRING)
 
96
            self._treeview.set_model(self.model)
 
97
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Conflicts'),
 
98
                                         Gtk.CellRendererText(), text=0))
 
99
            self._treeview.set_headers_visible(False)
 
100
            self.model.append([ _i18n("No conflicts in working tree.") ])
 
101
            self._button_diff3.set_sensitive(False)
 
102
        else:
 
103
            self.model = Gtk.ListStore(GObject.TYPE_STRING,
 
104
                                       GObject.TYPE_STRING,
 
105
                                       GObject.TYPE_STRING)
 
106
            self._treeview.set_model(self.model)
 
107
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Path'),
 
108
                                         Gtk.CellRendererText(), text=0))
 
109
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Type'),
 
110
                                         Gtk.CellRendererText(), text=1))
 
111
            self._treeview.set_search_column(0)
 
112
            for conflict in self.wt.conflicts():
 
113
                if conflict.typestring == 'path conflict':
 
114
                    t = _i18n("path conflict")
 
115
                elif conflict.typestring == 'contents conflict':
 
116
                    t = _i18n("contents conflict")
 
117
                elif conflict.typestring == 'text conflict':
 
118
                    t = _i18n("text conflict")
 
119
                elif conflict.typestring == 'duplicate id':
 
120
                    t = _i18n("duplicate id")
 
121
                elif conflict.typestring == 'duplicate':
 
122
                    t = _i18n("duplicate")
 
123
                elif conflict.typestring == 'parent loop':
 
124
                    t = _i18n("parent loop")
 
125
                elif conflict.typestring == 'unversioned parent':
 
126
                    t = _i18n("unversioned parent")
 
127
                elif conflict.typestring == 'missing parent':
 
128
                    t = _i18n("missing parent")
 
129
                elif conflict.typestring == 'deleting parent':
 
130
                    t = _i18n("deleting parent")
 
131
                else:
 
132
                    t = _i18n("unknown type of conflict")
 
133
 
 
134
                self.model.append([ conflict.path, t, conflict.typestring ])
 
135
 
 
136
    def _get_selected_file(self):
 
137
        """ Return the selected conflict's filename. """
 
138
        treeselection = self._treeview.get_selection()
 
139
        (model, iter) = treeselection.get_selected()
 
140
 
 
141
        if iter is None:
 
142
            return None
 
143
        else:
 
144
            return model.get_value(iter, 0)
 
145
 
 
146
    def _get_selected_type(self):
 
147
        """ Return the type of the selected conflict. """
 
148
        treeselection = self._treeview.get_selection()
 
149
        (model, iter) = treeselection.get_selected()
 
150
 
 
151
        if iter is None:
 
152
            return None
 
153
        else:
 
154
            return model.get_value(iter, 2)
 
155
 
 
156
    def _on_diff3_clicked(self, widget):
 
157
        """ Launch external utility to resolve conflicts. """
 
158
        self._set_diff3(self._entry_diff3.get_text())
 
159
        selected = self._get_selected_file()
 
160
        if selected is None:
 
161
            error_dialog(_i18n('No file was selected'),
 
162
                         _i18n('Please select a file from the list.'))
 
163
            return
 
164
        elif self._get_selected_type() == 'text conflict':
 
165
            base = self.wt.abspath(selected) + '.BASE'
 
166
            this = self.wt.abspath(selected) + '.THIS'
 
167
            other = self.wt.abspath(selected) + '.OTHER'
 
168
            try:
 
169
                p = subprocess.Popen([ self._entry_diff3.get_text(), base, this, other ])
 
170
                p.wait()
 
171
            except OSError, e:
 
172
                warning_dialog(_i18n('Call to external utility failed'), str(e))
 
173
        else:
 
174
            warning_dialog(_i18n('Cannot resolve conflict'),
 
175
                           _i18n('Only conflicts on the text of files can be resolved with Olive at the moment. Content conflicts, on the structure of the tree, need to be resolved using the command line.'))
 
176
            return