Commit ab0f761
Platform independent overwrite dialog
Changed files (4)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/NativeWindow.valaaddedlibbirdfont/OverwriteDialog.vala
Diff
@@ -242,31 +242,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { set_title (@"$(f.full_name)"); } - public void set_overwrite_dialog (OverWriteDialogListener d) {- Gtk.Dialog dialog = new Gtk.Dialog.with_buttons (d.message, null, 0);- - dialog.add_button (d.overwrite_message, 0);- dialog.add_button (d.cancel_message, 1);- dialog.add_button (d.dont_ask_again_message, 2);- - dialog.response.connect ((respons) => {- switch (respons) {- case 0:- d.overwrite ();- break;- case 1:- d.cancel ();- break;- case 2:- d.overwrite_dont_ask_again ();- break;- }- dialog.destroy ();- }); - - dialog.show_all ();- }- public void set_scrollbar_size (double size) { scrollbar.adjustment.page_size = size; scrollbar.set_visible (size != 0);@@ -469,7 +469,7 @@ public class MenuTab : FontDisplay { } public static void show_preview_tab () {- OverWriteDialogListener dialog = new OverWriteDialogListener ();+ OverWriteDialogListener listener = new OverWriteDialogListener (); TabBar tab_bar = MainWindow.get_tab_bar (); FontFormat format = BirdFont.get_current_font ().format; @@ -478,16 +478,16 @@ public class MenuTab : FontDisplay { return; } - dialog.overwrite_signal.connect (() => {+ listener.overwrite_signal.connect (() => { KeyBindings.set_modifier (NONE); tab_bar.add_unique_tab (new Preview (), true); PreviewTools.update_preview (); }); if ((format == FontFormat.SVG || format == FontFormat.FREETYPE) && !OverWriteDialogListener.dont_ask_again) {- MainWindow.native_window.set_overwrite_dialog (dialog);+ MainWindow.show_dialog (new OverwriteDialog (listener)); } else {- dialog.overwrite ();+ listener.overwrite (); } } @@ -29,9 +29,6 @@ public interface NativeWindow : GLib.Object { public abstract void set_scrollbar_size (double size); public abstract void set_scrollbar_position (double position);-- /** Show overwrite dialog */- public abstract void set_overwrite_dialog (OverWriteDialogListener dialog); /** Notify the UI about the new font. */ public abstract void font_loaded ();new file mode 100644@@ -0,0 +1,142 @@+/*+ Copyright (C) 2015 Johan Mattsson++ This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++using Cairo;++namespace BirdFont {++public class OverwriteDialog : Dialog {+ + OverWriteDialogListener listener;+ + Text question;+ Button overwrite_button;+ Button cancel_button;+ Button dont_ask_again_button;+ + double width = 0;+ double height;+ + static const double question_font_size = 23;+ + public OverwriteDialog (OverWriteDialogListener callbacks) {+ double font_size = question_font_size * MainWindow.units;+ + listener = callbacks;+ + question = new Text (callbacks.message, font_size);+ + overwrite_button = new Button (callbacks.message);+ overwrite_button.action.connect (() => {+ MainWindow.hide_dialog ();+ callbacks.overwrite ();+ });+ + cancel_button = new Button (callbacks.cancel_message);+ cancel_button.action.connect (() => {+ MainWindow.hide_dialog ();+ callbacks.cancel ();+ });+ + dont_ask_again_button = new Button (callbacks.dont_ask_again_message);+ dont_ask_again_button.action.connect (() => {+ MainWindow.hide_dialog ();+ callbacks.overwrite_dont_ask_again ();+ });+ + height = 90 * MainWindow.units;+ }++ void layout () {+ double cx = 0;+ double cy = (allocation.height - height) / 2.0;+ double center;+ double qh;+ + cx = 20 * MainWindow.units;+ overwrite_button.widget_x = cx;++ cx += 10 * MainWindow.units + overwrite_button.get_width ();+ cancel_button.widget_x = cx;++ cx += 10 * MainWindow.units + cancel_button.get_width ();+ dont_ask_again_button.widget_x = cx;++ width = cx + 20 * MainWindow.units + dont_ask_again_button.get_width ();+ + center = (allocation.width - width) / 2.0;+ + question.widget_x = overwrite_button.widget_x + center;+ question.widget_y = cy + 15 * MainWindow.units;+ Theme.text_color (question, "Text Tool Box");+ + qh = (question_font_size + 1) * MainWindow.units;+ + overwrite_button.widget_x += center;+ overwrite_button.widget_y = cy + qh + 25 * MainWindow.units;+ + cancel_button.widget_x += center;+ cancel_button.widget_y = cy + qh + 25 * MainWindow.units;+ + dont_ask_again_button.widget_x += center;+ dont_ask_again_button.widget_y = cy + qh + 25 * MainWindow.units;+ }++ public override void draw (Context cr) { + double cx, cy;+ + layout ();++ cx = (allocation.width - width) / 2.0;+ cy = (allocation.height - height) / 2.0;+ + cr.save ();+ Theme.color (cr, "Dialog Shadow");+ cr.rectangle (0, 0, allocation.width, allocation.height);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ Theme.color (cr, "Dialog Background");+ draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ Theme.color (cr, "Button Border 4");+ cr.set_line_width (1);+ draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+ cr.stroke ();+ cr.restore ();++ question.draw (cr);+ overwrite_button.draw (cr);+ cancel_button.draw (cr);+ dont_ask_again_button.draw (cr);+ }++ public override void button_press (uint button, double x, double y) {+ overwrite_button.button_press (button, x, y);+ cancel_button.button_press (button, x, y);+ dont_ask_again_button.button_press (button, x, y);+ }++ public override void button_release (uint button, double x, double y) {+ overwrite_button.button_release (button, x, y);+ cancel_button.button_release (button, x, y);+ dont_ask_again_button.button_release (button, x, y);+ }+}++}