/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
33
34
if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
35
    # function deprecated after 0.9
36
    from bzrlib.delta import compare_trees
37
38
from bzrlib.status import show_tree_status
39
from bzrlib.workingtree import WorkingTree
40
41
from dialog import OliveDialog
42
43
class OliveStatus:
44
    """ Display Status window and perform the needed actions. """
45
    def __init__(self, gladefile, comm):
46
        """ Initialize the Diff window. """
47
        self.gladefile = gladefile
48
        self.glade = gtk.glade.XML(self.gladefile, 'window_status')
49
        
50
        self.comm = comm
51
        
52
        self.dialog = OliveDialog(self.gladefile)
53
        
54
        # Check if current location is a branch
55
        try:
56
            (self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
57
            branch = self.wt.branch
58
        except errors.NotBranchError:
59
            self.notbranch = True
60
            return
61
        except:
62
            raise
63
        
64
        file_id = self.wt.path2id(path)
65
66
        self.notbranch = False
67
        if file_id is None:
68
            self.notbranch = True
69
            return
70
        
71
        # Set the old working tree
72
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
73
        
74
        # Get the Diff window widget
75
        self.window = self.glade.get_widget('window_status')
76
        
77
        # Dictionary for signal_autoconnect
78
        dic = { "on_button_status_close_clicked": self.close }
79
        
80
        # Connect the signals to the handlers
81
        self.glade.signal_autoconnect(dic)
82
        
83
        # Generate status output
84
        self._generate_status()
85
86
    def _generate_status(self):
87
        """ Generate 'bzr status' output. """
88
        self.model = gtk.TreeStore(str, str)
89
        self.treeview = self.glade.get_widget('treeview_status')
90
        self.treeview.set_model(self.model)
91
        
92
        cell = gtk.CellRendererText()
93
        cell.set_property("width-chars", 20)
94
        column = gtk.TreeViewColumn()
95
        column.pack_start(cell, expand=True)
96
        column.add_attribute(cell, "text", 0)
97
        self.treeview.append_column(column)
98
        
99
        if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
100
            delta = compare_trees(self.old_tree, self.wt)
101
        else:
102
            delta = self.wt.changes_from(self.old_tree)
103
104
        if len(delta.added):
105
            titer = self.model.append(None, [ "Added", None ])
106
            for path, id, kind in delta.added:
107
                self.model.append(titer, [ path, path ])
108
109
        if len(delta.removed):
110
            titer = self.model.append(None, [ "Removed", None ])
111
            for path, id, kind in delta.removed:
112
                self.model.append(titer, [ path, path ])
113
114
        if len(delta.renamed):
115
            titer = self.model.append(None, [ "Renamed", None ])
116
            for oldpath, newpath, id, kind, text_modified, meta_modified \
117
                    in delta.renamed:
118
                self.model.append(titer, [ oldpath, newpath ])
119
120
        if len(delta.modified):
121
            titer = self.model.append(None, [ "Modified", None ])
122
            for path, id, kind, text_modified, meta_modified in delta.modified:
123
                self.model.append(titer, [ path, path ])
124
        
125
        done_unknown = False
126
        for path in self.wt.unknowns():
127
            if not done_unknown:
128
                titer = self.model.append(None, [ "Unknown", None ])
129
                done_unknown = True
130
            self.model.append(titer, [ path, path ])
131
132
        self.treeview.expand_all()
133
    
134
    def display(self):
135
        """ Display the Diff window. """
136
        if self.notbranch:
137
            self.dialog.error_dialog('Directory is not a branch.')
138
        else:
139
            self.window.show_all()
140
141
    def close(self, widget=None):
142
        self.window.destroy()