Commit b54b5ed6 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added a (commented out) function to open files (to get rid of including

2001-07-09  Michael Natterer  <mitch@gimp.org>

	* app/core/gimp.[ch]: added a (commented out) function to open
	files (to get rid of including gui/file-open-dialog.h)

	* app/gui/file-open-dialog.[ch]
	* app/gui/file-save-dialog.[ch]: renamed all functions because they
	are no callbacks any more. Removed the _by_extension() callbacks.

	* app/gui/file-commands.[ch]: added the
	file_[open|save]_by_extension() callbaks here along with some
	other stuff which has nothing to do with the file dialogs.

	* app/gui/menus.c: added a helper function to create an item
	factory, cleanup.

	* app/gui/palette-editor.[ch]: contains only the editor for a
	single palette now (removed the notebook and the palette list).
	Renamed all functions to palette_editor_*(). Will be made a
	dockable later.

	* app/gui/palette-select.[ch]: made it work like the other
	selection dialogs.

	* app/app_procs.c
	* app/docindex.c
	* app/gui/dialogs-constructors.[ch]
	* app/gui/dialogs.c
	* app/gui/gradient-select.c
	* app/gui/gui.c
	* app/widgets/gimpdnd.c: changed accordingly.
parent c5609420
2001-07-09 Michael Natterer <mitch@gimp.org>
* app/core/gimp.[ch]: added a (commented out) function to open
files (to get rid of including gui/file-open-dialog.h)
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.[ch]: renamed all functions because they
are no callbacks any more. Removed the _by_extension() callbacks.
* app/gui/file-commands.[ch]: added the
file_[open|save]_by_extension() callbaks here along with some
other stuff which has nothing to do with the file dialogs.
* app/gui/menus.c: added a helper function to create an item
factory, cleanup.
* app/gui/palette-editor.[ch]: contains only the editor for a
single palette now (removed the notebook and the palette list).
Renamed all functions to palette_editor_*(). Will be made a
dockable later.
* app/gui/palette-select.[ch]: made it work like the other
selection dialogs.
* app/app_procs.c
* app/docindex.c
* app/gui/dialogs-constructors.[ch]
* app/gui/dialogs.c
* app/gui/gradient-select.c
* app/gui/gui.c
* app/widgets/gimpdnd.c: changed accordingly.
2001-07-08 Michael Natterer <mitch@gimp.org>
* app/disp_callbacks.c: the active_tool may change in the middle
......
......@@ -20,26 +20,46 @@
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "core/core-types.h"
#include "core/gimpimage.h"
#include "core/gimpobject.h"
#include "file-commands.h"
#include "file-new-dialog.h"
#include "file-open-dialog.h"
#include "file-save-dialog.h"
#include "menus.h"
#include "app_procs.h"
#include "file-open.h"
#include "file-save.h"
#include "gdisplay.h"
#include "gdisplay_ops.h"
#include "menus.h"
#include "gimprc.h"
#include "undo.h"
#include "libgimp/gimpintl.h"
#define REVERT_DATA_KEY "revert-confirm-dialog"
#define return_if_no_display(gdisp) \
gdisp = gdisplay_active (); \
if (!gdisp) return
/* local function prototypes */
static void file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data);
/* public functions */
void
file_new_cmd_callback (GtkWidget *widget,
gpointer data,
......@@ -62,11 +82,18 @@ file_new_cmd_callback (GtkWidget *widget,
file_new_dialog_create (gimage);
}
void
file_open_by_extension_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_open_dialog_menu_reset ();
}
void
file_open_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_open_callback (widget, data);
file_open_dialog_show ();
}
void
......@@ -86,7 +113,7 @@ file_last_opened_cmd_callback (GtkWidget *widget,
filename =
((GString *) g_slist_nth_data (last_opened_raw_filenames, action))->str;
status = file_open_with_display (filename, filename);
status = file_open_with_display (filename);
if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL)
......@@ -95,32 +122,129 @@ file_last_opened_cmd_callback (GtkWidget *widget,
}
}
void
file_save_by_extension_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_save_dialog_menu_reset ();
}
void
file_save_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_save_callback (widget, data);
GDisplay *gdisp;
return_if_no_display (gdisp);
if (! gimp_image_active_drawable (gdisp->gimage))
return;
/* Only save if the gimage has been modified */
if (! gimprc.trust_dirty_flag || gdisp->gimage->dirty != 0)
{
gchar *filename;
filename = g_strdup (gimp_object_get_name (GIMP_OBJECT (gdisp->gimage)));
if (! filename)
{
file_save_as_cmd_callback (widget, data);
}
else
{
gchar *raw_filename;
gint status;
raw_filename = g_basename (filename);
status = file_save (gdisp->gimage,
filename,
raw_filename,
RUN_WITH_LAST_VALS,
TRUE);
if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL)
{
g_message (_("Save failed.\n%s"), filename);
}
}
g_free (filename);
}
}
void
file_save_as_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_save_as_callback (widget, data);
GDisplay *gdisp;
return_if_no_display (gdisp);
file_save_dialog_show (gdisp->gimage);
}
void
file_save_a_copy_as_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_save_a_copy_as_callback (widget, data);
GDisplay *gdisp;
return_if_no_display (gdisp);
file_save_a_copy_dialog_show (gdisp->gimage);
}
void
file_revert_cmd_callback (GtkWidget *widget,
gpointer data)
{
file_revert_callback (widget, data);
GDisplay *gdisp;
GtkWidget *query_box;
const gchar *filename;
return_if_no_display (gdisp);
filename = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
query_box = gtk_object_get_data (GTK_OBJECT (gdisp->gimage), REVERT_DATA_KEY);
if (! filename)
{
g_message (_("Revert failed.\n"
"No filename associated with this image."));
}
else if (query_box)
{
gdk_window_raise (query_box->window);
}
else
{
gchar *text;
text = g_strdup_printf (_("Reverting %s to\n"
"%s\n\n"
"(You will lose all your changes\n"
"including all undo information)"),
g_basename (filename),
filename);
query_box = gimp_query_boolean_box (_("Revert Image?"),
gimp_standard_help_func,
"file/revert.html",
FALSE,
text,
_("Yes"), _("No"),
GTK_OBJECT (gdisp->gimage), "destroy",
file_revert_confirm_callback,
gdisp->gimage);
g_free (text);
gtk_object_set_data (GTK_OBJECT (gdisp->gimage), REVERT_DATA_KEY,
query_box);
gtk_widget_show (query_box);
}
}
void
......@@ -139,3 +263,48 @@ file_quit_cmd_callback (GtkWidget *widget,
{
app_exit (FALSE);
}
/* private functions */
static void
file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data)
{
GimpImage *old_gimage;
old_gimage = (GimpImage *) data;
gtk_object_set_data (GTK_OBJECT (old_gimage), REVERT_DATA_KEY, NULL);
if (revert)
{
GimpImage *new_gimage;
const gchar *filename;
gint status;
filename = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (old_gimage->gimp,
filename, filename,
_("Revert"),
NULL,
RUN_INTERACTIVE,
&status);
if (new_gimage != NULL)
{
undo_free (new_gimage);
gdisplays_reconnect (old_gimage, new_gimage);
gdisplays_resize_cursor_label (new_gimage);
gdisplays_update_full (new_gimage);
gdisplays_shrink_wrap (new_gimage);
gimp_image_clean_all (new_gimage);
}
else if (status != GIMP_PDB_CANCEL)
{
g_message (_("Revert failed.\n%s"), filename);
}
}
}
......@@ -20,28 +20,35 @@
#define __FILE_COMMANDS_H__
void file_new_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_cmd_callback (GtkWidget *widget,
gpointer data);
void file_last_opened_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_cmd_callback (GtkWidget *widget,
gpointer data);
void file_save_as_cmd_callback (GtkWidget *widget,
gpointer data);
void file_save_a_copy_as_cmd_callback (GtkWidget *widget,
gpointer data);
void file_revert_cmd_callback (GtkWidget *widget,
gpointer data);
void file_pref_cmd_callback (GtkWidget *widget,
gpointer data);
void file_close_cmd_callback (GtkWidget *widget,
gpointer data);
void file_quit_cmd_callback (GtkWidget *widget,
gpointer data);
void file_new_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_open_by_extension_cmd_callback (GtkWidget *widget,
gpointer data);
void file_open_cmd_callback (GtkWidget *widget,
gpointer data);
void file_last_opened_cmd_callback (GtkWidget *widget,
gpointer data,
guint action);
void file_save_by_extension_cmd_callback (GtkWidget *widget,
gpointer data);
void file_save_cmd_callback (GtkWidget *widget,
gpointer data);
void file_save_as_cmd_callback (GtkWidget *widget,
gpointer data);
void file_save_a_copy_as_cmd_callback (GtkWidget *widget,
gpointer data);
void file_revert_cmd_callback (GtkWidget *widget,
gpointer data);
void file_pref_cmd_callback (GtkWidget *widget,
gpointer data);
void file_close_cmd_callback (GtkWidget *widget,
gpointer data);
void file_quit_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __FILE_COMMANDS_H__ */
......@@ -197,7 +197,7 @@ app_init (gint gimp_argc,
while (gimp_argc--)
{
if (*gimp_argv)
file_open_with_display (*gimp_argv, *gimp_argv);
file_open_with_display (*gimp_argv);
gimp_argv++;
}
......
......@@ -382,6 +382,50 @@ gimp_create_display (Gimp *gimp,
gimp->create_display_func (gimage);
}
/*
void
gimp_open_file (Gimp *gimp,
const gchar *filename,
gboolean with_display)
{
GimpImage *gimage;
gint status;
g_return_if_fail (gimp != NULL);
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (filename != NULL);
gimage = file_open_image (gimp,
filename,
filename,
_("Open"),
NULL,
RUN_INTERACTIVE,
&status);
if (gimage)
{
gchar *absolute;
* enable & clear all undo steps *
gimp_image_undo_enable (gimage);
* set the image to clean *
gimp_image_clean_all (gimage);
if (with_display)
gimp_create_display (gimage->gimp, gimage);
absolute = file_open_absolute_filename (filename);
document_index_add (absolute);
menus_last_opened_add (absolute);
g_free (absolute);
}
}
*/
GimpContext *
gimp_create_context (Gimp *gimp,
const gchar *name,
......
......@@ -58,7 +58,7 @@ struct _Gimp
GimpContainer *tool_info_list;
/* image_new values */
/* image_new values */
GList *image_base_type_names;
GList *fill_type_names;
GimpImageNewValues image_new_last_values;
......@@ -101,6 +101,12 @@ GimpImage * gimp_create_image (Gimp *gimp,
void gimp_create_display (Gimp *gimp,
GimpImage *gimage);
/*
void gimp_open_file (Gimp *gimp,
const gchar *filename,
gboolean with_display);
*/
GimpContext * gimp_create_context (Gimp *gimp,
const gchar *name,
GimpContext *template);
......
......@@ -33,6 +33,7 @@
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimppalette.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpbrushfactoryview.h"
......@@ -66,6 +67,7 @@
#include "layers-commands.h"
#include "menus.h"
#include "palette-editor.h"
#include "palette-select.h"
#include "palettes-commands.h"
#include "paths-dialog.h"
#include "pattern-select.h"
......@@ -175,8 +177,8 @@ dialogs_gradient_select_get (GimpDialogFactory *factory,
}
GtkWidget *
dialogs_palette_get (GimpDialogFactory *factory,
GimpContext *context)
dialogs_palette_select_get (GimpDialogFactory *factory,
GimpContext *context)
{
return palette_dialog_create ();
}
......@@ -717,7 +719,18 @@ dialogs_edit_gradient_func (GimpData *data)
void
dialogs_edit_palette_func (GimpData *data)
{
palette_dialog_edit_palette (data);
static PaletteEditor *palette_editor_dialog = NULL;
GimpPalette *palette;
palette = GIMP_PALETTE (data);
if (! palette_editor_dialog)
{
palette_editor_dialog = palette_editor_new ();
}
palette_editor_set_palette (palette_editor_dialog, palette);
}
......
......@@ -34,7 +34,7 @@ GtkWidget * dialogs_pattern_select_get (GimpDialogFactory *factory,
GimpContext *context);
GtkWidget * dialogs_gradient_select_get (GimpDialogFactory *factory,
GimpContext *context);
GtkWidget * dialogs_palette_get (GimpDialogFactory *factory,
GtkWidget * dialogs_palette_select_get (GimpDialogFactory *factory,
GimpContext *context);
GtkWidget * dialogs_error_console_get (GimpDialogFactory *factory,
GimpContext *context);
......
......@@ -44,7 +44,7 @@ static const GimpDialogFactoryEntry toplevel_entries[] =
{ "gimp:brush-select-dialog", dialogs_brush_select_get, TRUE, TRUE, FALSE },
{ "gimp:pattern-select-dialog", dialogs_pattern_select_get, TRUE, TRUE, FALSE },
{ "gimp:gradient-select-dialog", dialogs_gradient_select_get, TRUE, TRUE, FALSE },
{ "gimp:palette-dialog", dialogs_palette_get, TRUE, TRUE, FALSE },
{ "gimp:palette-select-dialog", dialogs_palette_select_get, TRUE, TRUE, FALSE },
{ "gimp:error-console-dialog", dialogs_error_console_get, TRUE, TRUE, TRUE },
{ "gimp:document-index-dialog", dialogs_document_index_get, TRUE, TRUE, TRUE },
{ "gimp:preferences-dialog", dialogs_preferences_get, TRUE, FALSE, FALSE },
......
......@@ -54,7 +54,6 @@
#include "app_procs.h"
#include "dialog_handler.h"
#include "docindex.h"
#include "gdisplay.h"
#include "file-open.h"
#include "file-utils.h"
#include "plug_in.h"
......@@ -63,32 +62,21 @@
#include "libgimp/gimpintl.h"
#define REVERT_DATA_KEY "revert_confirm_dialog"
/* local function prototypes */
static int file_open_with_proc_and_display (gchar *filename,
gchar *raw_filename,
PlugInProcDef *file_proc);
static void file_open_dialog_create (void);
static void file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_clistrow_callback (GtkWidget *widget,
gint row);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static GSList * clist_to_slist (GtkCList *file_list);
static gint file_open_with_proc_and_display (gchar *filename,
gchar *raw_filename,
PlugInProcDef *file_proc);
static void file_open_dialog_create (void);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_clistrow_callback (GtkWidget *widget,
gint row);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static GSList * clist_to_slist (GtkCList *file_list);
......@@ -112,7 +100,7 @@ extern GSList *display_list; /* from gdisplay.c */
/* public functions */
void
file_open_menu_init (void)
file_open_dialog_menu_init (void)
{
GimpItemFactoryEntry entry;
PlugInProcDef *file_proc;
......@@ -137,6 +125,7 @@ file_open_menu_init (void)
entry.entry.callback = file_open_type_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = NULL;
entry.quark_string = NULL;
entry.help_page = help_page;
entry.description = NULL;
......@@ -145,10 +134,15 @@ file_open_menu_init (void)
}
void
file_open_callback (GtkWidget *widget,
gpointer data)
file_open_dialog_menu_reset (void)
{
load_file_proc = NULL;
}
void
file_open_dialog_show (void)
{
if (!fileload)
if (! fileload)
file_open_dialog_create ();
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
......@@ -162,81 +156,16 @@ file_open_callback (GtkWidget *widget,
file_dialog_show (fileload);
}
void
file_revert_callback (GtkWidget *widget,
gpointer data)
{
GDisplay *gdisplay;
GimpImage *gimage;
GtkWidget *query_box;
const gchar *filename;
gdisplay = gdisplay_active ();
if (!gdisplay || !gdisplay->gimage)
return;
gimage = gdisplay->gimage;
filename = gimp_object_get_name (GIMP_OBJECT (gimage));
query_box = gtk_object_get_data (GTK_OBJECT (gimage), REVERT_DATA_KEY);
if (! filename)
{
g_message (_("Revert failed.\n"
"No filename associated with this image."));
}
else if (query_box)
{
gdk_window_raise (query_box->window);
}
else
{
gchar *text;
text = g_strdup_printf (_("Reverting %s to\n"
"%s\n\n"
"(You will lose all your changes\n"
"including all undo information)"),
g_basename (filename),
filename);
query_box = gimp_query_boolean_box (_("Revert Image?"),
gimp_standard_help_func,
"file/revert.html",
FALSE,
text,
_("Yes"), _("No"),
GTK_OBJECT (gimage), "destroy",
file_revert_confirm_callback,
gimage);
g_free (text);
gtk_object_set_data (GTK_OBJECT (gimage), REVERT_DATA_KEY, query_box);
gtk_widget_show (query_box);
}
}
void
file_open_by_extension_callback (GtkWidget *widget,
gpointer data)
{
load_file_proc = NULL;
}
gint
file_open_with_display (gchar *filename,
gchar *raw_filename)
file_open_with_display (gchar *filename)
{
return file_open_with_proc_and_display (filename, raw_filename, NULL);
return file_open_with_proc_and_display (filename, filename, NULL);
}
/* private functions */
static int
static gint
file_open_with_proc_and_display (gchar *filename,
gchar *raw_filename,
PlugInProcDef *file_proc)
......@@ -916,45 +845,3 @@ clist_to_slist (GtkCList *file_list)
return list;
}
static void
file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data)
{
GimpImage *old_gimage;
old_gimage = (GimpImage *) data;
gtk_object_set_data (GTK_OBJECT (old_gimage), REVERT_DATA_KEY, NULL);
if (revert)
{
GimpImage *new_gimage;
const gchar *filename;
gint status;
filename = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (old_gimage->gimp,
filename, filename,
_("Revert"),
NULL,
RUN_INTERACTIVE,
&status);
if (new_gimage != NULL)
{
undo_free (new_gimage);
gdisplays_reconnect (old_gimage, new_gimage);
gdisplays_resize_cursor_label (new_gimage);
gdisplays_update_full (new_gimage);
gdisplays_shrink_wrap (new_gimage);
gimp_image_clean_all (new_gimage);
}
else if (status != GIMP_PDB_CANCEL)
{
g_message (_("Revert failed.\n%s"), filename);
}
}
}
......@@ -20,19 +20,12 @@
#define __FILE_OPEN_DIALOG_H__
void file_open_menu_init (void);
void file_open_dialog_menu_init (void);
void file_open_dialog_menu_reset (void);
void file_open_callback (GtkWidget *widget,
gpointer data);
void file_open_dialog_show (void);
void file_revert_callback (GtkWidget *widget,
gpointer data);
void file_open_by_extension_callback (GtkWidget *widget,
gpointer data);
gint file_open_with_display (gchar *filename,
gchar *raw_filename);
gint file_open_with_display (gchar *filename);
<