plug-ins/dbbrowser/Makefile.am new files holding more common code from the

2004-09-30  Michael Natterer  <mitch@gimp.org>

	* plug-ins/dbbrowser/Makefile.am
	* plug-ins/dbbrowser/gimpprocbox.c: new files holding more common
	code from the two browsers.

	* plug-ins/dbbrowser/gimpprocbrowser.c: use it.

	* plug-ins/dbbrowser/plugin-browser.c: ditto. Re-enabled sorting
	by all columns in both views. More cleanup.
This commit is contained in:
Michael Natterer 2004-09-30 10:57:57 +00:00 committed by Michael Natterer
parent 79fd36cf4a
commit 9ba57069e6
8 changed files with 796 additions and 821 deletions

View File

@ -1,3 +1,14 @@
2004-09-30 Michael Natterer <mitch@gimp.org>
* plug-ins/dbbrowser/Makefile.am
* plug-ins/dbbrowser/gimpprocbox.c: new files holding more common
code from the two browsers.
* plug-ins/dbbrowser/gimpprocbrowser.c: use it.
* plug-ins/dbbrowser/plugin-browser.c: ditto. Re-enabled sorting
by all columns in both views. More cleanup.
2004-09-30 Sven Neumann <sven@gimp.org>
* README: added missing linebreak.
@ -36,7 +47,7 @@
libgimpprocbrowser.a
* plug-ins/script-fu/script-fu-console.c: changed #includes
accordingly. Monir cleanup.
accordingly. Minor cleanup.
* tools/pdbgen/pdb/plug_in.pdb (plugins_query): fixed menu_path
return value. Was broken since the plug-in menu registering

View File

