/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import os
18
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
24
25
import gtk
26
import gtk.glade
27
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
28
from bzrlib.branch import Branch
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
29
import bzrlib.errors as errors
30
31
from __init__ import gladefile
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
32
from dialog import error_dialog, info_dialog, warning_dialog
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
33
34
class MergeDialog:
35
    """ Display the Merge dialog and perform the needed actions. """
36
    def __init__(self, wt, wtpath):
37
        """ Initialize the Merge dialog. """
38
        self.glade = gtk.glade.XML(gladefile, 'window_merge', 'olive-gtk')
39
        
40
        self.window = self.glade.get_widget('window_merge')
41
        
42
        # Dictionary for signal_autoconnect
43
        dic = { "on_button_merge_merge_clicked": self.merge,
44
                "on_button_merge_cancel_clicked": self.close,
45
                "on_button_merge_open_clicked": self.open }
46
        
47
        # Connect the signals to the handlers
48
        self.glade.signal_autoconnect(dic)
49
50
        self.wt = wt
51
        self.wtpath = wtpath
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
52
        
53
        # Get some widgets
54
        self.entry = self.glade.get_widget('entry_merge')
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
55
56
    def display(self):
57
        """ Display the Add file(s) dialog. """
58
        self.window.show_all()
59
60
    def merge(self, widget):
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
61
        branch = self.entry.get_text()
62
        if branch == "":
63
            error_dialog(_('Branch not given'),
64
                         _('Please specify a branch to merge from.'))
65
            return
66
67
        try:
68
            other_branch = Branch.open_containing(branch)[0]
69
        except errors.NotBranchError:
70
            error_dialog(_('Specified location not a branch'),
71
                         _('Please specify a branch you want to merge from.'))
72
            return
73
        
74
        try:
75
            conflicts = self.wt.merge_from_branch(other_branch)
76
        except errors.BzrCommandError, errmsg:
77
            error_dialog(_('Bazaar command error'), str(errmsg))
78
            return
79
        
80
        self.close()
81
        if conflicts == 0:
82
            # No conflicts found.
83
            info_dialog(_('Merge successful'),
84
                        _('All changes applied successfully.'))
85
        else:
86
            # There are conflicts to be resolved.
87
            warning_dialog(_('Conflicts encountered'),
88
                           _('Please resolve the conflicts manually before committing.'))
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
89
    
90
    def open(self, widget):
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
91
        fcd = gtk.FileChooserDialog(title="Please select a folder",
92
                                    parent=self.window,
93
                                    action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
94
                                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
95
                                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
96
        fcd.set_default_response(gtk.RESPONSE_OK)
97
        
98
        if fcd.run() == gtk.RESPONSE_OK:
99
            self.entry.set_text(fcd.get_filename())
100
        
101
        fcd.destroy()
102
        
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
103
    def close(self, widget=None):
104
        self.window.destroy()