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

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-07-24 14:32:01 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060724143201-d0df92c78dd2c610
2006-07-24  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * olive.glade: improvements to the Commit dialog
    * olive/frontend/gtk/commit.py: merged Jelmer Vernooij's integration branch
      and some code from bzr-gtk (select files to commit)
    * TODO: added some wishlist stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
try:
25
25
    import gtk
26
26
    import gtk.glade
 
27
    import gobject
27
28
except:
28
29
    sys.exit(1)
29
30
 
30
 
import olive.backend.commit as commit
31
 
import olive.backend.errors as errors
 
31
from bzrlib.delta import compare_trees
 
32
import bzrlib.errors as errors
 
33
from bzrlib.workingtree import WorkingTree
 
34
 
 
35
from dialog import OliveDialog
32
36
 
33
37
class OliveCommit:
34
38
    """ Display Commit dialog and perform the needed actions. """
39
43
        
40
44
        self.comm = comm
41
45
        
 
46
        self.dialog = OliveDialog(self.gladefile)
 
47
        
 
48
        # Check if current location is a branch
 
49
        try:
 
50
            (self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
 
51
            branch = self.wt.branch
 
52
        except errors.NotBranchError:
 
53
            self.notbranch = True
 
54
            return
 
55
        except:
 
56
            raise
 
57
 
 
58
        file_id = self.wt.path2id(path)
 
59
 
 
60
        self.notbranch = False
 
61
        if file_id is None:
 
62
            self.notbranch = True
 
63
            return
 
64
        
 
65
        # Set the delta
 
66
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
 
67
        self.delta = compare_trees(self.old_tree, self.wt)
 
68
        
 
69
        # Get the Commit dialog widget
42
70
        self.window = self.glade.get_widget('window_commit')
43
71
        
44
72
        # Dictionary for signal_autoconnect
47
75
        
48
76
        # Connect the signals to the handlers
49
77
        self.glade.signal_autoconnect(dic)
 
78
        
 
79
        # Create the file list
 
80
        self._create_file_view()
50
81
    
51
82
    def display(self):
52
83
        """ Display the Push dialog. """
53
 
        self.window.show_all()
 
84
        if self.notbranch:
 
85
            self.dialog.error_dialog('Directory is not a branch.')
 
86
        else:
 
87
            self.window.show_all()
 
88
    
 
89
    # This code is from Jelmer Vernooij's bzr-gtk branch
 
90
    def _create_file_view(self):
 
91
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING)
 
92
        self.file_view = self.glade.get_widget('treeview_commit_select')
 
93
        self.file_view.set_model(self.file_store)
 
94
        crt = gtk.CellRendererToggle()
 
95
        crt.set_property("activatable", True)
 
96
        crt.connect("toggled", self._toggle_commit, self.file_store)
 
97
        self.file_view.append_column(gtk.TreeViewColumn("Commit",crt,active=0))
 
98
        self.file_view.append_column(gtk.TreeViewColumn("Path",gtk.CellRendererText(),text=1))
 
99
        self.file_view.append_column(gtk.TreeViewColumn("Type",gtk.CellRendererText(),text=2))
 
100
 
 
101
        for path, id, kind in self.delta.added:
 
102
            self.file_store.append([ True, path, "added" ])
 
103
 
 
104
        for path, id, kind in self.delta.removed:
 
105
            self.file_store.append([ True, path, "removed" ])
 
106
 
 
107
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
 
108
            self.file_store.append([ True, oldpath, "renamed"])
 
109
 
 
110
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
 
111
            self.file_store.append([ True, path, "modified"])
 
112
    
 
113
    def _get_specific_files(self):
 
114
        ret = []
 
115
        it = self.file_store.get_iter_first()
 
116
        while it:
 
117
            if self.file_store.get_value(it, 0):
 
118
                ret.append(self.file_store.get_value(it,1))
 
119
            it = self.file_store.iter_next(it)
 
120
 
 
121
        return ret
 
122
    # end of bzr-gtk code
 
123
    
 
124
    def _toggle_commit(self, cell, path, model):
 
125
        model[path][0] = not model[path][0]
 
126
        return
54
127
    
55
128
    def commit(self, widget):
56
 
        from dialog import OliveDialog
57
 
        dialog = OliveDialog(self.gladefile)
58
 
        
59
129
        textview = self.glade.get_widget('textview_commit')
60
130
        textbuffer = textview.get_buffer()
61
131
        start, end = textbuffer.get_bounds()
65
135
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
66
136
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
67
137
        
 
138
        specific_files = self._get_specific_files()
 
139
        
 
140
        # merged from Jelmer Vernooij's olive integration branch
68
141
        try:
69
 
            commit.commit([self.comm.get_path()], message, None,
70
 
                          checkbutton_force.get_active(),
71
 
                          checkbutton_strict.get_active(),
72
 
                          checkbutton_local.get_active())
 
142
            self.wt.commit(message, 
 
143
                           allow_pointless=checkbutton_force.get_active(),
 
144
                           strict=checkbutton_strict.get_active(),
 
145
                           local=checkbutton_local.get_active(),
 
146
                           specific_files=specific_files)
73
147
        except errors.NotBranchError:
74
 
            dialog.error_dialog('Directory is not a branch.')
 
148
            self.dialog.error_dialog('Directory is not a branch.')
75
149
            return
76
150
        except errors.LocalRequiresBoundBranch:
77
 
            dialog.error_dialog('Local commit requires a bound branch.')
78
 
            return
79
 
        except errors.EmptyMessageError:
80
 
            dialog.error_dialog('Commit message is empty.')
81
 
            return
82
 
        except errors.NoChangesToCommitError:
83
 
            dialog.error_dialog('No changes to commit. Try force commit.')
84
 
            return
85
 
        except errors.ConflictsInTreeError:
86
 
            dialog.error_dialog('Conflicts in tree. Please resolve them first.')
87
 
            return
88
 
        except errors.StrictCommitError:
89
 
            dialog.error_dialog('Strict commit failed. There are unknown files.')
 
151
            self.dialog.error_dialog('Local commit requires a bound branch.')
 
152
            return
 
153
        except errors.PointlessCommit:
 
154
            self.dialog.error_dialog('No changes to commit. Try force commit.')
 
155
            return
 
156
        except errors.ConflictsInTree:
 
157
            self.dialog.error_dialog('Conflicts in tree. Please resolve them first.')
 
158
            return
 
159
        except errors.StrictCommitFailed:
 
160
            self.dialog.error_dialog('Strict commit failed. There are unknown files.')
90
161
            return
91
162
        except errors.BoundBranchOutOfDate, errmsg:
92
 
            dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
 
163
            self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
93
164
            return
94
165
        except:
95
166
            raise