/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
 
19
 
from gi.repository import Gtk
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
 
 
25
import gtk
 
26
import gtk.glade
20
27
 
21
28
from bzrlib.branch import Branch
22
29
import bzrlib.errors as errors
23
 
 
24
 
from bzrlib.plugins.gtk import icon_path
25
 
from bzrlib.plugins.gtk.dialog import (
26
 
    error_dialog,
27
 
    info_dialog,
28
 
    warning_dialog,
29
 
    )
30
 
from bzrlib.plugins.gtk.errors import show_bzr_error
31
 
from bzrlib.plugins.gtk.i18n import _i18n
32
 
 
33
 
 
34
 
class MergeDialog(Gtk.Dialog):
 
30
from bzrlib.plugins.gtk import _i18n
 
31
 
 
32
from dialog import error_dialog, info_dialog, warning_dialog
 
33
from errors import show_bzr_error
 
34
from olive.guifiles import GLADEFILENAME
 
35
 
 
36
 
 
37
class MergeDialog:
35
38
    """ Display the Merge dialog and perform the needed actions. """
36
 
    
37
 
    def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
 
39
    def __init__(self, wt, wtpath,default_branch_path=None):
38
40
        """ Initialize the Merge dialog. """
39
 
        super(MergeDialog, self).__init__(
40
 
            title="Merge changes", parent=parent, flags=0,
41
 
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
42
 
        self.set_icon_from_file(icon_path("bzr-icon-64.png"))
43
 
        # Get arguments
 
41
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_merge', 'olive-gtk')
 
42
        
 
43
        self.window = self.glade.get_widget('window_merge')
 
44
        
 
45
        # Dictionary for signal_autoconnect
 
46
        dic = { "on_button_merge_merge_clicked": self.merge,
 
47
                "on_button_merge_cancel_clicked": self.close,
 
48
                "on_button_merge_open_clicked": self.open }
 
49
        
 
50
        # Connect the signals to the handlers
 
51
        self.glade.signal_autoconnect(dic)
 
52
 
44
53
        self.wt = wt
45
54
        self.wtpath = wtpath
46
 
        self.default_branch_path = default_branch_path
47
 
        self.parent_window = parent
48
 
        
49
 
        # Create widgets
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()
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)
57
 
        self._button_merge = Gtk.Button(_i18n("_Merge"), use_underline=True)
58
 
        self._button_merge_icon = Gtk.Image()
59
 
        self._button_merge_icon.set_from_stock(Gtk.STOCK_APPLY, Gtk.IconSize.BUTTON)
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
64
 
        self.get_content_area().pack_start(self._hbox, False, False, 0)
65
 
        self._hbox.add(self._label_merge_from)
66
 
        self._hbox.add(self._combo_source)
67
 
        self._hbox.set_spacing(5)
68
 
        self.action_area.pack_end(self._button_merge, False, False, 0)
69
 
        
70
 
        if self.default_branch_path and os.path.isdir(
71
 
                            self.default_branch_path.partition('file://')[2]):
72
 
            self.directory = self.default_branch_path.partition('file://')[2]
73
 
            self._combo_source.set_active(0)
74
 
        elif self.default_branch_path:
75
 
            self._combo_source.set_active(1)
76
 
        else:
77
 
            # If no default_branch_path give, default to folder source with current folder
78
 
            self._combo_source.set_active(0)
79
 
        self.get_content_area().show_all()
80
 
    
81
 
    def _on_folder_source(self):
82
 
        """ Merge from folder, create a filechooser dialog and button """
83
 
        self._source = Gtk.HBox()
84
 
        self._filechooser_dialog = Gtk.FileChooserDialog(title="Please select a folder",
85
 
                                    parent=self.parent_window,
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)
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)
97
 
        self.get_content_area().pack_start(self._source, True, True, 5)
98
 
        self._source.show()
99
 
    
100
 
    def _on_custom_source(self):
101
 
        """ Merge from a custom source (can be folder, remote, etc), create entry """
102
 
        self._source = Gtk.HBox()
103
 
        self._custom_entry = Gtk.Entry()
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)
107
 
        self._custom_entry.show()
108
 
        self._source.pack_start(self._custom_entry, True, True, 0)
109
 
        self.get_content_area().pack_start(self._source, True, True, 5)
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
 
    
 
55
        
 
56
        # Get some widgets
 
57
        self.entry = self.glade.get_widget('entry_merge')
 
58
        if default_branch_path:
 
59
            self.entry.set_text(default_branch_path)
 
60
 
 
61
    def display(self):
 
62
        """ Display the Add file(s) dialog. """
 
63
        self.window.show_all()
 
64
 
122
65
    @show_bzr_error
123
 
    def _on_merge_clicked(self, widget):
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()
 
66
    def merge(self, widget):
 
67
        branch = self.entry.get_text()
129
68
        if branch == "":
130
69
            error_dialog(_i18n('Branch not given'),
131
70
                         _i18n('Please specify a branch to merge from.'))
139
78
            error_dialog(_i18n('Bazaar command error'), str(errmsg))
140
79
            return
141
80
        
 
81
        self.close()
142
82
        if conflicts == 0:
143
83
            # No conflicts found.
144
84
            info_dialog(_i18n('Merge successful'),
147
87
            # There are conflicts to be resolved.
148
88
            warning_dialog(_i18n('Conflicts encountered'),
149
89
                           _i18n('Please resolve the conflicts manually before committing.'))
150
 
        
151
 
        self.response(Gtk.ResponseType.OK)
 
90
    
 
91
    def open(self, widget):
 
92
        fcd = gtk.FileChooserDialog(title="Please select a folder",
 
93
                                    parent=self.window,
 
94
                                    action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
95
                                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
 
96
                                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
 
97
        fcd.set_default_response(gtk.RESPONSE_OK)
 
98
        
 
99
        if fcd.run() == gtk.RESPONSE_OK:
 
100
            self.entry.set_text(fcd.get_filename())
 
101
        
 
102
        fcd.destroy()
 
103
        
 
104
    def close(self, widget=None):
 
105
        self.window.destroy()