~javierder/bzr-gedit/0.3

« back to all changes in this revision

Viewing changes to plugins/bzr.py

  • Committer: Javier Derderian
  • Date: 2008-03-29 01:03:54 UTC
  • Revision ID: javierder@gmail.com-20080329010354-tfblzevddsfur079
nothing

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import gobject
7
7
 
8
8
from bzrlib import workingtree, branch, bzrdir
9
 
 
 
9
from bzrlib.plugin import load_plugins
 
10
load_plugins() #right now only used to make "branch lp:bla" work
10
11
import bzrlib.errors
11
12
 
12
13
import sys
23
24
            </menu>
24
25
            <menu name="BazaarBranch" action="BazaarBranch">
25
26
                <menuitem name="Comit" action="BazaarComit"/>
 
27
                <menuitem name="Add all..." action="BazaarAddAll"/>
 
28
                <menuitem name="Push to..." action="BazaarPush"/>
26
29
                <menuitem name="Update" action="BazaarUpdate"/>
27
30
            </menu>
28
31
        </menu>
54
57
            if os.path.exists(docuri):
55
58
                if not self._get_is_active_branch(docuri):
56
59
                    docpath = os.path.dirname(docuri)
57
 
                    code, newdocpath = self._bzrInputDialog(docpath,"<big><b>Select path to INIT</b></big>","Choose which is the path where you want to create this bzr")
 
60
                    code, newdocpath = self._bzrInputDialog(docpath,"Select path to INIT","Choose which is the path where you want to create this bzr")
58
61
 
59
62
                    if code == gtk.RESPONSE_OK and newdocpath != '' and os.path.exists(newdocpath) and os.path.isdir(newdocpath) and not self._get_is_active_branch(docuri):
60
63
                        self._bzr_init_wt(newdocpath)
69
72
                else:
70
73
                    print "error, file is already bazaar" # FIXME: ERROR MESSAGE
71
74
            else:
72
 
                print "error, file is not saved" # FIXME: ERROR MESSAGE
 
75
                print "error, file is not saved. save file before inniting" # FIXME: ERROR MESSAGE
 
76
 
 
77
 
73
78
    def on_bazaar_branchfrom(self,menu):
74
79
        doc = self._window.get_active_document()
75
80
        if doc == None:
81
86
            else:
82
87
                localpath = ''
83
88
 
84
 
        bigtext = "<big><b>Enter branch and local path info</b></big>"
 
89
        bigtext = "Enter branch and local path info"
85
90
        text1 = "Enter branch location"
86
91
        text2 = "Choose path where you want to creat your local branch"
87
92
        response,remotebranch, localpath = self._bzrDobleInputDialog("",localpath,bigtext, text1, text2, "")
108
113
                print "error, please enter a local path" # FIXME: ERROR MESSAGE
109
114
 
110
115
 
 
116
    def on_bazaar_commit(self,menu):
 
117
        doc = self._window.get_active_document()
 
118
        if doc == None:
 
119
            print "error, you need to do this from a saved document" # FIXME: ERROR MESSAGE
 
120
        else:
 
121
            docuri = doc.get_uri_for_display() # FIXME: is this the right one? or should i clean up get_uri?
 
122
            if os.path.exists(docuri):
 
123
                localpath = os.path.dirname(docuri)
 
124
                try:
 
125
                    wt,realpath = workingtree.WorkingTree.open_containing(localpath)
 
126
                except:
 
127
                    print "error, can't commit: %s"  % sys.exc_value
 
128
                else:
 
129
                    #let's show our "let's commit dialog!"
 
130
                    response, comment = self._bzrComitDialog(wt.basedir)
 
131
                    if response == gtk.RESPONSE_OK:
 
132
                        try:
 
133
                            wt.commit(comment)
 
134
                        except:
 
135
                            print "error, can't commit: %s"  % sys.exc_value
 
136
                        else:
 
137
                            print "commit ok!" # FIXME: say something to user!!!
 
138
 
 
139
            else:
 
140
                print "error, folder doesn't exists. THAT'S WEIRD!!!" # FIXME: ERROR MESSAGE
 
141
 
 
142
 
 
143
    def on_bazaar_add(self,menu):
 
144
        doc = self._window.get_active_document()
 
145
        if doc == None:
 
146
            print "error, you need to do this from a saved document" # FIXME: ERROR MESSAGE
 
147
        else:
 
148
            docuri = doc.get_uri_for_display() # FIXME: is this the right one? or should i clean up get_uri?
 
149
            if os.path.exists(docuri):
 
150
                localpath = os.path.dirname(docuri)
 
151
                try:
 
152
                    wt,realpath = workingtree.WorkingTree.open_containing(localpath)
 
153
                except:
 
154
                    print "error, can't add: %s"  % sys.exc_value
 
155
                else:
 
156
                    ret = wt.smart_add([wt.basedir])
 
157
            else:
 
158
                print "error, file doesn't exists!"
 
159
 
 
160
 
 
161
    def on_bazaar_push(self,menu):
 
162
        doc = self._window.get_active_document()
 
163
        if doc == None:
 
164
            print "error, you need to do this from a saved document" # FIXME: ERROR MESSAGE
 
165
        else:
 
166
            docuri = doc.get_uri_for_display() # FIXME: is this the right one? or should i clean up get_uri?
 
167
            if os.path.exists(docuri):
 
168
                localpath = os.path.dirname(docuri)
 
169
                try:
 
170
                    br,realpath = branch.Branch.open_containing(localpath)
 
171
                except:
 
