Commit 8d9a6b1b authored by Tristan Van Berkom's avatar Tristan Van Berkom

added glade_utils_hijack_key_press ()


	* gladeui/glade-utils.c: added glade_utils_hijack_key_press ()

	* src/glade-window.c: Moved hijack_key_press to glade_utils

	* gladeui/glade-editor.[ch]:
	  - Added "widget" property
	  - added glade_editor_dialog_for_widget()

	* plugins/gtk+/gtk+.xml.in, plugins/gtk+/glade-gtk.c: Added "Edit Separately" action



svn path=/trunk/; revision=2030
parent 4020dd82
......@@ -14,7 +14,17 @@
- No longer modal
- added "container" property on the editor
- dedicated dialogs self destruct if their container changes
* gladeui/glade-utils.c: added glade_utils_hijack_key_press ()
* src/glade-window.c: Moved hijack_key_press to glade_utils
* gladeui/glade-editor.[ch]:
- Added "widget" property
- added glade_editor_dialog_for_widget()
* plugins/gtk+/gtk+.xml.in, plugins/gtk+/glade-gtk.c: Added "Edit Separately" action
2008-11-12 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-utils.c: Refixed use of uninitialized variable (bug 559678).
......
......@@ -1917,29 +1917,6 @@ glade_base_editor_help (GtkButton *button, gchar *markup)
gtk_widget_destroy (dialog);
}
/* This function is meant to be attached to key-press-event of a toplevel,
* it simply allows the window contents to treat key events /before/
* accelerator keys come into play (this way widgets dont get deleted
* when cutting text in an entry etc.).
*/
static gint
hijack_key_press (GtkWindow *window,
GdkEventKey *event,
gpointer user_data)
{
if (window->focus_widget &&
(event->keyval == GDK_Delete || /* Filter Delete from accelerator keys */
((event->state & GDK_CONTROL_MASK) && /* CNTL keys... */
((event->keyval == GDK_c || event->keyval == GDK_C) || /* CNTL-C (copy) */
(event->keyval == GDK_x || event->keyval == GDK_X) || /* CNTL-X (cut) */
(event->keyval == GDK_v || event->keyval == GDK_V))))) /* CNTL-V (paste) */
{
return gtk_widget_event (window->focus_widget,
(GdkEvent *)event);
}
return FALSE;
}
/**
* glade_base_editor_pack_new_window:
* @editor: a #GladeBaseEditor
......@@ -2003,7 +1980,7 @@ glade_base_editor_pack_new_window (GladeBaseEditor *editor,
gtk_window_add_accel_group (GTK_WINDOW (window),
glade_app_get_accel_group ());
g_signal_connect (G_OBJECT (window), "key-press-event",
G_CALLBACK (hijack_key_press), NULL);
G_CALLBACK (glade_utils_hijack_key_press), NULL);
}
......
......@@ -57,7 +57,8 @@
enum
{
PROP_0,
PROP_SHOW_INFO
PROP_SHOW_INFO,
PROP_WIDGET
};
enum {
......@@ -101,6 +102,9 @@ glade_editor_set_property (GObject *object,
else
glade_editor_hide_info (editor);
break;
case PROP_WIDGET:
glade_editor_load_widget (editor, (GladeWidget *)g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -120,6 +124,9 @@ glade_editor_get_property (GObject *object,
case PROP_SHOW_INFO:
g_value_set_boolean (value, editor->show_info);
break;
case PROP_WIDGET:
g_value_set_object (value, editor->loaded_widget);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -149,6 +156,13 @@ glade_editor_class_init (GladeEditorClass *klass)
"button for the loaded widget"),
FALSE, G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_WIDGET,
g_param_spec_object ("widget",
_("Widget"),
_("The currently loaded widget in this editor"),
GLADE_TYPE_WIDGET, G_PARAM_READWRITE));
/**
* GladeEditor::gtk-doc-search:
......@@ -593,12 +607,26 @@ static void
glade_editor_close_cb (GladeProject *project,
GladeEditor *editor)
{
/* Detected project we are viewing was closed,
/* project we are viewing was closed,
* detatch from editor.
*/
glade_editor_load_widget (editor, NULL);
}
static void
glade_editor_removed_cb (GladeProject *project,
GladeWidget *widget,
GladeEditor *editor)
{
/* Widget we were viewing was removed from project,
* detatch from editor.
*/
if (widget == editor->loaded_widget)
glade_editor_load_widget (editor, NULL);
}
static void
glade_editor_load_editable (GladeEditor *editor,
GladeWidget *widget,
......@@ -658,6 +686,8 @@ glade_editor_load_widget_real (GladeEditor *editor, GladeWidget *widget)
project = glade_widget_get_project (editor->loaded_widget);
g_signal_handler_disconnect (G_OBJECT (project),
editor->project_closed_signal_id);
g_signal_handler_disconnect (G_OBJECT (project),
editor->project_removed_signal_id);
g_signal_handler_disconnect (G_OBJECT (editor->loaded_widget),
editor->widget_warning_id);
g_signal_handler_disconnect (G_OBJECT (editor->loaded_widget),
......@@ -678,6 +708,8 @@ glade_editor_load_widget_real (GladeEditor *editor, GladeWidget *widget)
gtk_widget_set_sensitive (editor->info_button, FALSE);
editor->loaded_widget = NULL;
g_object_notify (G_OBJECT (editor), "widget");
return;
}
gtk_widget_set_sensitive (editor->reset_button, TRUE);
......@@ -705,6 +737,9 @@ glade_editor_load_widget_real (GladeEditor *editor, GladeWidget *widget)
editor->project_closed_signal_id =
g_signal_connect (G_OBJECT (project), "close",
G_CALLBACK (glade_editor_close_cb), editor);
editor->project_removed_signal_id =
g_signal_connect (G_OBJECT (project), "remove-widget",
G_CALLBACK (glade_editor_removed_cb), editor);
editor->widget_warning_id =
g_signal_connect (G_OBJECT (widget), "notify::support-warning",
G_CALLBACK (glade_editor_update_class_warning_cb),
......@@ -715,6 +750,8 @@ glade_editor_load_widget_real (GladeEditor *editor, GladeWidget *widget)
editor);
gtk_container_check_resize (GTK_CONTAINER (editor));
g_object_notify (G_OBJECT (editor), "widget");
}
/**
......@@ -1273,3 +1310,60 @@ glade_editor_hide_info (GladeEditor *editor)
g_object_notify (G_OBJECT (editor), "show-info");
}
}
/**
* glade_editor_dialog_for_widget:
* @widget: a #GladeWidget
*
* This convenience function creates a new dialog window to edit @widget
* specifically.
*
* Returns: the newly created dialog window
*/
GtkWidget *
glade_editor_dialog_for_widget (GladeWidget *widget)
{
GtkWidget *window, *editor;
gchar *title, *prj_name;
g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
/* Window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
prj_name = glade_project_get_name (widget->project);
title = g_strdup_printf ("%s - %s Properties", prj_name,
glade_widget_get_name (widget));
gtk_window_set_title (GTK_WINDOW (window), title);
g_free (title);
g_free (prj_name);
if (glade_app_get_accel_group ())
{
gtk_window_add_accel_group (GTK_WINDOW (window),
glade_app_get_accel_group ());
g_signal_connect (G_OBJECT (window), "key-press-event",
G_CALLBACK (glade_utils_hijack_key_press), NULL);
}
editor = g_object_new (GLADE_TYPE_EDITOR,
"spacing", 6,
NULL);
glade_editor_load_widget (GLADE_EDITOR (editor), widget);
g_signal_connect_swapped (G_OBJECT (editor), "notify::widget",
G_CALLBACK (gtk_widget_destroy), window);
gtk_container_set_border_width (GTK_CONTAINER (editor), 6);
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (editor));
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
gtk_widget_show_all (editor);
return window;
}
......@@ -76,6 +76,8 @@ struct _GladeEditor
gulong project_closed_signal_id; /* Unload widget when widget's project closes.
*/
gulong project_removed_signal_id; /* Unload widget when its removed from the project.
*/
gulong widget_warning_id; /* Update when widget changes warning messages.
*/
gulong widget_name_id; /* Update class field when widget name changes
......@@ -130,6 +132,8 @@ GType glade_editor_get_type (void);
GladeEditor *glade_editor_new (void);
GtkWidget *glade_editor_dialog_for_widget (GladeWidget *widget);
void glade_editor_load_widget (GladeEditor *editor,
GladeWidget *widget);
......
......@@ -500,8 +500,9 @@ selection_foreach_func (GtkTreeModel *model,
GladeWidget *widget;
gtk_tree_model_get (model, iter, WIDGET_COLUMN, &widget, -1);
glade_app_selection_add (glade_widget_get_object (widget), FALSE);
if (widget)
glade_app_selection_add (glade_widget_get_object (widget), FALSE);
}
static void
......
......@@ -2266,3 +2266,38 @@ glade_utils_liststore_from_enum_type (GType enum_type,
return store;
}
/**
* glade_utils_hijack_key_press:
* @win: a #GtkWindow
* event: the GdkEventKey
* user_data: unused
*
* This function is meant to be attached to key-press-event of a toplevel,
* it simply allows the window contents to treat key events /before/
* accelerator keys come into play (this way widgets dont get deleted
* when cutting text in an entry etc.).
* Creates a liststore suitable for comboboxes and such to
* chose from a variety of types.
*
* Returns: whether the event was handled
*/
gint
glade_utils_hijack_key_press (GtkWindow *win,
GdkEventKey *event,
gpointer user_data)
{
if (win->focus_widget &&
(event->keyval == GDK_Delete || /* Filter Delete from accelerator keys */
((event->state & GDK_CONTROL_MASK) && /* CNTL keys... */
((event->keyval == GDK_c || event->keyval == GDK_C) || /* CNTL-C (copy) */
(event->keyval == GDK_x || event->keyval == GDK_X) || /* CNTL-X (cut) */
(event->keyval == GDK_v || event->keyval == GDK_V))))) /* CNTL-V (paste) */
{
return gtk_widget_event (win->focus_widget,
(GdkEvent *)event);
}
return FALSE;
}
......@@ -151,7 +151,10 @@ gchar *glade_utils_string_from_value (const GValue *value,
GtkListStore *glade_utils_liststore_from_enum_type (GType enum_type, gboolean include_empty);
gint glade_utils_hijack_key_press (GtkWindow *win,
GdkEventKey *event,
gpointer user_data);
G_END_DECLS
......
......@@ -1190,7 +1190,13 @@ glade_gtk_widget_action_activate (GladeWidgetAdaptor *adaptor,
else
gparent = NULL;
if (strcmp (action_path, "remove_parent") == 0)
if (strcmp (action_path, "edit_separate") == 0)
{
GtkWidget *dialog =
glade_editor_dialog_for_widget (gwidget);
gtk_widget_show_all (dialog);
}
else if (strcmp (action_path, "remove_parent") == 0)
{
GladeWidget *new_gparent;
......
......@@ -28,6 +28,7 @@
</signals>
<actions>
<action id="edit_separate" _name="Edit Separately" stock="gtk-edit"/>
<action id="remove_parent" _name="Remove Parent" stock="gtk-remove"/>
<action id="add_parent" _name="Add Parent" stock="gtk-add">
<action id="alignment" _name="Alignment"/>
......
......@@ -1778,29 +1778,6 @@ palette_toggle_small_icons_cb (GtkAction *action, GladeWindow *window)
gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
}
/* This function is meant to be attached to key-press-event of a toplevel,
* it simply allows the window contents to treat key events /before/
* accelerator keys come into play (this way widgets dont get deleted
* when cutting text in an entry etc.).
*/
static gint
hijack_key_press (GtkWidget *win,
GdkEventKey *event,
GladeWindow *window)
{
if (GTK_WINDOW (win)->focus_widget &&
(event->keyval == GDK_Delete || /* Filter Delete from accelerator keys */
((event->state & GDK_CONTROL_MASK) && /* CNTL keys... */
((event->keyval == GDK_c || event->keyval == GDK_C) || /* CNTL-C (copy) */
(event->keyval == GDK_x || event->keyval == GDK_X) || /* CNTL-X (cut) */
(event->keyval == GDK_v || event->keyval == GDK_V))))) /* CNTL-V (paste) */
{
return gtk_widget_event (GTK_WINDOW (win)->focus_widget,
(GdkEvent *)event);
}
return FALSE;
}
static gboolean
on_dock_deleted (GtkWidget *widget,
GdkEvent *event,
......@@ -1894,7 +1871,7 @@ toggle_dock_cb (GtkAction *action, GladeWindow *window)
gtk_ui_manager_get_accel_group (window->priv->ui));
g_signal_connect (G_OBJECT (toplevel), "key-press-event",
G_CALLBACK (hijack_key_press), window);
G_CALLBACK (glade_utils_hijack_key_press), window);
dock->detached = TRUE;
......@@ -3157,7 +3134,7 @@ glade_window_init (GladeWindow *window)
window);
g_signal_connect (G_OBJECT (window), "key-press-event",
G_CALLBACK (hijack_key_press), window);
G_CALLBACK (glade_utils_hijack_key_press), window);
/* GladeApp signals */
g_signal_connect (G_OBJECT (priv->app), "update-ui",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment