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);
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);
+}
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) {
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);
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) {
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);
+}
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);