/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-03-28 19:26:53 UTC
  • mto: (450.1.13 trunk)
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20080328192653-trzptkwahx1tulz9
Add module for preferences code.

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