Clone in a terminal:
Commit 2e72bc5
Johan Mattsson - 2014-11-28T16:32:13+00:00
2e72bc5c06ee420726e93bd842befe44ce203464johan.mattsson.m@gmail.com

New dialog for saving fonts on exit

Changed files (13)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex dd5b7f3..c423b64 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -52,7 +52,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	Label text_input_label; 	Entry text_entry; 	Box text_box;-	Button submit_text_button;+	Gtk.Button submit_text_button; 	 	Gtk.Window tooltip_window = new Gtk.Window (); 	@@ -84,7 +84,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		 		delete_event.connect (() => { 			MenuTab.quit ();-			return false;+			return true; 		}); 		 		set_size_and_position ();@@ -143,7 +143,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		canvas_box.pack_start (description.canvas, true, true, 0); 		canvas_box.pack_start (scrollbar, false, true, 0); -		submit_text_button = new Button ();+		submit_text_button = new Gtk.Button (); 		submit_text_button.set_label ("Submit"); 		text_input_label = new Label ("   " + "Text"); 		text_entry = new Entry ();@@ -208,27 +208,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		MainWindow.open_recent_files_tab (); 	} -	public void set_save_dialog (SaveDialogListener d) {-		Gtk.Dialog dialog = new Gtk.Dialog.with_buttons (d.message, null, 0);-		-		dialog.add_button (d.save_message, 0);-		dialog.add_button (d.discard_message, 1);-		-		dialog.response.connect ((respons) => {-			switch (respons) {-				case 0:-					d.save ();-					break;-				case 1:-					d.discard ();-					break;-			}-			dialog.destroy ();-		}); -		-		dialog.show_all ();-	}- 	public void font_loaded () { 		Font f = BirdFont.get_current_font (); 		set_title (@"BirdFont $(f.full_name)");@@ -278,7 +257,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		ColorChooserWidget color_selection; 		 		public ColorWindow (ColorTool color_tool) {-			Button set_button;+			Gtk.Button set_button; 			 			title = t_("Select color"); 			window_position = Gtk.WindowPosition.CENTER;@@ -309,7 +288,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 				color_selection.rgba = c; 			}); -			set_button = new Button.with_label (_("Set"));+			set_button = new Gtk.Button.with_label (_("Set")); 			box.add (set_button);  			set_button.clicked.connect (() => {diff --git a/birdfont/Main.vala b/birdfont/Main.valaindex 8c0c3de..9805e59 100644--- a/birdfont/Main.vala+++ b/birdfont/Main.vala@@ -35,7 +35,7 @@ public static int main (string[] arg) { 	window.set_native (native_window); 	native_window.init (); -	birdfont.load_file_from_command_line ();+	birdfont.load_font_from_command_line ();  	load_ucd (); 	Gtk.main ();diff --git a/libbirdfont/DescriptionDisplay.vala b/libbirdfont/DescriptionDisplay.valaindex 36e8d1d..a3bb115 100644--- a/libbirdfont/DescriptionDisplay.vala+++ b/libbirdfont/DescriptionDisplay.vala@@ -71,6 +71,7 @@ public class DescriptionDisplay : FontDisplay { 		postscript_name.set_text (font.postscript_name); 		postscript_name.text_changed.connect ((t) => { 			font.postscript_name = t;+			font.touch (); 		}); 		widgets.add (postscript_name); 		@@ -79,6 +80,7 @@ public class DescriptionDisplay : FontDisplay { 		name.set_text (font.name); 		name.text_changed.connect ((t) => { 			font.name = t;+			font.touch (); 		}); 		widgets.add (name); 				@@ -87,12 +89,14 @@ public class DescriptionDisplay : FontDisplay { 		style.set_text (font.subfamily); 		style.text_changed.connect ((t) => { 			font.subfamily = t;+			font.touch (); 		}); 		widgets.add (style); 		 		bold = new CheckBox (t_("Bold"), label_size); 		bold.updated.connect ((c) => { 			font.bold = c;+			font.touch (); 		}); 		bold.checked = font.bold; 		widgets.add (bold);@@ -100,6 +104,7 @@ public class DescriptionDisplay : FontDisplay { 		italic = new CheckBox (t_("Italic"), label_size); 		italic.updated.connect ((c) => { 			font.italic = c;+			font.touch (); 		}); 		italic.checked = font.italic; 		italic.margin_bottom = margin;@@ -110,6 +115,7 @@ public class DescriptionDisplay : FontDisplay { 		weight.set_text (font.get_weight ()); 		weight.text_changed.connect ((t) => { 			font.set_weight (t);+			font.touch (); 		}); 		widgets.add (weight); 		@@ -118,6 +124,7 @@ public class DescriptionDisplay : FontDisplay { 		full_name.set_text (font.full_name); 		full_name.text_changed.connect ((t) => { 			font.full_name = t;+			font.touch (); 		}); 		widgets.add (full_name); 		@@ -126,6 +133,7 @@ public class DescriptionDisplay : FontDisplay { 		unique_id.set_text (font.unique_identifier); 		unique_id.text_changed.connect ((t) => { 			font.unique_identifier = t;+			font.touch (); 		}); 		widgets.add (unique_id); 		@@ -134,6 +142,7 @@ public class DescriptionDisplay : FontDisplay { 		version.set_text (font.version); 		version.text_changed.connect ((t) => { 			font.version = t;+			font.touch (); 		}); 		widgets.add (version); @@ -143,6 +152,7 @@ public class DescriptionDisplay : FontDisplay { 		description.scroll.connect (scroll_event); 		description.text_changed.connect ((t) => { 			font.description = t;+			font.touch (); 		}); 		widgets.add (description); 		@@ -152,6 +162,7 @@ public class DescriptionDisplay : FontDisplay { 		copyright.scroll.connect (scroll_event); 		copyright.text_changed.connect ((t) => { 			font.copyright = t;+			font.touch (); 		}); 		copyright.set_editable (!disable_copyright); 		widgets.add (copyright);diff --git a/libbirdfont/Dialog.vala b/libbirdfont/Dialog.valanew file mode 100644index 0000000..60aae98--- /dev/null+++ b/libbirdfont/Dialog.vala@@ -0,0 +1,43 @@+/*+    Copyright (C) 2014 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 Dialog : Widget {++	public bool visible { get; set; }++	public Dialog () {+		visible = false;+	}++	public override void draw (Context cr) {	+	}++	public override double get_height () {+		return 0;	+	}++	public override double get_width () {+		return 0;	+	}+	+	public virtual void button_press (uint button, double x, double y) {+	}+	+}++}diff --git a/libbirdfont/FileTab.vala b/libbirdfont/FileTab.valaindex d7dd8ba..94da465 100644--- a/libbirdfont/FileTab.vala+++ b/libbirdfont/FileTab.vala@@ -93,11 +93,15 @@ public class FileTab : FontDisplay { 			}); 			MenuTab.save_callback.save (); // background thread 		});-		++		dialog.signal_cancel.connect (() => {+			MainWindow.hide_dialog ();+		});+				 		if (!font.is_modified ()) { 			dialog.signal_discard (); 		} else {-			MainWindow.native_window.set_save_dialog (dialog);+			MainWindow.show_dialog (new SaveDialog (dialog)); 		} 	} 	diff --git a/libbirdfont/LoadCallback.vala b/libbirdfont/LoadCallback.valaindex a356d13..6b994c6 100644--- a/libbirdfont/LoadCallback.vala+++ b/libbirdfont/LoadCallback.vala@@ -44,11 +44,15 @@ public class LoadCallback : GLib.Object { 			MenuTab.save_callback.file_saved.connect (load_new_font); 			MenuTab.save_callback.save (); // background thread 		});-		++		dialog.signal_cancel.connect (() => {+			MainWindow.hide_dialog ();+		});+				 		if (!font.is_modified ()) { 			dialog.signal_discard (); 		} else {-			MainWindow.native_window.set_save_dialog (dialog);+			MainWindow.show_dialog (new SaveDialog (dialog)); 		} 	} diff --git a/libbirdfont/MainWindow.vala b/libbirdfont/MainWindow.valaindex dad5a27..eb5c459 100644--- a/libbirdfont/MainWindow.vala+++ b/libbirdfont/MainWindow.vala@@ -1,5 +1,5 @@ /*
-    Copyright (C) 2012 Johan Mattsson
+    Copyright (C) 2012 2014 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 
@@ -30,6 +30,7 @@ public class MainWindow : GLib.Object { 	public static LigatureList ligature_display;
 	public static SpacingClassTab spacing_class_tab;
 	public static Menu menu;
+	public static Dialog dialog;
 	
 	/** Number of pixels per mm */
 	public static double units = 1;
@@ -49,6 +50,22 @@ public class MainWindow : GLib.Object { 		ligature_display = new LigatureList ();
 		spacing_class_tab = new SpacingClassTab ();
 		menu = new Menu ();
+		dialog = new Dialog ();
+	}
+
+	public static Dialog get_dialog () {
+		return dialog;
+	}
+
+	public static void show_dialog (Dialog d) {
+		dialog = d;
+		dialog.visible = true;
+		GlyphCanvas.redraw ();
+	}
+
+	public static void hide_dialog () {
+		dialog = new Dialog ();
+		dialog.visible = false;
 	}
 
 	public static Menu get_menu () {
diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex a9fc175..ee29600 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -210,11 +210,17 @@ public class MenuTab : FontDisplay { 			}); 			save_callback.save (); 		});-		++		dialog.signal_cancel.connect (() => {+			MainWindow.hide_dialog ();+		});+				 		if (!font.is_modified ()) {+			print ("NOT modified\n"); 			dialog.signal_discard (); 		} else {-			MainWindow.native_window.set_save_dialog (dialog);+			print ("Show dialog\n");+			MainWindow.show_dialog (new SaveDialog (dialog)); 		} 		 		return;@@ -246,11 +252,15 @@ public class MenuTab : FontDisplay { 			}); 			save_callback.save (); 		});-		++		dialog.signal_cancel.connect (() => {+			MainWindow.hide_dialog ();+		});+				 		if (!font.is_modified ()) { 			dialog.signal_discard (); 		} else {-			MainWindow.native_window.set_save_dialog (dialog);+			MainWindow.show_dialog (new SaveDialog (dialog)); 		} 	}  	diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex 2f76a02..28ef381 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -34,9 +34,6 @@ public interface NativeWindow : GLib.Object { 	/** Remove the text listener and hode the text area. */ 	public abstract void hide_text_input (); -	/** Show save dialog */-	public abstract void set_save_dialog (SaveDialogListener dialog);- 	/** Show overwrite dialog */ 	public abstract void set_overwrite_dialog (OverWriteDialogListener dialog); 	diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex 9271d24..2445106 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -140,6 +140,8 @@ public class PenTool : Tool { 			 			last_point_x = Glyph.path_coordinate_x (x); 			last_point_y = Glyph.path_coordinate_y (y);+			+			BirdFont.get_current_font ().touch (); 		}); 		 		double_click_action.connect ((self, b, x, y) => {@@ -186,6 +188,7 @@ public class PenTool : Tool { 			} 			 			point_selection_image = false;+			BirdFont.get_current_font ().touch (); 		});  		move_action.connect ((self, x, y) => {@@ -225,6 +228,7 @@ public class PenTool : Tool { 			} 			 			GlyphCanvas.redraw ();+			BirdFont.get_current_font ().touch (); 		}); 		 		key_release_action.connect ((self, keyval) => {diff --git a/libbirdfont/SaveDialog.vala b/libbirdfont/SaveDialog.valanew file mode 100644index 0000000..9730114--- /dev/null+++ b/libbirdfont/SaveDialog.vala@@ -0,0 +1,119 @@+/*+    Copyright (C) 2014 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 SaveDialog : Dialog {+	+	SaveDialogListener listener;+	+	Button save_button;+	Button discard_button;+	Button cancel_button;+	+	double width = 0;+	double height;+	+	public SaveDialog (SaveDialogListener callbacks) {+		listener = callbacks;+		+		save_button = new Button (t_("Save"));+		save_button.action.connect (() => {+			callbacks.signal_save ();+		});+		+		discard_button = new Button (t_("Discard"));+		discard_button.action.connect (() => {+			callbacks.signal_discard ();+		});+		+		cancel_button = new Button (t_("Cancel"));+		cancel_button.action.connect (() => {+			callbacks.signal_cancel ();+		});+		+		height = 70 * MainWindow.units;+	}++	void layout () {+		double cx = 0;+		double cy = (allocation.height - height) / 2.0;+		double center;+				+		cx = 20 * MainWindow.units;+		save_button.widget_x = cx;++		cx += 10 * MainWindow.units + save_button.get_width ();+		discard_button.widget_x = cx;++		cx += 10 * MainWindow.units + discard_button.get_width ();+		cancel_button.widget_x = cx;++		width = cx + 20 * MainWindow.units + cancel_button.get_width ();;+		+		center = (allocation.width - width) / 2.0;+		+		save_button.widget_x += center;+		save_button.widget_y = cy + 25 * MainWindow.units;+		+		discard_button.widget_x += center;+		discard_button.widget_y = cy + 25 * MainWindow.units;+		+		cancel_button.widget_x += center;+		cancel_button.widget_y = cy + 25 * MainWindow.units;+	}++	public override void draw (Context cr) {	+		Text headline;+		double cx, cy;+		+		layout ();++		cx = (allocation.width - width) / 2.0;+		cy = (allocation.height - height) / 2.0;+		+		cr.save ();+		cr.set_source_rgba (0, 0, 0, 0.3);+		cr.rectangle (0, 0, allocation.width, allocation.height);+		cr.fill ();+		cr.restore ();+		+		cr.save ();+		cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+		draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+		cr.fill ();+		cr.restore ();+		+		cr.save ();+		cr.set_source_rgba (0, 0, 0, 1);+		cr.set_line_width (1);+		draw_rounded_rectangle (cr, cx, cy, width, height, 10 * MainWindow.units);+		cr.stroke ();+		cr.restore ();++		save_button.draw (cr);+		discard_button.draw (cr);+		cancel_button.draw (cr);+	}++	public override void button_press (uint button, double x, double y) {+		save_button.button_press (button, x, y);+		discard_button.button_press (button, x, y);+		cancel_button.button_press (button, x, y);+	}+}++}diff --git a/libbirdfont/SaveDialogListener.vala b/libbirdfont/SaveDialogListener.valaindex d4039fa..1434017 100644--- a/libbirdfont/SaveDialogListener.vala+++ b/libbirdfont/SaveDialogListener.vala@@ -18,6 +18,7 @@ public class SaveDialogListener : GLib.Object { 	 	public signal void signal_save (); 	public signal void signal_discard ();+	public signal void signal_cancel (); 	 	public string message; 	public string discard_message;diff --git a/libbirdfont/TabContent.vala b/libbirdfont/TabContent.valaindex 3ff4d66..1282d7d 100644--- a/libbirdfont/TabContent.vala+++ b/libbirdfont/TabContent.vala@@ -59,19 +59,28 @@ public class TabContent : GLib.Object { 	} 	 	public static void draw (WidgetAllocation allocation, Context cr) {-		Menu menu = MainWindow.get_menu ();+		Menu menu;+		Dialog dialog; 		-		if (MenuTab.suppress_event) {+		if (unlikely (MenuTab.suppress_event)) { 			cr.save (); 			cr.set_source_rgba (1, 1, 1, 1); 			cr.rectangle (0, 0, allocation.width, allocation.height); 			cr.fill (); 			cr.restore (); 		} else {+			menu = MainWindow.get_menu ();+			dialog = MainWindow.get_dialog ();+		 			GlyphCanvas.set_allocation (allocation); 			MainWindow.get_current_glyph ().resized (allocation); 			GlyphCanvas.current_display.draw (allocation, cr); 			+			if (dialog.visible) {+				dialog.allocation = allocation;+				dialog.draw (cr);+			}+			 			if (menu.show_menu) { 				menu.draw (allocation, cr); 			}@@ -122,8 +131,10 @@ public class TabContent : GLib.Object { 		if (MenuTab.suppress_event) { 			return; 		}-		-		if (!MainWindow.get_menu ().show_menu) {++		if (MainWindow.get_dialog ().visible) {+			MainWindow.get_dialog ().button_press (button, x, y);+		} else if (!MainWindow.get_menu ().show_menu) { 			GlyphCanvas.current_display.button_press (button, x, y); 		} 	}@@ -232,4 +243,3 @@ public class TabContent : GLib.Object { }  }-

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112