/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: 2008-07-17 11:51:03 UTC
  • Revision ID: jelmer@samba.org-20080717115103-djh5sb0pvpse2zkb
Add note about glade.

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