Add plugin_show_configure() API utility function.

Add File Browser popup menu 'Preferences' item.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4244 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-09-27 14:07:24 +00:00
parent 7b122a3bf8
commit 8c38bdd745
10 changed files with 148 additions and 105 deletions

View File

@ -15,6 +15,11 @@
Make the multiple-configure dialog notebook tabs scrollable.
* src/pluginutils.c, src/pluginutils.h:
Don't build pluginutils.o if HAVE_PLUGINS is not defined.
* src/pluginprivate.h, src/plugindata.h, src/pluginutils.c,
src/plugins.c, src/pluginutils.h, src/plugins.h, po/POTFILES.in,
plugins/geanyfunctions.h, plugins/filebrowser.c:
Add plugin_show_configure() API utility function.
Add File Browser popup menu 'Preferences' item.
2009-09-24 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -546,6 +546,12 @@ static void on_hide_sidebar(void)
}
static void on_show_preferences(void)
{
plugin_show_configure(geany_plugin);
}
static GtkWidget *create_popup_menu(void)
{
GtkWidget *item, *menu;
@ -583,6 +589,15 @@ static GtkWidget *create_popup_menu(void)
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
item = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES, NULL);
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
g_signal_connect(item, "activate", G_CALLBACK(on_show_preferences), NULL);
item = gtk_separator_menu_item_new();
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("H_ide Sidebar"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);

View File

@ -24,6 +24,8 @@
geany_functions->p_plugin->signal_connect
#define plugin_set_key_group \
geany_functions->p_plugin->set_key_group
#define plugin_show_configure \
geany_functions->p_plugin->show_configure
#define document_new_file \
geany_functions->p_document->new_file
#define document_get_current \

View File

@ -23,6 +23,7 @@ src/msgwindow.c
src/navqueue.c
src/notebook.c
src/plugins.c
src/pluginutils.c
src/prefs.c
src/printing.c
src/project.c

View File

@ -50,7 +50,7 @@
enum {
/** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */
GEANY_API_VERSION = 157,
GEANY_API_VERSION = 158,
/** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */
@ -572,6 +572,7 @@ typedef struct PluginFuncs
GCallback callback, gpointer user_data);
struct GeanyKeyGroup* (*set_key_group)(GeanyPlugin *plugin,
const gchar *section_name, gsize count, _GeanyKeyGroupCallback callback);
void (*show_configure)(GeanyPlugin *plugin);
}
PluginFuncs;

View File

@ -59,5 +59,7 @@ typedef struct GeanyPluginPrivate
}
GeanyPluginPrivate;
typedef GeanyPluginPrivate Plugin; /* shorter alias */
#endif /* PLUGINPRIVATE_H */

View File

