/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: Curtis Hovey
  • Date: 2011-09-07 16:01:14 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110907160114-ytbap2x584bh1ehw
Fixed long lines created by conversion script. removed checks for obsolete methods.

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