aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarsVomMars2021-04-27 14:59:48 +0200
committerLarsVomMars2021-04-27 14:59:48 +0200
commitefbbd5533e2d66dcfb6d360792793f23a8f4dd05 (patch)
tree4e56aa769ed5728c3718725230008e9372ebd6d7
parent5fdd1e5c0112db4c0c8646cc8fbc629bdb83355c (diff)
Add linemarkers
-rw-r--r--src/gui.c29
-rw-r--r--src/inc/gui.h3
2 files changed, 31 insertions, 1 deletions
diff --git a/src/gui.c b/src/gui.c
index 5f9945d..aeab43b 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -1,5 +1,4 @@
#include <def.h>
-#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#include <gui.h>
#include <parser.h>
@@ -133,6 +132,31 @@ void gui_show_info(const char *text)
gtk_widget_destroy(info);
}
+static gchar *gui_show_tt(GtkSourceMarkAttributes *attributes, GtkSourceMark *mark,
+ const gchar *message)
+{
+ UNUSED(attributes);
+ UNUSED(mark);
+ return strdup(message);
+}
+
+void gui_add_line_marker(int line_number, const char *message, const char *category,
+ const char *icon, GdkRGBA rgba)
+{
+ GtkSourceMarkAttributes *attributes = gtk_source_mark_attributes_new();
+ gtk_source_mark_attributes_set_background(attributes, &rgba);
+ gtk_source_mark_attributes_set_icon_name(attributes, icon);
+ gtk_source_view_set_mark_attributes(GTK_SOURCE_VIEW(text_view), category, attributes, 10);
+
+ GtkTextIter iter;
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
+ gtk_text_buffer_get_iter_at_line(buffer, &iter, line_number);
+ gtk_source_view_set_mark_attributes(GTK_SOURCE_VIEW(text_view), category, attributes, 10);
+ gtk_source_buffer_create_source_mark(GTK_SOURCE_BUFFER(buffer), message, category, &iter);
+ g_signal_connect(G_OBJECT(attributes), "query-tooltip-text", G_CALLBACK(gui_show_tt),
+ strdup(message));
+}
+
static u8 gui_save_file(char *fname, char *fdata)
{
FILE *f = fopen(fname, "w");
@@ -299,6 +323,9 @@ static void gui_activate(GtkApplication *app, gpointer data)
gui_init_highlighter();
gui_call_syntax_highlighter();
+
+ GdkRGBA rgba = { 1, 0, 0, 0.3 };
+ gui_add_line_marker(2, "Help", "hc", "dialog-error", rgba);
}
int gui_init(int argc, char *argv[])
diff --git a/src/inc/gui.h b/src/inc/gui.h
index 128a703..8270623 100644
--- a/src/inc/gui.h
+++ b/src/inc/gui.h
@@ -2,11 +2,14 @@
#define GUI_H
#include <def.h>
+#include <gtk/gtk.h>
int gui_init(int argc, char *argv[]);
void gui_show_warning(const char *text);
void gui_show_info(const char *text);
+void gui_add_line_marker(int line_number, const char *message, const char *category, const char *icon, GdkRGBA rgba);
+
void gui_unhighlight(void);
void gui_unhighlight_name(const char *tag_name);
void gui_highlight(u32 column, u32 line, u32 length, const char *color);