From 53078345094f06a685445bcf67181c7e25736a76 Mon Sep 17 00:00:00 2001 From: Dan Breslau Date: Thu, 4 Aug 2016 20:46:55 -0400 Subject: [PATCH] Updated the appearance of two warning dialogs. Also fixed (somewhat) the appearance of the menu bar in the main window. --- Makefile.am | 3 +- src/moonshot-identity-dialog.vala | 19 +++---- src/moonshot-identity-management-view.vala | 31 +++++------ src/moonshot-warning-dialog.vala | 85 ++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 src/moonshot-warning-dialog.vala diff --git a/Makefile.am b/Makefile.am index 6f97610..5a537cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -69,7 +69,8 @@ src_moonshot_SOURCES = \ src/moonshot-provisioning-common.vala \ src/moonshot-utils.vala \ src/moonshot-futils.c \ - src/moonshot-logger.vala + src/moonshot-logger.vala \ + src/moonshot-warning-dialog.vala src_moonshot_webp_SOURCES = \ src/moonshot-webp-parser.vala \ diff --git a/src/moonshot-identity-dialog.vala b/src/moonshot-identity-dialog.vala index ce3899f..dba74ca 100644 --- a/src/moonshot-identity-dialog.vala +++ b/src/moonshot-identity-dialog.vala @@ -53,7 +53,6 @@ class IdentityDialog : Dialog static const string username_labeltext = _("Username"); static const string password_labeltext = _("Password"); - private IdentityManagerView parent; private Entry displayname_entry; private Label displayname_label; private Entry realm_entry; @@ -111,7 +110,6 @@ class IdentityDialog : Dialog this.set_title(title); this.set_modal(true); this.set_transient_for(parent); - this.parent = parent; this.add_buttons(_("OK"), ResponseType.OK, CANCEL, ResponseType.CANCEL); Box content_area = (Box) this.get_content_area(); @@ -364,16 +362,13 @@ class IdentityDialog : Dialog remove_button.clicked.connect((remove_button) => { - var dialog = new Gtk.MessageDialog(this, - Gtk.DialogFlags.DESTROY_WITH_PARENT, - Gtk.MessageType.QUESTION, - Gtk.ButtonsType.YES_NO, - _("You are about to remove the service '%s'. Are you sure you want to do this?"), - selected_item.label); - var ret = dialog.run(); - dialog.destroy(); - - if (ret == Gtk.ResponseType.YES) + var result = WarningDialog.confirm(this, + "You are about to remove the service '%s'." + .printf(selected_item.label) + + "\n\nAre you sure you want to do this?", + "delete_service"); + + if (result) { if (card != null) { SList services = new SList(); diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index c888762..8033d75 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -311,8 +311,10 @@ public class IdentityManagerView : Window { #else Gtk.MessageDialog dialog; IdCard? prev_id = identities_manager.find_id_card(id_card.nai, force_flat_file_store); + logger.trace("add_identity: find_id_card returned " + (prev_id != null ? "non-null" : "null")); if (prev_id!=null) { int flags = prev_id.Compare(id_card); + logger.trace("add_identity: compare returned " + flags.to_string()); if (flags == 0) { return false; // no changes, no need to update } else if ((flags & (1 << IdCard.DiffFlags.DISPLAY_NAME)) != 0) { @@ -426,20 +428,13 @@ public class IdentityManagerView : Window { { var id_card = id_card_widget.id_card; - var dialog = new MessageDialog(this, - DialogFlags.DESTROY_WITH_PARENT, - MessageType.QUESTION, - Gtk.ButtonsType.YES_NO, - _("Are you sure you want to delete %s ID Card?"), id_card.issuer); - var result = dialog.run(); - switch (result) { - case ResponseType.YES: + bool remove = WarningDialog.confirm(this, + "You are about to remove the identity '%s'." + .printf(id_card.display_name) + + "\n\nAre you sure you want to do this?", + "delete_idcard"); + if (remove) remove_identity(id_card_widget); - break; - default: - break; - } - dialog.destroy(); } private void set_prompting_service(string service) @@ -769,15 +764,20 @@ SUCH DAMAGE. vbox_right.pack_start(send_button, false, false, 24); id_and_button_box.pack_start(vbox_right, false, false, 0); + var main_vbox = new VBox(false, 0); + + // Note: This places a border above the menubar. Is that what we want? main_vbox.set_border_width(12); #if OS_MACOS // hide the File | Quit menu item which is now on the Mac Menu - Gtk.Widget quit_item = this.ui_manager.get_widget("/MenuBar/FileMenu/Quit"); - quit_item.hide(); +// Gtk.Widget quit_item = this.ui_manager.get_widget("/MenuBar/FileMenu/Quit"); +// quit_item.hide(); Gtk.MenuShell menushell = this.ui_manager.get_widget("/MenuBar") as Gtk.MenuShell; + menushell.modify_bg(StateType.NORMAL, white); + osxApp.set_menu_bar(menushell); osxApp.set_use_quartz_accelerators(true); osxApp.sync_menu_bar(); @@ -785,6 +785,7 @@ SUCH DAMAGE. #else var menubar = this.ui_manager.get_widget("/MenuBar"); main_vbox.pack_start(menubar, false, false, 0); + menubar.modify_bg(StateType.NORMAL, white); #endif main_vbox.pack_start(vbox_left, true, true, 0); add(main_vbox); diff --git a/src/moonshot-warning-dialog.vala b/src/moonshot-warning-dialog.vala new file mode 100644 index 0000000..8ec583a --- /dev/null +++ b/src/moonshot-warning-dialog.vala @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011-2016, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. +*/ +using Gtk; + +// MessageDialog doesn't allow subclassing, so we merely wrap the +// constructor for it the dialog, and then run it, returning the result. +class WarningDialog +{ + public static bool confirm(Window parent, string message, string dialog_name) + { + Gdk.Color white = make_color(65535, 65535, 65535); + + MessageDialog dialog = new Gtk.MessageDialog(parent, + Gtk.DialogFlags.DESTROY_WITH_PARENT, + Gtk.MessageType.WARNING, + Gtk.ButtonsType.YES_NO, + ""); + + var content_area = dialog.get_content_area(); + CheckButton remember_checkbutton; + + if (dialog_name != null && dialog_name != "") + { + remember_checkbutton = new CheckButton.with_label(_("Do not show this message again")); + remember_checkbutton.set_focus_on_click(false); + remember_checkbutton.has_focus = false; + content_area.has_focus = true; + +// Not sure if 0.26 is the minimum for MessageDialog.get_message_area. 0.16 sure isn't :-( +#if VALA_0_26 + var message_area = dialog.get_message_area(); + ((Box)message_area).pack_start(remember_checkbutton, false, false, 12); +#else + HBox hbox = new HBox(false, 0); + hbox.pack_start(new HBox(false, 0), true, true, 20); + hbox.pack_start(remember_checkbutton, false, false, 12); + ((Box)content_area).pack_start(hbox, true, true, 12); +#endif + } + + // dialog.set_modal(true); + dialog.set_title(_("Warning")); + dialog.modify_bg(StateType.NORMAL, white); + + // ((Box) content_area).set_spacing(12); + content_area.modify_bg(StateType.NORMAL, white); + + content_area.show_all(); + + dialog.set_markup(message); + + var ret = dialog.run(); + dialog.destroy(); + return (ret == Gtk.ResponseType.YES); + } +} -- 2.1.4