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

  • Committer: Jelmer Vernooij
  • Author(s): Fabio Zanini
  • Date: 2011-04-04 17:52:28 UTC
  • Revision ID: jelmer@samba.org-20110404175228-wz8eczzurrowmxju
Fix import of open_display in bzr-handle-patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
27
from bzrlib.branch import Branch
 
28
import bzrlib.errors as errors
 
29
 
 
30
from bzrlib.plugins.gtk import _i18n, icon_path
 
31
from bzrlib.plugins.gtk.dialog import (
 
32
    error_dialog,
 
33
    info_dialog,
 
34
    warning_dialog,
 
35
    )
 
36
from bzrlib.plugins.gtk.errors import show_bzr_error
 
37
 
 
38
 
 
39
class MergeDialog(gtk.Dialog):
 
40
    """ Display the Merge dialog and perform the needed actions. """
 
41
    
 
42
    def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
 
43
        """ Initialize the Merge dialog. """
 
44
        gtk.Dialog.__init__(self, title="Merge changes",
 
45
                                  parent=parent,
 
46
                                  flags=0,
 
47
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
48
        self.set_icon_from_file(icon_path("bzr-icon-64.png"))
 
49
        # Get arguments
 
50
        self.wt = wt
 
51
        self.wtpath = wtpath
 
52
        self.default_branch_path = default_branch_path
 
53
        self.parent_window = parent
 
54
        
 
55
        # Create widgets
 
56
        self._hbox = gtk.HBox()
 
57
        self._source = gtk.HBox()
 
58
        self._label_merge_from = gtk.Label(_i18n("Merge from"))
 
59
        self._combo_source = gtk.combo_box_new_text()
 
60
        for entry in [_i18n("Folder"),_i18n("Custom Location")]:
 
61
            self._combo_source.append_text(entry)
 
62
        self._combo_source.connect("changed", self._on_combo_changed)
 
63
        self._button_merge = gtk.Button(_i18n("_Merge"))
 
64
        self._button_merge_icon = gtk.Image()
 
65
        self._button_merge_icon.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
 
66
        self._button_merge.set_image(self._button_merge_icon)
 
67
        self._button_merge.connect('clicked', self._on_merge_clicked)
 
68
        
 
69
        # Add widgets to dialog
 
70
        self.vbox.pack_start(self._hbox, False, False, 0)
 
71
        self._hbox.add(self._label_merge_from)
 
72
        self._hbox.add(self._combo_source)
 
73
        self._hbox.set_spacing(5)
 
74
        self.action_area.pack_end(self._button_merge)
 
75
        
 
76
        if self.default_branch_path and os.path.isdir(
 
77
                            self.default_branch_path.partition('file://')[2]):
 
78
            self.directory = self.default_branch_path.partition('file://')[2]
 
79
            self._combo_source.set_active(0)
 
80
        elif self.default_branch_path:
 
81
            self._combo_source.set_active(1)
 
82
        else:
 
83
            # If no default_branch_path give, default to folder source with current folder
 
84
            self._combo_source.set_active(0)
 
85
        self.vbox.show_all()
 
86
    
 
87
    def _on_folder_source(self):
 
88
        """ Merge from folder, create a filechooser dialog and button """
 
89
        self._source = gtk.HBox()
 
90
        self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
 
91
                                    parent=self.parent_window,
 
92
                                    action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
93
                                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
 
94
                                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
 
95
        self._filechooser_dialog.set_default_response(gtk.RESPONSE_OK)
 
96
        self._filechooser = gtk.FileChooserButton(self._filechooser_dialog)
 
97
        self._filechooser.show()
 
98
        directory = getattr(self, 'directory', None)
 
99
        if not directory:
 
100
            directory = os.path.dirname(self.wt.abspath(self.wtpath))
 
101
        self._filechooser_dialog.set_current_folder(directory)
 
102
        self._source.pack_start(self._filechooser, True, True, 0)
 
103
        self.vbox.pack_start(self._source, True, True, 5)
 
104
        self._source.show()
 
105
    
 
106
    def _on_custom_source(self):
 
107
        """ Merge from a custom source (can be folder, remote, etc), create entry """
 
108
        self._source = gtk.HBox()
 
109
        self._custom_entry = gtk.Entry()
 
110
        if self.default_branch_path:
 
111
            self._custom_entry.set_text(self.default_branch_path)
 
112
        self._custom_entry.connect("activate", self._on_merge_clicked)
 
113
        self._custom_entry.show()
 
114
        self._source.pack_start(self._custom_entry, True, True, 0)
 
115
        self.vbox.pack_start(self._source, True, True, 5)
 
116
        self._source.show()
 
117
    
 
118
    def _on_combo_changed(self, widget):
 
119
        merge_source = self._combo_source.get_active()
 
120
        self._source.destroy()
 
121
        if merge_source == 0:
 
122
            # Merge from folder
 
123
            self._on_folder_source()
 
124
        elif merge_source == 1:
 
125
            # Merge from custom
 
126
            self._on_custom_source()
 
127
    
 
128
    @show_bzr_error
 
129
    def _on_merge_clicked(self, widget):
 
130
        merge_source = self._combo_source.get_active()
 
131
        if merge_source == 0:
 
132
            branch = self._filechooser.get_filename()
 
133
        elif merge_source == 1:
 
134
            branch = self._custom_entry.get_text()
 
135
        if branch == "":
 
136
            error_dialog(_i18n('Branch not given'),
 
137
                         _i18n('Please specify a branch to merge from.'))
 
138
            return
 
139
 
 
140
        other_branch = Branch.open_containing(branch)[0]
 
141
 
 
142
        try:
 
143
            conflicts = self.wt.merge_from_branch(other_branch)
 
144
        except errors.BzrCommandError, errmsg:
 
145
            error_dialog(_i18n('Bazaar command error'), str(errmsg))
 
146
            return
 
147
        
 
148
        if conflicts == 0:
 
149
            # No conflicts found.
 
150
            info_dialog(_i18n('Merge successful'),
 
151
                        _i18n('All changes applied successfully.'))
 
152
        else:
 
153
            # There are conflicts to be resolved.
 
154
            warning_dialog(_i18n('Conflicts encountered'),
 
155
                           _i18n('Please resolve the conflicts manually before committing.'))
 
156
        
 
157
        self.response(gtk.RESPONSE_OK)