Commit fbeceed5 authored by Kai Willadsen's avatar Kai Willadsen

ui.msgarea: Add helper for actionable messages and use for binary open

parent 4317f44c
......@@ -1086,22 +1086,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
primary = _("File %s appears to be a binary file.") % filename
secondary = _(
"Do you want to open the file using the default application?")
msgarea = self.msgarea_mgr[pane].new_from_text_and_icon(
Gtk.STOCK_DIALOG_WARNING, primary, secondary)
msgarea.add_button(_("Open"), Gtk.ResponseType.ACCEPT)
msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
def make_binary_callback(pane, filename):
def on_binary_file_open(msgarea, response_id, *args):
self.msgarea_mgr[pane].clear()
if response_id == Gtk.ResponseType.ACCEPT:
self._open_files([filename])
return on_binary_file_open
return on_binary_file_open
msgarea.connect(
"response", make_binary_callback(pane, gfile.get_path()))
msgarea.show_all()
self.msgarea_mgr[pane].add_action_msg(
Gtk.STOCK_DIALOG_WARNING, primary, secondary, _("Open"),
functools.partial(self._open_files, [gfile.get_path()]))
self.update_buffer_writable(buf)
......
......@@ -111,3 +111,16 @@ class MsgAreaController(Gtk.HBox):
msgarea.connect("response", lambda *args: self.clear())
msgarea.show_all()
return msgarea
def add_action_msg(self, icon, primary, secondary, action_label, callback):
def on_response(msgarea, response_id, *args):
self.clear()
if response_id == Gtk.ResponseType.ACCEPT:
callback()
msgarea = self.new_from_text_and_icon(icon, primary, secondary)
msgarea.add_button(action_label, Gtk.ResponseType.ACCEPT)
msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
msgarea.connect("response", on_response)
msgarea.show_all()
return msgarea
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment