Skip to content

Commit

Permalink
more statusbar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Dec 26, 2023
1 parent b4b7c1b commit 6fb4733
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
46 changes: 45 additions & 1 deletion src/statusbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,50 @@ class Statusbar : Gtk.Box {

var cursor_position_label = new Gtk.Label(null);
text_editor_widget.bind_property("cursor-position", cursor_position_label, "label", BindingFlags.SYNC_CREATE);
text_editor_widget.bind_property("cursor-position", cursor_position_label, "tooltip-text", BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => {
var from_values = ((string)from_value).split(":");
int row = int.parse(from_values[0]);
int column = int.parse(from_values[1]);
to_value = "Line %d, Column %d".printf(row, column);
return true;
});
pack_start(pack(cursor_position_label), false);

var selection_count_label = new Gtk.Label(null);
text_editor_widget.bind_property("selection-count", selection_count_label, "label", BindingFlags.SYNC_CREATE);
text_editor_widget.bind_property("selection-count", selection_count_label, "visible", BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => {
to_value = ((string)from_value).length > 0;
return true;
});
text_editor_widget.bind_property("selection-count", selection_count_label, "label", BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => {
if (((string)from_value).length == 0) {
to_value = "";
} else {
var from_values = ((string)from_value).split(":");
int line_count = int.parse(from_values[0]);
int count = int.parse(from_values[1]);
to_value = "(%d, %d)".printf(line_count, count);
}
return true;
});
text_editor_widget.bind_property("selection-count", selection_count_label, "tooltip-text", BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => {
if (((string)from_value).length == 0) {
to_value = "";
} else {
var from_values = ((string)from_value).split(":");
int line_count = int.parse(from_values[0]);
int count = int.parse(from_values[1]);
to_value = "%s, %s selected".printf(pluralize(line_count, "line"), pluralize(count, "character"));
}
return true;
});
pack_start(pack(selection_count_label), false);

var grammar_label = new Gtk.Label(null);
text_editor_widget.bind_property("grammar", grammar_label, "label", BindingFlags.SYNC_CREATE);
text_editor_widget.bind_property("grammar", grammar_label, "tooltip-text", BindingFlags.SYNC_CREATE, (binding, from_value, ref to_value) => {
to_value = "File uses the %s grammar".printf((string)from_value);
return true;
});
pack_end(pack(grammar_label), false);

var encoding_label = new Gtk.Label("UTF-8");
Expand All @@ -42,6 +78,14 @@ class Statusbar : Gtk.Box {
frame.add(box);
return frame;
}

private static string pluralize(int count, string singular) {
if (count == 1) {
return "%d %s".printf(count, singular);
} else {
return "%d %ss".printf(count, singular);
}
}
}

}
4 changes: 2 additions & 2 deletions src/text-editor-widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ gchar *atom_text_editor_widget_get_cursor_position(AtomTextEditorWidget *self) {
Point position = priv->text_editor->getCursorBufferPosition();
double row = position.row + 1;
double column = position.column + 1;
return g_strdup_printf("%.0f:%.0f", row, column);
return g_strdup_printf("%g:%g", row, column);
}

gchar *atom_text_editor_widget_get_selection_count(AtomTextEditorWidget *self) {
Expand All @@ -835,7 +835,7 @@ gchar *atom_text_editor_widget_get_selection_count(AtomTextEditorWidget *self) {
lineCount -= 1;
}
if (count > 0) {
return g_strdup_printf("(%.0f, %.0f)", lineCount, count);
return g_strdup_printf("%g:%g", lineCount, count);
} else {
return g_strdup("");
}
Expand Down

0 comments on commit 6fb4733

Please sign in to comment.