mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
Introduce gtkaccelmapprivate.h
Move internal accel map API there and update all users. Also, add an internal function to create an accel path for an action and parameter, and use it in gtkapplication.c and gtkmodelmenuitem.c instead of duplicating that code.
This commit is contained in:
parent
f05cfd55f0
commit
2398d7e900
@ -395,6 +395,7 @@ gtk_private_h_sources = \
|
||||
gactionobserver.h \
|
||||
gactionobservable.h \
|
||||
gtkaccelgroupprivate.h \
|
||||
gtkaccelmapprivate.h \
|
||||
gtkanimationdescription.h \
|
||||
gtkappchooserprivate.h \
|
||||
gtkappchoosermodule.h \
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkaccelmap.h"
|
||||
#include "gtkaccelmapprivate.h"
|
||||
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkwindowprivate.h"
|
||||
@ -1066,3 +1066,20 @@ do_accel_map_changed (AccelEntry *entry)
|
||||
entry->accel_key,
|
||||
entry->accel_mods);
|
||||
}
|
||||
|
||||
gchar *
|
||||
_gtk_accel_path_for_action (const gchar *action_name,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GString *s;
|
||||
|
||||
s = g_string_new ("<Actions>/");
|
||||
g_string_append (s, action_name);
|
||||
if (parameter)
|
||||
{
|
||||
g_string_append_c (s, '/');
|
||||
g_variant_print_string (parameter, s, FALSE);
|
||||
}
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
|
@ -90,16 +90,6 @@ GType gtk_accel_map_get_type (void) G_GNUC_CONST;
|
||||
GtkAccelMap *gtk_accel_map_get (void);
|
||||
|
||||
|
||||
/* --- internal API --- */
|
||||
void _gtk_accel_map_init (void);
|
||||
|
||||
void _gtk_accel_map_add_group (const gchar *accel_path,
|
||||
GtkAccelGroup *accel_group);
|
||||
void _gtk_accel_map_remove_group (const gchar *accel_path,
|
||||
GtkAccelGroup *accel_group);
|
||||
gboolean _gtk_accel_path_is_valid (const gchar *accel_path);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_ACCEL_MAP_H__ */
|
||||
|
45
gtk/gtkaccelmapprivate.h
Normal file
45
gtk/gtkaccelmapprivate.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 1998, 2001 Tim Janik
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GTK_ACCEL_MAP_PRIVATE_H__
|
||||
#define __GTK_ACCEL_MAP_PRIVATE_H__
|
||||
|
||||
|
||||
#include <gtk/gtkaccelmap.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void _gtk_accel_map_init (void);
|
||||
|
||||
void _gtk_accel_map_add_group (const gchar *accel_path,
|
||||
GtkAccelGroup *accel_group);
|
||||
void _gtk_accel_map_remove_group (const gchar *accel_path,
|
||||
GtkAccelGroup *accel_group);
|
||||
gboolean _gtk_accel_path_is_valid (const gchar *accel_path);
|
||||
|
||||
gchar * _gtk_accel_path_for_action (const gchar *action_name,
|
||||
GVariant *parameter);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_ACCEL_MAP_PRIVATE_H__ */
|
@ -31,7 +31,7 @@
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkmain.h"
|
||||
#include "gtkapplicationwindow.h"
|
||||
#include "gtkaccelmap.h"
|
||||
#include "gtkaccelmapprivate.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
@ -510,23 +510,6 @@ gtk_application_get_windows (GtkApplication *application)
|
||||
return application->priv->windows;
|
||||
}
|
||||
|
||||
/* keep this in sync with gtkmodelmenuitem.c */
|
||||
static gchar *
|
||||
get_accel_path (const gchar *action_name,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GString *s;
|
||||
|
||||
s = g_string_new ("<Actions>/");
|
||||
g_string_append (s, action_name);
|
||||
if (parameter)
|
||||
{
|
||||
g_string_append_c (s, '/');
|
||||
g_variant_print_string (parameter, s, FALSE);
|
||||
}
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_application_add_accelerator:
|
||||
* @application: a #GtkApplication
|
||||
@ -572,7 +555,7 @@ gtk_application_add_accelerator (GtkApplication *application,
|
||||
return;
|
||||
}
|
||||
|
||||
accel_path = get_accel_path (action_name, parameter);
|
||||
accel_path = _gtk_accel_path_for_action (action_name, parameter);
|
||||
|
||||
if (gtk_accel_map_lookup_entry (accel_path, NULL))
|
||||
gtk_accel_map_change_entry (accel_path, accel_key, accel_mods, TRUE);
|
||||
@ -603,7 +586,7 @@ gtk_application_remove_accelerator (GtkApplication *application,
|
||||
|
||||
g_return_if_fail (GTK_IS_APPLICATION (application));
|
||||
|
||||
accel_path = get_accel_path (action_name, parameter);
|
||||
accel_path = _gtk_accel_path_for_action (action_name, parameter);
|
||||
|
||||
if (!gtk_accel_map_lookup_entry (accel_path, NULL))
|
||||
{
|
||||
|
@ -111,7 +111,7 @@
|
||||
|
||||
#include "gtkintl.h"
|
||||
|
||||
#include "gtkaccelmap.h"
|
||||
#include "gtkaccelmapprivate.h"
|
||||
#include "gtkbox.h"
|
||||
#include "gtkclipboard.h"
|
||||
#include "gtkdebug.h"
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "gtkmodelmenuitem.h"
|
||||
|
||||
#include "gtkaccelmap.h"
|
||||
#include "gtkaccelmapprivate.h"
|
||||
#include "gtkmodelmenu.h"
|
||||
|
||||
struct _GtkModelMenuItem
|
||||
@ -189,22 +189,6 @@ gtk_model_menu_item_action_removed (GActionObserver *observer,
|
||||
gtk_widget_queue_resize (GTK_WIDGET (item));
|
||||
}
|
||||
|
||||
static gchar *
|
||||
get_accel_path (const gchar *action_name,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GString *s;
|
||||
|
||||
s = g_string_new ("<Actions>/");
|
||||
g_string_append (s, action_name);
|
||||
if (parameter)
|
||||
{
|
||||
g_string_append_c (s, '/');
|
||||
g_variant_print_string (parameter, s, FALSE);
|
||||
}
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_model_menu_item_setup (GtkModelMenuItem *item,
|
||||
GMenuModel *model,
|
||||
@ -262,7 +246,7 @@ gtk_model_menu_item_setup (GtkModelMenuItem *item,
|
||||
if (state != NULL)
|
||||
g_variant_unref (state);
|
||||
|
||||
path = get_accel_path (item->action_name, item->target);
|
||||
path = _gtk_accel_path_for_action (item->action_name, item->target);
|
||||
gtk_menu_item_set_accel_path (GTK_MENU_ITEM (item), path);
|
||||
g_free (path);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <cairo-gobject.h>
|
||||
|
||||
#include "gtkcontainer.h"
|
||||
#include "gtkaccelmap.h"
|
||||
#include "gtkaccelmapprivate.h"
|
||||
#include "gtkclipboard.h"
|
||||
#include "gtkiconfactory.h"
|
||||
#include "gtkintl.h"
|
||||
|
Loading…
Reference in New Issue
Block a user