/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
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
17
import sys
18
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
24
try:
25
    import gtk
26
    import gtk.glade
27
    import gobject
28
    import pango
29
except:
30
    sys.exit(1)
31
32
import bzrlib
0.8.35 by Szilveszter Farkas (Phanatic)
Fixed a small bug in the Status window.
33
import bzrlib.errors as errors
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
34
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
35
if bzrlib.version_info < (0, 9):
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
36
    # function deprecated after 0.9
37
    from bzrlib.delta import compare_trees
38
39
from bzrlib.status import show_tree_status
40
from bzrlib.workingtree import WorkingTree
41
42
from dialog import OliveDialog
43
44
class OliveStatus:
45
    """ Display Status window and perform the needed actions. """
0.12.1 by Jelmer Vernooij
Don't use communicator for status.
46
    def __init__(self, gladefile, wt, wtpath, dialog):
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
47
        """ Initialize the Status window. """
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
48
        self.gladefile = gladefile
49
        self.glade = gtk.glade.XML(self.gladefile, 'window_status')
50
        
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
51
        # Dialog object
52
        self.dialog = dialog
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
53
        
0.8.35 by Szilveszter Farkas (Phanatic)
Fixed a small bug in the Status window.
54
        # Get the Status window widget
55
        self.window = self.glade.get_widget('window_status')
0.12.1 by Jelmer Vernooij
Don't use communicator for status.
56
        self.wt = wt
57
        self.wtpath = wtpath
0.8.35 by Szilveszter Farkas (Phanatic)
Fixed a small bug in the Status window.
58
        
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
59
        # Check if current location is a branch
60
        try:
0.12.1 by Jelmer Vernooij
Don't use communicator for status.
61
            branch = wt.branch
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
62
        except errors.NotBranchError:
63
            self.notbranch = True
64
            return
65
        except:
66
            raise
67
        
0.12.1 by Jelmer Vernooij
Don't use communicator for status.
68
        file_id = self.wt.path2id(wtpath)
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
69
70
        self.notbranch = False
71
        if file_id is None:
72
            self.notbranch = True
73
            return
74
        
75
        # Set the old working tree
76
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
77
        
78
        # Dictionary for signal_autoconnect
79
        dic = { "on_button_status_close_clicked": self.close }
80
        
81
        # Connect the signals to the handlers
82
        self.glade.signal_autoconnect(dic)
83
        
84
        # Generate status output
85
        self._generate_status()
86
87
    def _generate_status(self):
88
        """ Generate 'bzr status' output. """
89
        self.model = gtk.TreeStore(str, str)
90
        self.treeview = self.glade.get_widget('treeview_status')
91
        self.treeview.set_model(self.model)
92
        
93
        cell = gtk.CellRendererText()
94
        cell.set_property("width-chars", 20)
95
        column = gtk.TreeViewColumn()
96
        column.pack_start(cell, expand=True)
97
        column.add_attribute(cell, "text", 0)
98
        self.treeview.append_column(column)
99
        
0.12.1 by Jelmer Vernooij
Don't use communicator for status.
100
        delta = self.wt.changes_from(self.old_tree)
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
101
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
102
        changes = False
103
        
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
104
        if len(delta.added):
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
105
            changes = True
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
106
            titer = self.model.append(None, [ _('Added'), None ])
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
107
            for path, id, kind in delta.added:
108
                self.model.append(titer, [ path, path ])
109
110
        if len(delta.removed):
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
111
            changes = True
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
112
            titer = self.model.append(None, [ _('Removed'), None ])
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
113
            for path, id, kind in delta.removed:
114
                self.model.append(titer, [ path, path ])
115
116
        if len(delta.renamed):
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
117
            changes = True
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
118
            titer = self.model.append(None, [ _('Renamed'), None ])
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
119
            for oldpath, newpath, id, kind, text_modified, meta_modified \
120
                    in delta.renamed:
121
                self.model.append(titer, [ oldpath, newpath ])
122
123
        if len(delta.modified):
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
124
            changes = True
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
125
            titer = self.model.append(None, [ _('Modified'), None ])
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
126
            for path, id, kind, text_modified, meta_modified in delta.modified:
127
                self.model.append(titer, [ path, path ])
128
        
129
        done_unknown = False
130
        for path in self.wt.unknowns():
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
131
            changes = True
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
132
            if not done_unknown:
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
133
                titer = self.model.append(None, [ _('Unknown'), None ])
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
134
                done_unknown = True
135
            self.model.append(titer, [ path, path ])
136
0.8.80 by Szilveszter Farkas (Phanatic)
If the TreeView in the Status window would be empty, display a "No changes." message.
137
        if not changes:
138
            self.model.append(None, [ _('No changes.'), None ])
139
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
140
        self.treeview.expand_all()
141
    
142
    def display(self):
143
        """ Display the Diff window. """
144
        if self.notbranch:
0.8.55 by Szilveszter Farkas (Phanatic)
Gettext support added.
145
            self.dialog.error_dialog(_('Directory is not a branch'),
146
                                     _('You can perform this action only in a branch.'))
0.8.35 by Szilveszter Farkas (Phanatic)
Fixed a small bug in the Status window.
147
            self.close()
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
148
        else:
149
            self.window.show_all()
150
151
    def close(self, widget=None):
152
        self.window.destroy()