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

  • Committer: Aaron Bentley
  • Date: 2007-01-17 06:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: aaron.bentley@utoronto.ca-20070117064255-x4gznz5e0lyjq3gk
Remove usused span selector

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import pango
27
27
 
28
28
import bzrlib.errors as errors
29
 
 
30
 
from dialog import error_dialog
31
 
from olive import gladefile
 
29
from bzrlib import osutils
 
30
 
 
31
from dialog import error_dialog, question_dialog
 
32
from guifiles import GLADEFILENAME
 
33
 
32
34
 
33
35
class CommitDialog:
34
36
    """ Display Commit dialog and perform the needed actions. """
35
 
    def __init__(self, wt, wtpath):
36
 
        """ Initialize the Commit dialog. """
37
 
        self.glade = gtk.glade.XML(gladefile, 'window_commit', 'olive-gtk')
 
37
    def __init__(self, wt, wtpath, notbranch):
 
38
        """ Initialize the Commit dialog.
 
39
        :param  wt:         bzr working tree object
 
40
        :param  wtpath:     path to working tree root
 
41
        :param  notbranch:  flag that path is not a brach
 
42
        :type   notbranch:  bool
 
43
        """
 
44
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_commit', 'olive-gtk')
38
45
        
39
46
        self.wt = wt
40
47
        self.wtpath = wtpath
 
48
        self.notbranch = notbranch
41
49
 
42
50
        # Get some important widgets
43
51
        self.window = self.glade.get_widget('window_commit')
44
52
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
45
53
        self.textview = self.glade.get_widget('textview_commit')
 
54
        self.file_expander = self.glade.get_widget('expander_commit_select')
46
55
        self.file_view = self.glade.get_widget('treeview_commit_select')
 
56
        self.pending_expander = self.glade.get_widget('expander_commit_pending')
47
57
        self.pending_label = self.glade.get_widget('label_commit_pending')
48
58
        self.pending_view = self.glade.get_widget('treeview_commit_pending')
49
59
 
50
 
        file_id = self.wt.path2id(wtpath)
51
 
 
52
 
        self.notbranch = False
53
 
        if file_id is None:
54
 
            self.notbranch = True
 
60
        if wt is None or notbranch:
55
61
            return
56
62
        
57
63
        # Set the delta
64
70
        # Dictionary for signal_autoconnect
65
71
        dic = { "on_button_commit_commit_clicked": self.commit,
66
72
                "on_button_commit_cancel_clicked": self.close }
67
 
        
 
73
 
68
74
        # Connect the signals to the handlers
69
75
        self.glade.signal_autoconnect(dic)
70
76
        
74
80
        self._create_pending_merges()
75
81
    
76
82
    def display(self):
77
 
        """ Display the Push dialog. """
 
83
        """ Display the Push dialog.
 
84
        @return:    True if dialog is shown.
 
85
        """
 
86
        if self.wt is None and not self.notbranch:
 
87
            error_dialog(_('Directory does not have a working tree'),
 
88
                         _('Operation aborted.'))
 
89
            self.close()
 
90
            return False
78
91
        if self.notbranch:
79
92
            error_dialog(_('Directory is not a branch'),
80
93
                         _('You can perform this action only in a branch.'))
81
94
            self.close()
 
95
            return False
82
96
        else:
83
97
            if self.wt.branch.get_bound_location() is not None:
84
98
                # we have a checkout, so the local commit checkbox must appear
86
100
            
87
101
            if self.pending:
88
102
                # There are pending merges, file selection not supported
 
103
                self.file_expander.set_expanded(False)
89
104
                self.file_view.set_sensitive(False)
90
105
            else:
91
106
                # No pending merges
92
 
                self.pending_view.set_sensitive(False)
 
107
                self.pending_expander.hide()
93
108
            
94
109
            self.textview.modify_font(pango.FontDescription("Monospace"))
95
110
            self.window.show()
96
 
            
 
111
            return True
97
112
    
98
113
    def _create_file_view(self):
99
 
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
100
 
                                        gobject.TYPE_STRING,
101
 
                                        gobject.TYPE_STRING)
 
114
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
 
115
                                        gobject.TYPE_STRING,    # [1] path to display
 
116
                                        gobject.TYPE_STRING,    # [2] changes type
 
