Skip to content

Commit

Permalink
SideBar.vala - Align titles. / StatusBar.vala - lines → sentences.
Browse files Browse the repository at this point in the history
In SideBar.vala, I've fixed clicking on entries to jump to them, and
made the section titles align with the start of what they're heading
of.

In Statusbar.vala, I've changed the algorithm to count sentences
instead of lines. Also chjanged the algorithm of Reading Time to be
more natural.
  • Loading branch information
Lains committed Feb 3, 2021
1 parent 6465301 commit 170d7d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/Widgets/SideBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ());
}
Expand Down
34 changes: 25 additions & 9 deletions src/Widgets/StatusBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ();
Expand Down Expand Up @@ -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;
Expand All @@ -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)(?<header>\\.)");
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);
}
}

Expand Down

0 comments on commit 170d7d6

Please sign in to comment.