Browse Source

Reflect current font in menu on app load

Previously, "Serif" would be selected in the menu when the app first
loaded, no matter what the actual setting was.
tags/v1.0.2
Matt Baer 5 years ago
parent
commit
8312087ec9
1 changed files with 17 additions and 3 deletions
  1. +17
    -3
      src/window.vala

+ 17
- 3
src/window.vala View File

@@ -20,6 +20,9 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
private Gtk.TextView canvas;
private Gtk.HeaderBar header;
private Granite.ModeSwitch darkmode_switch;
private Gtk.RadioMenuItem font_serif_option;
private Gtk.RadioMenuItem font_sans_option;
private Gtk.RadioMenuItem font_wrap_option;

private static string data_dir = ".writeas";
private static string version = "1.0.1";
@@ -162,10 +165,10 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
fonts.popup = new Gtk.Menu();
header.pack_start(fonts);

build_fontoption(fonts.popup, _("Serif"), "serif", font);
build_fontoption(fonts.popup, _("Sans-serif"), "sans",
font_serif_option = build_fontoption(fonts.popup, _("Serif"), "serif", font);
font_sans_option = build_fontoption(fonts.popup, _("Sans-serif"), "sans",
"'Open Sans', 'Segoe UI', Tahoma, Arial, sans-serif");
build_fontoption(fonts.popup, _("Monospace"), "wrap", "Hack, consolas," +
font_wrap_option = build_fontoption(fonts.popup, _("Monospace"), "wrap", "Hack, consolas," +
"Menlo-Regular, Menlo, Monaco, 'ubuntu mono', monospace");
fonts.popup.show_all();
}
@@ -193,6 +196,8 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
}

menu.add(option);

return option;
}

public override void grab_focus() {
@@ -213,6 +218,15 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
font = theme.get_string("Post", "font");
fontstyle = theme.get_string("Post", "fontstyle");

// Select the current font in the menu
if (fontstyle == "serif") {
font_serif_option.set_active(true);
} else if (fontstyle == "sans") {
font_sans_option.set_active(true);
} else if (fontstyle == "wrap") {
font_wrap_option.set_active(true);
}

adjust_text_style(false);
} catch (Error err) {/* No biggy... */}
}


Loading…
Cancel
Save