diff --git a/src/Widgets/SideBar.vala b/src/Widgets/SideBar.vala index e6018531..4943db4b 100644 --- a/src/Widgets/SideBar.vala +++ b/src/Widgets/SideBar.vala @@ -111,7 +111,6 @@ namespace Quilter.Widgets { var title = new Gtk.Label (_("Files")); title.get_style_context ().add_class ("heading"); title.xalign = 0; - title.margin_start = 6; title.margin_bottom = 6; files_grid = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); @@ -164,7 +163,6 @@ namespace Quilter.Widgets { var title = new Gtk.Label (_("Outline")); title.get_style_context ().add_class ("heading"); title.xalign = 0; - title.margin_start = 6; title.margin_bottom = 6; var sep = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); @@ -220,10 +218,10 @@ namespace Quilter.Widgets { get_selected_row ().title = match.fetch_named ("header") + " " + match.fetch_named ("text"); } else if (match.fetch_named ("header") == "##") { store.insert (out subheader, root, -1); - store.set (subheader, 0, " " + match.fetch_named ("header") + " " + match.fetch_named ("text"), -1); + store.set (subheader, 0, match.fetch_named ("header") + " " + match.fetch_named ("text"), -1); } else if (match.fetch_named ("header") == "###") { store.insert (out section, subheader, -1); - store.set (section, 0, " " + match.fetch_named ("header") + " " + match.fetch_named ("text"), -1); + store.set (section, 0, match.fetch_named ("header") + " " + match.fetch_named ("text"), -1); } } while (match.next ()); } diff --git a/src/Widgets/StatusBar.vala b/src/Widgets/StatusBar.vala index 6e8751f1..278059df 100644 --- a/src/Widgets/StatusBar.vala +++ b/src/Widgets/StatusBar.vala @@ -29,8 +29,8 @@ namespace Quilter { public Gtk.RadioButton track_rtc; public MainWindow window; - /* Averaged normal reading speed is 200 WPM */ - int WPM = 200; + /* Averaged normal reading speed is 265 WPM */ + int WPM = 265; public StatusBar (Gtk.SourceBuffer buf) { this.buf = buf; @@ -43,7 +43,7 @@ namespace Quilter { update_wordcount (); }); - track_lines = new Gtk.RadioButton.with_label_from_widget (track_words, _("Lines")); + track_lines = new Gtk.RadioButton.with_label_from_widget (track_words, _("Sentences")); track_lines.toggled.connect (() => { Quilter.Application.gsettings.set_string("track-type", "lines"); update_linecount (); @@ -96,10 +96,13 @@ namespace Quilter { if (Quilter.Application.gsettings.get_string("track-type") == "words") { update_wordcount (); + track_words.set_active (true); } else if (Quilter.Application.gsettings.get_string("track-type") == "lines") { update_linecount (); + track_lines.set_active (true); } else if (Quilter.Application.gsettings.get_string("track-type") == "rtc") { update_readtimecount (); + track_rtc.set_active (true); } this.transition_type = Gtk.RevealerTransitionType.SLIDE_UP; @@ -114,23 +117,36 @@ namespace Quilter { public void update_linecount () { var lc = get_count(); - track_type_menu.set_label ((_("Lines: ")) + lc.lines.to_string()); + track_type_menu.set_label ((_("Sentences: ")) + lc.lines.to_string()); } public void update_readtimecount () { var rtc = get_count(); - float rt = (rtc.words / WPM); - print ("%f", rt); + double rt = Math.round((rtc.words / WPM)); track_type_menu.set_label ((_("Reading Time: ")) + rt.to_string() + "m"); } public WordCount get_count() { - Gtk.TextIter start, end; + Gtk.TextIter start, end; buf.get_bounds (out start, out end); - var lines = buf.get_line_count (); + var buffer = buf.get_text (start, end, false); + int i = 0; + try { + GLib.MatchInfo match; + var reg = new Regex("(?m)(?
\\.)"); + if (reg.match (buffer, 0, out match)) { + do { + i++; + } while (match.next ()); + } + } catch (Error e) { + warning (e.message); + } + + var lines = i; var words = buf.get_text (start, end, false).split(" ").length; - return new WordCount(words, lines); + return new WordCount(words, lines); } }