Commit 527aa849 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/widgets/Makefile.am app/widgets/widgets-types.h new widget swallowing

2004-02-27  Michael Natterer  <mitch@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpfiledialog.[ch]: new widget swallowing most
	of file-dialog-utils.[ch]'s functionality.

	* app/widgets/widgets-types.h: added "gpointer callback_data" to
	GimpItemFactorySetupFunc so the setup_funcs can create items in
	the same context as the item factory's default items.

	* app/widgets/gimpmenufactory.c (gimp_menu_factory_menu_new):
	pass "callback_data" to setup_func().

	* app/gui/file-open-menu.[ch]
	* app/gui/file-save-menu.[ch]: use the passed callback_data
	when creating the menus and attach the file_proc to the
	menu items using g_object_set_data().

	* app/gui/file-commands.[ch]: merged separate file type callbacks
	for open and save dialogs into one callback which simply
	calls gimp_file_dialog_set_file_proc().

	* app/gui/file-dialog-utils.[ch]: removed file_dialog_new()
	and file_dialog_set_proc().

	* app/gui/file-open-dialog.[ch]
	* app/gui/file-save-dialog.[ch]: use the new widget and removed
	global variables except the dialog pointer itself.

	* app/gui/image-menu.[ch]
	* app/gui/tool-options-menu.[ch]
	* app/gui/toolbox-menu.[ch]: changed accordingly.
