diff --git a/data/one-dark.scss b/data/one-dark.scss index 4db47e0..326e0c7 100644 --- a/data/one-dark.scss +++ b/data/one-dark.scss @@ -444,8 +444,5 @@ window { background-color: $level-3-color; border-top: 1px solid $base-border-color; color: $text-color; - label { - padding: 0 0.75em; - } } } diff --git a/meson.build b/meson.build index a36f573..bd348b7 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,7 @@ executable( 'src/window.vala', 'src/notebook.vala', 'src/text-editor-container.vala', + 'src/statusbar.vala', 'src/atom.vapi', 'src/text-editor-widget.cc', import('gnome').compile_resources( diff --git a/screenshot.png b/screenshot.png index 8813c13..e0b2130 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/atom.vapi b/src/atom.vapi index ba390a7..f2f0a01 100644 --- a/src/atom.vapi +++ b/src/atom.vapi @@ -3,6 +3,7 @@ namespace Atom { public class TextEditorWidget : Gtk.Widget { public string title { owned get; } public bool modified { get; } + public string path { owned get; } public string cursor_position { owned get; } public string selection_count { owned get; } public string grammar { get; } diff --git a/src/statusbar.vala b/src/statusbar.vala new file mode 100644 index 0000000..5cdaf3b --- /dev/null +++ b/src/statusbar.vala @@ -0,0 +1,46 @@ +namespace Atom { + +class Statusbar : Gtk.Box { + static construct { + set_css_name("statusbar"); + } + + public Statusbar(Atom.TextEditorWidget text_editor_widget) { + Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 2); + + var path_label = new Gtk.Label(null); + text_editor_widget.bind_property("path", path_label, "label", BindingFlags.SYNC_CREATE); + pack_start(pack(path_label), false); + + var cursor_position_label = new Gtk.Label(null); + text_editor_widget.bind_property("cursor-position", cursor_position_label, "label", BindingFlags.SYNC_CREATE); + 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); + 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); + pack_end(pack(grammar_label), false); + + var encoding_label = new Gtk.Label("UTF-8"); + encoding_label.tooltip_text = "This file uses UTF-8 encoding"; + pack_end(pack(encoding_label), false); + } + + private static Gtk.Widget pack(Gtk.Widget child) { + var frame = new Gtk.Frame(null); + frame.shadow_type = Gtk.ShadowType.NONE; + var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 4); + box.margin_top = 4; + box.margin_bottom = 4; + box.margin_start = 11; + box.margin_end = 11; + box.add(child); + frame.add(box); + return frame; + } +} + +} diff --git a/src/text-editor-container.vala b/src/text-editor-container.vala index 0f94e19..d57d948 100644 --- a/src/text-editor-container.vala +++ b/src/text-editor-container.vala @@ -10,16 +10,7 @@ class TextEditorContainer : Gtk.Box { text_editor_widget = new Atom.TextEditorWidget(file); scrolled_window.add(text_editor_widget); pack_start(scrolled_window, true); - var status_bar = new Gtk.Statusbar(); - status_bar.margin = 0; - var cursor_position_label = new Gtk.Label(null); - text_editor_widget.bind_property("cursor-position", cursor_position_label, "label", BindingFlags.SYNC_CREATE); - status_bar.pack_start(cursor_position_label, false); - status_bar.reorder_child(cursor_position_label, 0); - var grammar_label = new Gtk.Label(null); - text_editor_widget.bind_property("grammar", grammar_label, "label", BindingFlags.SYNC_CREATE); - status_bar.pack_end(grammar_label, false); - status_bar.pack_end(new Gtk.Label("UTF-8"), false); + var status_bar = new Atom.Statusbar(text_editor_widget); pack_start(status_bar, false); } diff --git a/src/text-editor-widget.cc b/src/text-editor-widget.cc index 390ee75..4028f94 100644 --- a/src/text-editor-widget.cc +++ b/src/text-editor-widget.cc @@ -13,6 +13,7 @@ #include #include #include +#include extern "C" TreeSitterGrammar *atom_language_c(); extern "C" TreeSitterGrammar *atom_language_cpp(); @@ -324,6 +325,7 @@ typedef enum { PROP_VSCROLL_POLICY, PROP_TITLE, PROP_MODIFIED, + PROP_PATH, PROP_CURSOR_POSITION, PROP_SELECTION_COUNT, PROP_GRAMMAR, @@ -376,6 +378,7 @@ AtomTextEditorWidget *atom_text_editor_widget_new(GFile *file) { }); priv->text_editor->onDidChangeModified([self]() { g_object_notify(G_OBJECT(self), "modified"); + g_object_notify(G_OBJECT(self), "path"); }); priv->text_editor->onDidChangeGrammar([self]() { g_object_notify(G_OBJECT(self), "grammar"); @@ -584,6 +587,7 @@ static void atom_text_editor_widget_class_init(AtomTextEditorWidgetClass *klass) g_object_class_override_property(G_OBJECT_CLASS(klass), PROP_VSCROLL_POLICY, "vscroll-policy"); g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_TITLE, g_param_spec_string("title", NULL, NULL, NULL, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_MODIFIED, g_param_spec_boolean("modified", NULL, NULL, FALSE, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); + g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PATH, g_param_spec_string("path", NULL, NULL, NULL, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_CURSOR_POSITION, g_param_spec_string("cursor-position", NULL, NULL, NULL, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_SELECTION_COUNT, g_param_spec_string("selection-count", NULL, NULL, NULL, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_GRAMMAR, g_param_spec_string("grammar", NULL, NULL, NULL, (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); @@ -708,6 +712,9 @@ static void atom_text_editor_widget_get_property(GObject *object, guint property case PROP_MODIFIED: g_value_set_boolean(value, atom_text_editor_widget_get_modified(self)); break; + case PROP_PATH: + g_value_take_string(value, atom_text_editor_widget_get_path(self)); + break; case PROP_CURSOR_POSITION: g_value_take_string(value, atom_text_editor_widget_get_cursor_position(self)); break; @@ -797,6 +804,20 @@ gboolean atom_text_editor_widget_get_modified(AtomTextEditorWidget *self) { return priv->text_editor->isModified(); } +gchar *atom_text_editor_widget_get_path(AtomTextEditorWidget *self) { + AtomTextEditorWidgetPrivate *priv = GET_PRIVATE(self); + std::string path; + if (optional fullPath = priv->text_editor->getPath()) { + path = fsPlus::tildify(*fullPath); + } else { + path = priv->text_editor->getTitle(); + } + if (priv->text_editor->isModified()) { + path += '*'; + } + return g_strdup(path.c_str()); +} + gchar *atom_text_editor_widget_get_cursor_position(AtomTextEditorWidget *self) { AtomTextEditorWidgetPrivate *priv = GET_PRIVATE(self); Point position = priv->text_editor->getCursorBufferPosition(); diff --git a/src/text-editor-widget.h b/src/text-editor-widget.h index 051e3b5..7831335 100644 --- a/src/text-editor-widget.h +++ b/src/text-editor-widget.h @@ -70,6 +70,7 @@ struct _AtomTextEditorWidgetClass { AtomTextEditorWidget *atom_text_editor_widget_new(GFile *); gchar *atom_text_editor_widget_get_title(AtomTextEditorWidget *); gboolean atom_text_editor_widget_get_modified(AtomTextEditorWidget *); +gchar *atom_text_editor_widget_get_path(AtomTextEditorWidget *); gchar *atom_text_editor_widget_get_cursor_position(AtomTextEditorWidget *); gchar *atom_text_editor_widget_get_selection_count(AtomTextEditorWidget *); const gchar *atom_text_editor_widget_get_grammar(AtomTextEditorWidget *); diff --git a/subprojects/atom-native b/subprojects/atom-native index ea8980a..81cc991 160000 --- a/subprojects/atom-native +++ b/subprojects/atom-native @@ -1 +1 @@ -Subproject commit ea8980a28cc0503880efd64dfa76b613e999a209 +Subproject commit 81cc991a9db1b4a961b04daa3cbd1ef6ce1b8185