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