/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
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
27
from bzrlib.branch import Branch
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
28
import bzrlib.errors as errors
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
29
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
30
from bzrlib.plugins.gtk import _i18n
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
32
from bzrlib.plugins.gtk.errors import show_bzr_error
33
34
35
class MergeDialog(gtk.Dialog):
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
36
    """ Display the Merge dialog and perform the needed actions. """
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
37
    
38
    def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
39
        """ Initialize the Merge dialog. """
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
40
        gtk.Dialog.__init__(self, title="Olive - Merge",
41
                                  parent=parent,
42
                                  flags=0,
43
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
44
        
45
        # Get arguments
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
46
        self.wt = wt
47
        self.wtpath = wtpath
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
48
        
571.1.1 by Jasper Groenewegen
Add gmerge command and change MergeDialog to set parent as default if available
49
        if default_branch_path and os.path.isdir(default_branch_path.partition('file://')[2]):
50
            directory = default_branch_path.partition('file://')[2]
51
        else:
52
            directory = os.path.dirname(self.wt.abspath(self.wtpath))
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
53
        
54
        # Create widgets
55
        self._hbox = gtk.HBox()
56
        self._label_merge_from = gtk.Label(_i18n("Merge from"))
57
        self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
58
                                    parent=self.window,
59
                                    action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
60
                                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
61
                                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
62
        self._filechooser_dialog.set_default_response(gtk.RESPONSE_OK)
63
        self._filechooser = gtk.FileChooserButton(self._filechooser_dialog)
64
        self._button_merge = gtk.Button(_i18n("_Merge"))
65
        self._button_merge_icon = gtk.Image()
66
        self._button_merge_icon.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
67
        self._button_merge.set_image(self._button_merge_icon)
68
        
69
        self._button_merge.connect('clicked', self._on_merge_clicked)
70
        
71
        # Set location
72
        self._filechooser_dialog.set_current_folder(directory)
73
        
74
        # Add widgets to dialog
75
        self.vbox.add(self._hbox)
76
        self._hbox.add(self._label_merge_from)
533.2.4 by Jasper Groenewegen
Fix what is broken
77
        self._hbox.add(self._filechooser)
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
78
        self._hbox.set_spacing(5)
79
        self.action_area.pack_end(self._button_merge)
80
        
81
        self.vbox.show_all()
93 by Szilveszter Farkas (Phanatic)
Began to implement Merge dialog.
82
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
83
    @show_bzr_error
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
84
    def _on_merge_clicked(self, widget):
85
        branch = self._filechooser.get_filename()
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
86
        if branch == "":
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
87
            error_dialog(_i18n('Branch not given'),
88
                         _i18n('Please specify a branch to merge from.'))
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
89
            return
90
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
91
        other_branch = Branch.open_containing(branch)[0]
92
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
93
        try:
94
            conflicts = self.wt.merge_from_branch(other_branch)
95
        except errors.BzrCommandError, errmsg:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
96
            error_dialog(_i18n('Bazaar command error'), str(errmsg))
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
97
            return
98
        
99
        if conflicts == 0:
100
            # No conflicts found.
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
101
            info_dialog(_i18n('Merge successful'),
102
                        _i18n('All changes applied successfully.'))
98 by Szilveszter Farkas (Phanatic)
Implemented basic Merge functionality.
103
        else:
104
            # There are conflicts to be resolved.
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
105
            warning_dialog(_i18n('Conflicts encountered'),
106
                           _i18n('Please resolve the conflicts manually before committing.'))
533.1.1 by Jasper Groenewegen
Replace MergeDialog with glade-less version.
107
        
108
        self.response(gtk.RESPONSE_OK)