aboutsummaryrefslogtreecommitdiffhomepage
path: root/interface-gtk.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-16 14:42:47 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-16 14:42:47 +0100
commitf6ff327f0b7b50b74328e448ce862f7212dcae23 (patch)
tree4a773dcb9120d6a7fb96fce92422667e8702dbdf /interface-gtk.cpp
parent0a8f940ffe1aaf77ba12ccc02d4e382be2118151 (diff)
downloadsciteco-f6ff327f0b7b50b74328e448ce862f7212dcae23.tar.gz
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
Diffstat (limited to 'interface-gtk.cpp')
-rw-r--r--interface-gtk.cpp49
1 files changed, 47 insertions, 2 deletions
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 <ScintillaWidget.h>
#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();
@@ -96,6 +103,27 @@ InterfaceGtk::vmsg(MessageType type, const gchar *fmt, va_list ap)
}
void
+InterfaceGtk::info_update(QRegister *reg)
+{
+ gchar buf[255];
+
+ g_snprintf(buf, sizeof(buf), "%s - <QRegister> %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 - <Buffer> %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)
{
gint pos = 1;
@@ -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)))