172
                    print "error, can't push: %s"  % sys.exc_value # FIXME: error message
 
173
                else:
 
174
                    pushloc = br.get_push_location()
 
175
                    if pushloc == None:
 
176
                        pushloc = ''
 
177
                    response, pushlocation = self._bzrInputDialog(pushloc,"Push your changes", "Enter the location where you want to push your branch","Push")
 
178
                    if response == gtk.RESPONSE_OK and pushlocation != '':
 
179
                        try:
 
180
                            branch_dest = branch.Branch.open(pushlocation)
 
181
                        except:
 
182
                            print "error opening destination branch: %s"  % sys.exc_value # FIXME: error message
 
183
                        else:
 
184
                            res = br.push(branch_dest)
 
185
                            print "pushed!" # FIXME: say something to user!
 
186
                            print res
 
187
                    elif pushlocation == '':
 
188
                        print "error, you have to enter a push location" # FIXME: error message
 
189
 
 
190
                    #ret = wt.smart_add([wt.basedir])
 
191
            else:
 
192
                print "error, file doesn't exists!"
 
193
 
 
194
 
111
195
    def _bzr_init_wt(self,path):
112
196
        print "bazaar, inniting %s" % path
113
197
        wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
151
235
                                         None, _("Branch from..."),
152
236
                                         self.on_bazaar_branchfrom)])
153
237
 
154
 
        self._action_group.add_actions([("BazaarComit", None, _("Update"),
155
 
                                         None, _("Update"),
156
 
                                         self.on_clear_document_activate)])
 
238
        self._action_group.add_actions([("BazaarComit", None, _("Commit"),
 
239
                                         None, _("Commit"),
 
240
                                         self.on_bazaar_commit)])
 
241
        self._action_group.add_actions([("BazaarAddAll", None, _("Add all..."),
 
242
                                         None, _("Add all..."),
 
243
                                         self.on_bazaar_add)])
 
244
        self._action_group.add_actions([("BazaarPush", None, _("Push to..."),
 
245
                                         None, _("Push to..."),
 
246
                                         self.on_bazaar_push)])
 
247
 
 
248
 
 
249
 
157
250
        self._action_group.add_actions([("BazaarUpdate", None, _("Bazaar"),
158
251
                                         None, _("Bazaar"),
159
252
                                         None)])
258
351
        vbox.set_spacing(10)
259
352
        hbox.pack_start(vbox)
260
353
 
261
 
        lbltit = gtk.Label(bigtext)#"<big><b>Select path to INIT</b></big>")
 
354
        lbltit = gtk.Label("<big><b>%s</b></big>" % bigtext)#"<big><b>Select path to INIT</b></big>")
262
355
        lbltit.set_padding(0,10)
263
356
        lbltit.set_use_markup(True)
264
357
        lbltit.set_alignment(0,0)
291
384
        vbox.set_spacing(10)
292
385
        hbox.pack_start(vbox)
293
386
 
294
 
        lbltit = gtk.Label(bigtext)#"<big><b>Select path to INIT</b></big>")
 
387
        lbltit = gtk.Label("<big><b>%s</b></big>" % bigtext)#"<big><b>Select path to INIT</b></big>")
295
388
        lbltit.set_padding(0,10)
296
389
        lbltit.set_use_markup(True)
297
390
        lbltit.set_alignment(0,0)
316
409
        d.destroy()
317
410
        return ret
318
411
 
 
412
    def _bzrComitDialog(self,path):
 
413
        d = gtk.Dialog("Commit",None)
 
414
        hbox = gtk.HBox()
 
415
        d.vbox.pack_start(hbox)
 
416
        d.vbox.set_spacing(2)
 
417
        img = gtk.Image()
 
418
        img.set_from_stock(gtk.STOCK_DIALOG_QUESTION,gtk.ICON_SIZE_DIALOG)
 
419
        hbox.pack_start(img)
 
420
        hbox.set_spacing(10)
 
421
        vbox = gtk.VBox()
 
422
        vbox.set_spacing(10)
 
423
        hbox.pack_start(vbox)
 
424
 
 
425
        lbltit = gtk.Label("<big><b>Commit changes in %s.</b></big>" % path)
 
426
        lbltit.set_padding(0,10)
 
427
        lbltit.set_use_markup(True)
 
428
        lbltit.set_alignment(0,0)
 
429
        vbox.pack_start(lbltit)
 
430
        lbl = gtk.Label("Please enter a comment for your commit")#"Choose which is the path where you want to create this bzr")
 
431
        lbl.set_alignment(0,0)
 
432
        vbox.pack_start(lbl)
 
433
        scrollw = gtk.ScrolledWindow()
 
434
        textview = gtk.TextView()
 
435
        #textview.set_size_request(-1,100)
 
436
        scrollw.add(textview)
 
437
        scrollw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
 
438
        frame = gtk.Frame()
 
439
        frame.add(scrollw)
 
440
        vbox.pack_start(frame)
 
441
        d.vbox.show_all()
 
442
        d.add_buttons(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,gtk.STOCK_OK,gtk.RESPONSE_OK)
 
443
        ret = d.run()
 
444
        buf = textview.get_buffer()
 
445
        bounds = buf.get_bounds()
 
446
        mytext = buf.get_text(bounds[0],bounds[1])
 
447
        d.destroy()
 
448
        return (ret,mytext)
 
449
 
319
450
class BazaarPlugin(gedit.Plugin):
320
451
    def __init__(self):
321
452
        gedit.Plugin.__init__(self)