Clone in a terminal:
Commit 7605f70
Johan Mattsson - 2013-02-10T12:23:38+00:00
7605f70c5fc2409f2a64d92b6e3153bc30c1a2adjohan.mattsson.m@gmail.com

ask before overwriting files in preview

Changed files (3)

Diff

diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex c89e902..7734981 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -18,13 +18,13 @@ using Cairo; using Xml; -enum FontFormat {+namespace Supplement {++public enum FontFormat { 	FFI, 	SVG } -namespace Supplement {- public class Font : GLib.Object { 	 	GlyphTable glyph_cache = new GlyphTable ();@@ -756,11 +756,13 @@ public class Font : GLib.Object { 			if (path.has_suffix (".svg")) { 				font_file = path; 				loaded = parse_svg_file (path);+				format = FontFormat.SVG; 			} 			 			if (path.has_suffix (".ffi")) { 				font_file = path; 				loaded = parse_file (path);+				format = FontFormat.FFI; 			} 			 			if (Supplement.experimental) {diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex a147c3a..ea454ee 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -412,8 +412,19 @@ c.append (""" 	} 	 	public static void preview () {-		TabBar t = MainWindow.get_tab_bar ();-		t.add_unique_tab (new Preview (), 80);		+		TabBar tab_bar = MainWindow.get_tab_bar ();+		FontFormat format = Supplement.get_current_font ().format;+		OverwriteDialog overwrite = new OverwriteDialog ();++		overwrite.finished.connect (() => {+			tab_bar.add_unique_tab (new Preview (), 80);	+		});+				+		if (format == FontFormat.SVG && !OverwriteDialog.ignore) {+			tab_bar.add_unique_tab (overwrite);+		} else {+			overwrite.finished ();+		} 	} } }diff --git a/libbirdfont/OverwriteDialog.vala b/libbirdfont/OverwriteDialog.valanew file mode 100644index 0000000..3406e3e--- /dev/null+++ b/libbirdfont/OverwriteDialog.vala@@ -0,0 +1,87 @@+/*+    Copyright (C) 2013 Johan Mattsson++    This program is free software: you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation, either version 3 of the License, or+    (at your option) any later version.++    This program 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 General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with this program.  If not, see <http://www.gnu.org/licenses/>.+*/++using Cairo;++namespace Supplement {++public class OverwriteDialog : FontDisplay {++	public signal void finished ();+	public static bool ignore = false; // ignore this dialog+	+	public OverwriteDialog () {+		add_html_callback ("overwrite_dialog", (val) => {+			TabBar tb = MainWindow.get_tab_bar ();+			+			if (val == "overwrite") {+				tb.close_display (this);+				finished ();+			}+			+			if (val == "cancel") {+				tb.close_display (this);+			}+			+			if (val == "ignore") {+				ignore = true;+				tb.close_display (this);+				finished ();+			}+		});+	}++	public override string get_name () {+		return "Overwrite?";+	}++	public override bool is_html_canvas () {+		return true;+	}++	public override string get_html () {+#if FALSE +		_("Overwrite?"); // tell xgettext to extract this+#endif+		string mess = _("""The loaded font will be overwritten if you choose to continue with preview.""");+		return """+<html>+<head>+	<script type="text/javascript" src="supplement.js"></script>+	<style type="text/css">@import url("style.css");</style>+</head>+<body>+	+	<div style="width:300px; margin: 50px auto 0 auto;">+		<div class="heading"><h2>""" + _("Overwrite?") + """</h2></div>+		+		<p>""" + mess + """</p>+		+		<form>+			<input class="button" type="button" value=""" + "\"" + _("Continue") + "\"" + """    onclick="call ('overwrite_dialog:overwrite');"/>+			<input class="button" type="button" value=""" + "\"" + _("Cancel") + "\"" + """  onclick="call ('overwrite_dialog:cancel');"/>+			<input class="button" type="button" value=""" + "\"" + _("Continue and don't ask me again.") + "\"" + """  onclick="call ('overwrite_dialog:ignore');"/>+			<br />+		</form>+	</div>+</body>+</html>""";+	}+}+	+}+

Contact

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