@ -32,8 +32,9 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gimpprocview.h"
#include "gimpprocbox.h"
#include "gimpprocbrowser.h"
#include "gimpprocview.h"
#include "libgimp/stdplugins-intl.h"
@ -59,8 +60,7 @@ typedef struct
GtkWidget *count_label;
GtkWidget *search_entry;
GtkWidget *descr_vbox;
GtkWidget *description;
GtkWidget *proc_box;
GtkListStore *store;
GtkWidget *tv;
@ -229,20 +229,11 @@ gimp_proc_browser_dialog_new (GimpProcBrowserApplyCallback apply_callback)
/* right = description */
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (scrolled_window,
browser->proc_box = gimp_proc_box_new ();
gtk_widget_set_size_request (browser->proc_box,
DBL_WIDTH - DBL_LIST_WIDTH, -1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_paned_pack2 (GTK_PANED (paned), scrolled_window, TRUE, TRUE);
gtk_widget_show (scrolled_window);
browser->descr_vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (browser->descr_vbox), 12);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
browser->descr_vbox);
gtk_widget_show (browser->descr_vbox);
gtk_paned_pack2 (GTK_PANED (paned), browser->proc_box, TRUE, TRUE);
gtk_widget_show (browser->proc_box);
/* now build the list */
@ -250,7 +241,6 @@ gimp_proc_browser_dialog_new (GimpProcBrowserApplyCallback apply_callback)
/* initialize the "return" value (for "apply") */
browser->description = NULL;
browser->proc_name = NULL;
browser->scheme_proc_name = NULL;
browser->proc_blurb = NULL;
@ -306,8 +296,6 @@ static void
browser_show_procedure (GimpDBBrowser *browser,
gchar *proc_name)
{
GtkWidget *vbox;
g_free (browser->proc_name);
browser->proc_name = g_strdup (proc_name);
@ -335,51 +323,19 @@ browser_show_procedure (GimpDBBrowser *browser,
&browser->params,
&browser->return_vals);
vbox = gimp_proc_view_new (browser->scheme_proc_name,
NULL,
browser->proc_blurb,
browser->proc_help,
browser->proc_author,
browser->proc_copyright,
browser->proc_date,
browser->proc_type,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals);
if (browser->description)
gtk_container_remove (GTK_CONTAINER (browser->descr_vbox),
browser->description);
gtk_box_pack_start (GTK_BOX (browser->descr_vbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
browser->description = vbox;
}
static void
dialog_show_message (GimpDBBrowser *browser,
const gchar *message)
{
if (GTK_IS_LABEL (browser->description))
{
gtk_label_set_text (GTK_LABEL (browser->description), message);
}
else
{
if (browser->description)
gtk_container_remove (GTK_CONTAINER (browser->descr_vbox),
browser->description);
browser->description = gtk_label_new (message);
gtk_box_pack_start (GTK_BOX (browser->descr_vbox),
browser->description, FALSE, FALSE, 0);
gtk_widget_show (browser->description);
}
while (gtk_events_pending ())
gtk_main_iteration ();
gimp_proc_box_set_widget (browser->proc_box,
gimp_proc_view_new (browser->scheme_proc_name,
NULL,
browser->proc_blurb,
browser->proc_help,
browser->proc_author,
browser->proc_copyright,
browser->proc_date,
browser->proc_type,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals));
}
static void
@ -422,8 +378,8 @@ browser_response (GtkWidget *widget,
if (response_id == RESPONSE_SEARCH_NAME)
{
dialog_show_message (browser,
_("Searching by name - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching by name - please wait"));
query = g_string_new ("");
query_text = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
@ -446,8 +402,8 @@ browser_response (GtkWidget *widget,
}
else if (response_id == RESPONSE_SEARCH_BLURB)
{
dialog_show_message (browser,
_("Searching by blurb - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching by blurb - please wait"));
gimp_procedural_db_query (".*",
(gchar *) gtk_entry_get_text
@ -457,7 +413,8 @@ browser_response (GtkWidget *widget,
}
else
{
dialog_show_message (browser, _("Searching - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching - please wait"));
gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*",
&num_procs, &proc_list);
@ -493,9 +450,10 @@ browser_response (GtkWidget *widget,
g_free (proc_list);
/* now sort the store */
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->tv));
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (browser->store),
0, GTK_SORT_ASCENDING);
COLUMN_LABEL, GTK_SORT_ASCENDING);
if (num_procs > 0)
{
@ -505,7 +463,7 @@ browser_response (GtkWidget *widget,
}
else
{
dialog_show_message (browser, _("No matches"));
gimp_proc_box_show_message (browser->proc_box, _("No matches"));
}
}
break;

View File

@ -33,6 +33,7 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gimpprocbox.h"
#include "gimpprocview.h"
#include "libgimp/stdplugins-intl.h"
@ -71,10 +72,10 @@ typedef struct
GtkWidget *count_label;
GtkWidget *search_entry;
GtkWidget *descr_scroll;
GtkWidget *info_table;
GtkWidget *proc_box;
gint num_plugins;
} PDesc;
} PluginBrowser;
typedef struct
{
@ -97,21 +98,24 @@ static void run (const gchar *name,
GimpParam **return_vals);
static GtkWidget * gimp_plugin_desc (void);
static GtkWidget * browser_dialog_new (void);
static void browser_dialog_response (GtkWidget *widget,
gint response_id,
PluginBrowser *browser);
static void browser_list_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser);
static void browser_tree_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser);
static void browser_show_plugin (PluginBrowser *browser,
PInfo *pinfo);
static gboolean find_existing_mpath (GtkTreeModel *model,
gchar *mpath,
GtkTreeIter *return_iter);
static void list_store_select_callback (GtkTreeSelection *selection,
PDesc *browser);
static void tree_store_select_callback (GtkTreeSelection *selection,
PDesc *browser);
static void browser_show_plugin (PDesc *browser,
PInfo *pinfo);
static gboolean find_existing_mpath (GtkTreeModel *model,
gchar *mpath,
GtkTreeIter *return_iter);
static PDesc *browser = NULL;
static PluginBrowser *browser = NULL;
GimpPlugInInfo PLUG_IN_INFO =
{
@ -184,214 +188,12 @@ run (const gchar *name,
values[0].data.d_status = GIMP_PDB_SUCCESS;
plugin_dialog = gimp_plugin_desc ();
plugin_dialog = browser_dialog_new ();
gtk_main ();
}
}
static void
browser_show_plugin (PDesc *browser,
PInfo *pinfo)
{
gchar *selected_proc_blurb;
gchar *selected_proc_help;
gchar *selected_proc_author;
gchar *selected_proc_copyright;
gchar *selected_proc_date;
GimpPDBProcType selected_proc_type;
gint selected_nparams;
gint selected_nreturn_vals;
GimpParamDef *selected_params;
GimpParamDef *selected_return_vals;
GtkWidget *old_table;
g_return_if_fail (browser != NULL);
g_return_if_fail (pinfo != NULL);
if (browser->descr_scroll == NULL)
return;
selected_proc_blurb = NULL;
selected_proc_help = NULL;
selected_proc_author = NULL;
selected_proc_copyright = NULL;
selected_proc_date = NULL;
selected_proc_type = 0;
selected_nparams = 0;
selected_nreturn_vals = 0;
selected_params = NULL;
selected_return_vals = NULL;
gimp_procedural_db_proc_info (pinfo->realname,
&selected_proc_blurb,
&selected_proc_help,
&selected_proc_author,
&selected_proc_copyright,
&selected_proc_date,
&selected_proc_type,
&selected_nparams, &selected_nreturn_vals,
&selected_params, &selected_return_vals);
old_table = browser->info_table;
browser->info_table = gimp_proc_view_new (pinfo->realname,
pinfo->menu,
selected_proc_blurb,
selected_proc_help,
selected_proc_author,
selected_proc_copyright,
selected_proc_date,
selected_proc_type,
selected_nparams,
selected_nreturn_vals,
selected_params,
selected_return_vals);
gtk_container_set_border_width (GTK_CONTAINER (browser->info_table), 12);
if (old_table)
gtk_widget_destroy (old_table);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (browser->descr_scroll),
browser->info_table);
gtk_widget_show (browser->info_table);
g_free (selected_proc_blurb);
g_free (selected_proc_help);
g_free (selected_proc_author);
g_free (selected_proc_copyright);
g_free (selected_proc_date);
g_free (selected_params);
g_free (selected_return_vals);
}
static void
list_store_select_callback (GtkTreeSelection *selection,
PDesc *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
LIST_PINFO_COLUMN, &pinfo,
LIST_PATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
model = gtk_tree_view_get_model (browser->tree_view);
if (find_existing_mpath (model, mpath, &iter))
{
GtkTreeSelection *tree_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (browser->tree_view, tree_path);
tree_selection = gtk_tree_view_get_selection (browser->tree_view);
g_signal_handlers_block_by_func (tree_selection,
G_CALLBACK (tree_store_select_callback),
browser);
gtk_tree_selection_select_iter (tree_selection, &iter);
g_signal_handlers_unblock_by_func (tree_selection,
G_CALLBACK (tree_store_select_callback),
browser);
gtk_tree_view_scroll_to_cell (browser->tree_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in tree");
}
g_free (mpath);
browser_show_plugin (browser, pinfo);
}
static void
tree_store_select_callback (GtkTreeSelection *selection,
PDesc *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
gboolean valid, found;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
TREE_PINFO_COLUMN, &pinfo,
TREE_MPATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
/* Get the first iter in the list */
model = gtk_tree_view_get_model (browser->list_view);
valid = gtk_tree_model_get_iter_first (model, &iter);
found = FALSE;
while (valid)
{
/* Walk through the list, reading each row */
gchar *picked_mpath;
gtk_tree_model_get (model, &iter,
LIST_PATH_COLUMN, &picked_mpath,
-1);
if (picked_mpath && !strcmp (mpath, picked_mpath))
{
found = TRUE;
break;
}
g_free (picked_mpath);
valid = gtk_tree_model_iter_next (model, &iter);
}
g_free (mpath);
if (found)
{
GtkTreeSelection *list_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
list_selection = gtk_tree_view_get_selection (browser->list_view);
g_signal_handlers_block_by_func (list_selection,
G_CALLBACK (list_store_select_callback),
browser);
gtk_tree_selection_select_iter (list_selection, &iter);
g_signal_handlers_unblock_by_func (list_selection,
G_CALLBACK (list_store_select_callback),
browser);
gtk_tree_view_scroll_to_cell (browser->list_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in list");
}
browser_show_plugin (browser, pinfo);
}
#if 0
static void
pinfo_free (gpointer p)
@ -473,11 +275,10 @@ find_existing_mpath (GtkTreeModel *model,
gtk_tree_path_free (path);
}
static void
get_parent (PDesc *browser,
gchar *mpath,
GtkTreeIter *parent)
get_parent (PluginBrowser *browser,
gchar *mpath,
GtkTreeIter *parent)
{
GtkTreeIter last_parent;
gchar *tmp_ptr;
@ -524,12 +325,12 @@ get_parent (PDesc *browser,
}
static void
insert_into_tree_view (PDesc *browser,
gchar *name,
gchar *xtimestr,
gchar *menu_str,
gchar *types_str,
PInfo *pinfo)
insert_into_tree_view (PluginBrowser *browser,
gchar *name,
gchar *xtimestr,
gchar *menu_str,
gchar *types_str,
PInfo *pinfo)
{
gchar *labels[3];
gchar *str_ptr;
@ -565,17 +366,17 @@ insert_into_tree_view (PDesc *browser,
tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
gtk_tree_store_append (tree_store, &iter, &parent);
gtk_tree_store_set (tree_store, &iter,
TREE_MPATH_COLUMN, menu_str,
TREE_PATH_NAME_COLUMN, name,
TREE_PINFO_COLUMN, pinfo,
TREE_MPATH_COLUMN, menu_str,
TREE_PATH_NAME_COLUMN, name,
TREE_IMAGE_TYPES_COLUMN, types_str,
TREE_DATE_COLUMN, xtimestr,
TREE_DATE_COLUMN, xtimestr,
TREE_PINFO_COLUMN, pinfo,
-1);
}
static void
get_plugin_info (PDesc *browser,
const gchar *search_text)
get_plugin_info (PluginBrowser *browser,
const gchar *search_text)
{
GimpParam *return_vals;
gint nreturn_vals;
@ -589,9 +390,12 @@ get_plugin_info (PDesc *browser,
GtkTreeStore *tree_store;
GtkTreeIter iter;
if (!search_text)
if (! search_text)
search_text = "";
gimp_proc_box_show_message (browser->proc_box,
_("Searching by name - please wait"));
return_vals = gimp_run_procedure ("gimp_plugins_query",
&nreturn_vals,
GIMP_PDB_STRING, search_text,
@ -682,100 +486,37 @@ get_plugin_info (PDesc *browser,
types_strs[loop],
pinfo);
}
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->list_view));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->tree_view));
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
LIST_NAME_COLUMN,
GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (tree_store),
TREE_PATH_NAME_COLUMN,
GTK_SORT_ASCENDING);
if (browser->num_plugins)
{
GtkTreeSelection *sel =
gtk_tree_view_get_selection (GTK_TREE_VIEW (browser->list_view));
gtk_tree_model_get_iter_root (GTK_TREE_MODEL (list_store),
&iter);
gtk_tree_selection_select_iter (sel, &iter);
}
else
{
gimp_proc_box_show_message (browser->proc_box, _("No matches"));
}
}
gimp_destroy_params (return_vals, nreturn_vals);
}
#if 0
static gint
date_sort (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2)
{
GtkCListRow *row1 = (GtkCListRow *) ptr1;
GtkCListRow *row2 = (GtkCListRow *) ptr2;
/* Get the data for the row */
PInfo *row1_pinfo = row1->data;
PInfo *row2_pinfo = row2->data;
/* Want to sort on the date field */
if (row2_pinfo->instime < row1_pinfo->instime)
{
return -1;
}
if (row2_pinfo->instime > row1_pinfo->instime)
{
return 1;
}
return 0;
}
#endif
#if 0
static void
clist_click_column (GtkCList *clist,
gint column,
gpointer data)
{
if (column == 1)
{
gtk_clist_set_compare_func (clist, date_sort);
}
else
{
gtk_clist_set_compare_func (clist, NULL); /* Set back to default */
}
if (column == clist->sort_column)
{
if (clist->sort_type == GTK_SORT_ASCENDING)
clist->sort_type = GTK_SORT_DESCENDING;
else
clist->sort_type = GTK_SORT_ASCENDING;
}
else
gtk_clist_set_sort_column (clist, column);
gtk_clist_sort (clist);
}
#endif
static void
dialog_response (GtkWidget *widget,
gint response_id,
PDesc *browser)
{
const gchar *search_text = NULL;
switch (response_id)
{
case GTK_RESPONSE_OK:
if (widget != NULL)
{
/* The result of a button press... read entry data */
search_text =
gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
}
get_plugin_info (browser, search_text);
break;
default:
gtk_widget_destroy (browser->dialog);
gtk_main_quit ();
break;
}
}
static GtkWidget *
gimp_plugin_desc (void)
browser_dialog_new (void)
{
GtkWidget *paned;
GtkWidget *hbox, *vbox;
@ -791,7 +532,7 @@ gimp_plugin_desc (void)
gimp_ui_init ("plugindetails", FALSE);
browser = g_new0 (PDesc, 1);
browser = g_new0 (PluginBrowser, 1);
/* the dialog box */
browser->dialog =
@ -805,7 +546,7 @@ gimp_plugin_desc (void)
NULL);
g_signal_connect (browser->dialog, "response",
G_CALLBACK (dialog_response),
G_CALLBACK (browser_dialog_response),
browser);
/* paned : left=notebook ; right=description */
@ -848,25 +589,25 @@ gimp_plugin_desc (void)
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Name"),
renderer,
"text",
LIST_NAME_COLUMN,
"text", LIST_NAME_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_NAME_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Insertion Date"),
renderer,
"text",
LIST_DATE_COLUMN,
"text", LIST_DATE_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_DATE_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Menu Path"),
renderer,
"text",
LIST_PATH_COLUMN,
"text", LIST_PATH_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_PATH_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -875,6 +616,7 @@ gimp_plugin_desc (void)
"text",
LIST_IMAGE_TYPES_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_IMAGE_TYPES_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
swindow = gtk_scrolled_window_new (NULL, NULL);
@ -890,7 +632,7 @@ gimp_plugin_desc (void)
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed",
G_CALLBACK (list_store_select_callback),
G_CALLBACK (browser_list_selection_changed),
browser);
label = gtk_label_new (_("List View"));
@ -918,6 +660,7 @@ gimp_plugin_desc (void)
"text",
TREE_PATH_NAME_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_PATH_NAME_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -926,6 +669,7 @@ gimp_plugin_desc (void)
"text",
TREE_DATE_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_DATE_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -934,6 +678,7 @@ gimp_plugin_desc (void)
"text",
TREE_IMAGE_TYPES_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_IMAGE_TYPES_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
swindow = gtk_scrolled_window_new (NULL, NULL);
@ -948,7 +693,7 @@ gimp_plugin_desc (void)
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed",
G_CALLBACK (tree_store_select_callback),
G_CALLBACK (browser_tree_selection_changed),
browser);
label = gtk_label_new (_("Tree view"));
@ -978,17 +723,14 @@ gimp_plugin_desc (void)
/* right = description */
browser->descr_scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (browser->descr_scroll,
browser->proc_box = gimp_proc_box_new ();
gtk_widget_set_size_request (browser->proc_box,
DBL_WIDTH - DBL_LIST_WIDTH, -1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (browser->descr_scroll),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_paned_pack2 (GTK_PANED (paned), browser->descr_scroll, TRUE, TRUE);
gtk_widget_show (browser->descr_scroll);
gtk_paned_pack2 (GTK_PANED (paned), browser->proc_box, TRUE, TRUE);
gtk_widget_show (browser->proc_box);
/* now build the list */
dialog_response (NULL, GTK_RESPONSE_OK, browser);
browser_dialog_response (NULL, GTK_RESPONSE_OK, browser);
gtk_widget_show (browser->dialog);
@ -1000,3 +742,215 @@ gimp_plugin_desc (void)
return browser->dialog;
}
static void
browser_dialog_response (GtkWidget *widget,
gint response_id,
PluginBrowser *browser)
{
const gchar *search_text = NULL;
switch (response_id)
{
case GTK_RESPONSE_OK:
search_text = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
get_plugin_info (browser, search_text);
break;
default:
gtk_widget_destroy (browser->dialog);
gtk_main_quit ();
break;
}
}
static void
browser_list_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
LIST_PINFO_COLUMN, &pinfo,
LIST_PATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
model = gtk_tree_view_get_model (browser->tree_view);
if (find_existing_mpath (model, mpath, &iter))
{
GtkTreeSelection *tree_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (browser->tree_view, tree_path);
tree_selection = gtk_tree_view_get_selection (browser->tree_view);
g_signal_handlers_block_by_func (tree_selection,
browser_tree_selection_changed,
browser);
gtk_tree_selection_select_iter (tree_selection, &iter);
g_signal_handlers_unblock_by_func (tree_selection,
browser_tree_selection_changed,
browser);
gtk_tree_view_scroll_to_cell (browser->tree_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in tree");
}
g_free (mpath);
browser_show_plugin (browser, pinfo);
}
static void
browser_tree_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
gboolean valid, found;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
TREE_PINFO_COLUMN, &pinfo,
TREE_MPATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
/* Get the first iter in the list */
model = gtk_tree_view_get_model (browser->list_view);
valid = gtk_tree_model_get_iter_first (model, &iter);
found = FALSE;
while (valid)
{
/* Walk through the list, reading each row */
gchar *picked_mpath;
gtk_tree_model_get (model, &iter,
LIST_PATH_COLUMN, &picked_mpath,
-1);
if (picked_mpath && !strcmp (mpath, picked_mpath))
{
found = TRUE;
break;
}
g_free (picked_mpath);
valid = gtk_tree_model_iter_next (model, &iter);
}
g_free (mpath);
if (found)
{
GtkTreeSelection *list_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
list_selection = gtk_tree_view_get_selection (browser->list_view);
g_signal_handlers_block_by_func (list_selection,
browser_list_selection_changed,
browser);
gtk_tree_selection_select_iter (list_selection, &iter);
g_signal_handlers_unblock_by_func (list_selection,
browser_list_selection_changed,
browser);
gtk_tree_view_scroll_to_cell (browser->list_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in list");
}
browser_show_plugin (browser, pinfo);
}
static void
browser_show_plugin (PluginBrowser *browser,
PInfo *pinfo)
{
gchar *selected_proc_blurb;
gchar *selected_proc_help;
gchar *selected_proc_author;
gchar *selected_proc_copyright;
gchar *selected_proc_date;
GimpPDBProcType selected_proc_type;
gint selected_nparams;
gint selected_nreturn_vals;
GimpParamDef *selected_params;
GimpParamDef *selected_return_vals;
g_return_if_fail (browser != NULL);
g_return_if_fail (pinfo != NULL);
selected_proc_blurb = NULL;
selected_proc_help = NULL;
selected_proc_author = NULL;
selected_proc_copyright = NULL;
selected_proc_date = NULL;
selected_proc_type = 0;
selected_nparams = 0;
selected_nreturn_vals = 0;
selected_params = NULL;
selected_return_vals = NULL;
gimp_procedural_db_proc_info (pinfo->realname,
&selected_proc_blurb,
&selected_proc_help,
&selected_proc_author,
&selected_proc_copyright,
&selected_proc_date,
&selected_proc_type,
&selected_nparams, &selected_nreturn_vals,
&selected_params, &selected_return_vals);
gimp_proc_box_set_widget (browser->proc_box,
gimp_proc_view_new (pinfo->realname,
pinfo->menu,
selected_proc_blurb,
selected_proc_help,
selected_proc_author,
selected_proc_copyright,
selected_proc_date,
selected_proc_type,
selected_nparams,
selected_nreturn_vals,
selected_params,
selected_return_vals));
g_free (selected_proc_blurb);
g_free (selected_proc_help);
g_free (selected_proc_author);
g_free (selected_proc_copyright);
g_free (selected_proc_date);
g_free (selected_params);
g_free (selected_return_vals);
}

View File

@ -18,6 +18,8 @@ noinst_LIBRARIES = libgimpprocbrowser.a
libexec_PROGRAMS = plugin-browser procedure-browser
libgimpprocbrowser_a_SOURCES = \
gimpprocbox.c \
gimpprocbox.h \
gimpprocbrowser.c \
gimpprocbrowser.h \
gimpprocview.c \

View File

@ -0,0 +1,107 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "gimpprocbox.h"
#include "libgimp/stdplugins-intl.h"
/* public functions */
GtkWidget *
gimp_proc_box_new (void)
{
GtkWidget *scrolled_window;
GtkWidget *vbox;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
vbox);
gtk_widget_show (vbox);
g_object_set_data (G_OBJECT (scrolled_window), "vbox", vbox);
return scrolled_window;
}
void
gimp_proc_box_set_widget (GtkWidget *proc_box,
GtkWidget *widget)
{
GtkWidget *vbox;
GtkWidget *child;
vbox = g_object_get_data (G_OBJECT (proc_box), "vbox");
g_return_if_fail (GTK_IS_VBOX (vbox));
child = g_object_get_data (G_OBJECT (vbox), "child");
if (child)
gtk_container_remove (GTK_CONTAINER (vbox), child);
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
g_object_set_data (G_OBJECT (vbox), "child", widget);
}
void
gimp_proc_box_show_message (GtkWidget *proc_box,
const gchar *message)
{
GtkWidget *vbox;
GtkWidget *child;
vbox = g_object_get_data (G_OBJECT (proc_box), "vbox");
g_return_if_fail (GTK_IS_VBOX (vbox));
child = g_object_get_data (G_OBJECT (vbox), "child");
if (GTK_IS_LABEL (child))
{
gtk_label_set_text (GTK_LABEL (child), message);
}
else
{
if (child)
gtk_container_remove (GTK_CONTAINER (vbox), child);
child = gtk_label_new (message);
gtk_box_pack_start (GTK_BOX (vbox), child, FALSE, FALSE, 0);
gtk_widget_show (child);
g_object_set_data (G_OBJECT (vbox), "child", child);
}
while (gtk_events_pending ())
gtk_main_iteration ();
}

