/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: rodney.dawes at canonical
  • Date: 2008-10-25 06:02:09 UTC
  • Revision ID: rodney.dawes@canonical.com-20081025060209-irlizouino63cs1m
        * preferences/__init__.py:
        Remove the dialog separator
        Remove useless extra call to self._create_pages()
        Make the default window size smaller
        Set the default border width on various widgets
        Set the current notebook page to the first one

        * preferences/identity.py:
        Set various border widths appropriately
        Align the labels to the left
        Remove the unneeded bold markup from the labels
        Change the "User Id" label to "E-Mail"
        Align the radio group labels to the top of the groups

        * preferences/plugins.py:
        Set various border widths appropriately
        Set the default paned position to something more sensible
        Set the shadow type on the treeview's scrolled window to in
        Align the Author and Version labels to the left

Show diffs side-by-side

added added

removed removed

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