/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: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

Show diffs side-by-side

added added

removed removed

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