/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 status.py

  • Committer: Mateusz Korniak
  • Date: 2007-09-02 15:41:26 UTC
  • mto: This revision was merged to the branch mainline in revision 274.
  • Revision ID: matkor@laptop-hp-20070902154126-0zdi9vr4vvny0ayx
Proper import of question_dialog in context menu invocation.

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
 
from gi.repository import Gtk
18
 
from bzrlib.plugins.gtk import window
19
 
from bzrlib.plugins.gtk.i18n import _i18n
20
 
 
21
 
 
22
 
class StatusWindow(window.Window):
 
17
try:
 
18
    import pygtk
 
19
    pygtk.require("2.0")
 
20
except:
 
21
    pass
 
22
 
 
23
import gtk
 
24
 
 
25
class StatusDialog(gtk.Dialog):
23
26
    """ Display Status window and perform the needed actions. """
24
 
 
25
 
    def __init__(self, wt, wtpath, revision=None):
 
27
    def __init__(self, wt, wtpath):
26
28
        """ Initialize the Status window. """
27
 
        super(StatusWindow, self).__init__()
 
29
        super(StatusDialog, self).__init__(flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
28
30
        self.set_title("Working tree changes")
29
31
        self._create()
30
32
        self.wt = wt
31
33
        self.wtpath = wtpath
32
 
 
33
 
        if revision is None:
34
 
            revision = self.wt.branch.last_revision()
35
 
 
36
34
        # Set the old working tree
37
 
        self.old_tree = self.wt.branch.repository.revision_tree(revision)
 
35
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
38
36
        # Generate status output
39
37
        self._generate_status()
40
38
 
41
39
    def _create(self):
42
40
        self.set_default_size(400, 300)
43
 
        sw = Gtk.ScrolledWindow()
44
 
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
45
 
        sw.set_shadow_type(Gtk.ShadowType.IN)
46
 
        self.treeview = Gtk.TreeView()
47
 
        sw.add(self.treeview)
48
 
        self.add(sw)
49
 
 
50
 
        # sane border and spacing widths (as recommended by GNOME HIG) 
51
 
        self.set_border_width(5)
52
 
        sw.set_border_width(5)
53
 
        self.show_all()
54
 
 
 
41
        scrolledwindow = gtk.ScrolledWindow()
 
42
        scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 
43
        self.treeview = gtk.TreeView()
 
44
        scrolledwindow.add(self.treeview)
 
45
        self.vbox.pack_start(scrolledwindow, True, True)
 
46
        self.vbox.show_all()
55
47
 
56
48
    def row_diff(self, tv, path, tvc):
57
49
        file = self.model[path][1]
59
51
            return
60
52
        from bzrlib.plugins.gtk.diff import DiffWindow
61
53
        window = DiffWindow()
62
 
        window.set_diff("Working tree changes", self.wt, self.old_tree)
 
54
        window.set_diff("Working tree changes", self.old_tree, self.wt)
63
55
        window.set_file(file)
64
56
        window.show()
65
57
 
66
 
 
67
58
    def _generate_status(self):
68
59
        """ Generate 'bzr status' output. """
69
 
        self.model = Gtk.TreeStore(str, str)
 
60
        self.model = gtk.TreeStore(str, str)
70
61
        self.treeview.set_headers_visible(False)
71
62
        self.treeview.set_model(self.model)
72
63
        self.treeview.connect("row-activated", self.row_diff)
73
 
 
74
 
        cell = Gtk.CellRendererText()
 
64
        
 
65
        cell = gtk.CellRendererText()
75
66
        cell.set_property("width-chars", 20)
76
 
        column = Gtk.TreeViewColumn()
77
 
        column.pack_start(cell, True)
 
67
        column = gtk.TreeViewColumn()
 
68
        column.pack_start(cell, expand=True)
78
69
        column.add_attribute(cell, "text", 0)
79
70
        self.treeview.append_column(column)
80
 
 
 
71
        
81
72
        delta = self.wt.changes_from(self.old_tree)
82
73
 
83
74
        changes = False
84
 
 
 
75
        
85
76
        if len(delta.added):
86
77
            changes = True
87
 
            titer = self.model.append(None, [ _i18n('Added'), None ])
 
78
            titer = self.model.append(None, [ _('Added'), None ])
88
79
            for path, id, kind in delta.added:
89
80
                self.model.append(titer, [ path, path ])
90
81
 
91
82
        if len(delta.removed):
92
83
            changes = True
93
 
            titer = self.model.append(None, [ _i18n('Removed'), None ])
 
84
            titer = self.model.append(None, [ _('Removed'), None ])
94
85
            for path, id, kind in delta.removed:
95
86
                self.model.append(titer, [ path, path ])
96
87
 
97
88
        if len(delta.renamed):
98
89
            changes = True
99
 
            titer = self.model.append(None, [ _i18n('Renamed'), None ])
 
90
            titer = self.model.append(None, [ _('Renamed'), None ])
100
91
            for oldpath, newpath, id, kind, text_modified, meta_modified \
101
92
                    in delta.renamed:
102
93
                self.model.append(titer, [ oldpath, newpath ])
103
94
 
104
95
        if len(delta.modified):
105
96
            changes = True
106
 
            titer = self.model.append(None, [ _i18n('Modified'), None ])
 
97
            titer = self.model.append(None, [ _('Modified'), None ])
107
98
            for path, id, kind, text_modified, meta_modified in delta.modified:
108
99
                self.model.append(titer, [ path, path ])
109
 
 
 
100
        
110
101
        done_unknown = False
111
102
        for path in self.wt.unknowns():
112
103
            changes = True
113
104
            if not done_unknown:
114
 
                titer = self.model.append(None, [ _i18n('Unknown'), None ])
 
105
                titer = self.model.append(None, [ _('Unknown'), None ])
115
106
                done_unknown = True
116
107
            self.model.append(titer, [ path, path ])
117
108
 
118
109
        if not changes:
119
 
            self.model.append(None, [ _i18n('No changes.'), None ])
 
110
            self.model.append(None, [ _('No changes.'), None ])
120
111
 
121
112
        self.treeview.expand_all()
122
 
 
 
113
    
123
114
    def close(self, widget=None):
124
115
        self.window.destroy()