static gint open_dialog(EDITOR *e) { GtkWidget *dialog; gint response; dialog = gtk_file_chooser_dialog_new(_("Open"), GTK_WINDOW(e->window), GTK_FILE_CHOOSER_ACTION_OPEN, #ifdef HAVE_GTK_310 "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, #else GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, #endif NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), settings.studypaddir); response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_ACCEPT) { gchar *new_filename; new_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); _load_file(e, new_filename); g_free(new_filename); } gtk_widget_destroy(dialog); return response; }
static void recent_item_cb(GtkRecentChooser *chooser, EDITOR *e) { gchar *file_uri = gtk_recent_chooser_get_current_uri(chooser); XI_message(("file_uri: %s", file_uri)); if (e->filename) g_free(e->filename); e->filename = g_strdup(file_uri); //editor_open_recent (file_uri, e); _load_file(e, file_uri); xml_set_value("Xiphos", "studypad", "lastfile", e->filename); settings.studypadfilename = xml_get_value("studypad", "lastfile"); change_window_title(e->window, e->filename); }
// Use _load_file to read a file into memory // Returns: // read() size in *rv_size // memory buffer allocated (caller must free buffer) //------------------------------------------------------------------- char* load_file(const char* name, int* rv_size, int add0) { int rsize, ssize; char* buf = _load_file(name, &rsize, &ssize, add0); if (rv_size) *rv_size = rsize; if (rsize != ssize) { if (buf) free(buf); buf = 0; if (rv_size) *rv_size = -1; } return buf; }
static void _load_program(const char* path) { char* txt = 0; mb_assert(path); txt = _load_file(path); if(txt) { _new_program(); _set_code(txt); free(txt); if(_code()->count == 1) { _printf("Load done. %d line loaded.\n", _code()->count); } else { _printf("Load done. %d lines loaded.\n", _code()->count); } } else { _printf("Cannot load file \"%s\".\n", path); } }
G_MODULE_EXPORT void action_new_activate_cb(GtkWidget *widget, EDITOR *e) { /* for studypad only */ gchar *filename = NULL; if (e->is_changed) ask_about_saving(e); filename = g_strdup_printf("%s/%s", settings.gSwordDir, "studypad.spt"); _load_file(e, filename); if (e->filename) g_free(e->filename); e->filename = g_strdup(_("Untitled document")); xml_set_value("Xiphos", "studypad", "lastfile", e->filename); settings.studypadfilename = xml_get_value("studypad", "lastfile"); change_window_title(e->window, e->filename); e->is_changed = TRUE; }
static void action_new_cb(GtkAction *action, EDITOR *e) { /* for studypad only */ if (editor_is_dirty(e)) _save_file(e); _load_file(e, g_strdup_printf("%s/%s", settings.gSwordDir, "template.pad")); if (e->filename) g_free(e->filename); e->filename = g_strdup(_("Untitled document")); xml_set_value("Xiphos", "studypad", "lastfile", e->filename); settings.studypadfilename = xml_get_value("studypad", "lastfile"); change_window_title(e->window, e->filename); gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window), NULL); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), TRUE); }
static bool_t _try_import(struct mb_interpreter_t* s, const char* p) { bool_t result = false; int i = 0; mb_assert(s); for(i = 0; i < importing_dirs->count; i++) { char* t = 0; char* d = importing_dirs->dirs[i]; int m = (int)strlen(d); int n = (int)strlen(p); #if _USE_MEM_POOL char* buf = _pop_mem(m + n + 1); #else /* _USE_MEM_POOL */ char* buf = (char*)malloc(m + n + 1); #endif /* _USE_MEM_POOL */ memcpy(buf, d, m); memcpy(buf + m, p, n); buf[m + n] = '\0'; t = _load_file(buf); if(t) { if(mb_load_string(s, t, true) == MB_FUNC_OK) result = true; free(t); } #if _USE_MEM_POOL _push_mem(buf); #else /* _USE_MEM_POOL */ free(buf); #endif /* _USE_MEM_POOL */ if(result) break; } return result; }
gint editor_create_new(const gchar *filename, const gchar *key, gint editor_type) { GList *tmp = NULL; tmp = g_list_first(editors_all); while (tmp != NULL) { EDITOR *e = (EDITOR *)tmp->data; switch (editor_type) { case STUDYPAD_EDITOR: if (e->studypad) { if (editor_is_dirty(e)) _save_file(e); if (e->filename) g_free(e->filename); e->filename = g_strdup(filename); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); _load_file(e, g_strdup(filename)); return 1; } break; case NOTE_EDITOR: if (!e->noteeditor) break; if (editor_is_dirty(e)) _save_note(e); if (e->module) g_free(e->module); e->module = g_strdup(filename); if (e->key) g_free(e->key); e->key = g_strdup(key); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); editor_load_note(e, NULL, NULL); return 1; break; case BOOK_EDITOR: if (!e->bookeditor) break; if (editor_is_dirty(e)) _save_book(e); if (e->module) g_free(e->module); e->module = g_strdup(filename); if (e->key) g_free(e->key); e->key = g_strdup(key); gtk_widget_show(e->window); gdk_window_raise(gtk_widget_get_parent_window(GTK_WIDGET(e->window))); main_load_book_tree_in_editor(GTK_TREE_VIEW(e->treeview), e->module); editor_load_book(e); return 1; break; } tmp = g_list_next(tmp); } XI_message(("filename %s, key %s", (filename ? filename : "-null-"), (key ? key : "-null-"))); return _create_new(filename, key, editor_type); }
static gint _create_new(const gchar *filename, const gchar *key, gint editor_type) { EDITOR *editor; GtkWidget *vbox = NULL; GtkWidget *toolbar_nav = NULL; editor = g_new(EDITOR, 1); editor->html_widget = NULL; editor->sync = FALSE; editor->type = editor_type; switch (editor_type) { case STUDYPAD_EDITOR: editor->studypad = TRUE; editor->bookeditor = FALSE; editor->noteeditor = FALSE; editor->module = NULL; editor->key = NULL; editor->filename = NULL; widgets.studypad_dialog = editor_new(_("StudyPad"), editor); if (filename) { editor->filename = g_strdup(filename); _load_file(editor, g_strdup(filename)); } break; case NOTE_EDITOR: editor->noteeditor = TRUE; editor->bookeditor = FALSE; editor->studypad = FALSE; editor->filename = NULL; editor->module = g_strdup(filename); editor->key = g_strdup(key); editor->navbar.key = NULL; editor_new(_("Note Editor"), editor); vbox = GTKHTML_EDITOR(editor->window)->vbox; toolbar_nav = gui_navbar_versekey_editor_new(editor); gtk_widget_show(toolbar_nav); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(toolbar_nav), FALSE, TRUE, 0); gtk_box_reorder_child(GTK_BOX(vbox), GTK_WIDGET(toolbar_nav), 1); editor_load_note(editor, NULL, NULL); break; case BOOK_EDITOR: editor->bookeditor = TRUE; editor->noteeditor = FALSE; editor->studypad = FALSE; editor->filename = NULL; editor->module = g_strdup(filename); editor->key = g_strdup(key); editor_new(_("Prayer List/Journal Editor"), editor); GtkWidget *box; UI_VBOX(box, TRUE, 0); gtk_widget_show(box); GtkWidget *hpaned1 = UI_HPANE(); gtk_widget_show(hpaned1); gtk_paned_pack2(GTK_PANED(hpaned1), box, TRUE, TRUE); GtkWidget *scrollbar = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrollbar); gtk_paned_pack1(GTK_PANED(hpaned1), GTK_WIDGET(scrollbar), TRUE, TRUE); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type((GtkScrolledWindow *) scrollbar, settings.shadow_type); editor->treeview = gui_create_editor_tree(editor); gtk_widget_show(editor->treeview); gtk_container_add(GTK_CONTAINER(scrollbar), editor->treeview); gtk_paned_set_position(GTK_PANED(hpaned1), 125); gtk_tree_view_collapse_all((GtkTreeView *) editor->treeview); // then we should expand on the item to which we've opened for edit. vbox = GTKHTML_EDITOR(editor->window)->vbox; gtk_widget_reparent(vbox, box); gtk_container_add(GTK_CONTAINER(editor->window), hpaned1); editor_load_book(editor); break; } editor->is_changed = FALSE; editors_all = g_list_append(editors_all, (EDITOR *)editor); return 1; }
int luas_load_file(luas_state* s, const char* file) { return _load_file(file, s); }