Skip to content

Commit

Permalink
statusbar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Oct 29, 2023
1 parent 44140a9 commit 71a3479
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 14 deletions.
3 changes: 0 additions & 3 deletions data/one-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/atom.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
46 changes: 46 additions & 0 deletions src/statusbar.vala
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
11 changes: 1 addition & 10 deletions src/text-editor-container.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
21 changes: 21 additions & 0 deletions src/text-editor-widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <bracket-matcher-view.h>
#include <select-next.h>
#include <whitespace.h>
#include <fs-plus.h>

extern "C" TreeSitterGrammar *atom_language_c();
extern "C" TreeSitterGrammar *atom_language_cpp();
Expand Down Expand Up @@ -324,6 +325,7 @@ typedef enum {
PROP_VSCROLL_POLICY,
PROP_TITLE,
PROP_MODIFIED,
PROP_PATH,
PROP_CURSOR_POSITION,
PROP_SELECTION_COUNT,
PROP_GRAMMAR,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string> 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();
Expand Down
1 change: 1 addition & 0 deletions src/text-editor-widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit 71a3479

Please sign in to comment.