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

  • Committer: Jelmer Vernooij
  • Date: 2011-03-14 20:12:19 UTC
  • Revision ID: jelmer@samba.org-20110314201219-wo692nzwywu6mevh
Fix formatting, imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import gtk
26
26
 
27
 
from errors import show_bzr_error
28
 
 
 
27
from bzrlib import (
 
28
    errors,
 
29
    )
29
30
from bzrlib.branch import Branch
30
 
import bzrlib.errors as errors
 
31
from bzrlib.transport import get_transport
 
32
 
31
33
 
32
34
from bzrlib.plugins.gtk import _i18n
33
35
 
34
 
from dialog import error_dialog, info_dialog
 
36
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog
 
37
from bzrlib.plugins.gtk.errors import show_bzr_error
 
38
from bzrlib.plugins.gtk.branchbox import BranchSelectionBox
35
39
 
36
 
from branchbox import BranchSelectionBox
37
40
 
38
41
class BranchDialog(gtk.Dialog):
39
42
    """ New implementation of the Branch dialog. """
44
47
                                  parent=parent,
45
48
                                  flags=0,
46
49
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
47
 
        
 
50
 
48
51
        # Get arguments
49
52
        self.path = path
50
 
        
 
53
 
51
54
        # Create the widgets
52
55
        self._button_branch = gtk.Button(_i18n("_Branch"), use_underline=True)
53
56
        self._remote_branch = BranchSelectionBox()
62
65
        self._hbox_revision = gtk.HBox()
63
66
        self._entry_revision = gtk.Entry()
64
67
        self._entry_nick = gtk.Entry()
65
 
        
 
68
 
66
69
        # Set callbacks
67
70
        self._button_branch.connect('clicked', self._on_branch_clicked)
68
71
        self._button_revision.connect('clicked', self._on_revision_clicked)
78
81
        self._table.attach(self._filechooser, 1, 2, 1, 2)
79
82
        self._table.attach(self._entry_nick, 1, 2, 2, 3)
80
83
        self._table.attach(self._hbox_revision, 1, 2, 3, 4)
81
 
        
 
84
 
82
85
        # Set properties
83
86
        self._image_browse = gtk.Image()
84
87
        self._image_browse.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
94
97
            self._remote_branch.set_url(remote_path)
95
98
        if self.path is not None:
96
99
            self._filechooser.set_filename(self.path)
97
 
        
 
100
 
98
101
        # Pack some widgets
99
102
        self._hbox_revision.pack_start(self._entry_revision, True, True)
100
103
        self._hbox_revision.pack_start(self._button_revision, False, False)
101
104
        self.vbox.add(self._table)
102
105
        self.action_area.pack_end(self._button_branch)
103
 
        
 
106
 
104
107
        # Show the dialog
105
108
        self.vbox.show_all()
106
 
    
 
109
 
107
110
    def _get_last_revno(self):
108
111
        """ Get the revno of the last revision (if any). """
109
112
        try:
111
114
            return br.revno()
112
115
        except:
113
116
            pass
114
 
    
 
117
 
115
118
    def _on_revision_clicked(self, button):
116
119
        """ Browse for revision button clicked handler. """
117
120
        from revbrowser import RevisionBrowser
118
 
        
119
 
        
 
121
 
 
122
 
120
123
        try:
121
124
            br = self._remote_branch.get_branch()
122
125
        except:
125
128
        response = revb.run()
126
129
        if response != gtk.RESPONSE_NONE:
127
130
            revb.hide()
128
 
    
 
131
 
129
132
            if response == gtk.RESPONSE_OK:
130
133
                if revb.selected_revno is not None:
131
134
                    self._entry_revision.set_text(revb.selected_revno)
132
 
        
 
135
 
133
136
            revb.destroy()
134
 
    
 
137
 
135
138
    @show_bzr_error
136
139
    def _on_branch_clicked(self, button):
137
140
        """ Branch button clicked handler. """
140
143
            error_dialog(_i18n('Missing branch location'),
141
144
                         _i18n('You must specify a branch location.'))
142
145
            return
143
 
        
 
146
 
144
147
        destination = self._filechooser.get_filename()
145
148
        try:
146
149
            revno = int(self._entry_revision.get_text())
147
150
        except:
148
151
            revno = None
149
 
        
 
152
 
150
153
        nick = self._entry_nick.get_text()
151
154
        if nick is '':
152
155
            nick = os.path.basename(location.rstrip("/\\"))
153
 
        
 
156
 
154
157
        br_from = Branch.open(location)
155
 
        
 
158
 
156
159
        br_from.lock_read()
157
160
        try:
158
 
            from bzrlib.transport import get_transport
159
 
 
160
161
            revision_id = br_from.get_rev_id(revno)
161
162
 
162
163
            basis_dir = None
163
 
            
 
164
 
164
165
            to_location = destination + os.sep + nick
165
166
            to_transport = get_transport(to_location)
166
 
            
 
167
 
167
168
            to_transport.mkdir('.')
168
 
            
 
169
 
169
170
            try:
170
171
                # preserve whatever source format we have.
171
172
                dir = br_from.bzrdir.sprout(to_transport.base,
178
179
                raise
179
180
        finally:
180
181
            br_from.unlock()
181
 
                
 
182
 
182
183
        info_dialog(_i18n('Branching successful'),
183
184
                    _i18n('%d revision(s) branched.') % revs)
184
 
        
 
185
 
185
186
        self.response(gtk.RESPONSE_OK)
186
 
    
 
187
 
187
188
    def _on_branch_changed(self, widget, event):
188
189
        """ We try to get the last revision if focus lost. """
189
190
        rev = self._get_last_revno()