[california] Return to event editor when event cannot be created: Bug #735796
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Return to event editor when event cannot be created: Bug #735796
- Date: Thu, 11 Sep 2014 21:51:11 +0000 (UTC)
commit c586f34d8a24152a509a23aec3c67e6b5764a060
Author: Jim Nelson <jim yorba org>
Date: Thu Sep 11 14:50:32 2014 -0700
Return to event editor when event cannot be created: Bug #735796
Small overhaul of the Deck/Card reporting system to break out
reporting Card error messages from dismissing the Deck.
src/application/california-application.vala | 6 +-
src/host/host-create-update-event.vala | 8 ++--
src/host/host-main-window.vala | 10 ++--
src/host/host-quick-create-event.vala | 6 +-
src/toolkit/toolkit-card.vala | 71 ++++++++++++++++-----------
src/toolkit/toolkit-deck-popover.vala | 11 ++--
src/toolkit/toolkit-deck-window.vala | 34 ++++++-------
src/toolkit/toolkit-deck.vala | 27 +++-------
8 files changed, 87 insertions(+), 86 deletions(-)
---
diff --git a/src/application/california-application.vala b/src/application/california-application.vala
index 07590bf..605b941 100644
--- a/src/application/california-application.vala
+++ b/src/application/california-application.vala
@@ -181,7 +181,7 @@ public class Application : Gtk.Application {
Manager.init();
Activator.init();
} catch (Error err) {
- error_message(_("Unable to open California: %s").printf(err.message));
+ error_message(null, _("Unable to open California: %s").printf(err.message));
quit();
}
@@ -222,8 +222,8 @@ public class Application : Gtk.Application {
/*
* Presents a modal error dialog to the user.
*/
- public void error_message(string msg) {
- Gtk.MessageDialog dialog = new Gtk.MessageDialog(main_window, Gtk.DialogFlags.MODAL,
+ public void error_message(Gtk.Window? parent, string msg) {
+ Gtk.MessageDialog dialog = new Gtk.MessageDialog(parent ?? main_window, Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "%s", msg);
dialog.run();
dialog.destroy();
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 94c5cb1..c43363c 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -283,7 +283,7 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
private async void create_event_async(Component.Event target, Cancellable? cancellable) {
if (target.calendar_source == null) {
- notify_failure(_("Unable to create event: calendar must be specified"));
+ report_error(_("Unable to create event: calendar must be specified"));
return;
}
@@ -302,12 +302,12 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
if (create_err == null)
notify_success();
else
- notify_failure(_("Unable to create event: %s").printf(create_err.message));
+ report_error(_("Unable to create event: %s").printf(create_err.message));
}
private async void update_event_async(Component.Event target, Cancellable? cancellable) {
if (target.calendar_source == null) {
- notify_failure(_("Unable to update event: calendar must be specified"));
+ report_error(_("Unable to update event: calendar must be specified"));
return;
}
@@ -352,7 +352,7 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
if (update_err == null)
notify_success();
else
- notify_failure(_("Unable to update event: %s").printf(update_err.message));
+ report_error(_("Unable to update event: %s").printf(update_err.message));
}
}
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index c2f439a..dcbfb84 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -341,8 +341,8 @@ public class MainWindow : Gtk.ApplicationWindow {
Toolkit.spin_event_loop();
});
- deck_window.deck.failure.connect((msg) => {
- Application.instance.error_message(msg);
+ deck_window.deck.error_message.connect((msg) => {
+ Application.instance.error_message(deck_window, msg);
});
deck_window.show_all();
@@ -360,8 +360,8 @@ public class MainWindow : Gtk.ApplicationWindow {
Toolkit.destroy_later(deck_popover);
});
- deck_popover.deck.failure.connect((msg) => {
- Application.instance.error_message(msg);
+ deck_popover.deck.error_message.connect((msg) => {
+ Application.instance.error_message(this, msg);
});
deck_popover.show_all();
@@ -483,7 +483,7 @@ public class MainWindow : Gtk.ApplicationWindow {
try {
clone = event.clone() as Component.Event;
} catch (Error err) {
- Application.instance.error_message(_("Unable to edit event: %s").printf(err.message));
+ Application.instance.error_message(this, _("Unable to edit event: %s").printf(err.message));
return;
}
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index 5b887c9..c30fe73 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -96,7 +96,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
try {
Gtk.show_uri(null, Application.QUICK_ADD_HELP_URL, Gtk.get_current_event_time());
} catch (Error err) {
- Application.instance.error_message("Error opening help: %s".printf(err.message));
+ report_error(_("Error opening help: %s").printf(err.message));
}
}
@@ -153,7 +153,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
private async void create_event_async(Cancellable? cancellable) {
if (event.calendar_source == null) {
- notify_failure(_("Unable to create event: calendar must be specified"));
+ report_error(_("Unable to create event: calendar must be specified"));
return;
}
@@ -172,7 +172,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
if (create_err == null)
notify_success();
else
- notify_failure(_("Unable to create event: %s").printf(create_err.message));
+ report_error(_("Unable to create event: %s").printf(create_err.message));
}
}
diff --git a/src/toolkit/toolkit-card.vala b/src/toolkit/toolkit-card.vala
index 7450aea..fbdd817 100644
--- a/src/toolkit/toolkit-card.vala
+++ b/src/toolkit/toolkit-card.vala
@@ -39,6 +39,28 @@ public interface Card : Gtk.Widget {
}
/**
+ * Reason for dismissing the { link Deck}.
+ */
+ public enum DismissReason {
+ /**
+ * The { link Deck}'s operation has completed successfully.
+ */
+ SUCCESS,
+ /**
+ * The { link Deck}'s operation has failed to complete and cannot go forward.
+ */
+ FAILED,
+ /**
+ * The user has closed or cancelled the { link Deck}.
+ */
+ USER_CLOSED,
+ /**
+ * The { link Deck} programmatically aborted itself.
+ */
+ ABORTED
+ }
+
+ /**
* Each { link Card} has its own identifier that should be unique within the { link Deck}.
*
* In the Gtk.Stack, this is its name.
@@ -110,38 +132,21 @@ public interface Card : Gtk.Widget {
* Fired when the { link Deck}'s work is cancelled, closed, failure, or a success, whether due
* to programmatic reasons or by user request.
*
- * user_request indicates if the dismissal is due to a user request or programmatic reasons.
- * closed indicates that there is no qualitative signal (i.e. { link success}, { link failure})
- * to follow.
- *
* Implementing classes should use one of the notify_ methods to ensure that proper signal
- * order is maintained.
- */
- public signal void dismiss(bool user_request, bool final);
-
- /**
- * Fired when the { link Deck}'s work has completed successfully.
- *
- * This should only be fired if the Deck requires valid input from the user to perform
- * some intensive operation. Merely displaying information and closing the Deck
- * should simply fire { link dismiss}.
- *
- * Implementing classes should use one of the notify_ methods to ensure that proper signal
- * order is maintained.
+ * order and values are issued.
*/
- public signal void success();
+ public signal void dismiss(DismissReason reason);
/**
- * Fired when the { link Deck}'s work has failed to complete.
+ * Fired when the { link Card} needs to report an important error message to the user.
*
- * This should only be fired if the Deck requires valid input from the user to perform
- * some intensive operation. Merely displaying information and closing the Deck
- * should simply fire { link dismiss}.
+ * Signal subscribers should not use this signal to close the deck, but merely report the
+ * message.
*
* Implementing classes should use one of the notify_ methods to ensure that proper signal
* order is maintained.
*/
- public signal void failure(string? user_message);
+ public signal void error_message(string user_message);
/**
* Called by { link Deck} when the { link Card} has been activated, i.e. put to the "top" of
@@ -169,30 +174,38 @@ public interface Card : Gtk.Widget {
* Dismiss the { link Deck} due to the user requesting it be closed or cancelled.
*/
protected void notify_user_closed() {
- dismiss(true, true);
+ dismiss(DismissReason.USER_CLOSED);
}
/**
* Dismiss the { link Deck} due to programmatic reasons.
*/
protected void notify_aborted() {
- dismiss(false, true);
+ dismiss(DismissReason.ABORTED);
}
/**
* Dismiss the { link Deck} and notify that the user has successfully completed the task.
*/
protected void notify_success() {
- dismiss(true, false);
- success();
+ dismiss(DismissReason.SUCCESS);
}
/**
* Dismiss the { link Deck} and notify that the operation has failed.
*/
protected void notify_failure(string? user_message) {
- dismiss(true, false);
- failure(user_message);
+ if (!String.is_empty(user_message))
+ error_message(user_message);
+
+ dismiss(DismissReason.FAILED);
+ }
+
+ /**
+ * Report a failure message but do not dismiss the { link Deck}.
+ */
+ protected void report_error(string user_message) {
+ error_message(user_message);
}
/**
diff --git a/src/toolkit/toolkit-deck-popover.vala b/src/toolkit/toolkit-deck-popover.vala
index 8775a86..25407d7 100644
--- a/src/toolkit/toolkit-deck-popover.vala
+++ b/src/toolkit/toolkit-deck-popover.vala
@@ -18,9 +18,10 @@ public class DeckPopover : Gtk.Popover {
public Deck deck { get; private set; }
/**
- * See { link Card.dismiss}
+ * Fired when the { link DeckPopover} is dismissed, either by a { link Card} or the user
+ * clicking off of it.
*/
- public signal void dismiss(bool user_request, bool final);
+ public signal void dismiss();
private bool preserve_mode;
private bool forcing_mode = false;
@@ -33,7 +34,7 @@ public class DeckPopover : Gtk.Popover {
// treat "closed" signal as dismissal by user request
closed.connect(() => {
- dismiss(true, true);
+ dismiss();
});
notify["modal"].connect(on_modal_changed);
@@ -98,8 +99,8 @@ public class DeckPopover : Gtk.Popover {
force_mode(preserve_mode);
}
- private void on_deck_dismissed(bool user_request, bool final) {
- dismiss(user_request, final);
+ private void on_deck_dismissed(Card.DismissReason reason) {
+ dismiss();
}
}
diff --git a/src/toolkit/toolkit-deck-window.vala b/src/toolkit/toolkit-deck-window.vala
index fa81775..794389f 100644
--- a/src/toolkit/toolkit-deck-window.vala
+++ b/src/toolkit/toolkit-deck-window.vala
@@ -11,7 +11,6 @@ namespace California.Toolkit {
*
* This is designed for UI panes that want to control their own interaction with the user (in
* particular, button placement) but need all the benefits interaction-wise of GtkDialog.
- *
*/
public class DeckWindow : Gtk.Dialog {
@@ -26,8 +25,6 @@ public class DeckWindow : Gtk.Dialog {
decorated = false;
deck.dismiss.connect(on_deck_dismissed);
- deck.success.connect(on_deck_success);
- deck.failure.connect(on_deck_failure);
Gtk.Box content_area = (Gtk.Box) get_content_area();
content_area.margin = 8;
@@ -39,24 +36,25 @@ public class DeckWindow : Gtk.Dialog {
~DeckWindow() {
deck.dismiss.disconnect(on_deck_dismissed);
- deck.success.disconnect(on_deck_success);
- deck.failure.disconnect(on_deck_failure);
- }
-
- private void on_deck_dismissed(bool user_request, bool final) {
- if (final)
- response(Gtk.ResponseType.CLOSE);
- }
-
- private void on_deck_success() {
- response(Gtk.ResponseType.OK);
}
- private void on_deck_failure(string? user_message) {
- if (!String.is_empty(user_message))
- Application.instance.error_message(user_message);
+ private void on_deck_dismissed(Card.DismissReason reason) {
+ Gtk.ResponseType response_type;
+ switch (reason) {
+ case Card.DismissReason.SUCCESS:
+ response_type = Gtk.ResponseType.OK;
+ break;
+
+ case Card.DismissReason.USER_CLOSED:
+ response_type = Gtk.ResponseType.CANCEL;
+ break;
+
+ default:
+ response_type = Gtk.ResponseType.CLOSE;
+ break;
+ }
- response(Gtk.ResponseType.CLOSE);
+ response(response_type);
}
}
diff --git a/src/toolkit/toolkit-deck.vala b/src/toolkit/toolkit-deck.vala
index e4798f4..9a3563b 100644
--- a/src/toolkit/toolkit-deck.vala
+++ b/src/toolkit/toolkit-deck.vala
@@ -56,17 +56,12 @@ public class Deck : Gtk.Stack {
/**
* @see Card.dismiss
*/
- public signal void dismiss(bool user_request, bool final);
-
- /**
- * @see Card.success
- */
- public signal void success();
+ public signal void dismiss(Card.DismissReason reason);
/**
* @see Card.failure
*/
- public signal void failure(string? user_message);
+ public signal void error_message(string user_message);
/**
* Create a new { link Deck}.
@@ -97,8 +92,7 @@ public class Deck : Gtk.Stack {
top.jump_back.disconnect(on_jump_back);
top.jump_home.disconnect(on_jump_home);
top.dismiss.disconnect(on_dismiss);
- top.success.disconnect(on_success);
- top.failure.disconnect(on_failure);
+ top.error_message.disconnect(on_error_message);
navigation_stack.offer_head(top);
top = null;
@@ -112,8 +106,7 @@ public class Deck : Gtk.Stack {
top.jump_back.connect(on_jump_back);
top.jump_home.connect(on_jump_home);
top.dismiss.connect(on_dismiss);
- top.success.connect(on_success);
- top.failure.connect(on_failure);
+ top.error_message.connect(on_error_message);
}
}
@@ -297,16 +290,12 @@ public class Deck : Gtk.Stack {
message("No home card in Deck");
}
- private void on_dismiss(bool user_request, bool final) {
- dismiss(user_request, final);
- }
-
- private void on_success() {
- success();
+ private void on_dismiss(Card.DismissReason reason) {
+ dismiss(reason);
}
- private void on_failure(string? user_message) {
- failure(user_message);
+ private void on_error_message(string user_message) {
+ error_message(user_message);
}
private void on_card_mapped(Gtk.Widget widget) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]