plug-ins/dbbrowser/Makefile.am plug-ins/dbbrowser/gimpprocbrowser.[ch]

2005-08-02  Michael Natterer  <mitch@gimp.org>

	* plug-ins/dbbrowser/Makefile.am
	* plug-ins/dbbrowser/gimpprocbrowser.[ch]
	* plug-ins/dbbrowser/gimpprocview.[ch]: removed these files...

	* libgimp/Makefile.am
	* libgimp/gimpui.h
	* libgimp/gimpui.def
	* libgimp/gimpprocbrowserdialog.[ch]
	* libgimp/gimpprocview.[ch]: ...and added them here. Turned the
	procedure browser into a widget called GimpProcBrowserDialog and
	changed its API completely. Fixes bug #165009.

	* plug-ins/dbbrowser/plugin-browser.c
	* plug-ins/dbbrowser/procedure-browser.c
	* plug-ins/script-fu/Makefile.am
	* plug-ins/script-fu/script-fu-console.c: changed accordingly.

	* plug-ins/pygimp/Makefile.am
	* plug-ins/pygimp/procbrowser.c: ditto (#if 0'ed stuff so it compiles).
This commit is contained in:
Michael Natterer
2005-08-02 16:49:42 +00:00
committed by Michael Natterer
parent 4182c8366f
commit 4d369ec2c0
20 changed files with 570 additions and 1323 deletions

View File

@ -28,8 +28,6 @@
#include "siod-wrapper.h"
#include "script-fu-console.h"
#include <plug-ins/dbbrowser/gimpprocbrowser.h>
#define TEXT_WIDTH 480
#define TEXT_HEIGHT 400
@ -39,11 +37,18 @@
typedef struct
{
GtkWidget *dialog;
GtkTextBuffer *console;
GtkWidget *cc;
GtkWidget *text_view;
GtkWidget *proc_browser;
gint32 input_id;
GList *history;
gint history_len;
gint history_cur;
gint history_max;
} ConsoleInterface;
@ -51,15 +56,18 @@ typedef struct
* Local Functions
*/
static void script_fu_console_interface (void);
static void script_fu_response (GtkWidget *widget,
gint response_id,
gpointer data);
static void script_fu_browse_callback (GtkWidget *widget,
gpointer data);
static gboolean script_fu_cc_is_empty (void);
static gboolean script_fu_cc_key_function (GtkWidget *widget,
GdkEventKey *event,
gpointer data);
static void script_fu_response (GtkWidget *widget,
gint response_id,
ConsoleInterface *console);
static void script_fu_browse_callback (GtkWidget *widget,
ConsoleInterface *console);
static void script_fu_browse_response (GtkWidget *widget,
gint response_id,
ConsoleInterface *console);
static gboolean script_fu_cc_is_empty (ConsoleInterface *console);
static gboolean script_fu_cc_key_function (GtkWidget *widget,
GdkEventKey *event,
ConsoleInterface *console);
static void script_fu_open_siod_console (void);
static void script_fu_close_siod_console (void);
@ -70,18 +78,20 @@ static void script_fu_close_siod_console (void);
*/
static ConsoleInterface cint =
{
NULL, /* dialog */
NULL, /* console */
NULL, /* current command */
NULL, /* text view */
NULL, /* proc browser */
-1 /* input id */
-1, /* input id */
NULL,
0,
0,
50
};
static GList *history = NULL;
static gint history_len = 0;
static gint history_cur = 0;
static gint history_max = 50;
/*
* Function definitions
@ -133,34 +143,42 @@ script_fu_console_run (const gchar *name,
static void
script_fu_console_interface (void)
{
GtkWidget *dialog;
GtkWidget *vbox;
GtkWidget *button;
GtkWidget *scrolled_window;
GtkWidget *hbox;
ConsoleInterface *console;
GtkWidget *vbox;
GtkWidget *button;
GtkWidget *scrolled_window;
GtkWidget *hbox;
gimp_ui_init ("script-fu", FALSE);
dialog = gimp_dialog_new (_("Script-Fu Console"), "script-fu-console",
NULL, 0,
gimp_standard_help_func,
"plug-in-script-fu-console",
console = &cint;
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
console->input_id = -1;
console->history = NULL;
console->history_len = 0;
console->history_cur = 0;
console->history_max = 50;
NULL);
console->dialog = gimp_dialog_new (_("Script-Fu Console"), "script-fu-console",
NULL, 0,
gimp_standard_help_func,
"plug-in-script-fu-console",
g_signal_connect (dialog, "response",
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
g_signal_connect (console->dialog, "response",
G_CALLBACK (script_fu_response),
NULL);
g_signal_connect (dialog, "destroy",
console);
g_signal_connect (console->dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&dialog);
&console->dialog);
/* The main vbox */
vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (console->dialog)->vbox), vbox,
TRUE, TRUE, 0);
gtk_widget_show (vbox);
@ -172,26 +190,26 @@ script_fu_console_interface (void)
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (scrolled_window);
cint.console = gtk_text_buffer_new (NULL);
cint.text_view = gtk_text_view_new_with_buffer (cint.console);
g_object_unref (cint.console);
console->console = gtk_text_buffer_new (NULL);
console->text_view = gtk_text_view_new_with_buffer (console->console);
g_object_unref (console->console);
gtk_text_view_set_editable (GTK_TEXT_VIEW (cint.text_view), FALSE);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (cint.text_view), 12);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (cint.text_view), 12);
gtk_widget_set_size_request (cint.text_view, TEXT_WIDTH, TEXT_HEIGHT);
gtk_container_add (GTK_CONTAINER (scrolled_window), cint.text_view);
gtk_widget_show (cint.text_view);
gtk_text_view_set_editable (GTK_TEXT_VIEW (console->text_view), FALSE);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (console->text_view), 12);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (console->text_view), 12);
gtk_widget_set_size_request (console->text_view, TEXT_WIDTH, TEXT_HEIGHT);
gtk_container_add (GTK_CONTAINER (scrolled_window), console->text_view);
gtk_widget_show (console->text_view);
gtk_text_buffer_create_tag (cint.console, "strong",
gtk_text_buffer_create_tag (console->console, "strong",
"weight", PANGO_WEIGHT_BOLD,
"size", 12 * PANGO_SCALE,
NULL);
gtk_text_buffer_create_tag (cint.console, "emphasis",
gtk_text_buffer_create_tag (console->console, "emphasis",
"style", PANGO_STYLE_OBLIQUE,
"size", 10 * PANGO_SCALE,
NULL);
gtk_text_buffer_create_tag (cint.console, "weak",
gtk_text_buffer_create_tag (console->console, "weak",
"size", 10 * PANGO_SCALE,
NULL);
@ -209,11 +227,11 @@ script_fu_console_interface (void)
GtkTextIter cursor;
gint i;
gtk_text_buffer_get_end_iter (cint.console, &cursor);
gtk_text_buffer_get_end_iter (console->console, &cursor);
for (i = 0; greeting_texts[i]; i += 2)
{
gtk_text_buffer_insert_with_tags_by_name (cint.console, &cursor,
gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
greeting_texts[i + 1], -1,
greeting_texts[i],
NULL);
@ -225,14 +243,14 @@ script_fu_console_interface (void)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
cint.cc = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (hbox), cint.cc, TRUE, TRUE, 0);
gtk_widget_grab_focus (cint.cc);
gtk_widget_show (cint.cc);
console->cc = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (hbox), console->cc, TRUE, TRUE, 0);
gtk_widget_grab_focus (console->cc);
gtk_widget_show (console->cc);
g_signal_connect (cint.cc, "key-press-event",
g_signal_connect (console->cc, "key-press-event",
G_CALLBACK (script_fu_cc_key_function),
NULL);
console);
button = gtk_button_new_with_mnemonic (_("_Browse..."));
gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
@ -241,50 +259,94 @@ script_fu_console_interface (void)
g_signal_connect (button, "clicked",
G_CALLBACK (script_fu_browse_callback),
NULL);
console);
/* Initialize the history */
history = g_list_append (history, NULL);
history_len = 1;
console->history = g_list_append (console->history, NULL);
console->history_len = 1;
gtk_widget_show (dialog);
gtk_widget_show (console->dialog);
gtk_main ();
g_source_remove (cint.input_id);
g_source_remove (console->input_id);
if (dialog)
gtk_widget_destroy (dialog);
if (console->dialog)
gtk_widget_destroy (console->dialog);
}
static void
script_fu_response (GtkWidget *widget,
gint response_id,
gpointer data)
script_fu_response (GtkWidget *widget,
gint response_id,
ConsoleInterface *console)
{
gtk_main_quit ();
}
static void
apply_callback (const gchar *proc_name,
const gchar *proc_blurb,
const gchar *proc_help,
const gchar *proc_author,
const gchar *proc_copyright,
const gchar *proc_date,
GimpPDBProcType proc_type,
gint n_params,
gint n_return_vals,
const GimpParamDef *params,
const GimpParamDef *return_vals,
gpointer user_data)
script_fu_browse_callback (GtkWidget *widget,
ConsoleInterface *console)
{
gint i;
GString *text;
if (! console->proc_browser)
{
console->proc_browser = gimp_proc_browser_dialog_new (TRUE, TRUE);
g_object_add_weak_pointer (G_OBJECT (console->proc_browser),
(gpointer) &console->proc_browser);
gtk_window_set_transient_for (GTK_WINDOW (console->proc_browser),
GTK_WINDOW (console->dialog));
g_signal_connect (console->proc_browser, "response",
G_CALLBACK (script_fu_browse_response),
console);
}
gtk_window_present (GTK_WINDOW (console->proc_browser));
}
static void
script_fu_browse_response (GtkWidget *widget,
gint response_id,
ConsoleInterface *console)
{
GimpProcBrowserDialog *dialog = GIMP_PROC_BROWSER_DIALOG (widget);
gchar *proc_name;
gchar *proc_blurb;
gchar *proc_help;
gchar *proc_author;
gchar *proc_copyright;
gchar *proc_date;
GimpPDBProcType proc_type;
gint n_params;
gint n_return_vals;
GimpParamDef *params;
GimpParamDef *return_vals;
gint i;
GString *text;
if (response_id != GTK_RESPONSE_APPLY)
{
gtk_widget_destroy (widget);
return;
}
proc_name = gimp_proc_browser_dialog_get_selected (dialog);
if (proc_name == NULL)
return;
gimp_procedural_db_proc_info (proc_name,
&proc_blurb,
&proc_help,
&proc_author,
&proc_copyright,
&proc_date,
&proc_type,
&n_params,
&n_return_vals,
&params,
&return_vals);
text = g_string_new ("(");
text = g_string_append (text, proc_name);
@ -296,22 +358,24 @@ apply_callback (const gchar *proc_name,
text = g_string_append_c (text, ')');
gtk_entry_set_text (GTK_ENTRY (cint.cc), text->str);
gtk_entry_set_text (GTK_ENTRY (console->cc), text->str);
g_string_free (text, TRUE);
}
static void
script_fu_browse_callback (GtkWidget *widget,
gpointer data)
{
gtk_quit_add_destroy (1, (GtkObject *)
gimp_proc_browser_dialog_new (TRUE, apply_callback, NULL));
g_free (proc_name);
g_free (proc_blurb);
g_free (proc_help);
g_free (proc_author);
g_free (proc_copyright);
g_free (proc_date);
gimp_destroy_paramdefs (params, n_params);
gimp_destroy_paramdefs (return_vals, n_return_vals);
}
static gboolean
script_fu_console_idle_scroll_end (gpointer data)
script_fu_console_idle_scroll_end (ConsoleInterface *console)
{
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
GtkAdjustment *adj = GTK_TEXT_VIEW (console->text_view)->vadjustment;
gtk_adjustment_set_value (adj, adj->upper - adj->page_size);
@ -319,12 +383,11 @@ script_fu_console_idle_scroll_end (gpointer data)
}
static void
script_fu_console_scroll_end (void)
script_fu_console_scroll_end (ConsoleInterface *console)
{
/* the text view idle updates so we need to idle scroll too
*/
g_idle_add (script_fu_console_idle_scroll_end,
GTK_TEXT_VIEW (cint.text_view)->vadjustment);
g_idle_add ((GSourceFunc) script_fu_console_idle_scroll_end, console);
}
void
@ -338,15 +401,15 @@ script_fu_output_to_console (gchar *text)
"weak",
NULL);
script_fu_console_scroll_end ();
script_fu_console_scroll_end (&cint);
}
static gboolean
script_fu_cc_is_empty (void)
script_fu_cc_is_empty (ConsoleInterface *console)
{
const gchar *str;
if ((str = gtk_entry_get_text (GTK_ENTRY (cint.cc))) == NULL)
if ((str = gtk_entry_get_text (GTK_ENTRY (console->cc))) == NULL)
return TRUE;
while (*str)
@ -361,9 +424,9 @@ script_fu_cc_is_empty (void)
}
static gboolean
script_fu_cc_key_function (GtkWidget *widget,
GdkEventKey *event,
gpointer data)
script_fu_cc_key_function (GtkWidget *widget,
GdkEventKey *event,
ConsoleInterface *console)
{
GList *list;
gint direction = 0;
@ -372,48 +435,50 @@ script_fu_cc_key_function (GtkWidget *widget,
switch (event->keyval)
{
case GDK_Return:
if (script_fu_cc_is_empty ())
if (script_fu_cc_is_empty (console))
return TRUE;
list = g_list_nth (history, (g_list_length (history) - 1));
list = g_list_nth (console->history,
(g_list_length (console->history) - 1));
if (list->data)
g_free (list->data);
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc)));
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));
gtk_text_buffer_get_end_iter (cint.console, &cursor);
gtk_text_buffer_get_end_iter (console->console, &cursor);
gtk_text_buffer_insert_with_tags_by_name (cint.console, &cursor,
gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
"\n=> ", -1,
"strong",
NULL);
gtk_text_buffer_insert_with_tags_by_name (cint.console, &cursor,
gtk_entry_get_text (GTK_ENTRY (cint.cc)), -1,
gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
gtk_entry_get_text (GTK_ENTRY (console->cc)), -1,
"weak",
NULL);
gtk_text_buffer_insert_with_tags_by_name (cint.console, &cursor,
gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
"\n", -1,
"weak",
NULL);
script_fu_console_scroll_end ();
script_fu_console_scroll_end (console);
gtk_entry_set_text (GTK_ENTRY (cint.cc), "");
gtk_entry_set_text (GTK_ENTRY (console->cc), "");
siod_interpret_string ((char *) list->data);
gimp_displays_flush ();
history = g_list_append (history, NULL);
if (history_len == history_max)
console->history = g_list_append (console->history, NULL);
if (console->history_len == console->history_max)
{
history = g_list_remove (history, history->data);
if (history->data)
g_free (history->data);
console->history = g_list_remove (console->history,
console->history->data);
if (console->history->data)
g_free (console->history->data);
}
else
history_len++;
history_cur = g_list_length (history) - 1;
console->history_len++;
console->history_cur = g_list_length (console->history) - 1;
return TRUE;
break;
@ -447,24 +512,25 @@ script_fu_cc_key_function (GtkWidget *widget,
if (direction)
{
/* Make sure we keep track of the current one */
if (history_cur == g_list_length (history) - 1)
if (console->history_cur == g_list_length (console->history) - 1)
{
list = g_list_nth (history, history_cur);
list = g_list_nth (console->history, console->history_cur);
if (list->data)
g_free (list->data);
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (cint.cc)));
list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));
}
history_cur += direction;
if (history_cur < 0)
history_cur = 0;
if (history_cur >= history_len)
history_cur = history_len - 1;
console->history_cur += direction;
if (console->history_cur < 0)
console->history_cur = 0;
if (console->history_cur >= console->history_len)
console->history_cur = console->history_len - 1;
gtk_entry_set_text (GTK_ENTRY (cint.cc),
(gchar *) (g_list_nth (history, history_cur))->data);
gtk_entry_set_text (GTK_ENTRY (console->cc),
(gchar *) (g_list_nth (console->history,
console->history_cur))->data);
gtk_editable_set_position (GTK_EDITABLE (cint.cc), -1);
gtk_editable_set_position (GTK_EDITABLE (console->cc), -1);
return TRUE;
}