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

  • Committer: Jelmer Vernooij
  • Date: 2006-09-27 21:05:19 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927210519-7bc2662211808af5
Bunch of other small updates, add more items to 
the TODO list.

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
import sys
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
 
 
25
import gtk
 
26
import gtk.glade
 
27
import gobject
 
28
import pango
 
29
 
 
30
import bzrlib
 
31
import bzrlib.errors as errors
 
32
 
 
33
from bzrlib.status import show_tree_status
 
34
from bzrlib.workingtree import WorkingTree
 
35
 
 
36
from dialog import OliveDialog
 
37
 
 
38
from olive import gladefile
 
39
 
 
40
class OliveStatus:
23
41
    """ Display Status window and perform the needed actions. """
24
 
 
25
 
    def __init__(self, wt, wtpath, revision=None):
 
42
    def __init__(self, gladefile, wt, wtpath):
26
43
        """ Initialize the Status window. """
27
 
        super(StatusWindow, self).__init__()
28
 
        self.set_title("Working tree changes")
29
 
        self._create()
 
44
        self.glade = gtk.glade.XML(gladefile, 'window_status')
 
45
        
 
46
        # Get the Status window widget
 
47
        self.window = self.glade.get_widget('window_status')
30
48
        self.wt = wt
31
49
        self.wtpath = wtpath
32
 
 
33
 
        if revision is None:
34
 
            revision = self.wt.branch.last_revision()
35
 
 
 
50
        
 
51
        # Check if current location is a branch
 
52
        try:
 
53
            branch = wt.branch
 
54
        except errors.NotBranchError:
 
55
            self.notbranch = True
 
56
            return
 
57
        
 
58
        file_id = self.wt.path2id(wtpath)
 
59
 
 
60
        self.notbranch = False
 
61
        if file_id is None:
 
62
            self.notbranch = True
 
63
            return
 
64
        
36
65
        # Set the old working tree
37
 
        self.old_tree = self.wt.branch.repository.revision_tree(revision)
 
66
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
 
67
        
 
68
        # Dictionary for signal_autoconnect
 
69
        dic = { "on_button_status_close_clicked": self.close }
 
70
        
 
71
        # Connect the signals to the handlers
 
72
        self.glade.signal_autoconnect(dic)
 
73
        
38
74
        # Generate status output
39
75
        self._generate_status()
40
76
 
41
 
    def _create(self):
42
 
        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
 
 
55
 
 
56
 
    def row_diff(self, tv, path, tvc):
57
 
        file = self.model[path][1]
58
 
        if file is None:
59
 
            return
60
 
        from bzrlib.plugins.gtk.diff import DiffWindow
61
 
        window = DiffWindow()
62
 
        window.set_diff("Working tree changes", self.wt, self.old_tree)
63
 
        window.set_file(file)
64
 
        window.show()
65
 
 
66
 
 
67
77
    def _generate_status(self):
68
78
        """ Generate 'bzr status' output. """
69
 
        self.model = Gtk.TreeStore(str, str)
70
 
        self.treeview.set_headers_visible(False)
 
79
        self.model = gtk.TreeStore(str, str)
 
80
        self.treeview = self.glade.get_widget('treeview_status')
71
81
        self.treeview.set_model(self.model)
72
 
        self.treeview.connect("row-activated", self.row_diff)
73
 
 
74
 
        cell = Gtk.CellRendererText()
 
82
        
 
83
        cell = gtk.CellRendererText()
75
84
        cell.set_property("width-chars", 20)
76
 
        column = Gtk.TreeViewColumn()
77
 
        column.pack_start(cell, True)
 
85
        column = gtk.TreeViewColumn()
 
86
        column.pack_start(cell, expand=True)
78
87
        column.add_attribute(cell, "text", 0)
79
88
        self.treeview.append_column(column)
80
 
 
 
89
        
81
90
        delta = self.wt.changes_from(self.old_tree)
82
91
 
83
92
        changes = False
84
 
 
 
93
        
85
94
        if len(delta.added):
86
95
            changes = True
87
 
            titer = self.model.append(None, [ _i18n('Added'), None ])
 
96
            titer = self.model.append(None, [ _('Added'), None ])
88
97
            for path, id, kind in delta.added:
89
98
                self.model.append(titer, [ path, path ])
90
99
 
91
100
        if len(delta.removed):
92
101
            changes = True
93
 
            titer = self.model.append(None, [ _i18n('Removed'), None ])
 
102
            titer = self.model.append(None, [ _('Removed'), None ])
94
103
            for path, id, kind in delta.removed:
95
104
                self.model.append(titer, [ path, path ])
96
105
 
97
106
        if len(delta.renamed):
98
107
            changes = True
99
 
            titer = self.model.append(None, [ _i18n('Renamed'), None ])
 
108
            titer = self.model.append(None, [ _('Renamed'), None ])
100
109
            for oldpath, newpath, id, kind, text_modified, meta_modified \
101
110
                    in delta.renamed:
102
111
                self.model.append(titer, [ oldpath, newpath ])
103
112
 
104
113
        if len(delta.modified):
105
114
            changes = True
106
 
            titer = self.model.append(None, [ _i18n('Modified'), None ])
 
115
            titer = self.model.append(None, [ _('Modified'), None ])
107
116
            for path, id, kind, text_modified, meta_modified in delta.modified:
108
117
                self.model.append(titer, [ path, path ])
109
 
 
 
118
        
110
119
        done_unknown = False
111
120
        for path in self.wt.unknowns():
112
121
            changes = True
113
122
            if not done_unknown:
114
 
                titer = self.model.append(None, [ _i18n('Unknown'), None ])
 
123
                titer = self.model.append(None, [ _('Unknown'), None ])
115
124
                done_unknown = True
116
125
            self.model.append(titer, [ path, path ])
117
126
 
118
127
        if not changes:
119
 
            self.model.append(None, [ _i18n('No changes.'), None ])
 
128
            self.model.append(None, [ _('No changes.'), None ])
120
129
 
121
130
        self.treeview.expand_all()
 
131
    
 
132
    def display(self):
 
133
        """ Display the Diff window. """
 
134
        if self.notbranch:
 
135
            error_dialog(_('Directory is not a branch'),
 
136
                                     _('You can perform this action only in a branch.'))
 
137
            self.close()
 
138
        else:
 
139
            self.window.show_all()
122
140
 
123
141
    def close(self, widget=None):
124
142
        self.window.destroy()