/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: Curtis Hovey
  • Date: 2012-09-02 19:29:42 UTC
  • mfrom: (794.1.1 get_style_context)
  • Revision ID: sinzui.is@verizon.net-20120902192942-cwtww9wxvznx0wod
Do not call deprecated get_style(); use get_style_context().

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
 
from bzrlib.plugins.gtk import _i18n
30
 
 
31
 
from dialog import error_dialog, warning_dialog
32
 
 
33
 
 
34
 
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):
35
31
    """ This dialog displays the list of conflicts. """
36
32
 
37
33
    def __init__(self, wt, parent=None):
38
34
        """ 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
 
        
 
35
        super(ConflictsDialog, self).__init__(
 
36
            title="Conflicts - Olive", parent=parent, flags=0,
 
37
            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CANCEL))
 
38
 
44
39
        # Get arguments
45
40
        self.wt = wt
46
 
        
 
41
 
47
42
        # Create the widgets
48
 
        self._scrolledwindow = gtk.ScrolledWindow()
49
 
        self._treeview = gtk.TreeView()
50
 
        self._label_diff3 = gtk.Label(_i18n("External utility:"))
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
 
        
 
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
 
56
51
        # Set callbacks
57
52
        self._button_diff3.connect('clicked', self._on_diff3_clicked)
58
 
        
 
53
 
59
54
        # 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)
 
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)
63
58
        self._button_diff3.set_image(self._image_diff3)
64
59
        self._entry_diff3.set_text(self._get_diff3())
65
60
        self._hbox_diff3.set_spacing(3)
66
 
        self.vbox.set_spacing(3)
 
61
        content_area = self.get_content_area()
 
62
        content_area.set_spacing(3)
67
63
        self.set_default_size(400, 300)
68
 
        
 
64
 
69
65
        # 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)
 
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)
73
69
        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
 
        
 
70
        content_area.pack_start(self._scrolledwindow, True, True, 0)
 
71
        content_area.pack_start(self._hbox_diff3, False, False, 0)
 
72
 
77
73
        # Create the conflict list
78
74
        self._create_conflicts()
79
 
        
 
75
 
80
76
        # Show the dialog
81
 
        self.vbox.show_all()
82
 
    
 
77
        content_area.show_all()
 
78
 
83
79
    def _get_diff3(self):
84
80
        """ Get the specified diff3 utility. Default is meld. """
85
81
        config = GlobalConfig()
87
83
        if diff3 is None:
88
84
            diff3 = 'meld'
89
85
        return diff3
90
 
    
 
86
 
91
87
    def _set_diff3(self, cmd):
92
88
        """ Set the default diff3 utility to cmd. """
93
89
        config = GlobalConfig()
94
90
        config.set_user_option('gconflicts_diff3', cmd)
95
 
    
 
91
 
96
92
    def _create_conflicts(self):
97
93
        """ Construct the list of conflicts. """
98
94
        if len(self.wt.conflicts()) == 0:
99
 
            self.model = gtk.ListStore(gobject.TYPE_STRING)
 
95
            self.model = Gtk.ListStore(GObject.TYPE_STRING)
100
96
            self._treeview.set_model(self.model)
101
 
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Conflicts'),
102
 
                                         gtk.CellRendererText(), text=0))
103
 
            self._treeview.set_headers_visible(False)            
 
97
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Conflicts'),
 
98
                                         Gtk.CellRendererText(), text=0))
 
99
            self._treeview.set_headers_visible(False)
104
100
            self.model.append([ _i18n("No conflicts in working tree.") ])
105
101
            self._button_diff3.set_sensitive(False)
106
102
        else:
107
 
            self.model = gtk.ListStore(gobject.TYPE_STRING,
108
 
                                       gobject.TYPE_STRING,
109
 
                                       gobject.TYPE_STRING)
 
103
            self.model = Gtk.ListStore(GObject.TYPE_STRING,
 
104
                                       GObject.TYPE_STRING,
 
105
                                       GObject.TYPE_STRING)
110
106
            self._treeview.set_model(self.model)
111
 
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Path'),
112
 
                                         gtk.CellRendererText(), text=0))
113
 
            self._treeview.append_column(gtk.TreeViewColumn(_i18n('Type'),
114
 
                                         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))
115
111
            self._treeview.set_search_column(0)
116
112
            for conflict in self.wt.conflicts():
117
113
                if conflict.typestring == 'path conflict':
134
130
                    t = _i18n("deleting parent")
135
131
                else:
136
132
                    t = _i18n("unknown type of conflict")
137
 
                
138
 
                self.model.append([ conflict.path, t, conflict.typestring ]) 
139
 
    
 
133
 
 
134
                self.model.append([ conflict.path, t, conflict.typestring ])
 
135
 
140
136
    def _get_selected_file(self):
141
137
        """ Return the selected conflict's filename. """
142
138
        treeselection = self._treeview.get_selection()
143
139
        (model, iter) = treeselection.get_selected()
144
 
        
 
140
 
145
141
        if iter is None:
146
142
            return None
147
143
        else:
148
144
            return model.get_value(iter, 0)
149
 
    
 
145
 
150
146
    def _get_selected_type(self):
151
147
        """ Return the type of the selected conflict. """
152
148
        treeselection = self._treeview.get_selection()
153
149
        (model, iter) = treeselection.get_selected()
154
 
        
 
150
 
155
151
        if iter is None:
156
152
            return None
157
153
        else:
158
154
            return model.get_value(iter, 2)
159
 
    
 
155
 
160
156
    def _on_diff3_clicked(self, widget):
161
157
        """ Launch external utility to resolve conflicts. """
162
158
        self._set_diff3(self._entry_diff3.get_text())