/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
242.1.1 by Adeodato Simó
Use subprocess.Popen() instead of os.system().
17
import subprocess
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
18
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
19
from gi.repository import Gtk
20
from gi.repository import GObject
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
21
22
from bzrlib.config import GlobalConfig
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
23
from bzrlib.plugins.gtk.i18n import _i18n
724 by Jelmer Vernooij
Fix formatting, imports.
24
from bzrlib.plugins.gtk.dialog import (
25
    error_dialog,
26
    warning_dialog,
27
    )
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
28
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
29
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
30
class ConflictsDialog(Gtk.Dialog):
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
31
    """ This dialog displays the list of conflicts. """
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
32
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
33
    def __init__(self, wt, parent=None):
34
        """ Initialize the Conflicts dialog. """
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
35
        Gtk.Dialog.__init__(self, title="Conflicts - Olive",
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
36
                                  parent=parent,
37
                                  flags=0,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
38
                                  buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CANCEL))
724 by Jelmer Vernooij
Fix formatting, imports.
39
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
40
        # Get arguments
41
        self.wt = wt
724 by Jelmer Vernooij
Fix formatting, imports.
42
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
43
        # Create the widgets
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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()
724 by Jelmer Vernooij
Fix formatting, imports.
51
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
52
        # Set callbacks
53
        self._button_diff3.connect('clicked', self._on_diff3_clicked)
724 by Jelmer Vernooij
Fix formatting, imports.
54
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
55
        # Set properties
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
59
        self._button_diff3.set_image(self._image_diff3)
60
        self._entry_diff3.set_text(self._get_diff3())
61
        self._hbox_diff3.set_spacing(3)
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
62
        content_area = self.get_content_area()
63
        content_area.set_spacing(3)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
64
        self.set_default_size(400, 300)
724 by Jelmer Vernooij
Fix formatting, imports.
65
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
66
        # Construct dialog
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
67
        self._hbox_diff3.pack_start(self._label_diff3, False, False, 0)
68
        self._hbox_diff3.pack_start(self._entry_diff3, True, True, 0)
69
        self._hbox_diff3.pack_start(self._button_diff3, False, False, 0)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
70
        self._scrolledwindow.add(self._treeview)
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
71
        content_area.pack_start(self._scrolledwindow, True, True, 0)
72
        content_area.pack_start(self._hbox_diff3, False, False, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
73
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
74
        # Create the conflict list
75
        self._create_conflicts()
724 by Jelmer Vernooij
Fix formatting, imports.
76
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
77
        # Show the dialog
734.1.9 by Curtis Hovey
Updated gconflicts to gtk3.
78
        content_area.show_all()
724 by Jelmer Vernooij
Fix formatting, imports.
79
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
80
    def _get_diff3(self):
81
        """ Get the specified diff3 utility. Default is meld. """
82
        config = GlobalConfig()
83
        diff3 = config.get_user_option('gconflicts_diff3')
84
        if diff3 is None:
85
            diff3 = 'meld'
86
        return diff3
724 by Jelmer Vernooij
Fix formatting, imports.
87
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
88
    def _set_diff3(self, cmd):
89
        """ Set the default diff3 utility to cmd. """
90
        config = GlobalConfig()
91
        config.set_user_option('gconflicts_diff3', cmd)
724 by Jelmer Vernooij
Fix formatting, imports.
92
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
93
    def _create_conflicts(self):
94
        """ Construct the list of conflicts. """
95
        if len(self.wt.conflicts()) == 0:
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
96
            self.model = Gtk.ListStore(GObject.TYPE_STRING)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
97
            self._treeview.set_model(self.model)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
98
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Conflicts'),
99
                                         Gtk.CellRendererText(), text=0))
724 by Jelmer Vernooij
Fix formatting, imports.
100
            self._treeview.set_headers_visible(False)
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
101
            self.model.append([ _i18n("No conflicts in working tree.") ])
442.1.1 by Szilveszter Farkas (Phanatic)
Fixed bug #131471 (don't allow pressing the button if there are no conflicts).
102
            self._button_diff3.set_sensitive(False)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
103
        else:
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
104
            self.model = Gtk.ListStore(GObject.TYPE_STRING,
105
                                       GObject.TYPE_STRING,
106
                                       GObject.TYPE_STRING)
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
107
            self._treeview.set_model(self.model)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
108
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Path'),
109
                                         Gtk.CellRendererText(), text=0))
110
            self._treeview.append_column(Gtk.TreeViewColumn(_i18n('Type'),
111
                                         Gtk.CellRendererText(), text=1))
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
112
            self._treeview.set_search_column(0)
113
            for conflict in self.wt.conflicts():
114
                if conflict.typestring == 'path conflict':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
115
                    t = _i18n("path conflict")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
116
                elif conflict.typestring == 'contents conflict':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
117
                    t = _i18n("contents conflict")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
118
                elif conflict.typestring == 'text conflict':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
119
                    t = _i18n("text conflict")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
120
                elif conflict.typestring == 'duplicate id':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
121
                    t = _i18n("duplicate id")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
122
                elif conflict.typestring == 'duplicate':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
123
                    t = _i18n("duplicate")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
124
                elif conflict.typestring == 'parent loop':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
125
                    t = _i18n("parent loop")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
126
                elif conflict.typestring == 'unversioned parent':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
127
                    t = _i18n("unversioned parent")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
128
                elif conflict.typestring == 'missing parent':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
129
                    t = _i18n("missing parent")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
130
                elif conflict.typestring == 'deleting parent':
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
131
                    t = _i18n("deleting parent")
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
132
                else:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
133
                    t = _i18n("unknown type of conflict")
724 by Jelmer Vernooij
Fix formatting, imports.
134
135
                self.model.append([ conflict.path, t, conflict.typestring ])
136
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
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()
724 by Jelmer Vernooij
Fix formatting, imports.
141
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
142
        if iter is None:
143
            return None
144
        else:
145
            return model.get_value(iter, 0)
724 by Jelmer Vernooij
Fix formatting, imports.
146
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
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()
724 by Jelmer Vernooij
Fix formatting, imports.
151
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
152
        if iter is None:
153
            return None
154
        else:
155
            return model.get_value(iter, 2)
724 by Jelmer Vernooij
Fix formatting, imports.
156
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
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:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
162
            error_dialog(_i18n('No file was selected'),
163
                         _i18n('Please select a file from the list.'))
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
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:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
173
                warning_dialog(_i18n('Call to external utility failed'), str(e))
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
174
        else:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
175
            warning_dialog(_i18n('Cannot resolve conflict'),
176
                           _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.'))
126.1.24 by Szilveszter Farkas (Phanatic)
Implemented Conflicts dialog. Added gconflicts command.
177
            return