/** * @brief load plugin's configuration or set default values * @param void * @return void * */ static void load_configuration(void) { GKeyFile *config = NULL; gchar *config_filename = NULL; gchar **impl_list = NULL, **head_list = NULL; gsize head_list_len, impl_list_len; gsize i; /* Load user configuration */ config = g_key_file_new(); config_filename = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S, "codenav", G_DIR_SEPARATOR_S, "codenav.conf", NULL); gboolean is_configured = g_key_file_load_from_file(config, config_filename, G_KEY_FILE_NONE, NULL); if ( is_configured ) { log_debug("Loading user configuration"); impl_list = g_key_file_get_string_list(config, "switch_head_impl", "implementations_list", &impl_list_len, NULL); head_list = g_key_file_get_string_list(config, "switch_head_impl", "headers_list", &head_list_len, NULL); // Wrong lists if ( head_list_len != impl_list_len ) { dialogs_show_msgbox(GTK_MESSAGE_WARNING, _("Codenav head/impl lists should have been same length. " \ "Geany will use the default configuration.")); fill_default_languages_list(); } else fill_languages_list((const gchar**) impl_list, (const gchar**) head_list, head_list_len); } else { log_debug("Fresh configuration"); fill_default_languages_list(); } /* Freeing memory */ g_key_file_free(config); g_free(config_filename); if ( impl_list != NULL ) { for ( i = 0; i < impl_list_len; i++ ) g_free(impl_list[i]); g_free(impl_list); } if ( head_list != NULL ) { for ( i = 0; i < head_list_len; i++ ) g_free(head_list[i]); g_free(head_list); } }
/* --------------------------------------------------------------------- * Initialization * --------------------------------------------------------------------- */ void switch_head_impl_init() { log_func(); GtkWidget* edit_menu = ui_lookup_widget(geany->main_widgets->window, "edit1_menu"); /* Add the menu item and make it sensitive only when a document is opened */ menu_item = gtk_menu_item_new_with_mnemonic(_("Switch header/implementation")); gtk_widget_show(menu_item); gtk_container_add(GTK_CONTAINER(edit_menu), menu_item); ui_add_document_sensitive(menu_item); /* Callback connection */ g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(menu_item_activate), NULL); /* Initialize the key binding : */ keybindings_set_item( plugin_key_group, KEY_ID_SWITCH_HEAD_IMPL, (GeanyKeyCallback)(&menu_item_activate), GDK_s, GDK_MOD1_MASK | GDK_SHIFT_MASK, "switch_head_impl", _("Switch header/implementation"), /* used in the Preferences dialog */ menu_item); /* TODO : we should use the languages specified by the user or the default list */ fill_default_languages_list(); }
/** * @brief Callback for reset to default languages in the configuration dialog * @param button the button, not used here * @param data null * * @return void * */ static void on_configure_reset_to_default(GtkWidget* button, gpointer data) { GSList *iter_lang; GtkWidget* dialog_new; /* ask to user if he's sure */ dialog_new = gtk_message_dialog_new(GTK_WINDOW(geany_data->main_widgets->window), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK_CANCEL, _("Are you sure you want to delete all languages " \ "and restore defaults?\nThis action cannot be undone.")); gtk_window_set_title(GTK_WINDOW(dialog_new), "Geany"); if(gtk_dialog_run(GTK_DIALOG(dialog_new)) == GTK_RESPONSE_OK) { /* OK, reset! */ fill_default_languages_list(); /* clear and refill the GtkListStore with default extensions */ gtk_list_store_clear(list_store); for(iter_lang = switch_head_impl_get_languages(); iter_lang != NULL ; iter_lang = iter_lang->next) add_language(list_store, (Language*)(iter_lang->data)); } gtk_widget_destroy(dialog_new); }