parent 2c936cc9
2004-02-27 Michael Natterer <mitch@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpfiledialog.[ch]: new widget swallowing most
of file-dialog-utils.[ch]'s functionality.
* app/widgets/widgets-types.h: added "gpointer callback_data" to
GimpItemFactorySetupFunc so the setup_funcs can create items in
the same context as the item factory's default items.
* app/widgets/gimpmenufactory.c (gimp_menu_factory_menu_new):
pass "callback_data" to setup_func().
* app/gui/file-open-menu.[ch]
* app/gui/file-save-menu.[ch]: use the passed callback_data
when creating the menus and attach the file_proc to the
menu items using g_object_set_data().
* app/gui/file-commands.[ch]: merged separate file type callbacks
for open and save dialogs into one callback which simply
calls gimp_file_dialog_set_file_proc().
* app/gui/file-dialog-utils.[ch]: removed file_dialog_new()
and file_dialog_set_proc().
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.[ch]: use the new widget and removed
global variables except the dialog pointer itself.
* app/gui/image-menu.[ch]
* app/gui/tool-options-menu.[ch]
* app/gui/toolbox-menu.[ch]: changed accordingly.
2004-02-26 Sven Neumann <sven@gimp.org>
* INSTALL: improved help on missing libraries at run-time.
......@@ -43,6 +43,7 @@
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
......@@ -124,19 +125,13 @@ file_new_cmd_callback (GtkWidget *widget,
}
void
file_open_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_open_dialog_set_type (NULL);
}
void
file_open_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
file_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_open_dialog_set_type ((PlugInProcDef *) data);
gimp_file_dialog_set_file_proc (GIMP_FILE_DIALOG (data),
g_object_get_data (G_OBJECT (widget),
"file-proc"));
}
void
......@@ -200,22 +195,6 @@ file_last_opened_cmd_callback (GtkWidget *widget,
}
}
void
file_save_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_save_dialog_set_type (NULL);
}
void
file_save_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_save_dialog_set_type ((PlugInProcDef *) data);
}
void
file_save_cmd_callback (GtkWidget *widget,
gpointer data,
......
......@@ -20,58 +20,50 @@
#define __FILE_COMMANDS_H__
void file_new_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_new_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_last_opened_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_as_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_a_copy_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_template_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_last_opened_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_revert_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_pref_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_close_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_quit_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_as_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_a_copy_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_template_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_file_open_dialog (Gimp *gimp,
const gchar *uri,
GtkWidget *parent);
void file_revert_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_pref_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_close_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_quit_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_file_open_dialog (Gimp *gimp,
const gchar *uri,
GtkWidget *parent);
#endif /* __FILE_COMMANDS_H__ */
......@@ -32,6 +32,7 @@
#include "plug-in/plug-in-proc.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpmenufactory.h"
......@@ -40,87 +41,6 @@
#include "gimp-intl.h"
GtkWidget *
file_dialog_new (Gimp *gimp,
GimpDialogFactory *dialog_factory,
const gchar *dialog_identifier,
GimpMenuFactory *menu_factory,
const gchar *menu_identifier,
const gchar *title,
const gchar *role,
const gchar *help_id)
{
GtkWidget *filesel;
GtkFileSelection *fs;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
g_return_val_if_fail (dialog_identifier != NULL, NULL);
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
g_return_val_if_fail (menu_identifier != NULL, NULL);
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (role != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL);
filesel = gtk_file_selection_new (title);
fs = GTK_FILE_SELECTION (filesel);
g_object_set_data (G_OBJECT (filesel), "gimp", gimp);
gtk_window_set_role (GTK_WINDOW (filesel), role);
gimp_help_connect (filesel, gimp_standard_help_func, help_id, NULL);
gtk_container_set_border_width (GTK_CONTAINER (filesel), 6);
gtk_container_set_border_width (GTK_CONTAINER (fs->button_area), 4);
g_signal_connect (filesel, "delete_event",
G_CALLBACK (gtk_true),
NULL);
/* The file type menu */
{
GimpItemFactory *item_factory;
GtkWidget *hbox;
GtkWidget *option_menu;
GtkWidget *label;
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_end (GTK_BOX (fs->main_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
item_factory = gimp_menu_factory_menu_new (menu_factory,
menu_identifier,
GTK_TYPE_MENU,
gimp,
FALSE);
g_object_set_data (G_OBJECT (filesel), "gimp-item-factory", item_factory);
option_menu = gtk_option_menu_new ();
gtk_box_pack_end (GTK_BOX (hbox), option_menu, FALSE, FALSE, 0);
gtk_widget_show (option_menu);
g_object_weak_ref (G_OBJECT (option_menu),
(GWeakNotify) g_object_unref,
item_factory);
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu),
GTK_ITEM_FACTORY (item_factory)->widget);
label = gtk_label_new_with_mnemonic (_("Determine File _Type:"));
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
}
gimp_dialog_factory_add_foreign (dialog_factory, dialog_identifier, filesel);
return filesel;
}
void
file_dialog_show (GtkWidget *filesel,
GtkWidget *parent)
......@@ -151,33 +71,3 @@ file_dialog_hide (GtkWidget *filesel)
gimp_item_factories_set_sensitive ("<Image>", "/File/Save as...", TRUE);
gimp_item_factories_set_sensitive ("<Image>", "/File/Save a Copy...", TRUE);
}
void
file_dialog_update_name (PlugInProcDef *proc,
GtkFileSelection *filesel)
{
if (proc->extensions_list)
{
const gchar *text;
gchar *last_dot;
GString *s;
text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
last_dot = strrchr (text, '.');
if (last_dot == text || !text[0])
return;
s = g_string_new (text);
if (last_dot)
g_string_truncate (s, last_dot-text);
g_string_append (s, ".");
g_string_append (s, (gchar *) proc->extensions_list->data);
gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), s->str);
g_string_free (s, TRUE);
}
}
......@@ -20,21 +20,9 @@
#define __FILE_DIALOG_UTILS_H__
GtkWidget * file_dialog_new (Gimp *gimp,
GimpDialogFactory *dialog_factory,
const gchar *dialog_identifier,
GimpMenuFactory *menu_factory,
const gchar *menu_identifier,
const gchar *title,
const gchar *role,
const gchar *help_id);
void file_dialog_show (GtkWidget *filesel,
GtkWidget *parent);
void file_dialog_hide (GtkWidget *filesel);
void file_dialog_update_name (PlugInProcDef *proc,
GtkFileSelection *filesel);
#endif /* __FILE_DIALOG_UTILS_H__ */
......@@ -38,6 +38,8 @@
#include "file/file-open.h"
#include "file/file-utils.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmenufactory.h"
#include "widgets/gimpthumbbox.h"
......@@ -65,21 +67,12 @@ static void file_open_dialog_open_image (GtkWidget *open_dialog,
PlugInProcDef *load_proc);
static GtkWidget *fileload = NULL;
static GtkWidget *thumb_box = NULL;
static PlugInProcDef *load_file_proc = NULL;
static GtkWidget *fileload = NULL;
static GtkWidget *thumb_box = NULL;
/* public functions */
void
file_open_dialog_set_type (PlugInProcDef *proc)
{
/* Don't call file_dialog_update_name() here, see bug #112273. */
load_file_proc = proc;
}
void
file_open_dialog_show (Gimp *gimp,
GimpImage *gimage,
......@@ -146,12 +139,15 @@ file_open_dialog_create (Gimp *gimp,
GtkWidget *open_dialog;
GtkFileSelection *fs;
open_dialog = file_dialog_new (gimp,
global_dialog_factory,
"gimp-file-open-dialog",
menu_factory, "<Load>",
_("Open Image"), "gimp-file-open",
GIMP_HELP_FILE_OPEN);
open_dialog = gimp_file_dialog_new (gimp,
menu_factory, "<Load>",
_("Open Image"), "gimp-file-open",
GTK_STOCK_OPEN,
GIMP_HELP_FILE_OPEN);
gimp_dialog_factory_add_foreign (global_dialog_factory,
"gimp-file-open-dialog",
open_dialog);
g_signal_connect (open_dialog, "response",
G_CALLBACK (file_open_response_callback),
......@@ -202,8 +198,8 @@ static void
file_open_selchanged_callback (GtkTreeSelection *sel,
GtkWidget *open_dialog)
{
GtkFileSelection *fs;
Gimp *gimp;
GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog);
GtkFileSelection *fs = GTK_FILE_SELECTION (open_dialog);
const gchar *fullfname;
gboolean selected = FALSE;
......@@ -211,17 +207,14 @@ file_open_selchanged_callback (GtkTreeSelection *sel,
selchanged_foreach,
&selected);
fs = GTK_FILE_SELECTION (open_dialog);
gimp = GIMP (g_object_get_data (G_OBJECT (open_dialog), "gimp"));
if (selected)
{
gchar *uri;
fullfname = gtk_file_selection_get_filename (fs);
uri = file_utils_filename_to_uri (gimp->load_procs, fullfname, NULL);
uri = file_utils_filename_to_uri (dialog->gimp->load_procs,
fullfname, NULL);
gimp_thumb_box_set_uri (GIMP_THUMB_BOX (thumb_box), uri);
g_free (uri);
}
......@@ -310,7 +303,7 @@ file_open_response_callback (GtkWidget *open_dialog,
gimp,
uri,
entered_filename,
load_file_proc);
GIMP_FILE_DIALOG (open_dialog)->file_proc);
g_free (uri);
......@@ -328,7 +321,7 @@ file_open_response_callback (GtkWidget *open_dialog,
gimp,
uri,
uri,
load_file_proc);
GIMP_FILE_DIALOG (open_dialog)->file_proc);
g_free (uri);
}
......
......@@ -20,13 +20,11 @@
#define __FILE_OPEN_DIALOG_H__
void file_open_dialog_set_type (PlugInProcDef *proc);
void file_open_dialog_show (Gimp *gimp,
GimpImage *gimage,
const gchar *uri,
GimpMenuFactory *menu_factory,
GtkWidget *parent);
void file_open_dialog_show (Gimp *gimp,
GimpImage *gimage,
const gchar *uri,
GimpMenuFactory *menu_factory,
GtkWidget *parent);
#endif /* __FILE_OPEN_DIALOG_H__ */
......@@ -36,6 +36,8 @@
#include "file/file-save.h"
#include "file/file-utils.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpmenufactory.h"
......@@ -69,32 +71,17 @@ static void file_save_dialog_save_image (GtkWidget *save_dialog,
gboolean set_image_clean);
static GtkWidget *filesave = NULL;
static PlugInProcDef *save_file_proc = NULL;
static GimpImage *the_gimage = NULL;
static gboolean set_uri_and_proc = TRUE;
static gboolean set_image_clean = TRUE;
static GtkWidget *filesave = NULL;
/* public functions */
void
file_save_dialog_set_type (PlugInProcDef *proc)
{
if (proc)
file_dialog_update_name (proc, GTK_FILE_SELECTION (filesave));
save_file_proc = proc;
}
void
file_save_dialog_show (GimpImage *gimage,
GimpMenuFactory *menu_factory,
GtkWidget *parent)
{
GimpItemFactory *item_factory;
gchar *filename;
gchar *filename;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (GIMP_IS_MENU_FACTORY (menu_factory));
......@@ -102,13 +89,13 @@ file_save_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage))
return;
the_gimage = gimage;
set_uri_and_proc = TRUE;
set_image_clean = TRUE;
if (! filesave)
filesave = file_save_dialog_create (gimage->gimp, menu_factory);
GIMP_FILE_DIALOG (filesave)->gimage = gimage;
GIMP_FILE_DIALOG (filesave)->set_uri_and_proc = TRUE;
GIMP_FILE_DIALOG (filesave)->set_image_clean = TRUE;
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave))
......@@ -128,9 +115,7 @@ file_save_dialog_show (GimpImage *gimage,
g_free (filename);
item_factory = g_object_get_data (G_OBJECT (filesave), "gimp-item-factory");
gimp_item_factory_update (item_factory,
gimp_item_factory_update (GIMP_FILE_DIALOG (filesave)->item_factory,
gimp_image_active_drawable (gimage));
file_dialog_show (filesave, parent);
......@@ -141,9 +126,8 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
GimpMenuFactory *menu_factory,
GtkWidget *parent)
{
GimpItemFactory *item_factory;
const gchar *uri;
gchar *filename = NULL;
const gchar *uri;
gchar *filename = NULL;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
g_return_if_fail (GIMP_IS_MENU_FACTORY (menu_factory));
......@@ -151,10 +135,6 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! gimp_image_active_drawable (gimage))
return;
the_gimage = gimage;
set_uri_and_proc = FALSE;
set_image_clean = FALSE;
uri = gimp_object_get_name (GIMP_OBJECT (gimage));
if (uri)
......@@ -163,6 +143,10 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! filesave)
filesave = file_save_dialog_create (gimage->gimp, menu_factory);
GIMP_FILE_DIALOG (filesave)->gimage = gimage;
GIMP_FILE_DIALOG (filesave)->set_uri_and_proc = FALSE;
GIMP_FILE_DIALOG (filesave)->set_image_clean = FALSE;
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave))
......@@ -180,9 +164,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
g_free (filename);
item_factory = g_object_get_data (G_OBJECT (filesave), "gimp-item-factory");
gimp_item_factory_update (item_factory,
gimp_item_factory_update (GIMP_FILE_DIALOG (filesave)->item_factory,
gimp_image_active_drawable (gimage));
file_dialog_show (filesave, parent);
......@@ -197,12 +179,15 @@ file_save_dialog_create (Gimp *gimp,
{
GtkWidget *save_dialog;
save_dialog = file_dialog_new (gimp,
global_dialog_factory,
"gimp-file-save-dialog",
menu_factory, "<Save>",
_("Save Image"), "gimp-file-save",
GIMP_HELP_FILE_SAVE);
save_dialog = gimp_file_dialog_new (gimp,
menu_factory, "<Save>",
_("Save Image"), "gimp-file-save",
GTK_STOCK_SAVE,
GIMP_HELP_FILE_SAVE);
gimp_dialog_factory_add_foreign (global_dialog_factory,
"gimp-file-save-dialog",
save_dialog);
g_signal_connect (save_dialog, "response",
G_CALLBACK (file_save_response_callback),
......@@ -258,17 +243,19 @@ file_save_response_callback (GtkWidget *save_dialog,
}
else
{
gtk_widget_set_sensitive (GTK_WIDGET (fs), FALSE);
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gtk_widget_set_sensitive (save_dialog, FALSE);
file_save_dialog_save_image (save_dialog,
the_gimage,
dialog->gimage,
uri,
raw_filename,
save_file_proc,
set_uri_and_proc,
set_image_clean);
dialog->file_proc,
dialog->set_uri_and_proc,
dialog->set_image_clean);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
gtk_widget_set_sensitive (save_dialog, TRUE);
}
g_free (uri);
......@@ -336,13 +323,15 @@ file_save_overwrite_callback (GtkWidget *widget,
if (overwrite)
{
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
file_save_dialog_save_image (overwrite_data->save_dialog,
the_gimage,
dialog->gimage,
overwrite_data->uri,
overwrite_data->raw_filename,
save_file_proc,
set_uri_and_proc,
set_image_clean);
dialog->file_proc,
dialog->set_uri_and_proc,
dialog->set_image_clean);
}
gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE);
......
......@@ -20,8 +20,6 @@
#define __FILE_SAVE_DIALOG_H__
void file_save_dialog_set_type (PlugInProcDef *proc);
void file_save_dialog_show (GimpImage *gimage,
GimpMenuFactory *menu_factory,
GtkWidget *parent);
......
......@@ -43,6 +43,7 @@
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
......@@ -124,19 +125,13 @@ file_new_cmd_callback (GtkWidget *widget,
}
void
file_open_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_open_dialog_set_type (NULL);
}
void
file_open_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
file_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_open_dialog_set_type ((PlugInProcDef *) data);
gimp_file_dialog_set_file_proc (GIMP_FILE_DIALOG (data),
g_object_get_data (G_OBJECT (widget),
"file-proc"));
}
void
......@@ -200,22 +195,6 @@ file_last_opened_cmd_callback (GtkWidget *widget,
}
}
void
file_save_by_extension_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_save_dialog_set_type (NULL);
}
void
file_save_type_cmd_callback (GtkWidget *widget,
gpointer data,
guint action)
{
file_save_dialog_set_type ((PlugInProcDef *) data);
}
void
file_save_cmd_callback (GtkWidget *widget,
gpointer data,
......