|
@@ -17,8 +17,10 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include <gtksourceview/gtksource.h>
|
|
#include <gtksourceview/gtksource.h>
|
|
|
|
|
+#include <webkit2/webkit2.h>
|
|
|
|
|
|
|
|
#include "iridium-config.h"
|
|
#include "iridium-config.h"
|
|
|
|
|
+#include "iridium-markdown.h"
|
|
|
#include "iridium-note.h"
|
|
#include "iridium-note.h"
|
|
|
#include "iridium-note-row.h"
|
|
#include "iridium-note-row.h"
|
|
|
#include "iridium-tag-row.h"
|
|
#include "iridium-tag-row.h"
|
|
@@ -36,9 +38,14 @@ struct _IridiumWindow
|
|
|
GtkWidget *main_pane;
|
|
GtkWidget *main_pane;
|
|
|
GtkSearchBar *search_bar;
|
|
GtkSearchBar *search_bar;
|
|
|
GtkSearchEntry *search_entry;
|
|
GtkSearchEntry *search_entry;
|
|
|
|
|
+ GtkToggleButton *toggle_html_view;
|
|
|
|
|
+ GtkRevealer *html_view_revealer;
|
|
|
|
|
+ WebKitWebView *html_view;
|
|
|
|
|
|
|
|
GBinding *title_binding;
|
|
GBinding *title_binding;
|
|
|
GBinding *content_binding;
|
|
GBinding *content_binding;
|
|
|
|
|
+
|
|
|
|
|
+ IridiumMarkdown *markdown;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (IridiumWindow, iridium_window, GTK_TYPE_APPLICATION_WINDOW)
|
|
G_DEFINE_TYPE (IridiumWindow, iridium_window, GTK_TYPE_APPLICATION_WINDOW)
|
|
@@ -55,12 +62,30 @@ on_search_changed (IridiumWindow *self, GtkSearchEntry *entry)
|
|
|
gtk_list_box_invalidate_filter (self->note_list);
|
|
gtk_list_box_invalidate_filter (self->note_list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void
|
|
|
|
|
+on_markdown_compiled (GObject *object,
|
|
|
|
|
+ GAsyncResult *result,
|
|
|
|
|
+ gpointer user_data)
|
|
|
|
|
+{
|
|
|
|
|
+ IridiumWindow *window;
|
|
|
|
|
+ gchar *html;
|
|
|
|
|
+ GError *error = NULL;
|
|
|
|
|
+
|
|
|
|
|
+ window = IRIDIUM_WINDOW (user_data);
|
|
|
|
|
+ html = iridium_markdown_compile_finish (object, result, &error);
|
|
|
|
|
+ webkit_web_view_load_html (window->html_view, html, NULL);
|
|
|
|
|
+ g_free (html);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void
|
|
static void
|
|
|
on_note_selected (IridiumWindow *self, IridiumNoteRow *row, gpointer user_data)
|
|
on_note_selected (IridiumWindow *self, IridiumNoteRow *row, gpointer user_data)
|
|
|
{
|
|
{
|
|
|
IridiumNote *note;
|
|
IridiumNote *note;
|
|
|
GtkTextBuffer *buffer;
|
|
GtkTextBuffer *buffer;
|
|
|
GBindingFlags flags;
|
|
GBindingFlags flags;
|
|
|
|
|
+ GtkTextIter start;
|
|
|
|
|
+ GtkTextIter end;
|
|
|
|
|
+ gchar *text;
|
|
|
|
|
|
|
|
if (self->title_binding != NULL)
|
|
if (self->title_binding != NULL)
|
|
|
g_clear_object (&self->title_binding);
|
|
g_clear_object (&self->title_binding);
|
|
@@ -76,6 +101,13 @@ on_note_selected (IridiumWindow *self, IridiumNoteRow *row, gpointer user_data)
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
|
|
|
self->title_binding = g_object_bind_property (note, "title", self->title_entry, "text", flags);
|
|
self->title_binding = g_object_bind_property (note, "title", self->title_entry, "text", flags);
|
|
|
self->content_binding = g_object_bind_property (note, "content", buffer, "text", flags);
|
|
self->content_binding = g_object_bind_property (note, "content", buffer, "text", flags);
|
|
|
|
|
+
|
|
|
|
|
+ gtk_text_buffer_get_start_iter (buffer, &start);
|
|
|
|
|
+ gtk_text_buffer_get_end_iter (buffer, &end);
|
|
|
|
|
+ text = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
|
|
|
|
|
+ iridium_markdown_compile_async (self->markdown, text, G_PRIORITY_DEFAULT, NULL,
|
|
|
|
|
+ on_markdown_compiled, self);
|
|
|
|
|
+ g_free (text);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -117,6 +149,7 @@ iridium_window_dispose (GObject *object)
|
|
|
self = IRIDIUM_WINDOW (object);
|
|
self = IRIDIUM_WINDOW (object);
|
|
|
g_clear_object (&self->title_binding);
|
|
g_clear_object (&self->title_binding);
|
|
|
g_clear_object (&self->content_binding);
|
|
g_clear_object (&self->content_binding);
|
|
|
|
|
+ g_clear_object (&self->markdown);
|
|
|
G_OBJECT_CLASS (iridium_window_parent_class)->dispose (object);
|
|
G_OBJECT_CLASS (iridium_window_parent_class)->dispose (object);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -140,6 +173,9 @@ iridium_window_class_init (IridiumWindowClass *klass)
|
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, main_pane);
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, main_pane);
|
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, search_bar);
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, search_bar);
|
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, search_entry);
|
|
gtk_widget_class_bind_template_child (widget_class, IridiumWindow, search_entry);
|
|
|
|
|
+ gtk_widget_class_bind_template_child (widget_class, IridiumWindow, html_view);
|
|
|
|
|
+ gtk_widget_class_bind_template_child (widget_class, IridiumWindow, html_view_revealer);
|
|
|
|
|
+ gtk_widget_class_bind_template_child (widget_class, IridiumWindow, toggle_html_view);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_tag_selected);
|
|
gtk_widget_class_bind_template_callback (widget_class, on_tag_selected);
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_note_selected);
|
|
gtk_widget_class_bind_template_callback (widget_class, on_note_selected);
|
|
@@ -160,12 +196,15 @@ iridium_window_init (IridiumWindow *self)
|
|
|
|
|
|
|
|
self->title_binding = NULL;
|
|
self->title_binding = NULL;
|
|
|
self->content_binding = NULL;
|
|
self->content_binding = NULL;
|
|
|
|
|
+ self->markdown = iridium_markdown_new ();
|
|
|
|
|
|
|
|
action = g_simple_action_new ("search", NULL);
|
|
action = g_simple_action_new ("search", NULL);
|
|
|
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
|
|
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
|
|
|
g_signal_connect (action, "activate", G_CALLBACK (search_activated), self);
|
|
g_signal_connect (action, "activate", G_CALLBACK (search_activated), self);
|
|
|
g_object_unref (action);
|
|
g_object_unref (action);
|
|
|
|
|
|
|
|
|
|
+ g_object_bind_property (self->toggle_html_view, "active",
|
|
|
|
|
+ self->html_view_revealer, "reveal-child", G_BINDING_DEFAULT);
|
|
|
gtk_search_bar_connect_entry (self->search_bar, GTK_ENTRY (self->search_entry));
|
|
gtk_search_bar_connect_entry (self->search_bar, GTK_ENTRY (self->search_entry));
|
|
|
|
|
|
|
|
notes[0] = iridium_note_new ("Hello", NULL);
|
|
notes[0] = iridium_note_new ("Hello", NULL);
|