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