/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-04-10 18:44:39 UTC
  • mto: This revision was merged to the branch mainline in revision 730.
  • Revision ID: jelmer@samba.org-20110410184439-g7hqaacexqtviq13
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.

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
try:
 
18
    import pygtk
 
19
    pygtk.require("2.0")
 
20
except:
 
21
    pass
 
22
 
 
23
import subprocess
 
24
 
 
25
import gtk
 
26
import gobject
 
27
 
 
28
from bzrlib.config import GlobalConfig
 
29
from bzrlib.plugins.gtk import _i18n
 
30
from bzrlib.plugins.gtk.dialog import (
 
31
    error_dialog,
 
32
    warning_dialog,
 
33
    )
 
34
 
 
35
 
 
36
class ConflictsDialog(gtk.Dialog):
 
37
    """ This dialog displays the list of conflicts. """
 
38
 
 
39
    def __init__(self, wt, parent=None):
 
40
        """ Initialize the Conflicts dialog. """
 
41
        gtk.Dialog.__init__(self, title="Conflicts - Olive",
 
42
                                  parent=parent,
 
43
                                  flags=0,
 
44
                                  buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL))
 
45
 
 
46
        # Get arguments
 
47
        self.wt = wt
 
48
 
 
49
        # Create the widgets
 
50
        self._scrolledwindow = gtk.ScrolledWindow()
 
51
        self._treeview = gtk.TreeView()
 
52
        self._label_diff3 = gtk.Label(_i18n("External utility:"))
 
53
        self._entry_diff3 = gtk.Entry()
 
54
        self._image_diff3 = gtk.Image()
 
55
        self._button_diff3 = gtk.Button()
 
56
        self._hbox_diff3 = gtk.HBox()
 
57
 
 
58
        # Set callbacks
 
59
        self._button_diff3.connect('clicked', self._on_diff3_clicked)
 
60
 
 
61
        # Set properties
 
62
        self._scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,
 
63
                                        gtk.POLICY_AUTOMATIC)
 
64
        self._image_diff3.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
 
65
        self._button_diff3.set_image(self._image_diff3)
 
66
        self._entry_diff3.set_text(self._get_diff3())
 
67
        self._hbox_diff3.set_spacing(3)
 
68
        self.vbox.set_spacing(3)
 
69
        self.set_default_size(400, 300)
 
70
 
 
71
        # Construct dialog
 
72
        self._hbox_diff3.pack_start(self._label_diff3, False, False)
 
73
        self._hbox_diff3.pack_start(self._entry_diff3, True, True)
 
74
        self._hbox_diff3.pack_start(self._button_diff3, False, False)
 
75
        self._scrolledwindow.add(self._treeview)
 
76
        self.vbox.pack_start(self._scrolledwindow, True, True)
 
77
        self.vbox.pack_start(self._hbox_diff3, False, False)
 
78
 
 
79
        # Create the conflict list
 
80
        self._create_conflicts()
 
81
 
 
82
        # Show the dialog
 
83
        self.vbox.show_all()
 
84
 
 
85
    def _get_diff3(self):
 
86
        """ Get the specified diff3 utility. Default is meld. """
 
87
        config = GlobalConfig()
 
88
        diff3 = config.get_user_option('gconflicts_diff3')
 
89
        if diff3 is None:
 
90
            diff3 = 'meld'
 
91
        return diff3
 
92
 
 
93
    def _set_diff3(self, cmd):
 
94
        """ Set the default diff3 utility to cmd. """
 
95
        config = GlobalConfig()
 
96
        config.set_user_option('gconflicts_diff3', cmd)
 
97
 
 
98
    def _create_conflicts(self):
 
99
        """ Construct the list of conflicts. """
 
100
        if len(self.wt.conflicts()) == 0:
 
101
            self.model = gtk.ListStore(gobject.TYPE_STRING)
 
102
            self._treeview.set_model(self.model)
 
103
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Conflicts'),
 
104
                                         gtk.CellRendererText(), text=0))
 
105
            self._treeview.set_headers_visible(False)
 
106
            self.model.append([ _i18n("No conflicts in working tree.") ])
 
107
            self._button_diff3.set_sensitive(False)
 
108
        else:
 
109
            self.model = gtk.ListStore(gobject.TYPE_STRING,
 
110
                                       gobject.TYPE_STRING,
 
111
                                       gobject.TYPE_STRING)
 
112
            self._treeview.set_model(self.model)
 
113
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Path'),
 
114
                                         gtk.CellRendererText(), text=0))
 
115
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Type'),
 
116
                                         gtk.CellRendererText(), text=1))
 
117
            self._treeview.set_search_column(0)
 
118
            for conflict in self.wt.conflicts():
 
119
                if conflict.typestring == 'path conflict':
 
120
                    t = _i18n("path conflict")
 
121
                elif conflict.typestring == 'contents conflict':
 
122
                    t = _i18n("contents conflict")
 
123
                elif conflict.typestring == 'text conflict':
 
124
                    t = _i18n("text conflict")
 
125
                elif conflict.typestring == 'duplicate id':
 
126
                    t = _i18n("duplicate id")
 
127
                elif conflict.typestring == 'duplicate':
 
128
                    t = _i18n("duplicate")
 
129
                elif conflict.typestring == 'parent loop':
 
130
                    t = _i18n("parent loop")
 
131
                elif conflict.typestring == 'unversioned parent':
 
132
                    t = _i18n("unversioned parent")
 
133
                elif conflict.typestring == 'missing parent':
 
134
                    t = _i18n("missing parent")
 
135
                elif conflict.typestring == 'deleting parent':
 
136
                    t = _i18n("deleting parent")
 
137
                else:
 
138
                    t = _i18n("unknown type of conflict")
 
139
 
 
140
                self.model.append([ conflict.path, t, conflict.typestring ])
 
141
 
 
142
    def _get_selected_file(self):
 
143
        """ Return the selected conflict's filename. """
 
144
        treeselection = self._treeview.get_selection()
 
145
        (model, iter) = treeselection.get_selected()
 
146
 
 
147
        if iter is None:
 
148
            return None
 
149
        else:
 
150
            return model.get_value(iter, 0)
 
151
 
 
152
    def _get_selected_type(self):
 
153
        """ Return the type of the selected conflict. """
 
154
        treeselection = self._treeview.get_selection()
 
155
        (model, iter) = treeselection.get_selected()
 
156
 
 
157
        if iter is None:
 
158
            return None
 
159
        else:
 
160
            return model.get_value(iter, 2)
 
161
 
 
162
    def _on_diff3_clicked(self, widget):
 
163
        """ Launch external utility to resolve conflicts. """
 
164
        self._set_diff3(self._entry_diff3.get_text())
 
165
        selected = self._get_selected_file()
 
166
        if selected is None:
 
167
            error_dialog(_i18n('No file was selected'),
 
168
                         _i18n('Please select a file from the list.'))
 
169
            return
 
170
        elif self._get_selected_type() == 'text conflict':
 
171
            base = self.wt.abspath(selected) + '.BASE'
 
172
            this = self.wt.abspath(selected) + '.THIS'
 
173
            other = self.wt.abspath(selected) + '.OTHER'
 
174
            try:
 
175
                p = subprocess.Popen([ self._entry_diff3.get_text(), base, this, other ])
 
176
                p.wait()
 
177
            except OSError, e:
 
178
                warning_dialog(_i18n('Call to external utility failed'), str(e))
 
179
        else:
 
180
            warning_dialog(_i18n('Cannot resolve conflict'),
 
181
                           _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.'))
 
182
            return