View File

@ -0,0 +1,31 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_PROC_BOX_H__
#define __GIMP_PROC_BOX_H__
GtkWidget * gimp_proc_box_new (void);
void gimp_proc_box_set_widget (GtkWidget *proc_box,
GtkWidget *widget);
void gimp_proc_box_show_message (GtkWidget *proc_box,
const gchar *message);
#endif /* __GIMP_PROC_BOX_H__ */

View File

@ -32,8 +32,9 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gimpprocview.h"
#include "gimpprocbox.h"
#include "gimpprocbrowser.h"
#include "gimpprocview.h"
#include "libgimp/stdplugins-intl.h"
@ -59,8 +60,7 @@ typedef struct
GtkWidget *count_label;
GtkWidget *search_entry;
GtkWidget *descr_vbox;
GtkWidget *description;
GtkWidget *proc_box;
GtkListStore *store;
GtkWidget *tv;
@ -229,20 +229,11 @@ gimp_proc_browser_dialog_new (GimpProcBrowserApplyCallback apply_callback)
/* right = description */
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (scrolled_window,
browser->proc_box = gimp_proc_box_new ();
gtk_widget_set_size_request (browser->proc_box,
DBL_WIDTH - DBL_LIST_WIDTH, -1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_paned_pack2 (GTK_PANED (paned), scrolled_window, TRUE, TRUE);
gtk_widget_show (scrolled_window);
browser->descr_vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (browser->descr_vbox), 12);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
browser->descr_vbox);
gtk_widget_show (browser->descr_vbox);
gtk_paned_pack2 (GTK_PANED (paned), browser->proc_box, TRUE, TRUE);
gtk_widget_show (browser->proc_box);
/* now build the list */
@ -250,7 +241,6 @@ gimp_proc_browser_dialog_new (GimpProcBrowserApplyCallback apply_callback)
/* initialize the "return" value (for "apply") */
browser->description = NULL;
browser->proc_name = NULL;
browser->scheme_proc_name = NULL;
browser->proc_blurb = NULL;
@ -306,8 +296,6 @@ static void
browser_show_procedure (GimpDBBrowser *browser,
gchar *proc_name)
{
GtkWidget *vbox;
g_free (browser->proc_name);
browser->proc_name = g_strdup (proc_name);
@ -335,51 +323,19 @@ browser_show_procedure (GimpDBBrowser *browser,
&browser->params,
&browser->return_vals);
vbox = gimp_proc_view_new (browser->scheme_proc_name,
NULL,
browser->proc_blurb,
browser->proc_help,
browser->proc_author,
browser->proc_copyright,
browser->proc_date,
browser->proc_type,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals);
if (browser->description)
gtk_container_remove (GTK_CONTAINER (browser->descr_vbox),
browser->description);
gtk_box_pack_start (GTK_BOX (browser->descr_vbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
browser->description = vbox;
}
static void
dialog_show_message (GimpDBBrowser *browser,
const gchar *message)
{
if (GTK_IS_LABEL (browser->description))
{
gtk_label_set_text (GTK_LABEL (browser->description), message);
}
else
{
if (browser->description)
gtk_container_remove (GTK_CONTAINER (browser->descr_vbox),
browser->description);
browser->description = gtk_label_new (message);
gtk_box_pack_start (GTK_BOX (browser->descr_vbox),
browser->description, FALSE, FALSE, 0);
gtk_widget_show (browser->description);
}
while (gtk_events_pending ())
gtk_main_iteration ();
gimp_proc_box_set_widget (browser->proc_box,
gimp_proc_view_new (browser->scheme_proc_name,
NULL,
browser->proc_blurb,
browser->proc_help,
browser->proc_author,
browser->proc_copyright,
browser->proc_date,
browser->proc_type,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals));
}
static void
@ -422,8 +378,8 @@ browser_response (GtkWidget *widget,
if (response_id == RESPONSE_SEARCH_NAME)
{
dialog_show_message (browser,
_("Searching by name - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching by name - please wait"));
query = g_string_new ("");
query_text = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
@ -446,8 +402,8 @@ browser_response (GtkWidget *widget,
}
else if (response_id == RESPONSE_SEARCH_BLURB)
{
dialog_show_message (browser,
_("Searching by blurb - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching by blurb - please wait"));
gimp_procedural_db_query (".*",
(gchar *) gtk_entry_get_text
@ -457,7 +413,8 @@ browser_response (GtkWidget *widget,
}
else
{
dialog_show_message (browser, _("Searching - please wait"));
gimp_proc_box_show_message (browser->proc_box,
_("Searching - please wait"));
gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*",
&num_procs, &proc_list);
@ -493,9 +450,10 @@ browser_response (GtkWidget *widget,
g_free (proc_list);
/* now sort the store */
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->tv));
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (browser->store),
0, GTK_SORT_ASCENDING);
COLUMN_LABEL, GTK_SORT_ASCENDING);
if (num_procs > 0)
{
@ -505,7 +463,7 @@ browser_response (GtkWidget *widget,
}
else
{
dialog_show_message (browser, _("No matches"));
gimp_proc_box_show_message (browser->proc_box, _("No matches"));
}
}
break;

View File

@ -33,6 +33,7 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gimpprocbox.h"
#include "gimpprocview.h"
#include "libgimp/stdplugins-intl.h"
@ -71,10 +72,10 @@ typedef struct
GtkWidget *count_label;
GtkWidget *search_entry;
GtkWidget *descr_scroll;
GtkWidget *info_table;
GtkWidget *proc_box;
gint num_plugins;
} PDesc;
} PluginBrowser;
typedef struct
{
@ -97,21 +98,24 @@ static void run (const gchar *name,
GimpParam **return_vals);
static GtkWidget * gimp_plugin_desc (void);
static GtkWidget * browser_dialog_new (void);
static void browser_dialog_response (GtkWidget *widget,
gint response_id,
PluginBrowser *browser);
static void browser_list_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser);
static void browser_tree_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser);
static void browser_show_plugin (PluginBrowser *browser,
PInfo *pinfo);
static gboolean find_existing_mpath (GtkTreeModel *model,
gchar *mpath,
GtkTreeIter *return_iter);
static void list_store_select_callback (GtkTreeSelection *selection,
PDesc *browser);
static void tree_store_select_callback (GtkTreeSelection *selection,
PDesc *browser);
static void browser_show_plugin (PDesc *browser,
PInfo *pinfo);
static gboolean find_existing_mpath (GtkTreeModel *model,
gchar *mpath,
GtkTreeIter *return_iter);
static PDesc *browser = NULL;
static PluginBrowser *browser = NULL;
GimpPlugInInfo PLUG_IN_INFO =
{
@ -184,214 +188,12 @@ run (const gchar *name,
values[0].data.d_status = GIMP_PDB_SUCCESS;
plugin_dialog = gimp_plugin_desc ();
plugin_dialog = browser_dialog_new ();
gtk_main ();
}
}
static void
browser_show_plugin (PDesc *browser,
PInfo *pinfo)
{
gchar *selected_proc_blurb;
gchar *selected_proc_help;
gchar *selected_proc_author;
gchar *selected_proc_copyright;
gchar *selected_proc_date;
GimpPDBProcType selected_proc_type;
gint selected_nparams;
gint selected_nreturn_vals;
GimpParamDef *selected_params;
GimpParamDef *selected_return_vals;
GtkWidget *old_table;
g_return_if_fail (browser != NULL);
g_return_if_fail (pinfo != NULL);
if (browser->descr_scroll == NULL)
return;
selected_proc_blurb = NULL;
selected_proc_help = NULL;
selected_proc_author = NULL;
selected_proc_copyright = NULL;
selected_proc_date = NULL;
selected_proc_type = 0;
selected_nparams = 0;
selected_nreturn_vals = 0;
selected_params = NULL;
selected_return_vals = NULL;
gimp_procedural_db_proc_info (pinfo->realname,
&selected_proc_blurb,
&selected_proc_help,
&selected_proc_author,
&selected_proc_copyright,
&selected_proc_date,
&selected_proc_type,
&selected_nparams, &selected_nreturn_vals,
&selected_params, &selected_return_vals);
old_table = browser->info_table;
browser->info_table = gimp_proc_view_new (pinfo->realname,
pinfo->menu,
selected_proc_blurb,
selected_proc_help,
selected_proc_author,
selected_proc_copyright,
selected_proc_date,
selected_proc_type,
selected_nparams,
selected_nreturn_vals,
selected_params,
selected_return_vals);
gtk_container_set_border_width (GTK_CONTAINER (browser->info_table), 12);
if (old_table)
gtk_widget_destroy (old_table);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (browser->descr_scroll),
browser->info_table);
gtk_widget_show (browser->info_table);
g_free (selected_proc_blurb);
g_free (selected_proc_help);
g_free (selected_proc_author);
g_free (selected_proc_copyright);
g_free (selected_proc_date);
g_free (selected_params);
g_free (selected_return_vals);
}
static void
list_store_select_callback (GtkTreeSelection *selection,
PDesc *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
LIST_PINFO_COLUMN, &pinfo,
LIST_PATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
model = gtk_tree_view_get_model (browser->tree_view);
if (find_existing_mpath (model, mpath, &iter))
{
GtkTreeSelection *tree_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (browser->tree_view, tree_path);
tree_selection = gtk_tree_view_get_selection (browser->tree_view);
g_signal_handlers_block_by_func (tree_selection,
G_CALLBACK (tree_store_select_callback),
browser);
gtk_tree_selection_select_iter (tree_selection, &iter);
g_signal_handlers_unblock_by_func (tree_selection,
G_CALLBACK (tree_store_select_callback),
browser);
gtk_tree_view_scroll_to_cell (browser->tree_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in tree");
}
g_free (mpath);
browser_show_plugin (browser, pinfo);
}
static void
tree_store_select_callback (GtkTreeSelection *selection,
PDesc *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
gboolean valid, found;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
TREE_PINFO_COLUMN, &pinfo,
TREE_MPATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
/* Get the first iter in the list */
model = gtk_tree_view_get_model (browser->list_view);
valid = gtk_tree_model_get_iter_first (model, &iter);
found = FALSE;
while (valid)
{
/* Walk through the list, reading each row */
gchar *picked_mpath;
gtk_tree_model_get (model, &iter,
LIST_PATH_COLUMN, &picked_mpath,
-1);
if (picked_mpath && !strcmp (mpath, picked_mpath))
{
found = TRUE;
break;
}
g_free (picked_mpath);
valid = gtk_tree_model_iter_next (model, &iter);
}
g_free (mpath);
if (found)
{
GtkTreeSelection *list_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
list_selection = gtk_tree_view_get_selection (browser->list_view);
g_signal_handlers_block_by_func (list_selection,
G_CALLBACK (list_store_select_callback),
browser);
gtk_tree_selection_select_iter (list_selection, &iter);
g_signal_handlers_unblock_by_func (list_selection,
G_CALLBACK (list_store_select_callback),
browser);
gtk_tree_view_scroll_to_cell (browser->list_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in list");
}
browser_show_plugin (browser, pinfo);
}
#if 0
static void
pinfo_free (gpointer p)
@ -473,11 +275,10 @@ find_existing_mpath (GtkTreeModel *model,
gtk_tree_path_free (path);
}
static void
get_parent (PDesc *browser,
gchar *mpath,
GtkTreeIter *parent)
get_parent (PluginBrowser *browser,
gchar *mpath,
GtkTreeIter *parent)
{
GtkTreeIter last_parent;
gchar *tmp_ptr;
@ -524,12 +325,12 @@ get_parent (PDesc *browser,
}
static void
insert_into_tree_view (PDesc *browser,
gchar *name,
gchar *xtimestr,
gchar *menu_str,
gchar *types_str,
PInfo *pinfo)
insert_into_tree_view (PluginBrowser *browser,
gchar *name,
gchar *xtimestr,
gchar *menu_str,
gchar *types_str,
PInfo *pinfo)
{
gchar *labels[3];
gchar *str_ptr;
@ -565,17 +366,17 @@ insert_into_tree_view (PDesc *browser,
tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
gtk_tree_store_append (tree_store, &iter, &parent);
gtk_tree_store_set (tree_store, &iter,
TREE_MPATH_COLUMN, menu_str,
TREE_PATH_NAME_COLUMN, name,
TREE_PINFO_COLUMN, pinfo,
TREE_MPATH_COLUMN, menu_str,
TREE_PATH_NAME_COLUMN, name,
TREE_IMAGE_TYPES_COLUMN, types_str,
TREE_DATE_COLUMN, xtimestr,
TREE_DATE_COLUMN, xtimestr,
TREE_PINFO_COLUMN, pinfo,
-1);
}
static void
get_plugin_info (PDesc *browser,
const gchar *search_text)
get_plugin_info (PluginBrowser *browser,
const gchar *search_text)
{
GimpParam *return_vals;
gint nreturn_vals;
@ -589,9 +390,12 @@ get_plugin_info (PDesc *browser,
GtkTreeStore *tree_store;
GtkTreeIter iter;
if (!search_text)
if (! search_text)
search_text = "";
gimp_proc_box_show_message (browser->proc_box,
_("Searching by name - please wait"));
return_vals = gimp_run_procedure ("gimp_plugins_query",
&nreturn_vals,
GIMP_PDB_STRING, search_text,
@ -682,100 +486,37 @@ get_plugin_info (PDesc *browser,
types_strs[loop],
pinfo);
}
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->list_view));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->tree_view));
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
LIST_NAME_COLUMN,
GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (tree_store),
TREE_PATH_NAME_COLUMN,
GTK_SORT_ASCENDING);
if (browser->num_plugins)
{
GtkTreeSelection *sel =
gtk_tree_view_get_selection (GTK_TREE_VIEW (browser->list_view));
gtk_tree_model_get_iter_root (GTK_TREE_MODEL (list_store),
&iter);
gtk_tree_selection_select_iter (sel, &iter);
}
else
{
gimp_proc_box_show_message (browser->proc_box, _("No matches"));
}
}
gimp_destroy_params (return_vals, nreturn_vals);
}
#if 0
static gint
date_sort (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2)
{
GtkCListRow *row1 = (GtkCListRow *) ptr1;
GtkCListRow *row2 = (GtkCListRow *) ptr2;
/* Get the data for the row */
PInfo *row1_pinfo = row1->data;
PInfo *row2_pinfo = row2->data;
/* Want to sort on the date field */
if (row2_pinfo->instime < row1_pinfo->instime)
{
return -1;
}
if (row2_pinfo->instime > row1_pinfo->instime)
{
return 1;
}
return 0;
}
#endif
#if 0
static void
clist_click_column (GtkCList *clist,
gint column,
gpointer data)
{
if (column == 1)
{
gtk_clist_set_compare_func (clist, date_sort);
}
else
{
gtk_clist_set_compare_func (clist, NULL); /* Set back to default */
}
if (column == clist->sort_column)
{
if (clist->sort_type == GTK_SORT_ASCENDING)
clist->sort_type = GTK_SORT_DESCENDING;
else
clist->sort_type = GTK_SORT_ASCENDING;
}
else
gtk_clist_set_sort_column (clist, column);
gtk_clist_sort (clist);
}
#endif
static void
dialog_response (GtkWidget *widget,
gint response_id,
PDesc *browser)
{
const gchar *search_text = NULL;
switch (response_id)
{
case GTK_RESPONSE_OK:
if (widget != NULL)
{
/* The result of a button press... read entry data */
search_text =
gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
}
get_plugin_info (browser, search_text);
break;
default:
gtk_widget_destroy (browser->dialog);
gtk_main_quit ();
break;
}
}
static GtkWidget *
gimp_plugin_desc (void)
browser_dialog_new (void)
{
GtkWidget *paned;
GtkWidget *hbox, *vbox;
@ -791,7 +532,7 @@ gimp_plugin_desc (void)
gimp_ui_init ("plugindetails", FALSE);
browser = g_new0 (PDesc, 1);
browser = g_new0 (PluginBrowser, 1);
/* the dialog box */
browser->dialog =
@ -805,7 +546,7 @@ gimp_plugin_desc (void)
NULL);
g_signal_connect (browser->dialog, "response",
G_CALLBACK (dialog_response),
G_CALLBACK (browser_dialog_response),
browser);
/* paned : left=notebook ; right=description */
@ -848,25 +589,25 @@ gimp_plugin_desc (void)
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Name"),
renderer,
"text",
LIST_NAME_COLUMN,
"text", LIST_NAME_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_NAME_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Insertion Date"),
renderer,
"text",
LIST_DATE_COLUMN,
"text", LIST_DATE_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_DATE_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Menu Path"),
renderer,
"text",
LIST_PATH_COLUMN,
"text", LIST_PATH_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_PATH_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -875,6 +616,7 @@ gimp_plugin_desc (void)
"text",
LIST_IMAGE_TYPES_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, LIST_IMAGE_TYPES_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
swindow = gtk_scrolled_window_new (NULL, NULL);
@ -890,7 +632,7 @@ gimp_plugin_desc (void)
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed",
G_CALLBACK (list_store_select_callback),
G_CALLBACK (browser_list_selection_changed),
browser);
label = gtk_label_new (_("List View"));
@ -918,6 +660,7 @@ gimp_plugin_desc (void)
"text",
TREE_PATH_NAME_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_PATH_NAME_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -926,6 +669,7 @@ gimp_plugin_desc (void)
"text",
TREE_DATE_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_DATE_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
renderer = gtk_cell_renderer_text_new ();
@ -934,6 +678,7 @@ gimp_plugin_desc (void)
"text",
TREE_IMAGE_TYPES_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, TREE_IMAGE_TYPES_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
swindow = gtk_scrolled_window_new (NULL, NULL);
@ -948,7 +693,7 @@ gimp_plugin_desc (void)
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection, "changed",
G_CALLBACK (tree_store_select_callback),
G_CALLBACK (browser_tree_selection_changed),
browser);
label = gtk_label_new (_("Tree view"));
@ -978,17 +723,14 @@ gimp_plugin_desc (void)
/* right = description */
browser->descr_scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (browser->descr_scroll,
browser->proc_box = gimp_proc_box_new ();
gtk_widget_set_size_request (browser->proc_box,
DBL_WIDTH - DBL_LIST_WIDTH, -1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (browser->descr_scroll),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_paned_pack2 (GTK_PANED (paned), browser->descr_scroll, TRUE, TRUE);
gtk_widget_show (browser->descr_scroll);
gtk_paned_pack2 (GTK_PANED (paned), browser->proc_box, TRUE, TRUE);
gtk_widget_show (browser->proc_box);
/* now build the list */
dialog_response (NULL, GTK_RESPONSE_OK, browser);
browser_dialog_response (NULL, GTK_RESPONSE_OK, browser);
gtk_widget_show (browser->dialog);
@ -1000,3 +742,215 @@ gimp_plugin_desc (void)
return browser->dialog;
}
static void
browser_dialog_response (GtkWidget *widget,
gint response_id,
PluginBrowser *browser)
{
const gchar *search_text = NULL;
switch (response_id)
{
case GTK_RESPONSE_OK:
search_text = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
get_plugin_info (browser, search_text);
break;
default:
gtk_widget_destroy (browser->dialog);
gtk_main_quit ();
break;
}
}
static void
browser_list_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
LIST_PINFO_COLUMN, &pinfo,
LIST_PATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
model = gtk_tree_view_get_model (browser->tree_view);
if (find_existing_mpath (model, mpath, &iter))
{
GtkTreeSelection *tree_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (browser->tree_view, tree_path);
tree_selection = gtk_tree_view_get_selection (browser->tree_view);
g_signal_handlers_block_by_func (tree_selection,
browser_tree_selection_changed,
browser);
gtk_tree_selection_select_iter (tree_selection, &iter);
g_signal_handlers_unblock_by_func (tree_selection,
browser_tree_selection_changed,
browser);
gtk_tree_view_scroll_to_cell (browser->tree_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in tree");
}
g_free (mpath);
browser_show_plugin (browser, pinfo);
}
static void
browser_tree_selection_changed (GtkTreeSelection *selection,
PluginBrowser *browser)
{
PInfo *pinfo = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *mpath = NULL;
gboolean valid, found;
g_return_if_fail (browser != NULL);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
TREE_PINFO_COLUMN, &pinfo,
TREE_MPATH_COLUMN, &mpath,
-1);
}
if (!pinfo || !mpath)
return;
/* Get the first iter in the list */
model = gtk_tree_view_get_model (browser->list_view);
valid = gtk_tree_model_get_iter_first (model, &iter);
found = FALSE;
while (valid)
{
/* Walk through the list, reading each row */
gchar *picked_mpath;
gtk_tree_model_get (model, &iter,
LIST_PATH_COLUMN, &picked_mpath,
-1);
if (picked_mpath && !strcmp (mpath, picked_mpath))
{
found = TRUE;
break;
}
g_free (picked_mpath);
valid = gtk_tree_model_iter_next (model, &iter);
}
g_free (mpath);
if (found)
{
GtkTreeSelection *list_selection;
GtkTreePath *tree_path;
tree_path = gtk_tree_model_get_path (model, &iter);
list_selection = gtk_tree_view_get_selection (browser->list_view);
g_signal_handlers_block_by_func (list_selection,
browser_list_selection_changed,
browser);
gtk_tree_selection_select_iter (list_selection, &iter);
g_signal_handlers_unblock_by_func (list_selection,
browser_list_selection_changed,
browser);
gtk_tree_view_scroll_to_cell (browser->list_view,
tree_path, NULL,
TRUE, 0.5, 0.0);
}
else
{
g_warning ("Failed to find node in list");
}
browser_show_plugin (browser, pinfo);
}
static void
browser_show_plugin (PluginBrowser *browser,
PInfo *pinfo)
{
gchar *selected_proc_blurb;
gchar *selected_proc_help;
gchar *selected_proc_author;
gchar *selected_proc_copyright;
gchar *selected_proc_date;
GimpPDBProcType selected_proc_type;
gint selected_nparams;
gint selected_nreturn_vals;
GimpParamDef *selected_params;
GimpParamDef *selected_return_vals;
g_return_if_fail (browser != NULL);
g_return_if_fail (pinfo != NULL);
selected_proc_blurb = NULL;
selected_proc_help = NULL;
selected_proc_author = NULL;
selected_proc_copyright = NULL;
selected_proc_date = NULL;
selected_proc_type = 0;
selected_nparams = 0;
selected_nreturn_vals = 0;
selected_params = NULL;
selected_return_vals = NULL;
gimp_procedural_db_proc_info (pinfo->realname,
&selected_proc_blurb,
&selected_proc_help,
&selected_proc_author,
&selected_proc_copyright,
&selected_proc_date,
&selected_proc_type,
&selected_nparams, &selected_nreturn_vals,
&selected_params, &selected_return_vals);
gimp_proc_box_set_widget (browser->proc_box,
gimp_proc_view_new (pinfo->realname,
pinfo->menu,
selected_proc_blurb,
selected_proc_help,
selected_proc_author,
selected_proc_copyright,
selected_proc_date,
selected_proc_type,
selected_nparams,
selected_nreturn_vals,
selected_params,
selected_return_vals));
g_free (selected_proc_blurb);
g_free (selected_proc_help);
g_free (selected_proc_author);
g_free (selected_proc_copyright);
g_free (selected_proc_date);
g_free (selected_params);
g_free (selected_return_vals);
}