Commit 3ed87f4a authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/fileops.c app/menus.[ch] app/menus.h show a help page for all menu

1999-10-03  Michael Natterer  <mitch@gimp.org>

	* app/fileops.c
	* app/menus.[ch]
	* app/menus.h
	* app/plug_in.c: show a help page for all menu entries registered
	by plugins.
	Changed menus_create() to menus_create_item_from_full_path() which
	takes a single GimpItemFactoryEntry instead of an array as
	parameter.
parent bbb71305
1999-10-03 Michael Natterer <mitch@gimp.org>
* app/fileops.c
* app/menus.[ch]
* app/menus.h
* app/plug_in.c: show a help page for all menu entries registered
by plugins.
Changed menus_create() to menus_create_item_from_full_path() which
takes a single GimpItemFactoryEntry instead of an array as
parameter.
1999-10-03 Michael Natterer <mitch@gimp.org>
The GIMP Help System part II: press "F1" while browsing a menu
......@@ -32,6 +43,8 @@
GimpItemFactoryEntry to allow a help path to be stored.
Will be partially exported and moved to gimphelp.[ch] later to
catch key_press for plug-in menu items (don't try this now ;-)
Renamed "Channel Ops" under <Image>/Image to "Channels" and moved
some entries to more useful places.
* app/app_procs.c
* app/brush_edit.c
......@@ -71,6 +84,9 @@
* modules/colorsel_triangle.c
* modules/colorsel_water.c: register a help page.
* plug-ins/common/compose.c
* plug-ins/common/decompose.c: changed the menu path.
* plug-ins/helpbrowser/helpbrowser.c: load the help files
according to the new help file structure.
......
......@@ -1628,7 +1628,7 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
PlugInProcDef *proc_def;
ProcRecord *proc = NULL;
GSList *tmp = NULL;
GtkMenuEntry entry;
GimpItemFactoryEntry entry;
char *prog = NULL;
int add_proc_def;
int i;
......@@ -1833,12 +1833,23 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
/* If there is a menu path specified, create a menu entry */
if (proc_install->menu_path)
{
entry.path = proc_install->menu_path;
entry.accelerator = NULL;
entry.callback = plug_in_callback;
entry.callback_data = proc;
gchar *help_page;
menus_create (&entry, 1);
help_page = g_strconcat ("filters/",
g_basename (proc_def->prog),
".html",
NULL);
g_strdown (help_page);
entry.entry.path = proc_install->menu_path;
entry.entry.accelerator = NULL;
entry.entry.callback = plug_in_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = NULL;
entry.help_page = help_page;
entry.description = NULL;
menus_create_item_from_full_path (&entry, proc);
}
break;
}
......@@ -2254,7 +2265,7 @@ plug_in_add_to_db (void)
static void
plug_in_make_menu (void)
{
GtkMenuEntry entry;
GimpItemFactoryEntry entry;
PlugInProcDef *proc_def;
GSList *tmp;
......@@ -2268,12 +2279,23 @@ plug_in_make_menu (void)
!proc_def->prefixes &&
!proc_def->magics))
{
entry.path = proc_def->menu_path;
entry.accelerator = proc_def->accelerator;
entry.callback = plug_in_callback;
entry.callback_data = &proc_def->db_info;
gchar *help_page;
help_page = g_strconcat ("filters/",
g_basename (proc_def->prog),
".html",
NULL);
g_strdown (help_page);
entry.entry.path = proc_def->menu_path;
entry.entry.accelerator = proc_def->accelerator;
entry.entry.callback = plug_in_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = NULL;
entry.help_page = help_page;
entry.description = NULL;
menus_create (&entry, 1);
menus_create_item_from_full_path (&entry, &proc_def->db_info);
}
}
}
......@@ -2317,7 +2339,7 @@ plug_in_callback (GtkWidget *widget,
/* initialize the first 3 plug-in arguments */
args[0].value.pdb_int = RUN_INTERACTIVE;
args[1].value.pdb_int = pdb_image_to_id(gdisplay->gimage);
args[1].value.pdb_int = pdb_image_to_id (gdisplay->gimage);
args[2].value.pdb_int = drawable_ID (gimage_active_drawable (gdisplay->gimage));
argc = 3;
}
......@@ -2340,7 +2362,7 @@ plug_in_callback (GtkWidget *widget,
{
gdisp_ID = gdisplay->ID;
args[1].value.pdb_int = pdb_image_to_id(gdisplay->gimage);
args[1].value.pdb_int = pdb_image_to_id (gdisplay->gimage);
args[2].value.pdb_int = drawable_ID (gimage_active_drawable (gdisplay->gimage));
argc = 3;
}
......
......@@ -161,7 +161,7 @@ file_ops_pre_init (void)
void
file_ops_post_init (void)
{
GtkMenuEntry entry;
GimpItemFactoryEntry entry;
PlugInProcDef *file_proc;
GSList *tmp;
......@@ -171,29 +171,49 @@ file_ops_post_init (void)
tmp = load_procs;
while (tmp)
{
gchar *help_page;
file_proc = tmp->data;
tmp = tmp->next;
entry.path = file_proc->menu_path;
entry.accelerator = NULL;
entry.callback = file_load_type_callback;
entry.callback_data = file_proc;
help_page = g_strconcat (g_basename (file_proc->prog),
".html",
NULL);
g_strdown (help_page);
entry.entry.path = file_proc->menu_path;
entry.entry.accelerator = NULL;
entry.entry.callback = file_load_type_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = NULL;
entry.help_page = help_page;
entry.description = NULL;
menus_create (&entry, 1);
menus_create_item_from_full_path (&entry, file_proc);
}
tmp = save_procs;
while (tmp)
{
gchar *help_page;
file_proc = tmp->data;
tmp = tmp->next;
entry.path = file_proc->menu_path;
entry.accelerator = NULL;
entry.callback = file_save_type_callback;
entry.callback_data = file_proc;
help_page = g_strconcat (g_basename (file_proc->prog),
".html",
NULL);
g_strdown (help_page);
entry.entry.path = file_proc->menu_path;
entry.entry.accelerator = NULL;
entry.entry.callback = file_save_type_callback;
entry.entry.callback_action = 0;
entry.entry.item_type = NULL;
entry.help_page = help_page;
entry.description = NULL;
menus_create (&entry, 1);
menus_create_item_from_full_path (&entry, file_proc);
}
}
......@@ -234,7 +254,7 @@ file_open_callback (GtkWidget *widget,
/* Connect the "F1" help key */
gimp_help_connect_help_accel (fileload,
gimp_standard_help_func,
"dialogs/file_open.html");
"open/index.html");
}
else
{
......@@ -445,8 +465,16 @@ file_save_as_callback (GtkWidget *widget,
"delete_event",
GTK_SIGNAL_FUNC (file_dialog_hide),
NULL);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesave)->ok_button), "clicked", (GtkSignalFunc) file_save_ok_callback, filesave);
gtk_signal_connect
(GTK_OBJECT (GTK_FILE_SELECTION (filesave)->ok_button), "clicked",
(GtkSignalFunc) file_save_ok_callback,
filesave);
gtk_quit_add_destroy (1, GTK_OBJECT (filesave));
/* Connect the "F1" help key */
gimp_help_connect_help_accel (filesave,
gimp_standard_help_func,
"save/index.html");
}
else
{
......@@ -457,11 +485,6 @@ file_save_as_callback (GtkWidget *widget,
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filesave),
"." G_DIR_SEPARATOR_S);
gtk_window_set_title (GTK_WINDOW (filesave), _("Save Image"));
/* Connect the "F1" help key */
gimp_help_connect_help_accel (filesave,
gimp_standard_help_func,
"dialogs/file_save.html");
}
gdisplay = gdisplay_active ();
......@@ -471,7 +494,8 @@ file_save_as_callback (GtkWidget *widget,
if (!save_options)
{
save_options = gtk_frame_new (_("Save Options"));
gtk_frame_set_shadow_type (GTK_FRAME (save_options), GTK_SHADOW_ETCHED_IN);
gtk_frame_set_shadow_type (GTK_FRAME (save_options),
GTK_SHADOW_ETCHED_IN);
hbox = gtk_hbox_new (FALSE, 1);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
......@@ -1592,7 +1616,7 @@ file_overwrite (char *filename,
overwrite_box->obox =
gimp_dialog_new (_("File Exists!"), "file_exists",
gimp_standard_help_func,
"dialogs/file_exists.html",
"save/file_exists.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
......
......@@ -44,15 +44,21 @@
#define MRU_MENU_ENTRY_SIZE (strlen (_("/File/MRU00 ")) + 1)
#define MRU_MENU_ACCEL_SIZE sizeof ("<control>0")
typedef struct _GimpItemFactoryEntry GimpItemFactoryEntry;
struct _GimpItemFactoryEntry
{
GtkItemFactoryEntry entry;
gchar *help_page;
gchar *description;
};
static void menus_create_item (GtkItemFactory *item_factory,
GimpItemFactoryEntry *entry,
gpointer callback_data,
guint callback_type);
static void menus_create_items (GtkItemFactory *item_factory,
guint n_entries,
GimpItemFactoryEntry *entries,
gpointer callback_data,
guint callback_type);
static void menus_init (void);
static gchar *menu_translate (const gchar *path,
gpointer data);
static void tearoff_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);
static char* G_GNUC_UNUSED dummyMenus[] = { N_("/File/MRU00 "),
N_("/File"),
......@@ -64,17 +70,6 @@ static char* G_GNUC_UNUSED dummyMenus[] = { N_("/File/MRU00 "),
N_("/View/Zoom"),
N_("/Stack")};
static void menus_create_item (GtkItemFactory *item_factory,
GimpItemFactoryEntry *entry,
gpointer callback_data,
guint callback_type);
static void menus_init (void);
static gchar *menu_translate (const gchar *path,
gpointer data);
static void tearoff_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action);
static GSList *last_opened_raw_filenames = NULL;
static GimpItemFactoryEntry toolbox_entries[] =
......@@ -84,7 +79,7 @@ static GimpItemFactoryEntry toolbox_entries[] =
{ { N_("/File/New"), "<control>N", file_new_cmd_callback, 0 },
"file/dialogs/file_new.html", NULL },
{ { N_("/File/Open"), "<control>O", file_open_cmd_callback, 0 },
"file/dialogs/file_open.html", NULL },
"open/index.html", NULL },
{ { N_("/File/Acquire/tearoff1"), NULL, NULL, 0, "<Tearoff>" },
NULL, NULL },
{ { N_("/File/About..."), NULL, about_dialog_cmd_callback, 0 },
......@@ -149,11 +144,11 @@ static GimpItemFactoryEntry image_entries[] =
{ { N_("/File/New"), "<control>N", file_new_cmd_callback, 1 },
"file/dialogs/file_new.html", NULL },
{ { N_("/File/Open"), "<control>O", file_open_cmd_callback, 0 },
"file/dialogs/file_open.html", NULL },
"open/index.html", NULL },
{ { N_("/File/Save"), "<control>S", file_save_cmd_callback, 0 },
"file/dialogs/file_save.html", NULL },
"save/index.html", NULL },
{ { N_("/File/Save as"), NULL, file_save_as_cmd_callback, 0 },
"file/dialogs/save_as.html", NULL },
"save/index.html", NULL },
{ { N_("/File/Revert"), NULL, file_revert_cmd_callback, 0 },
"file/revert.html", NULL },
{ { N_("/File/Preferences..."), NULL, file_pref_cmd_callback, 0 },
......@@ -414,21 +409,27 @@ static GimpItemFactoryEntry image_entries[] =
static guint n_image_entries = (sizeof (image_entries) /
sizeof (image_entries[0]));
static GtkItemFactory *image_factory = NULL;
static GtkItemFactoryEntry load_entries[] =
static GimpItemFactoryEntry load_entries[] =
{
{ N_("/Automatic"), NULL, file_load_by_extension_callback, 0 },
{ "/---", NULL, NULL, 0, "<Separator>" },
{ { N_("/Automatic"), NULL, file_load_by_extension_callback, 0 },
NULL, NULL },
{ { "/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL }
};
static guint n_load_entries = sizeof (load_entries) / sizeof (load_entries[0]);
static guint n_load_entries = (sizeof (load_entries) /
sizeof (load_entries[0]));
static GtkItemFactory *load_factory = NULL;
static GtkItemFactoryEntry save_entries[] =
static GimpItemFactoryEntry save_entries[] =
{
{ N_("/By extension"), NULL, file_save_by_extension_callback, 0 },
{ "/---", NULL, NULL, 0, "<Separator>" },
{ { N_("/By extension"), NULL, file_save_by_extension_callback, 0 },
NULL, NULL },
{ { "/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },
};
static guint n_save_entries = sizeof (save_entries) / sizeof (save_entries[0]);
static guint n_save_entries = (sizeof (save_entries) /
sizeof (save_entries[0]));
static GtkItemFactory *save_factory = NULL;
static GimpItemFactoryEntry layers_entries[] =
......@@ -540,7 +541,7 @@ static guint n_paths_entries = (sizeof (paths_entries) /
sizeof (paths_entries[0]));
static GtkItemFactory *paths_factory = NULL;
static int initialize = TRUE;
static gboolean initialize = TRUE;
void
menus_get_toolbox_menubar (GtkWidget **menubar,
......@@ -634,48 +635,69 @@ menus_get_paths_menu (GtkWidget **menu,
}
void
menus_create (GtkMenuEntry *entries,
int n_menu_entries)
menus_create_item_from_full_path (GimpItemFactoryEntry *entry,
gpointer callback_data)
{
GtkItemFactory *ifactory;
GtkWidget *menu_item;
int i;
int redo_image_menu = FALSE;
gboolean redo_image_menu = FALSE;
GString *tearoff_path;
gchar *path;
if (initialize)
menus_init ();
tearoff_path = g_string_new ("");
for (i = 0; i < n_menu_entries; i++)
if (! strncmp (entries[i].path, "<Image>", 7))
{
char *p;
if (! strncmp (entry->entry.path, "<Image>", 7))
{
gchar *p;
p = strchr (entries[i].path + 8, '/');
while (p)
{
g_string_assign (tearoff_path, entries[i].path + 7);
g_string_truncate (tearoff_path, p - entries[i].path + 1 - 7);
g_string_append (tearoff_path, "tearoff1");
p = strchr (entry->entry.path + 8, '/');
while (p)
{
g_string_assign (tearoff_path, entry->entry.path + 7);
g_string_truncate (tearoff_path,
p - entry->entry.path + 1 - 7);
g_string_append (tearoff_path, "tearoff1");
if (! gtk_item_factory_get_widget (image_factory, tearoff_path->str))
{
GtkItemFactoryEntry entry = { NULL, NULL, NULL, 0, "<Tearoff>" };
entry.path = tearoff_path->str;
entry.callback = tearoff_cmd_callback;
gtk_item_factory_create_items_ac (image_factory, 1, &entry, NULL,2);
}
p = strchr (p + 1, '/');
}
redo_image_menu = TRUE;
}
if (! gtk_item_factory_get_widget (image_factory,
tearoff_path->str))
{
GimpItemFactoryEntry tearoff_entry =
{ { NULL, NULL, NULL, 0, "<Tearoff>" },
NULL, NULL };
tearoff_entry.entry.path = tearoff_path->str;
tearoff_entry.entry.callback = tearoff_cmd_callback;
menus_create_item (image_factory, &tearoff_entry, NULL, 2);
}
p = strchr (p + 1, '/');
}
redo_image_menu = TRUE;
}
g_string_free (tearoff_path, TRUE);
gtk_item_factory_create_menu_entries (n_menu_entries, entries);
path = entry->entry.path;
ifactory = gtk_item_factory_from_path (path);
if (!ifactory)
{
g_warning ("menus_create_item_from_full_path(): "
"entry refers to unknown item factory: \"%s\"", path);
return;
}
while (*path != '>')
path++;
path++;
entry->entry.path = path;
menus_create_item (ifactory, entry,
callback_data, 2);
if (redo_image_menu)
{
......@@ -719,8 +741,8 @@ menus_tools_create (ToolInfo *tool_info)
}
void
menus_set_sensitive (gchar *path,
gint sensitive)
menus_set_sensitive (gchar *path,
gboolean sensitive)
{
GtkItemFactory *ifactory;
GtkWidget *widget = NULL;
......@@ -737,16 +759,17 @@ menus_set_sensitive (gchar *path,
gtk_widget_set_sensitive (widget, sensitive);
}
if (!ifactory || !widget)
g_warning ("Unable to set sensitivity for menu which doesn't exist:\n%s", path);
g_warning ("Unable to set sensitivity for menu which doesn't exist:\n%s",
path);
}
/* The following function will enhance our localesystem because
we don't need to have our menuentries twice in our catalog */
void
menus_set_sensitive_glue (gchar *prepath,
gchar *path,
gint sensitive)
menus_set_sensitive_glue (gchar *prepath,
gchar *path,
gboolean sensitive)
{
gchar *menupath;
......@@ -756,8 +779,8 @@ menus_set_sensitive_glue (gchar *prepath,
}
void
menus_set_state (gchar *path,
gint state)
menus_set_state (gchar *path,
gboolean state)
{
GtkItemFactory *ifactory;
GtkWidget *widget = NULL;
......@@ -777,13 +800,14 @@ menus_set_state (gchar *path,
widget = NULL;
}
if (!ifactory || !widget)
g_warning ("Unable to set state for menu which doesn't exist:\n%s\n", path);
g_warning ("Unable to set state for menu which doesn't exist:\n%s\n",
path);
}
void
menus_set_state_glue (gchar *prepath,
gchar *path,
gint state)
menus_set_state_glue (gchar *prepath,
gchar *path,
gboolean state)
{
gchar *menupath;
......@@ -793,7 +817,7 @@ menus_set_state_glue (gchar *prepath,
}
void
menus_destroy (char *path)
menus_destroy (gchar *path)
{
if (initialize)
menus_init ();
......@@ -920,12 +944,12 @@ menus_last_opened_add (gchar *filename)
void
menus_init_mru (void)
{
gchar *paths, *accelerators;
gint i;
GtkItemFactoryEntry *last_opened_entries;
GtkWidget *widget;
gchar *paths, *accelerators;
gint i;
GimpItemFactoryEntry *last_opened_entries;
GtkWidget *widget;
last_opened_entries = g_new (GtkItemFactoryEntry, last_opened_size);
last_opened_entries = g_new (GimpItemFactoryEntry, last_opened_size);
paths = g_new (gchar, last_opened_size * MRU_MENU_ENTRY_SIZE);
accelerators = g_new (gchar, 9 * MRU_MENU_ACCEL_SIZE);
......@@ -933,40 +957,41 @@ menus_init_mru (void)
for (i = 0; i < last_opened_size; i++)
{
gchar *path, *accelerator;
path = &paths[i * MRU_MENU_ENTRY_SIZE];
if (i < 9)
accelerator = &accelerators[i * MRU_MENU_ACCEL_SIZE];
else
accelerator = NULL;
last_opened_entries[i].path = path;
last_opened_entries[i].accelerator = accelerator;
last_opened_entries[i].callback = (GtkItemFactoryCallback) menus_last_opened_cmd_callback;
last_opened_entries[i].callback_action = i;
last_opened_entries[i].item_type = NULL;
last_opened_entries[i].entry.path = path;
last_opened_entries[i].entry.accelerator = accelerator;
last_opened_entries[i].entry.callback =
(GtkItemFactoryCallback) menus_last_opened_cmd_callback;
last_opened_entries[i].entry.callback_action = i;
last_opened_entries[i].entry.item_type = NULL;
last_opened_entries[i].help_page = "file/last_opened.html";
last_opened_entries[i].description = NULL;
g_snprintf (path, MRU_MENU_ENTRY_SIZE, N_("/File/MRU%02d"), i + 1);
if (accelerator != NULL)
g_snprintf (accelerator, MRU_MENU_ACCEL_SIZE, "<control>%d", i + 1);
}
gtk_item_factory_create_items_ac (toolbox_factory, last_opened_size,
last_opened_entries, NULL, 2);
menus_create_items (toolbox_factory, last_opened_size,
last_opened_entries, NULL, 2);
for (i=0; i < last_opened_size; i++)
{
widget = gtk_item_factory_get_widget (toolbox_factory,
last_opened_entries[i].path);
gtk_object_set_data (GTK_OBJECT (widget), "help_page",
(gpointer) "file/last_opened.html");
last_opened_entries[i].entry.path);
gtk_widget_hide (widget);
}
widget = gtk_item_factory_get_widget (toolbox_factory,
file_menu_separator.entry.path);
gtk_widget_hide (widget);
g_free (paths);
g_free (accelerators);
g_free (last_opened_entries);
......@@ -1106,7 +1131,7 @@ menus_init_toolbox (void)
static void
menus_init (void)
{
int i;
gint i;
if (initialize)
{
......@@ -1128,22 +1153,26 @@ menus_init (void)
NULL, 2);
load_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<Load>", NULL);
gtk_object_set_data (GTK_OBJECT (load_factory), "help_path",
(gpointer) "open");
gtk_item_factory_set_translate_func (load_factory,
menu_translate,
NULL, NULL);
gtk_item_factory_create_items_ac (load_factory,
n_load_entries,
load_entries,
NULL, 2);
menus_create_items (load_factory,
n_load_entries,
load_entries,
NULL, 2);
save_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<Save>", NULL);
gtk_object_set_data (GTK_OBJECT (save_factory), "help_path",
(gpointer) "save");
gtk_item_factory_set_translate_func (save_factory,
menu_translate,
NULL, NULL);
gtk_item_factory_create_items_ac (save_factory,
n_save_entries,
save_entries,
NULL, 2);
menus_create_items (save_factory,
n_save_entries,
save_entries,