/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
  • Date: 2011-04-06 14:53:44 UTC
  • Revision ID: jelmer@samba.org-20110406145344-m6s0i7q7ssjwhmwq
Support use without gtk.Spinner, which is only available in pygtk >= 2.22.

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
20
26
 
21
27
from bzrlib.branch import Branch
22
28
import bzrlib.errors as errors
23
29
 
24
 
from bzrlib.plugins.gtk import icon_path
 
30
from bzrlib.plugins.gtk import _i18n, icon_path
25
31
from bzrlib.plugins.gtk.dialog import (
26
32
    error_dialog,
27
33
    info_dialog,
28
34
    warning_dialog,
29
35
    )
30
36
from bzrlib.plugins.gtk.errors import show_bzr_error
31
 
from bzrlib.plugins.gtk.i18n import _i18n
32
 
 
33
 
 
34
 
class MergeDialog(Gtk.Dialog):
 
37
 
 
38
 
 
39
class MergeDialog(gtk.Dialog):
35
40
    """ Display the Merge dialog and perform the needed actions. """
36
41
    
37
42
    def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
38
43
        """ 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))
 
44
        gtk.Dialog.__init__(self, title="Merge changes",
 
45
                                  parent=parent,
 
46
                                  flags=0,
 
47
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
42
48
        self.set_icon_from_file(icon_path("bzr-icon-64.png"))
43
49
        # Get arguments
44
50
        self.wt = wt
47
53
        self.parent_window = parent
48
54
        
49
55
        # 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()
 
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()
54
60
        for entry in [_i18n("Folder"),_i18n("Custom Location")]:
55
61
            self._combo_source.append_text(entry)
56
62
        self._combo_source.connect("changed", self._on_combo_changed)
57
 
        self._button_merge = Gtk.Button(_i18n("_Merge"))
58
 
        self._button_merge_icon = Gtk.Image()
59
 
        self._button_merge_icon.set_from_stock(Gtk.STOCK_APPLY, Gtk.IconSize.BUTTON)
 
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)
60
66
        self._button_merge.set_image(self._button_merge_icon)
61
67
        self._button_merge.connect('clicked', self._on_merge_clicked)
62
68
        
63
69
        # Add widgets to dialog
64
 
        self.get_content_area().pack_start(self._hbox, False, False, 0)
 
70
        self.vbox.pack_start(self._hbox, False, False, 0)
65
71
        self._hbox.add(self._label_merge_from)
66
72
        self._hbox.add(self._combo_source)
67
73
        self._hbox.set_spacing(5)
68
 
        self.action_area.pack_end(self._button_merge, False, False, 0)
 
74
        self.action_area.pack_end(self._button_merge)
69
75
        
70
76
        if self.default_branch_path and os.path.isdir(
71
77
                            self.default_branch_path.partition('file://')[2]):
76
82
        else:
77
83
            # If no default_branch_path give, default to folder source with current folder
78
84
            self._combo_source.set_active(0)
79
 
        self.get_content_area().show_all()
 
85
        self.vbox.show_all()
80
86
    
81
87
    def _on_folder_source(self):
82
88
        """ 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",
 
89
        self._source = gtk.HBox()
 
90
        self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
85
91
                                    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)
 
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)
91
97
        self._filechooser.show()
92
98
        directory = getattr(self, 'directory', None)
93
99
        if not directory:
94
100
            directory = os.path.dirname(self.wt.abspath(self.wtpath))
95
101
        self._filechooser_dialog.set_current_folder(directory)
96
102
        self._source.pack_start(self._filechooser, True, True, 0)
97
 
        self.get_content_area().pack_start(self._source, True, True, 5)
 
103
        self.vbox.pack_start(self._source, True, True, 5)
98
104
        self._source.show()
99
105
    
100
106
    def _on_custom_source(self):
101
107
        """ Merge from a custom source (can be folder, remote, etc), create entry """
102
 
        self._source = Gtk.HBox()
103
 
        self._custom_entry = Gtk.Entry()
 
108
        self._source = gtk.HBox()
 
109
        self._custom_entry = gtk.Entry()
104
110
        if self.default_branch_path:
105
111
            self._custom_entry.set_text(self.default_branch_path)
106
112
        self._custom_entry.connect("activate", self._on_merge_clicked)
107
113
        self._custom_entry.show()
108
114
        self._source.pack_start(self._custom_entry, True, True, 0)
109
 
        self.get_content_area().pack_start(self._source, True, True, 5)
 
115
        self.vbox.pack_start(self._source, True, True, 5)
110
116
        self._source.show()
111
117
    
112
118
    def _on_combo_changed(self, widget):
148
154
            warning_dialog(_i18n('Conflicts encountered'),
149
155
                           _i18n('Please resolve the conflicts manually before committing.'))
150
156
        
151
 
        self.response(Gtk.ResponseType.OK)
 
157
        self.response(gtk.RESPONSE_OK)