117
                                        gobject.TYPE_STRING)    # [3] real path
102
118
        self.file_view.set_model(self.file_store)
103
119
        crt = gtk.CellRendererToggle()
104
120
        crt.set_property("activatable", True)
111
127
                                     gtk.CellRendererText(), text=2))
112
128
 
113
129
        for path, id, kind in self.delta.added:
114
 
            self.file_store.append([ True, path, _('added') ])
 
130
            marker = osutils.kind_marker(kind)
 
131
            self.file_store.append([ True, path+marker, _('added'), path ])
115
132
 
116
133
        for path, id, kind in self.delta.removed:
117
 
            self.file_store.append([ True, path, _('removed') ])
 
134
            marker = osutils.kind_marker(kind)
 
135
            self.file_store.append([ True, path+marker, _('removed'), path ])
118
136
 
119
137
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
120
 
            self.file_store.append([ True, oldpath, _('renamed') ])
 
138
            marker = osutils.kind_marker(kind)
 
139
            if text_modified or meta_modified:
 
140
                changes = _('renamed and modified')
 
141
            else:
 
142
                changes = _('renamed')
 
143
            self.file_store.append([ True,
 
144
                                     oldpath+marker + '  =>  ' + newpath+marker,
 
145
                                     changes,
 
146
                                     newpath
 
147
                                   ])
121
148
 
122
149
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
123
 
            self.file_store.append([ True, path, _('modified') ])
 
150
            marker = osutils.kind_marker(kind)
 
151
            self.file_store.append([ True, path+marker, _('modified'), path ])
124
152
    
125
153
    def _create_pending_merges(self):
 
154
        if not self.pending:
 
155
            # hide unused pending merge part
 
156
            scrolled_window = self.glade.get_widget('scrolledwindow_commit_pending')
 
157
            parent = scrolled_window.get_parent()
 
158
            parent.remove(scrolled_window)
 
159
            parent = self.pending_label.get_parent()
 
160
            parent.remove(self.pending_label)
 
161
            return
 
162
        
126
163
        liststore = gtk.ListStore(gobject.TYPE_STRING,
127
164
                                  gobject.TYPE_STRING,
128
165
                                  gobject.TYPE_STRING)
135
172
        self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
136
173
                                        gtk.CellRendererText(), text=2))
137
174
        
138
 
        if not self.pending:
139
 
            return
140
 
        
141
175
        for item in self.pending:
142
176
            liststore.append([ item['date'],
143
177
                               item['committer'],
148
182
        it = self.file_store.get_iter_first()
149
183
        while it:
150
184
            if self.file_store.get_value(it, 0):
151
 
                ret.append(self.file_store.get_value(it, 1))
 
185
                # get real path from hidden column 3
 
186
                ret.append(self.file_store.get_value(it, 3))
152
187
            it = self.file_store.iter_next(it)
153
188
 
154
189
        return ret
224
259
    def commit(self, widget):
225
260
        textbuffer = self.textview.get_buffer()
226
261
        start, end = textbuffer.get_bounds()
227
 
        message = textbuffer.get_text(start, end)
 
262
        message = textbuffer.get_text(start, end).decode('utf-8')
228
263
        
229
264
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
230
265
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
233
268
            specific_files = self._get_specific_files()
234
269
        else:
235
270
            specific_files = None
236
 
        
 
271
 
 
272
        if message == '':
 
273
            response = question_dialog('Commit with an empty message ?',
 
274
                                       'You can describe your commit intent'
 
275
                                       +' in the message')
 
276
            if response == gtk.RESPONSE_NO:
 
277
                # Kindly give focus to message area
 
278
                self.textview.grab_focus()
 
279
                return
 
280
 
237
281
        try:
238
 
            self.wt.commit(message, 
 
282
            self.wt.commit(message,
239
283
                           allow_pointless=checkbutton_force.get_active(),
240
284
                           strict=checkbutton_strict.get_active(),
241
285
                           local=self.checkbutton_local.get_active(),
270
314
        except Exception, msg:
271
315
            error_dialog(_('Unknown error'), str(msg))
272
316
            return
273
 
        
 
317
 
274
318
        self.close()
275
 
        
 
319
 
276
320
    def close(self, widget=None):
277
321
        self.window.destroy()