Commit cd195dc91c312d686b1d29efb2c95108e9545401

  • avatar
  • Sam Thursfield <sam @dja…go.(none)>
  • Sun Jul 05 04:03:24 CEST 2009
  • Tree SHA1: fa64191
  • Parent SHA1: e68c498 ( * plugins/gtk+/glade-gtk.c: Fixed loading state of assigned GtkTreeModels of GtkCellRendererCombo)
  • raw diff | raw patch
[gsettings] Add popup menu item & glade_settings_editor dialog.
  
4444 glade-utils.c \
4545 glade-signal.c \
4646 glade-signal-editor.c \
47 glade-settings-editor.c \
4748 glade-clipboard.c \
4849 glade-clipboard-view.c \
4950 glade-command.c \
9797 glade-editor.h \
9898 glade-editor-property.h \
9999 glade-signal-editor.h \
100 glade-settings-editor.h \
100101 glade-palette.h \
101102 glade-palette-item.h \
102103 glade-design-layout.h \
  
7575{
7676 GtkWidget *window;
7777
78 GladePalette *palette; /* See glade-palette */
79 GladeProject *active_project; /* Currently active project (if there is at least one
80 * project; then this is always valid) */
81 GladeEditor *editor; /* See glade-editor */
82 GladeClipboard *clipboard; /* See glade-clipboard */
83 GList *catalogs; /* See glade-catalog */
78 GladePalette *palette; /* See glade-palette */
79 GladeProject *active_project; /* Currently active project (if there is at least one
80 * project; then this is always valid) */
81 GladeEditor *editor; /* See glade-editor */
82 GladeSettingsEditor *settings_editor; /* See glade-settings-editor */
83 GladeClipboard *clipboard; /* See glade-clipboard */
84 GList *catalogs; /* See glade-catalog */
8485
8586 GList *projects; /* The list of Projects */
8687
172172 g_object_unref (priv->editor);
173173 priv->editor = NULL;
174174 }
175 if (priv->settings_editor)
176 {
177 g_object_unref (priv->settings_editor);
178 priv->settings_editor = NULL;
179 };
175180 if (priv->palette)
176181 {
177182 g_object_unref (priv->palette);
305305 glade_signal_editor_construct_signals_list (signal_editor);
306306}
307307
308static void
309glade_app_show_settings_default (GladeApp *app, GladeWidget *widget, GladeProperty *property)
310{
311 glade_settings_editor_show (app->priv->settings_editor, widget, property);
312}
313
308314static gboolean
309315clipboard_view_on_delete_cb (GtkWidget *clipboard_view, GdkEvent *e, GladeApp *app)
310316{
458458 /* Create Editor */
459459 app->priv->editor = GLADE_EDITOR (glade_editor_new ());
460460 g_object_ref_sink (GTK_OBJECT (app->priv->editor));
461
461
462462 glade_editor_refresh (app->priv->editor);
463
463
464 /* Create Settings Connection Editor */
465 app->priv->settings_editor = GLADE_SETTINGS_EDITOR (glade_settings_editor_new ());
466 g_object_ref_sink (GTK_OBJECT (app->priv->settings_editor));
467
464468 /* Create clipboard */
465469 app->priv->clipboard = glade_clipboard_new ();
466470 app->priv->clipboard->view = glade_clipboard_view_new (app->priv->clipboard);
497497 klass->signal_editor_created = glade_app_signal_editor_created_default;
498498 klass->show_properties = NULL;
499499 klass->hide_properties = NULL;
500 klass->show_settings = glade_app_show_settings_default;
500501
501502 /**
502503 * GladeApp::update-ui:
515515 g_cclosure_marshal_VOID__VOID,
516516 G_TYPE_NONE, 0);
517517
518 /**
518 /**editor
519519 * GladeApp::signal-editor-created:
520520 * @gladeapp: the #GladeApp which received the signal.
521521 * @signal_editor: the new #GladeSignalEditor.
942942 GLADE_APP_GET_CLASS (app)->hide_properties (app);
943943 else
944944 g_critical ("%s not implemented\n", G_STRFUNC);
945
946945}
946
947/* Show dialog for binding settings to 'widget'. If 'property' is non-NULL this
948 * is intially entered or selected in the editor. */
949void
950glade_app_show_settings (GladeWidget *widget, GladeProperty *property)
951{
952 GladeApp *app = glade_app_get ();
953
954 if (GLADE_APP_GET_CLASS (app)->show_settings)
955 GLADE_APP_GET_CLASS (app)->show_settings (app, widget, property);
956 else
957 g_critical ("%s not implemented\n", G_STRFUNC);
958};
947959
948960void
949961glade_app_update_instance_count (GladeProject *project)
  
7979 void (* show_properties) (GladeApp* app,
8080 gboolean raise);
8181 void (* hide_properties) (GladeApp* app);
82 void (* show_settings) (GladeApp *app, GladeWidget *widget, GladeProperty *property);
8283
8384 /* signals */
8485 void (* update_ui_signal) (GladeApp *app);
141141
142142void glade_app_hide_properties (void);
143143
144void glade_app_show_settings (GladeWidget *widget, GladeProperty *property);
144145
146
145147void glade_app_command_copy (void);
146148
147149void glade_app_command_cut (void);
  
696696}
697697
698698static void
699glade_popup_connect_property_to_setting_cb (GtkMenuItem *item,
700 GladeProperty *property)
701{
702 glade_app_show_settings (property->widget, property);
703}
704
705static void
699706glade_popup_clear_property_cb (GtkMenuItem *item,
700707 GladeProperty *property)
701708{
750750 g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
751751
752752 popup_menu = gtk_menu_new ();
753
754 glade_popup_append_item (popup_menu, NULL, _("Connect to setting..."), NULL,
755 TRUE, glade_popup_connect_property_to_setting_cb, property);
753756
754757 glade_popup_append_item (popup_menu, GTK_STOCK_CLEAR, _("Set default value"), NULL,
755758 TRUE, glade_popup_clear_property_cb, property);
  
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2001 Ximian, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * Authors:
20 * Sam Thursfield <ssssam@gmail.com>
21 */
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26/**
27 * SECTION:glade-settings-editor
28 * @Title: GladeSettingsEditor
29 * @Short_Description: An interface to edit settings for a #GladeWidget.
30 */
31
32#include <string.h>
33#include <glib/gi18n-lib.h>
34
35#include "glade.h"
36/*#include "glade-widget.h"
37#include "glade-widget-adaptor.h"
38#include "glade-signal.h"
39#include "glade-signal-editor.h"
40#include "glade-editor.h"
41#include "glade-command.h"
42#include "glade-marshallers.h"
43#include "glade-accumulators.h"*/
44
45
46G_DEFINE_TYPE (GladeSettingsEditor, glade_settings_editor, GTK_TYPE_OBJECT)
47
48#define KEY_DEFAULT _("<Type here>")
49
50void
51glade_settings_editor_show (GladeSettingsEditor *self,
52 GladeWidget *widget,
53 GladeProperty *property)
54{
55 glade_settings_editor_set_widget (self, widget);
56 glade_settings_editor_set_property (self, property);
57
58 gtk_widget_show_all (self->dialog);
59};
60
61void
62glade_settings_editor_set_widget (GladeSettingsEditor *self,
63 GladeWidget *widget)
64{
65 if (widget == self->widget)
66 return;
67
68 // FIXME: load all bound properties into treeview
69 // should a widget keep a list of all its bound properties to save us going through
70 // each one?
71
72 self->widget = widget;
73};
74
75void
76glade_settings_editor_set_property (GladeSettingsEditor *self,
77 GladeProperty *property)
78{
79 GladePropertyClass *property_class;
80 GtkTreeIter iter;
81
82 property_class = property->klass;
83
84 if (property->widget != self->widget)
85 glade_settings_editor_set_widget (self, property->widget);
86
87 // FIXME: look for property in list
88 gtk_list_store_append (GTK_LIST_STORE (self->data), &iter);
89 // FIXME: set tooltip as klass->name
90 gtk_list_store_set (GTK_LIST_STORE (self->data), &iter,
91 GLADE_SETTINGS_EDITOR_COLUMN_PROPERTY, property_class->id,
92 GLADE_SETTINGS_EDITOR_COLUMN_KEY, KEY_DEFAULT,
93 -1);
94};
95
96static void
97dialog_response (GtkDialog *dialog)
98{
99 gtk_widget_hide (GTK_WIDGET (dialog));
100};
101
102static GObject*
103glade_settings_editor_constructor (GType type,
104 guint n_construct_properties,
105 GObjectConstructParam *construct_properties)
106{
107 GladeSettingsEditor *self;
108 GObject *retval;
109 GtkWidget *tree_view;
110 GtkCellRenderer *cell_renderer;
111 GtkTreeViewColumn *column;
112
113 retval = G_OBJECT_CLASS (glade_settings_editor_parent_class)->constructor
114 (type, n_construct_properties, construct_properties);
115 self = GLADE_SETTINGS_EDITOR (retval);
116
117 self->data = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING));
118
119 self->dialog = gtk_dialog_new_with_buttons (_("Settings connections"),
120 GTK_WINDOW (glade_app_get_window ()), 0,
121 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
122 NULL);
123
124 tree_view = gtk_tree_view_new_with_model (self->data);
125 gtk_widget_set_size_request (tree_view, 200, 200);
126
127 cell_renderer = gtk_cell_renderer_text_new ();
128 column = gtk_tree_view_column_new_with_attributes
129 (_("Property Name"), cell_renderer,
130 "text", GLADE_SETTINGS_EDITOR_COLUMN_PROPERTY,
131 NULL);
132 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
133
134 cell_renderer = gtk_cell_renderer_text_new ();
135 g_object_set (cell_renderer, "editable", TRUE, NULL);
136 column = gtk_tree_view_column_new_with_attributes
137 (_("Settings Key"), cell_renderer,
138 "text", GLADE_SETTINGS_EDITOR_COLUMN_KEY,
139 NULL);
140 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
141
142 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self->dialog))),
143 tree_view);
144
145 g_signal_connect (self->dialog, "response", G_CALLBACK (dialog_response), NULL);
146
147 return retval;
148};
149
150/**
151 * glade_settings_editor_new:
152 *
153 * Returns: a new #GladeSettingsEditor
154 */
155GladeSettingsEditor *
156glade_settings_editor_new ()
157{
158 GladeSettingsEditor *settings_editor;
159
160 settings_editor = GLADE_SETTINGS_EDITOR (g_object_new (GLADE_TYPE_SETTINGS_EDITOR,
161 NULL, NULL));
162
163 return settings_editor;
164}
165
166static void
167glade_settings_editor_finalize (GObject *object)
168{
169 //GladeSettingsEditor *self = GLADE_SETTINGS_EDITOR (object);
170
171 G_OBJECT_CLASS (glade_settings_editor_parent_class)->finalize (object);
172}
173
174static void
175glade_settings_editor_init (GladeSettingsEditor *self)
176{
177 self->widget = NULL;
178};
179
180static void
181glade_settings_editor_class_init (GladeSettingsEditorClass *klass)
182{
183 GObjectClass *object_class;
184
185 glade_settings_editor_parent_class = g_type_class_peek_parent (klass);
186 object_class = G_OBJECT_CLASS (klass);
187
188 object_class->constructor = glade_settings_editor_constructor;
189 object_class->finalize = glade_settings_editor_finalize;
190};
  
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2#ifndef __GLADE_SETTINGS_EDITOR_H__
3#define __GLADE_SETTINGS_EDITOR_H__
4
5#include <gladeui/glade.h>
6
7G_BEGIN_DECLS
8
9#define GLADE_TYPE_SETTINGS_EDITOR (glade_settings_editor_get_type ())
10#define GLADE_SETTINGS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_SETTINGS_EDITOR, GladeSettingsEditor))
11#define GLADE_SETTINGS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_SETTINGS_EDITOR, GladeSettingsEditorClass))
12#define GLADE_IS_SETTINGS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_SETTINGS_EDITOR))
13#define GLADE_IS_SETTINGS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_SETTINGS_EDITOR))
14#define GLADE_SETTINGS_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_SETTINGS_EDITOR, GladeSettingsEditorClass))
15
16typedef struct _GladeSettingsEditor GladeSettingsEditor;
17typedef struct _GladeSettingsEditorClass GladeSettingsEditorClass;
18
19enum
20{
21 GLADE_SETTINGS_EDITOR_COLUMN_PROPERTY,
22 GLADE_SETTINGS_EDITOR_COLUMN_KEY,
23 GLADE_SETTINGS_EDITOR_NUM_COLUMNS
24};
25
26/* The GladeSettingsEditor is used to house the signal editor interface and
27 * associated functionality.
28 */
29struct _GladeSettingsEditor
30{
31 GtkObject parent;
32
33 GladeWidget *widget; /* Widget currently having its properties bound */
34
35 GtkWidget *dialog;
36 GtkTreeModel *data;
37};
38
39struct _GladeSettingsEditorClass
40{
41 GtkObjectClass parent_class;
42};
43
44GType glade_settings_editor_get_type (void) G_GNUC_CONST;
45
46GladeSettingsEditor *glade_settings_editor_new ();
47
48void glade_settings_editor_show (GladeSettingsEditor *self, GladeWidget *widget,
49 GladeProperty *property);
50
51void glade_settings_editor_set_widget (GladeSettingsEditor *self, GladeWidget *widget);
52void glade_settings_editor_set_property (GladeSettingsEditor *self, GladeProperty *property);
53
54G_END_DECLS
55
56#endif /* __GLADE_SETTINGS_EDITOR_H__ */
  
3535#include <gladeui/glade-design-view.h>
3636#include <gladeui/glade-editor.h>
3737#include <gladeui/glade-editor-property.h>
38#include <gladeui/glade-settings-editor.h>
3839#include <gladeui/glade-palette.h>
3940#include <gladeui/glade-clipboard.h>
4041#include <gladeui/glade-clipboard-view.h>