]> uap-core.de Git - note.git/commitdiff
implement insert-image button
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 3 Aug 2025 19:07:29 +0000 (21:07 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 3 Aug 2025 19:07:29 +0000 (21:07 +0200)
application/editor.h
application/gtk-text.c
application/note.c
application/note.h
application/window.c
application/window.h

index e973d5d5a74a729280ee079163d53a9aa82ae233..c2aba27cf06238b0b8bd65859bfb7cef8e46b9b3 100644 (file)
@@ -135,6 +135,7 @@ void editor_init_textview(UiObject *obj, UIWIDGET textview);
 void editor_init_textbuf(UiText *text);
 void editor_apply_styles(Note *note, UIWIDGET textview, UiText *text, CxList /* MDDocStyleSection */ *styles);
 cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a);
+void editor_insert_image_file(UiText *text, const char *filepath);
 
 UiBool editor_set_style(UiText *text, const char *style, UiBool enabled);
 void editor_set_paragraph_style(UiText *text, const char *style);
index 0ef8ab71d8793563e6eda19f8184977cb3c7e897..2f9ad3f67a164e46de67d94f3c71e70481b64f9b 100644 (file)
@@ -1298,3 +1298,11 @@ void editor_insert_list(UiText *text, UiBool ordered) {
     const char *style = ordered ? EDITOR_STYLE_ORDLIST0 : EDITOR_STYLE_LIST0;
     editor_insert_list_element(editor, &iter, style, 0);
 }
+
+void editor_insert_image_file(UiText *text, const char *filepath) {
+    GtkTextBuffer *buffer = text->data1;
+    NoteEditor *editor = g_object_get_data(text->obj, "editor");
+    
+    GFile *file = g_file_new_for_path(filepath);
+    editor_dnd_add_file(editor, file);
+}
index 86cdea8be29ddb9c78aebd981e37cb46ab6ceef6..de5214fda1d1d9516ba3ce8ab76fe2ab0f048ac1 100644 (file)
@@ -253,6 +253,9 @@ void note_insert_list(NoteModel *note, UiBool ordered) {
     editor_insert_list(note->text, ordered);
 }
 
+void note_insert_image(NoteModel *note, const char *filepath) {
+    editor_insert_image_file(note->text, filepath);
+}
 
 
 void note_update_title(NotebookModel *notebook, Note *note) {
index 190d1d50b953fde6e40144ac0a72a0999dc16968..948664729a539045da8c41f5f0fc4cb9f9eaed89 100644 (file)
@@ -61,6 +61,7 @@ void note_text_style_set_emphasis(NoteModel *note, UiBool enabled);
 void note_text_style_set_underline(NoteModel *note, UiBool enabled);
 void note_text_style_set_code(NoteModel *note, UiBool enabled);
 void note_insert_list(NoteModel *note, UiBool ordered);
+void note_insert_image(NoteModel *note, const char *filepath);
 
 void note_update_title(NotebookModel *notebook, Note *note);
 
index 63889933d34741374ace05ab14e47098566f3266..6bf6754c00dbd011ddcdfe5221d8a46fceb09570 100644 (file)
@@ -95,7 +95,7 @@ void window_create() {
                         ui_togglebutton(obj, .label = "code", .varname = "note_textnote_code", .onchange = action_textnote_style_code);
                         ui_button(obj, .icon = "view-list-bullet", .onclick = action_textnote_insertlist, .onclickdata = ACTION_DATA_INSERT_LIST_UNORDERED);
                         ui_button(obj, .icon = "view-list-ordered", .onclick = action_textnote_insertlist, .onclickdata = ACTION_DATA_INSERT_LIST_ORDERED);
-                        ui_button(obj, .icon = "insert-image");
+                        ui_button(obj, .icon = "insert-image", .onclick = action_textnote_insertimg);
                         ui_button(obj, .icon = "insert-link");
                     }
                     ui_hbox_w(obj, wdata->attachments, .margin = 10) {
@@ -519,3 +519,17 @@ void action_textnote_insertlist(UiEvent *event, void *userdata) {
         note_insert_list(notebook->current_note->model, (UiBool)ordered);
     }
 }
+
+static void insertimg_file(UiEvent *event, void *userdata) {
+    MainWindow *window = event->window;
+    NotebookModel *notebook = window->current_notebook;
+    UiFileList *flist = event->eventdata;
+    if(flist->nfiles == 1 && notebook && notebook->current_note && notebook->current_note->model) {
+        const char *file = flist->files[0];
+        note_insert_image(notebook->current_note->model, file);
+    }
+}
+
+void action_textnote_insertimg(UiEvent *event, void *userdata) {
+    ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_SINGLE, insertimg_file, NULL);
+}
index 63fc9bb55a9d2016ce2ff00a66fec5ba970b774f..b0ea783d23ea9aa92903a4ae9e7a1a00c1d830ea 100644 (file)
@@ -80,6 +80,7 @@ void action_textnote_style_emphasis(UiEvent *event, void *userdata);
 void action_textnote_style_underline(UiEvent *event, void *userdata);
 void action_textnote_style_code(UiEvent *event, void *userdata);
 void action_textnote_insertlist(UiEvent *event, void *userdata);
+void action_textnote_insertimg(UiEvent *event, void *userdata);