From f6ff327f0b7b50b74328e448ce862f7212dcae23 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 16 Nov 2012 14:42:47 +0100 Subject: keep a buffer dirty flag and display infos about the current buffer in the interfaces (including the dirty flag) * was a bit tricky because the Scintilla SAVEPOINTS cannot be (fully) used * when a file is loaded or saved, a Scintilla SAVEPOINT is set * SAVEPOINTLEFT notifications are used to set a buffer dirty * SAVEPOINTREACHED notifications are useless since Scintilla does not consider the saves themselves to be undoable * GTK interface displays infos in window title bar * NCURSES interface has also been updated and cleaned up a bit. Infos are displayed in a new info line. * NCURSES: fixed popup display after terminal resizing --- interface-gtk.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'interface-gtk.cpp') diff --git a/interface-gtk.cpp b/interface-gtk.cpp index ed0b36c..d348a09 100644 --- a/interface-gtk.cpp +++ b/interface-gtk.cpp @@ -14,26 +14,31 @@ #include #include "sciteco.h" +#include "qbuffers.h" #include "interface.h" #include "interface-gtk.h" InterfaceGtk interface; extern "C" { +static void scintilla_notify(ScintillaObject *sci, uptr_t idFrom, + SCNotification *notify, gpointer user_data); static gboolean cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data); static gboolean exit_app(GtkWidget *w, GdkEventAny *e, gpointer p); } +#define UNNAMED_FILE "(Unnamed)" + InterfaceGtk::InterfaceGtk() { - GtkWidget *window, *vbox; + GtkWidget *vbox; GtkWidget *info_content; gtk_init(NULL, NULL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(window), "SciTECO"); + gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME); g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(exit_app), NULL); @@ -43,6 +48,8 @@ InterfaceGtk::InterfaceGtk() scintilla_set_id(SCINTILLA(editor_widget), 0); gtk_widget_set_usize(editor_widget, 500, 300); gtk_widget_set_can_focus(editor_widget, FALSE); + g_signal_connect(G_OBJECT(editor_widget), SCINTILLA_NOTIFY, + G_CALLBACK(scintilla_notify), NULL); gtk_box_pack_start(GTK_BOX(vbox), editor_widget, TRUE, TRUE, 0); info_widget = gtk_info_bar_new(); @@ -95,6 +102,27 @@ InterfaceGtk::vmsg(MessageType type, const gchar *fmt, va_list ap) gtk_label_set_text(GTK_LABEL(message_widget), buf); } +void +InterfaceGtk::info_update(QRegister *reg) +{ + gchar buf[255]; + + g_snprintf(buf, sizeof(buf), "%s - %s", PACKAGE_NAME, + reg->name); + gtk_window_set_title(GTK_WINDOW(window), buf); +} + +void +InterfaceGtk::info_update(Buffer *buffer) +{ + gchar buf[255]; + + g_snprintf(buf, sizeof(buf), "%s - %s%s", PACKAGE_NAME, + buffer->filename ? : UNNAMED_FILE, + buffer->dirty ? "*" : ""); + gtk_window_set_title(GTK_WINDOW(window), buf); +} + void InterfaceGtk::cmdline_update(const gchar *cmdline) { @@ -142,10 +170,27 @@ InterfaceGtk::widget_set_font(GtkWidget *widget, const gchar *font_name) pango_font_description_free(font_desc); } +InterfaceGtk::~InterfaceGtk() +{ + gtk_widget_destroy(popup_widget); + gtk_widget_destroy(window); + + scintilla_release_resources(); +} + /* * GTK+ callbacks */ +static void +scintilla_notify(ScintillaObject *sci __attribute__((unused)), + uptr_t idFrom __attribute__((unused)), + SCNotification *notify, + gpointer user_data __attribute__((unused))) +{ + interface.process_notify(notify); +} + static gboolean cmdline_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data __attribute__((unused))) -- cgit v1.2.3