void bmark_add(Tbfwin * bfwin) { GtkTextMark *im; GtkTextIter it; gint offset; /* check for unnamed document */ if (!DOCUMENT(bfwin->current_document)->filename) { error_dialog(bfwin->main_window, _("Add bookmark"), _("Cannot add bookmarks in unnamed files.")); /*\nPlease save the file first. A Save button in this dialog would be cool -- Alastair*/ return; } /* if the left panel is disabled, we simply should add the bookmark to the list, and do nothing else */ /* if (bfwin->bmark == NULL) { DEBUG_MSG("no left panel, this is not implemented yet\n"); } else */ { gboolean has_mark; im = gtk_text_buffer_get_insert(DOCUMENT(bfwin->current_document)->buffer); gtk_text_buffer_get_iter_at_mark(DOCUMENT(bfwin->current_document)->buffer, &it, im); offset = gtk_text_iter_get_offset(&it); /* check for existing bookmark in this place */ has_mark = (bmark_get_bmark_at_line(DOCUMENT(bfwin->current_document), offset) != NULL); if (has_mark) { info_dialog(bfwin->main_window, _("Add bookmark"), _("You already have a bookmark here!")); {/* delete bookmark stuff */ } return; } bmark_add_current_doc_backend(bfwin, "", offset, !main_v->props.bookmarks_default_store); } }
static void document_manager_close_document_cb (DocumentManager *docmg, Documentable *doc, gpointer user_data) { MainWindow *main_window = (MainWindow *) user_data; close_page(main_window, DOCUMENT(doc)); update_app_title(main_window, document_manager_get_current_documentable(docmg)); gchar *filename = documentable_get_filename (doc); gint ftype; g_object_get(doc, "type", &ftype, NULL); symbol_manager_purge_file (main_window->symbolmg, filename, ftype); g_free(filename); }
/* this function will load the bookmarks * from bfwin->session->bmarks and parse * them into treestore bfwin->bookmarkstore * * this function should ALSO check all dcouments that are * opened (bfwin->documentlist) if they have bookmarks !! */ void bmark_reload(Tbfwin * bfwin) { GList *tmplist = g_list_first(bfwin->session->bmarks); DEBUG_MSG("bmark_reload for bfwin %p\n",bfwin); if (bfwin->bmark_files != NULL) g_hash_table_destroy(bfwin->bmark_files); bfwin->bmark_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); while (tmplist) { gchar **items = (gchar **) tmplist->data; if (items && count_array(items) == 6) { gchar *ptr; Tbmark *b; b = g_new0(Tbmark, 1); b->name = g_strdup(items[0]); b->description = g_strdup(items[1]); b->filepath = g_strdup(items[2]); b->offset = atoi(items[3]); b->text = g_strdup(items[4]); b->len = atoi(items[5]); b->strarr = items; bmark_get_iter_at_tree_position(bfwin, b); if (b->name && strlen(b->name)>0) { ptr = g_strconcat(b->name, " - ", b->text, NULL); } else { ptr = g_strdup(b->text); } gtk_tree_store_set(bfwin->bookmarkstore, &(b->iter), NAME_COLUMN, ptr, PTR_COLUMN, b, -1); g_free(ptr); } tmplist = g_list_next(tmplist); } tmplist = g_list_first(bfwin->documentlist); while (tmplist) { DEBUG_MSG("bmark_reload, calling bmark_set_for_doc for doc=%p\n",tmplist->data); bmark_set_for_doc(DOCUMENT(tmplist->data)); bmark_check_length(bfwin, DOCUMENT(tmplist->data)); tmplist = g_list_next(tmplist); } }
/* TODO: can we make this function faster? when adding bookmarks from a search this function uses a lot of time, perhaps that can be improved */ static Tbmark *bmark_get_bmark_at_line(Tdocument *doc, gint offset) { GtkTextIter sit, eit; GtkTreeIter tmpiter; gint linenum; gtk_text_buffer_get_iter_at_offset(doc->buffer,&sit,offset); linenum = gtk_text_iter_get_line(&sit); eit = sit; gtk_text_iter_set_line_offset(&sit, 0); gtk_text_iter_forward_to_line_end(&eit); #ifdef DEBUG { gchar *tmp = gtk_text_buffer_get_text(doc->buffer, &sit,&eit,FALSE); DEBUG_MSG("bmark_get_bmark_at_line, searching bookmarks at line %d between offsets %d - %d --> '%s'\n",linenum,gtk_text_iter_get_offset(&sit),gtk_text_iter_get_offset(&eit),tmp); g_free(tmp); } #endif /* check for existing bookmark in this place */ if (DOCUMENT(doc)->bmark_parent) { GtkTextIter testit; Tbmark *m, *m2; m = bmark_find_bookmark_before_offset(BFWIN(doc->bfwin), offset, doc->bmark_parent); if (m == NULL) { DEBUG_MSG("bmark_get_bmark_at_line, m=NULL, get first child\n"); if (gtk_tree_model_iter_children(GTK_TREE_MODEL(BFWIN(doc->bfwin)->bookmarkstore), &tmpiter,doc->bmark_parent)) { gtk_tree_model_get(GTK_TREE_MODEL(BFWIN(doc->bfwin)->bookmarkstore), &tmpiter, PTR_COLUMN, &m2, -1); gtk_text_buffer_get_iter_at_mark(doc->buffer, &testit,m2->mark); if (gtk_text_iter_get_line(&testit) == linenum) { return m2; } } } else { gtk_text_buffer_get_iter_at_mark(doc->buffer, &testit,m->mark); DEBUG_MSG("bmark_get_bmark_at_line, m=%p, has linenum=%d\n",m,gtk_text_iter_get_line(&testit)); if (gtk_text_iter_get_line(&testit) == linenum) { return m; } tmpiter = m->iter; if (gtk_tree_model_iter_next(GTK_TREE_MODEL(BFWIN(doc->bfwin)->bookmarkstore),&tmpiter)) { gtk_tree_model_get(GTK_TREE_MODEL(BFWIN(doc->bfwin)->bookmarkstore), &tmpiter, PTR_COLUMN, &m2, -1); gtk_text_buffer_get_iter_at_mark(doc->buffer, &testit,m2->mark); if (gtk_text_iter_get_line(&testit) == linenum) { return m2; } } } DEBUG_MSG("bmark_get_bmark_at_line, nothing found at this line, return NULL\n"); return NULL; } DEBUG_MSG("bmark_get_bmark_at_line, no existing bookmark found, return NULL\n"); return NULL; }
gboolean document_manager_set_current_document_from_position(DocumentManager *docmg, gint page_num) { gphpedit_debug(DEBUG_DOC_MANAGER); if (!docmg) return FALSE; DocumentManagerDetails *docmgdet = DOCUMENT_MANAGER_GET_PRIVATE(docmg); Document *new_current_editor; new_current_editor = DOCUMENT(g_slist_nth_data(docmgdet->editors, page_num)); if (new_current_editor){ _document_manager_set_current_document(docmg, new_current_editor); return TRUE; } return FALSE; }
gboolean document_manager_set_current_document_from_widget (DocumentManager *docmg, GtkWidget *child) { gphpedit_debug(DEBUG_DOC_MANAGER); if (!docmg) return FALSE; Document *data = DOCUMENT(document_manager_find_documentable_from_widget (docmg, (void *) child)); if (data){ _document_manager_set_current_document(docmg, data); gtk_widget_grab_focus(child); } else { return FALSE; } return TRUE; }
/* this function will add a bookmark to the current document at current cursor / selection */ static void bmark_add_current_doc_backend(Tbfwin *bfwin, const gchar *name, gint offset, gboolean is_temp) { GtkTextIter it, eit, sit; DEBUG_MSG("bmark_add_backend, adding bookmark at offset=%d for bfwin=%p\n",offset,bfwin); /* create bookmark */ gtk_text_buffer_get_iter_at_offset(DOCUMENT(bfwin->current_document)->buffer,&it,offset); /* if there is a selection, and the offset is within the selection, we'll use it as text content */ if (gtk_text_buffer_get_selection_bounds(DOCUMENT(bfwin->current_document)->buffer,&sit,&eit) && gtk_text_iter_in_range(&it,&sit,&eit)) { gchar *text = gtk_text_iter_get_text(&sit, &eit); bmark_add_backend(DOCUMENT(bfwin->current_document), &sit, offset, name, text, is_temp); g_free(text); } else { gchar *text; text = bmark_text_for_offset(DOCUMENT(bfwin->current_document), &it, offset); bmark_add_backend(DOCUMENT(bfwin->current_document), &it, offset, name, text, is_temp); g_free(text); } if (bfwin->bmark) { /* only if there is a left panel we should do this */ gtk_tree_view_expand_all(bfwin->bmark); gtk_widget_grab_focus(bfwin->current_document->view); } }
void jsbeautify_dialog(Tbfwin * bfwin) { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *dialog, *grid, *hbox, *inselection, *usetabs, *tabsize, *nopreservenewline, *jslinthappy, *unescape_encoded_chars; #else GtkWidget *dialog, *table, *inselection, *usetabs, *tabsize, *nopreservenewline, *jslinthappy, *unescape_encoded_chars; #endif gint result, begin, end; gchar *command; dialog = gtk_dialog_new_with_buttons(_("Javascript Beautify"), GTK_WINDOW(bfwin->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); #if GTK_CHECK_VERSION(3,0,0) grid = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(grid), 12); gtk_grid_set_row_spacing(GTK_GRID(grid), 6); gtk_container_set_border_width(GTK_CONTAINER(grid), 6); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), grid, FALSE, FALSE, 0); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); tabsize = dialog_spin_button_labeled(1, 99, 3, _("_Indent size:"), hbox, 12); gtk_container_add(GTK_CONTAINER(grid), hbox); usetabs = dialog_check_button_new(_("Use _tabs to indent, not spaces"), TRUE); gtk_grid_attach_next_to(GTK_GRID(grid), usetabs, hbox, GTK_POS_BOTTOM, 1, 1); nopreservenewline = dialog_check_button_new(_("Do not _preserve existing line breaks"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), nopreservenewline, usetabs, GTK_POS_BOTTOM, 1, 1); jslinthappy = dialog_check_button_new(_("More _jslint-compatible output"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), jslinthappy, nopreservenewline, GTK_POS_BOTTOM, 1, 1); unescape_encoded_chars = dialog_check_button_new(_("_Decode printable chars encoded in \\\\xNN notation"), FALSE); gtk_grid_attach_next_to(GTK_GRID(grid), unescape_encoded_chars, jslinthappy, GTK_POS_BOTTOM, 1, 1); /* TODO: Is this a bug? Altering the option doesn't change anything */ if (doc_get_selection(DOCUMENT(bfwin->current_document), &begin, &end)) { inselection = dialog_check_button_new(_("Beautify only in _selection"), TRUE); gtk_grid_attach_next_to(GTK_GRID(grid), inselection, unescape_encoded_chars, GTK_POS_BOTTOM, 1, 1); } else { begin = 0; end = -1; } #else table = dialog_table_in_vbox_defaults(3, 2, 6, gtk_dialog_get_content_area(GTK_DIALOG(dialog))); if (doc_get_selection(DOCUMENT(bfwin->current_document), &begin, &end)) { inselection = dialog_check_button_in_table(_("Beautify only in _selection"), TRUE, table, 0, 2, 0, 1); } else { begin = 0; end = -1; } usetabs = dialog_check_button_in_table(_("Use _tabs to indent, not spaces"), TRUE, table, 0, 2, 1, 2); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("_Indent size")), 0, 1, 2, 3); tabsize = dialog_spin_button_in_table(1, 99, 3, table, 1, 2, 2, 3); nopreservenewline = dialog_check_button_in_table(_("Do not _preserve existing line breaks"), FALSE, table, 0, 2, 3, 4); jslinthappy = dialog_check_button_in_table(_("More _jslint-compatible output"), FALSE, table, 0, 2, 4, 5); unescape_encoded_chars = dialog_check_button_in_table(_("_Decode printable chars encoded in \\\\xNN notation"), FALSE, table, 0, 2, 5, 6); #endif /* in selection or all text -s, --indent-size=NUMBER indentation size. (default 4). -c, --indent-char=CHAR character to indent with. (default space). -t, --indent-with-tabs Indent with tabs, overrides -s and -c -d, --disable-preserve-newlines do not preserve existing line breaks. -j, --jslint-happy more jslint-compatible output -b, --brace-style=collapse brace style (collapse, expand, end-expand) -k, --keep-array-indentation keep array indentation. -o, --outfile=FILE specify a file to output to (default stdout) -f, --keep-function-indentation Do not re-indent function bodies defined in var lines. -x, --unescape-strings Decode printable chars encoded in \\xNN notation. */ gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: #ifdef WIN32 command = g_strdup_printf("|python " PKGDATADIR "/jsbeautify %s -s %d %s %s %s -|", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usetabs)) ? "-t" : "", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(tabsize)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nopreservenewline)) ? "-d" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(jslinthappy)) ? "-j" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(unescape_encoded_chars)) ? "-x" : ""); #else command = g_strdup_printf("|" PKGDATADIR "/jsbeautify %s -s %d %s %s %s -|", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usetabs)) ? "-t" : "", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(tabsize)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nopreservenewline)) ? "-d" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(jslinthappy)) ? "-j" : "", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(unescape_encoded_chars)) ? "-x" : ""); #endif filter_command(bfwin, command, begin, end); g_free(command); break; default: break; } gtk_widget_destroy(dialog); }
static void ew_response_lcb(GtkDialog * dialog, gint response, Tentwin * ew) { if (response == GTK_RESPONSE_ACCEPT) { gint start = 0, end = -1; gint scope = gtk_combo_box_get_active(GTK_COMBO_BOX(ew->scope)); if (ew->numerical) ew->eset->convert_num = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->numerical)); ew->eset->convert_iso = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->iso8859_1)); ew->eset->convert_symbol = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->symbol)); ew->eset->convert_special = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->special)); ew->eset->convert_xml = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->xml)); if (ew->IE_apos_workaround) ew->eset->IE_apos_workaround = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->IE_apos_workaround)); if (scope == 0 || (scope == 1 && doc_get_selection(ew->bfwin->current_document, &start, &end))) { doc_unre_new_group_action_id(ew->bfwin->current_document, 0); if (ew->mode == mode_char2ent) { doc_utf8_to_entities(ew->bfwin->current_document, start, end, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->iso8859_1)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->symbol)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->special)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->xml)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->numerical)), ew->eset->IE_apos_workaround); } else { doc_entities_to_utf8(ew->bfwin->current_document, start, end, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->numerical)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->iso8859_1)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->symbol)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->special)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->xml))); } doc_unre_new_group_action_id(ew->bfwin->current_document, 0); } else { /* (scope == 2) */ guint unre_action_id = new_unre_action_id(); GList *tmplist; for (tmplist = g_list_first(ew->bfwin->documentlist); tmplist; tmplist = tmplist->next) { doc_unre_new_group_action_id(DOCUMENT(tmplist->data), unre_action_id); if (ew->mode == mode_char2ent) { doc_utf8_to_entities(DOCUMENT(tmplist->data), 0, -1, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->iso8859_1)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->symbol)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->special)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->xml)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->numerical)), ew->eset->IE_apos_workaround); } else { doc_entities_to_utf8(DOCUMENT(tmplist->data), 0, -1, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->numerical)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->iso8859_1)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->symbol)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->special)), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ew->xml))); } doc_unre_new_group_action_id(DOCUMENT(tmplist->data), 0); } } } gtk_widget_destroy(ew->dialog); g_free(ew); }