Commit db57bf5b authored by Kai Willadsen's avatar Kai Willadsen

filediff: Add a helper for showing user-criticial errors

The idea behind this decorator is that it should be used with functions
where failure is important to the user (and may not be obvious
otherwise). The only current use is on save, where it's possible to hit
a traceback and have the callback handling crash out, but other than a
log message or traceback on the command line... the user may not notice
anything.

This is made necessary by the GTK+/pygobject philosophy (which is
generally extremely good) of treating errors of this kind as non-fatal.
We also want it to not be fatal in this case, but... the user needs to
know if they tried to save a file and it didn't work.

On the other hand, if they tried to e.g., go to the next diff and we
messed something up and didn't go to the next diff, (a) they'd notice
and (b) showing them a modal dialog would be even more annoying than
the actual error.
parent 88d511ab
......@@ -47,7 +47,7 @@ from meld.ui.gnomeglade import Component, ui_file
from meld.undo import UndoSequence
def user_critical(message):
def user_critical(primary, message):
def wrap(function):
@functools.wraps(function)
def wrap_function(locked, *args, **kwargs):
......@@ -55,13 +55,12 @@ def user_critical(message):
return function(locked, *args, **kwargs)
except Exception:
misc.error_dialog(
primary=message,
primary=primary,
secondary=_(
"Meld encountered a critical error while running: "
"<tt>{}</tt>\n\n"
"We're sorry this isn't a more useful error, but we "
"thought you needed to know about this."
"".format(GLib.markup_escape_text(str(function)))
"{}\n\n"
"Meld encountered a critical error while running:\n"
"<tt>{}</tt>".format(
message, GLib.markup_escape_text(str(function)))
),
)
raise
......@@ -1519,10 +1518,11 @@ class FileDiff(MeldDoc, Component):
self.text_filters = []
self.refresh_comparison()
# FIXME: Should have a decorator that catches exceptions, shows a dialog
# if it does so, and reraises. Basically, this is for stuff that the user
# should *really* know about if it fails.
@user_critical(_('Saving failed')) # FIXME: better error...
@user_critical(
_("Saving failed"),
_("Please consider copying any critical changes to "
"another program or file to avoid data loss."),
)
def save_file(self, pane, saveas=False, force_overwrite=False):
buf = self.textbuffer[pane]
bufdata = buf.data
......
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