/* * inits markers staff */ void markers_init(void) { /* set markers in all currently opened documents */ guint i; foreach_document(i) markers_set_for_document(document_index(i)->editor->sci); }
static PyObject* Document_get_from_index(PyObject *self, PyObject *args, PyObject *kwargs) { gint idx; GeanyDocument *doc; static gchar *kwlist[] = { "index", NULL }; if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &idx)) { doc = document_index(idx); if (DOC_VALID(doc)) return (PyObject *) Document_create_new_from_geany_document(doc); } Py_RETURN_NONE; }
/* --------------------------------------------------------------------- * Callback when the menu item is clicked. * --------------------------------------------------------------------- */ static void menu_item_activate(guint key_id) { GeanyDocument* current_doc = document_get_current(); GeanyDocument* new_doc = NULL; guint nb_documents = geany->documents_array->len; gchar* extension = NULL; /* e.g. : "hpp" */ GSList* p_extensions_to_test = NULL; /* e.g. : ["cpp", "cxx", ...] */ GSList* filenames_to_test = NULL; /* e.g. : ["f.cpp", "f.cxx", ...] */ GSList* iter_lang = NULL; GSList* iter_ext = NULL; GSList* iter_filename = NULL; gint i=0; gchar* dirname = NULL; gchar* basename = NULL; gchar* basename_no_extension = NULL; gchar* p_str = NULL; /* Local variables, used as temporary buffers */ gchar* p_str2 = NULL; log_func(); log_debug("current_doc->file_name == %s", current_doc->file_name); log_debug("geany->documents_array->len == %d", geany->documents_array->len); if(current_doc != NULL && current_doc->file_name != NULL && current_doc->file_name[0] != '\0') { /* Get the basename, e.g. : "/home/me/file.cpp" -> "file.cpp" */ basename = g_path_get_basename(current_doc->file_name); if(g_utf8_strlen(basename, -1) < 2) goto free_mem; log_debug("basename == %s", basename); /* Get the extension , e.g. : "cpp" */ extension = get_extension(basename); if(extension == NULL || g_utf8_strlen(extension, -1) == 0) goto free_mem; log_debug("extension == %s", extension); /* Get the basename without any extension */ basename_no_extension = copy_and_remove_extension(basename); if(basename_no_extension == NULL || g_utf8_strlen(basename_no_extension, -1) == 0) goto free_mem; /* Identify the language and whether the file is a header or an implementation. */ /* For each recognized language : */ for(iter_lang = languages ; iter_lang != NULL ; iter_lang = iter_lang->next) { Language* lang = (Language*)(iter_lang->data); /* Test the headers : */ if(g_slist_find_custom(lang->head_extensions, extension, (GCompareFunc)(&compare_strings)) != NULL) { p_extensions_to_test = lang->impl_extensions; break; } /* Test the implementations : */ else if(g_slist_find_custom(lang->impl_extensions, extension, (GCompareFunc)(&compare_strings)) != NULL) { p_extensions_to_test = lang->head_extensions; break; } } if(p_extensions_to_test == NULL) goto free_mem; #ifdef CODE_NAVIGATION_DEBUG log_debug("extension known !"); log_debug("p_extensions_to_test : "); g_slist_foreach(p_extensions_to_test, (GFunc)(&log_debug), NULL); #endif /* Build a list of filenames to test : */ filenames_to_test = NULL; for(iter_ext = p_extensions_to_test ; iter_ext != NULL ; iter_ext = iter_ext->next) { p_str = g_strdup_printf("%s.%s", basename_no_extension, (const gchar*)(iter_ext->data)); filenames_to_test = g_slist_prepend(filenames_to_test, p_str); } filenames_to_test = g_slist_reverse(filenames_to_test); #ifdef CODE_NAVIGATION_DEBUG log_debug("filenames to test :"); g_slist_foreach(filenames_to_test, (GFunc)(&log_debug), NULL); #endif /* First : look for a corresponding file in the opened files. * If found, open it. */ for(i=0 ; i < nb_documents ; i++) { new_doc = document_index(i); for(iter_filename = filenames_to_test ; iter_filename != NULL ; iter_filename = iter_filename->next) { p_str = g_path_get_basename(new_doc->file_name); log_debug("comparing \"%s\" and \"%s\"", (const gchar*)(iter_filename->data), p_str); if(utils_str_equal((const gchar*)(iter_filename->data), p_str)) { log_debug("FOUND !"); g_free(p_str); p_str = g_locale_from_utf8(new_doc->file_name, -1, NULL, NULL, NULL); document_open_file(p_str, FALSE, NULL, NULL); g_free(p_str); goto free_mem; } g_free(p_str); } } /* Second : if not found, look for a corresponding file in the same directory. * If found, open it. */ /* -> compute dirname */ dirname = g_path_get_dirname(current_doc->real_path); if(dirname == NULL) goto free_mem; log_debug("dirname == \"%s\"", dirname); /* -> try all the extensions we should test */ for(iter_ext = p_extensions_to_test ; iter_ext != NULL ; iter_ext = iter_ext->next) { p_str = g_strdup_printf( "%s" G_DIR_SEPARATOR_S "%s.%s", dirname, basename_no_extension, (const gchar*)(iter_ext->data)); p_str2 = g_locale_from_utf8(p_str, -1, NULL, NULL, NULL); g_free(p_str); log_debug("trying to open the file \"%s\"\n", p_str2); /* Try without read-only and in read-only mode */ if( document_open_file(p_str2, FALSE, NULL, NULL) != NULL || document_open_file(p_str2, TRUE, NULL, NULL) != NULL) { g_free(p_str2); goto free_mem; } g_free(p_str2); } /* Third : if not found, ask the user if he wants to create it or not. */ { p_str = g_strdup_printf("%s.%s", basename_no_extension, (const gchar*)(p_extensions_to_test->data)); GtkWidget* dialog = gtk_message_dialog_new( GTK_WINDOW(geany_data->main_widgets->window), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, _("%s not found, create it?"), p_str); gtk_window_set_title(GTK_WINDOW(dialog), "Geany"); if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { p_str2 = g_strdup_printf( "%s" G_DIR_SEPARATOR_S "%s", dirname, p_str); document_new_file(p_str2, current_doc->file_type, NULL); document_set_text_changed(document_get_current(), TRUE); g_free(p_str2); } log_debug("DESTROY"); gtk_widget_destroy(dialog); g_free(p_str); } /* Free the memory */ free_mem: g_slist_foreach(filenames_to_test, (GFunc)(&g_free), NULL); g_free(dirname); g_free(basename_no_extension); g_free(extension); g_free(basename); } }
static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { GSList *header_patterns, *source_patterns; GeanyDocument *doc; gboolean known_type = TRUE; gboolean is_header; gchar *doc_basename; doc = document_get_current(); if (!g_prj || !geany_data->app->project || !doc || !doc->file_name) return; header_patterns = get_precompiled_patterns(g_prj->header_patterns); source_patterns = get_precompiled_patterns(g_prj->source_patterns); doc_basename = g_path_get_basename(doc->file_name); if (patterns_match(header_patterns, doc_basename)) is_header = TRUE; else if (patterns_match(source_patterns, doc_basename)) is_header = FALSE; else known_type = FALSE; if (known_type) { gboolean swapped; GSList *elem, *list = NULL; gint i; foreach_document(i) { gchar *filename; filename = document_index(i)->file_name; if (gprj_project_is_in_project(filename)) list = g_slist_prepend(list, filename); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); list = NULL; if (!swapped) { gchar *doc_dir; doc_dir = g_path_get_dirname(doc->file_name); setptr(doc_dir, utils_get_locale_from_utf8(doc_dir)); list = utils_get_file_list(doc_dir, NULL, NULL); for (elem = list; elem != NULL; elem = g_slist_next(elem)) { gchar *full_name; full_name = g_build_filename(doc_dir, elem->data, NULL); setptr(full_name, utils_get_utf8_from_locale(full_name)); setptr(elem->data, full_name); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_foreach(list, (GFunc) g_free, NULL); g_slist_free(list); g_free(doc_dir); list = NULL; } if (!swapped) { g_hash_table_foreach(g_prj->file_tag_table, (GHFunc) get_project_file_list, &list); try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); } } g_free(doc_basename); g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(header_patterns); g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(source_patterns); }
/* Called by Geany to initialize the plugin. * Note: data is the same as geany_data. */ void plugin_init(GeanyData *data) { GtkWidget* vbox; int i; plugin_module_make_resident(geany_plugin); keys_init(); pixbufs_init(); /* main box */ hbox = gtk_hbox_new(FALSE, 7); gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); /* add target page */ tpage_init(); /* init brekpoints */ breaks_init(editor_open_position); /* init markers */ markers_init(); /* init debug */ debug_init(); /* load config */ config_init(); /* init paned */ dpaned_init(); tpage_pack_widgets(config_get_tabbed()); vbox = btnpanel_create(on_paned_mode_changed); gtk_box_pack_start(GTK_BOX(hbox), dpaned_get_paned(), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); gtk_widget_show_all(hbox); gtk_notebook_append_page( GTK_NOTEBOOK(geany->main_widgets->message_window_notebook), hbox, gtk_label_new(_("Debug"))); if (geany_data->app->project) { config_update_project_keyfile(); } config_set_debug_store( config_get_save_to_project() && geany_data->app->project ? DEBUG_STORE_PROJECT : DEBUG_STORE_PLUGIN ); /* set calltips for all currently opened documents */ foreach_document(i) { scintilla_send_message(document_index(i)->editor->sci, SCI_SETMOUSEDWELLTIME, 500, 0); scintilla_send_message(document_index(i)->editor->sci, SCI_CALLTIPUSESTYLE, 20, (long)NULL); } }