@ -62,7 +62,8 @@
#include "pluginutils.h"
#include "pluginprivate.h"
typedef GeanyPluginPrivate Plugin; /* shorter alias */
GList *active_plugin_list = NULL; /* list of only actually loaded plugins, always valid */
static gboolean want_plugins = FALSE;
@ -70,7 +71,6 @@ static gboolean want_plugins = FALSE;
/* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
* opened, afterwards it will be destroyed */
static GList *plugin_list = NULL;
static GList *active_plugin_list = NULL; /* list of only actually loaded plugins, always valid */
static gchar **active_plugins_pref = NULL; /* list of plugin filenames to load at startup */
static GList *failed_plugins_list = NULL; /* plugins the user wants active but can't be used */
@ -83,7 +83,8 @@ static PluginFuncs plugin_funcs = {
&plugin_add_toolbar_item,
&plugin_module_make_resident,
&plugin_signal_connect,
&plugin_set_key_group
&plugin_set_key_group,
&plugin_show_configure
};
static DocumentFuncs doc_funcs = {
@ -1140,97 +1141,6 @@ static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
}
static void on_pref_btn_clicked(gpointer btn, Plugin *p)
{
p->configure_single(main_widgets.window);
}
static GtkWidget *create_pref_page(Plugin *p, GtkWidget *dialog)
{
GtkWidget *page = NULL; /* some plugins don't have prefs */
if (p->configure)
{
page = p->configure(GTK_DIALOG(dialog));
if (! GTK_IS_WIDGET(page))
{
geany_debug("Invalid widget returned from plugin_configure() in plugin \"%s\"!",
p->info.name);
return NULL;
}
else
{
GtkWidget *align = gtk_alignment_new(0.5, 0.5, 1, 1);
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 6, 6, 6, 6);
gtk_container_add(GTK_CONTAINER(align), page);
page = align;
}
}
else if (p->configure_single)
{
GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0, 0);
GtkWidget *btn;
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 6, 6, 6, 6);
btn = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
g_signal_connect(btn, "clicked", G_CALLBACK(on_pref_btn_clicked), p);
gtk_container_add(GTK_CONTAINER(align), btn);
page = align;
}
return page;
}
/* multiple plugin configure dialog */
static void configure_plugins(Plugin *current_plugin)
{
GtkWidget *parent = pm_widgets.dialog;
GtkWidget *dialog, *vbox, *nb;
GList *node;
gint cur_page = -1;
dialog = gtk_dialog_new_with_buttons(_("Configure Plugins"),
GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
gtk_widget_set_name(dialog, "GeanyDialog");
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
nb = gtk_notebook_new();
gtk_notebook_set_scrollable(GTK_NOTEBOOK(nb), TRUE);
gtk_container_add(GTK_CONTAINER(vbox), nb);
foreach_list(node, active_plugin_list)
{
Plugin *p = node->data;
GtkWidget *page = create_pref_page(p, dialog);
if (page)
{
GtkWidget *label = gtk_label_new(p->info.name);
gint n = gtk_notebook_append_page(GTK_NOTEBOOK(nb), page, label);
if (p == current_plugin)
cur_page = n;
}
}
if (cur_page >= 0)
{
gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), cur_page);
gtk_widget_show_all(vbox);
/* run the dialog */
while (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY);
}
gtk_widget_destroy(dialog);
}
static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
{
GtkTreeModel *model;
@ -1246,15 +1156,7 @@ static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
if (p != NULL)
{
if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
{
if (p->configure)
configure_plugins(p);
else
{
g_return_if_fail(p->configure_single);
p->configure_single(main_widgets.window);
}
}
plugin_show_configure(&p->public);
else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
p->help();
}

View File

@ -28,6 +28,9 @@
#ifdef HAVE_PLUGINS
extern GList *active_plugin_list;
void plugins_init(void);
void plugins_finalize(void);

View File

@ -36,6 +36,8 @@
#include "ui_utils.h"
#include "toolbar.h"
#include "utils.h"
#include "support.h"
#include "plugins.h"
/** Insert a toolbar item before the Quit button, or after the previous plugin toolbar item.
@ -140,7 +142,7 @@ void plugin_signal_connect(GeanyPlugin *plugin,
GeanyKeyGroup *plugin_set_key_group(GeanyPlugin *plugin,
const gchar *section_name, gsize count, GeanyKeyGroupCallback callback)
{
GeanyPluginPrivate *priv = plugin->priv;
Plugin *priv = plugin->priv;
priv->key_group = keybindings_set_group(priv->key_group, section_name,
priv->info.name, count, callback);
@ -148,4 +150,112 @@ GeanyKeyGroup *plugin_set_key_group(GeanyPlugin *plugin,
}
static void on_pref_btn_clicked(gpointer btn, Plugin *p)
{
p->configure_single(main_widgets.window);
}
static GtkWidget *create_pref_page(Plugin *p, GtkWidget *dialog)
{
GtkWidget *page = NULL; /* some plugins don't have prefs */
if (p->configure)
{
page = p->configure(GTK_DIALOG(dialog));
if (! GTK_IS_WIDGET(page))
{
geany_debug("Invalid widget returned from plugin_configure() in plugin \"%s\"!",
p->info.name);
return NULL;
}
else
{
GtkWidget *align = gtk_alignment_new(0.5, 0.5, 1, 1);
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 6, 6, 6, 6);
gtk_container_add(GTK_CONTAINER(align), page);
page = align;
}
}
else if (p->configure_single)
{
GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0, 0);
GtkWidget *btn;
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 6, 6, 6, 6);
btn = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
g_signal_connect(btn, "clicked", G_CALLBACK(on_pref_btn_clicked), p);
gtk_container_add(GTK_CONTAINER(align), btn);
page = align;
}
return page;
}
/* multiple plugin configure dialog */
static void configure_plugins(Plugin *current_plugin)
{
GtkWidget *dialog, *vbox, *nb;
GList *node;
gint cur_page = -1;
dialog = gtk_dialog_new_with_buttons(_("Configure Plugins"),
GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
gtk_widget_set_name(dialog, "GeanyDialog");
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
nb = gtk_notebook_new();
gtk_notebook_set_scrollable(GTK_NOTEBOOK(nb), TRUE);
gtk_container_add(GTK_CONTAINER(vbox), nb);
foreach_list(node, active_plugin_list)
{
Plugin *p = node->data;
GtkWidget *page = create_pref_page(p, dialog);
if (page)
{
GtkWidget *label = gtk_label_new(p->info.name);
gint n = gtk_notebook_append_page(GTK_NOTEBOOK(nb), page, label);
if (p == current_plugin)
cur_page = n;
}
}
if (cur_page >= 0)
{
gtk_notebook_set_current_page(GTK_NOTEBOOK(nb), cur_page);
gtk_widget_show_all(vbox);
/* run the dialog */
while (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY);
}
gtk_widget_destroy(dialog);
}
/** Show the plugin's configure dialog.
* The plugin must implement one of the plugin_configure() or plugin_configure_single() symbols.
* @param plugin Must be @ref geany_plugin.
* @since 0.19. */
void plugin_show_configure(GeanyPlugin *plugin)
{
Plugin *p = plugin->priv;
if (p->configure)
configure_plugins(p);
else
{
g_return_if_fail(p->configure_single);
p->configure_single(main_widgets.window);
}
}
#endif

View File

@ -43,5 +43,7 @@ void plugin_signal_connect(GeanyPlugin *plugin,
struct GeanyKeyGroup *plugin_set_key_group(GeanyPlugin *plugin,
const gchar *section_name, gsize count, GeanyKeyGroupCallback callback);
void plugin_show_configure(GeanyPlugin *plugin);
#endif /* HAVE_PLUGINS */
#endif /* PLUGINUTILS_H */