/b-gtk/fix-viz

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