#include <cx/string.h>
#include <cx/printf.h>
+#include <libidav/utils.h>
+
#include <ctype.h>
#include <string.h>
return FALSE; // TODO
}
-static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf) {
+void md_serialize_image(EmbeddedWidget *em, CxBuffer *out) {
+ cx_bprintf(out, "", em->name);
+}
+
+static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *attachment_path) {
GtkTextView *textview = GTK_TEXT_VIEW(editor->textview);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
EmbeddedWidget *em = malloc(sizeof(EmbeddedWidget));
em->widget = image;
em->anchor = anchor;
- em->restore = NULL;
+ em->name = attachment_path ? strdup(util_resource_name(attachment_path)) : NULL;
+ em->path = attachment_path;
+ em->data1 = pixbuf;
+ em->data2 = NULL;
+ em->serialize = md_serialize_image;
g_object_ref(image);
g_object_ref(anchor);
+ g_object_set_data(G_OBJECT(anchor), "em", em);
+
BufferEmbeddedObjects *embedded_objects = g_object_get_data(G_OBJECT(buffer), "embedded");
cxListAdd(embedded_objects->objects, em);
}
double y,
NoteEditor *editor)
{
+ char *attachment_path = NULL;
+
gboolean success = TRUE;
GdkPixbuf *pixbuf = NULL;
if(G_VALUE_HOLDS(value, G_TYPE_FILE)) {
g_free(scheme);
char *path = g_file_get_path(file);
+ attachment_path = strdup(path);
printf("dnd file: %s\n", path);
if(path_is_image_file(cx_str(path))) {
}
if(pixbuf && success) {
- editor_attach_image(editor, pixbuf);
+ editor_attach_image(editor, pixbuf, attachment_path);
+ } else {
+ free(attachment_path);
}
return success;
CxMap *prev_tags = cxHashMapCreateSimple(CX_STORE_POINTERS);
+ GtkTextChildAnchor *anchor = NULL;
+
GtkTextIter start;
GtkTextIter iter;
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
start = iter;
while(gtk_text_iter_forward_to_tag_toggle(&iter, NULL)) {
+ if(anchor) {
+ EmbeddedWidget *em = g_object_get_data(G_OBJECT(anchor), "em");
+ if(em) {
+ em->serialize(em, &out);
+ }
+ anchor = NULL;
+ }
+
+ // check for anchors
+ GtkTextIter a = start;
+ while(!gtk_text_iter_equal(&a, &iter)) {
+ anchor = gtk_text_iter_get_child_anchor(&a);
+ gtk_text_iter_forward_char(&a);
+ if(anchor) {
+ iter = a;
+ break;
+ }
+ }
+ if(!anchor) {
+ anchor = gtk_text_iter_get_child_anchor(&iter);
+ }
+
gchar *text = gtk_text_buffer_get_text(buffer, &start, &iter, TRUE);
GSList *tags = gtk_text_iter_get_tags(&start);