glade-app.c 38.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2001 Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * 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
20
21
22
23
24
 *
 * Authors:
 *   Naba Kumar <naba@gnome.org>
 */

#include <config.h>

25
26
27
28
29
30
31
32
33
34
/**
 * SECTION:glade-app
 * @Short_Description: The central control point of the Glade core.
 *
 * This main control object is where we try to draw the line between
 * what is the Glade core and what is the main application. The main
 * application must derive from the GladeApp object and create an instance
 * to initialize the Glade core.
 */

35
36
37
38
39
#include "glade.h"
#include "glade-clipboard-view.h"
#include "glade-debug.h"
#include "glade-cursor.h"
#include "glade-catalog.h"
40
#include "glade-fixed.h"
41
#include "glade-design-view.h"
42
#include "glade-marshallers.h"
43
#include "glade-accumulators.h"
44

45
46
47
48
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
49
#include <gdk/gdkkeysyms.h>
50
#include <gtk/gtk.h>
51

52
53
54
55
#ifdef MAC_INTEGRATION
#  include <ige-mac-integration.h>
#endif

56
57
#define GLADE_CONFIG_FILENAME "glade-3.conf"

58
59
60
61
62
#define GLADE_APP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GLADE_TYPE_APP, GladeAppPrivate))

enum
{
	UPDATE_UI,
63
	SIGNAL_EDITOR_CREATED,
64
65
66
67
68
69
	LAST_SIGNAL
};

enum
{
	PROP_0,
70
71
	PROP_ACTIVE_PROJECT,
	PROP_POINTER_MODE
72
73
74
75
};

struct _GladeAppPrivate
{
76
77
78
79
80
81
82
83
	GtkWidget *window;
	
	GladePalette *palette;         /* See glade-palette */
	GladeProject *active_project;  /* Currently active project (if there is at least one
				        * project; then this is always valid) */
	GladeEditor *editor;           /* See glade-editor */
	GladeClipboard *clipboard;     /* See glade-clipboard */
	GList *catalogs;               /* See glade-catalog */
84

85
	GList *projects; /* The list of Projects */
Tristan Van Berkom's avatar
Tristan Van Berkom committed
86
87
	
	GKeyFile *config;/* The configuration file */
88
89
90
91
92

	GtkWindow *transient_parent; /* If set by glade_app_set_transient_parent(); this
				      * will be used as the transient parent of all toplevel
				      * GladeWidgets.
				      */
93
	GtkAccelGroup *accel_group;	/* Default acceleration group for this app */
94
	GList *undo_list, *redo_list;	/* Lists of buttons to refresh in update-ui signal */
95
96

	GladePointerMode pointer_mode;  /* Current mode for the pointer in the workspace */
97
98
99
100
};

static guint glade_app_signals[LAST_SIGNAL] = { 0 };

101
102
103
104
105
106
/* installation paths */
static gchar *catalogs_dir = NULL;
static gchar *modules_dir  = NULL;
static gchar *plugins_dir  = NULL;
static gchar *pixmaps_dir  = NULL;
static gchar *locale_dir   = NULL;
107

108
109
static GladeApp *singleton_app = NULL;

110
111
static void glade_init_check (void);

112
G_DEFINE_TYPE (GladeApp, glade_app, G_TYPE_OBJECT);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
113
114


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
GType
glade_pointer_mode_get_type (void)
{
	static GType etype = 0;

	if (etype == 0) 
	{
		static const GEnumValue values[] = 
		{
			{ GLADE_POINTER_SELECT,      "select",      "Select widgets" },
			{ GLADE_POINTER_ADD_WIDGET,  "add",         "Add widgets" },
			{ GLADE_POINTER_DRAG_RESIZE, "drag-resize", "Drag and resize widgets" },
			{ 0, NULL, NULL }
		};
		etype = g_enum_register_static ("GladePointerMode", 
						values);
	}
	return etype;
}


Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
136
137
138
139
/*****************************************************************
 *                    GObjectClass                               *
 *****************************************************************/
static GObject *
140
141
142
glade_app_constructor (GType                   type,
                       guint                   n_construct_properties,
                       GObjectConstructParam  *construct_properties)
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
143
{
144
145
146
147
148
149
150
151
152
153
	GObject *object;
	
	/* singleton */
	if (!singleton_app)
	{
		object = G_OBJECT_CLASS (glade_app_parent_class)->constructor (type,
									       n_construct_properties,
									       construct_properties);
		singleton_app = GLADE_APP (object);
	}
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
154
	else
155
156
157
158
159
	{
		g_object_ref (singleton_app);
	}
	  
	return G_OBJECT (singleton_app);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
160
161
162
}


163
164
165
166

static void
glade_app_dispose (GObject *app)
{
167
	GladeAppPrivate *priv = GLADE_APP_GET_PRIVATE (app);
168
	
Tristan Van Berkom's avatar
Tristan Van Berkom committed
169
170
	if (priv->editor)
	{
171
172
173
		g_object_unref (priv->editor);
		priv->editor = NULL;
	}
Tristan Van Berkom's avatar
Tristan Van Berkom committed
174
175
	if (priv->palette)
	{
176
177
178
		g_object_unref (priv->palette);
		priv->palette = NULL;
	}
Tristan Van Berkom's avatar
Tristan Van Berkom committed
179
180
	if (priv->clipboard)
	{
181
182
183
		gtk_widget_destroy (GTK_WIDGET (priv->clipboard->view));
		priv->clipboard = NULL;
	}
184
	/* FIXME: Remove projects */
185
	
Tristan Van Berkom's avatar
Tristan Van Berkom committed
186
187
188
189
190
191
	if (priv->config)
	{
		g_key_file_free (priv->config);
		priv->config = NULL;
	}
	
192
	G_OBJECT_CLASS (glade_app_parent_class)->dispose (app);
193
194
195
196
197
}

static void
glade_app_finalize (GObject *app)
{
198
199
200
201
	g_free (catalogs_dir);
	g_free (modules_dir);
	g_free (pixmaps_dir);	
	g_free (locale_dir);
202
	
203
	glade_catalog_destroy_all ();
204

205
	G_OBJECT_CLASS (glade_app_parent_class)->finalize (app);
206
207
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
208
209
210
211
212
213
214
215
216
217
218
static void
glade_app_set_property (GObject      *object,
                        guint         property_id,
                        const GValue *value,
                        GParamSpec   *pspec)
{
	switch (property_id) 
	{
	case PROP_ACTIVE_PROJECT:
		glade_app_set_project (g_value_get_object (value));
		break;
219
220
221
	case PROP_POINTER_MODE:
		glade_app_set_pointer_mode (g_value_get_enum (value));
		break;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID
			(object, property_id, pspec);
		break;
	}
}

static void
glade_app_get_property (GObject      *object,
                        guint         property_id,
                        GValue       *value,
                        GParamSpec   *pspec)
{
	GladeApp *app = GLADE_APP (object);


	switch (property_id) 
	{
	case PROP_ACTIVE_PROJECT:
		g_value_set_object (value, app->priv->active_project);
		break;
243
244
245
	case PROP_POINTER_MODE:
		g_value_set_enum (value, app->priv->pointer_mode);
		break;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
246
247
248
249
250
251
252
253
254
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
		break;
	}
}

/*****************************************************************
 *                    GladeAppClass                              *
 *****************************************************************/
255
256
257
258
259
260
261
262
263
static void
glade_app_refresh_undo_redo_button (GladeApp *app,
				    GtkWidget *button,
				    gboolean undo)
{
	GladeCommand *command = NULL;
	GladeProject *project;
	gchar *desc;

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
264
	if ((project = glade_app_get_project ()) != NULL)
265
266
	{
		if (undo)
267
			command = glade_project_next_undo_item (project);
268
		else
269
			command = glade_project_next_redo_item (project);
270
271
272
273
274
	}

	/* Change tooltips */
	desc = g_strdup_printf ((undo) ? _("Undo: %s") : _("Redo: %s"),
			command ? command->description : _("the last action"));
275
        gtk_widget_set_tooltip_text (button, desc);
276
277
278
279
280
281
	g_free (desc);

	/* Set sensitivity on the button */
	gtk_widget_set_sensitive (button, command != NULL);
}

282
static void
283
284
285
286
287
288
289
290
291
292
293
294
295
glade_app_update_ui_default (GladeApp *app)
{
	GList *list;
	
	for (list = app->priv->undo_list; list; list = list->next)
		if (list->data)
			glade_app_refresh_undo_redo_button (app, list->data, TRUE);

	for (list = app->priv->redo_list; list; list = list->next)
		if (list->data)
			glade_app_refresh_undo_redo_button (app, list->data, FALSE);
}

296
297
298
299
300
301
static void
glade_app_signal_editor_created_default (GladeApp *app, GladeSignalEditor *signal_editor)
{
	glade_signal_editor_construct_signals_list (signal_editor);
}

302
303
304
305
306
307
308
static gboolean
clipboard_view_on_delete_cb (GtkWidget *clipboard_view, GdkEvent *e, GladeApp *app)
{
	glade_util_hide_window (GTK_WINDOW (clipboard_view));
	return TRUE;
}

Tristan Van Berkom's avatar
Tristan Van Berkom committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
static GKeyFile *
glade_app_config_load (GladeApp *app)
{
	GKeyFile *config = g_key_file_new ();
	gchar *filename;

	filename = g_build_filename (g_get_user_config_dir (), GLADE_CONFIG_FILENAME, NULL);

	g_key_file_load_from_file (config, filename, G_KEY_FILE_NONE, NULL);
	
	g_free (filename);
	
	return config;
}

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
const gchar *
glade_app_get_catalogs_dir (void)
{
	glade_init_check ();
	
	return catalogs_dir;
}

const gchar *
glade_app_get_modules_dir (void)
{
	glade_init_check ();

	return modules_dir;
}

const gchar *
glade_app_get_plugins_dir (void)
{
	glade_init_check ();

	return plugins_dir;
}


const gchar *
glade_app_get_pixmaps_dir (void)
{
	glade_init_check ();

	return pixmaps_dir;
}

const gchar *
glade_app_get_locale_dir (void)
{
	glade_init_check ();
	
	return locale_dir;
}

/* build package paths at runtime */
static void
build_package_paths (void)
{
369
#if defined (G_OS_WIN32) || (defined (MAC_INTEGRATION) && defined (MAC_BUNDLE))
370
	gchar *prefix;
371
372

# ifdef G_OS_WIN32
373
	prefix = g_win32_get_package_installation_directory_of_module (NULL);
374
375

# else // defined (MAC_INTEGRATION) && defined (MAC_BUNDLE)
376
377
378
379
380
	IgeMacBundle *bundle = ige_mac_bundle_get_default ();

	prefix = g_build_filename (ige_mac_bundle_get_path (bundle), "Contents", "Resources", NULL);
# endif 

381
382
383
384
	pixmaps_dir  = g_build_filename (prefix, "share", PACKAGE, "pixmaps", NULL);
	catalogs_dir = g_build_filename (prefix, "share", PACKAGE, "catalogs", NULL);
	modules_dir  = g_build_filename (prefix, "lib", PACKAGE, "modules", NULL);
	locale_dir   = g_build_filename (prefix, "share", "locale", NULL);
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
	g_free (prefix);
#else
	catalogs_dir = g_strdup (GLADE_CATALOGSDIR);
	modules_dir  = g_strdup (GLADE_MODULESDIR);
	plugins_dir  = g_strdup (GLADE_PLUGINSDIR);
	pixmaps_dir  = g_strdup (GLADE_PIXMAPSDIR);
	locale_dir   = g_strdup (GLADE_LOCALEDIR);
#endif
}

/* initialization function for libgladeui (not GladeApp) */
static void
glade_init_check (void)
{
	static gboolean initialised = FALSE;
	
	if (initialised)
		return;

405
406
407
	/* Make sure path accessors work on osx */
	g_type_init ();

408
409
410
411
412
413
414
415
	build_package_paths ();

	bindtextdomain (GETTEXT_PACKAGE, locale_dir);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	initialised = TRUE;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
416
417
418
419
420
static void
glade_app_init (GladeApp *app)
{
	static gboolean initialized = FALSE;
	
421
	app->priv = GLADE_APP_GET_PRIVATE (app);	
422
423

	singleton_app = app;
424
	
425
426
	glade_init_check ();	
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
427
428
	if (!initialized)
	{
Vincent Geddes's avatar
Vincent Geddes committed
429
		gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
Vincent Geddes's avatar
Vincent Geddes committed
430
						   pixmaps_dir);	
Vincent Geddes's avatar
Vincent Geddes committed
431
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
432
		glade_cursor_init ();
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
433
		
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
434
435
		initialized = TRUE;
	}
436

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
437
438
439
	app->priv->accel_group = NULL;
	
	/* Initialize app objects */
440
	app->priv->catalogs = (GList *) glade_catalog_load_all ();
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
441
442
	
	/* Create palette */
443
	app->priv->palette = (GladePalette *) glade_palette_new (app->priv->catalogs);
444
445
	g_object_ref_sink (app->priv->palette);
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
446
447
	/* Create Editor */
	app->priv->editor = GLADE_EDITOR (glade_editor_new ());
448
449
	g_object_ref_sink (GTK_OBJECT (app->priv->editor));
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
	glade_editor_refresh (app->priv->editor);
	
	/* Create clipboard */
	app->priv->clipboard = glade_clipboard_new ();
	app->priv->clipboard->view = glade_clipboard_view_new (app->priv->clipboard);
	gtk_window_set_title (GTK_WINDOW (app->priv->clipboard->view), _("Clipboard"));
	g_signal_connect_after (G_OBJECT (app->priv->clipboard->view), "delete_event",
			  G_CALLBACK (clipboard_view_on_delete_cb),
			  app);

	/* Load the configuration file */
	app->priv->config = glade_app_config_load (app);
	
	/* Undo/Redo button list */
	app->priv->undo_list = app->priv->redo_list = NULL;
}

static void
glade_app_class_init (GladeAppClass * klass)
{
	GObjectClass *object_class;
	
472
	object_class = G_OBJECT_CLASS (klass);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
473
474
475
476
477
478
479
480
	
	object_class->constructor  = glade_app_constructor;
	object_class->dispose      = glade_app_dispose;
	object_class->finalize     = glade_app_finalize;
	object_class->get_property = glade_app_get_property;
	object_class->set_property = glade_app_set_property;

	klass->update_ui_signal = glade_app_update_ui_default;
481
	klass->signal_editor_created = glade_app_signal_editor_created_default;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
482
483
484
485
486
487
488
489
490
	klass->show_properties  = NULL;
	klass->hide_properties  = NULL;

	/**
	 * GladeApp::update-ui:
	 * @gladeapp: the #GladeApp which received the signal.
	 *
	 * Emitted when a project name changes or a cut/copy/paste/delete occurred.
	 */
491
	glade_app_signals[UPDATE_UI] =
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
492
493
494
495
496
497
498
499
500
		g_signal_new ("update-ui",
			      G_TYPE_FROM_CLASS (object_class),
			      G_SIGNAL_RUN_FIRST,
			      G_STRUCT_OFFSET (GladeAppClass,
					       update_ui_signal),
			      NULL, NULL,
			      g_cclosure_marshal_VOID__VOID,
			      G_TYPE_NONE, 0);

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
	/**
	 * GladeApp::signal-editor-created:
	 * @gladeapp: the #GladeApp which received the signal.
	 * @signal_editor: the new #GladeSignalEditor.
	 *
	 * Emitted when a new signal editor created.
	 * A tree view is created in the default handler.
	 * Connect your handler before the default handler for setting a custom column or renderer
	 * and after it for connecting to the tree view signals
	 */
	glade_app_signals[SIGNAL_EDITOR_CREATED] =
		g_signal_new ("signal-editor-created",
			      G_TYPE_FROM_CLASS (object_class),
			      G_SIGNAL_RUN_LAST,
			      G_STRUCT_OFFSET (GladeAppClass,
					       signal_editor_created),
			      NULL, NULL,
			      glade_marshal_VOID__OBJECT,
			      G_TYPE_NONE, 1, G_TYPE_OBJECT);

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
521
522
523
524
525
526
527
	g_object_class_install_property 
		(object_class, PROP_ACTIVE_PROJECT,
		 g_param_spec_object 
		 ("active-project", _("Active Project"), 
		  _("The active project"),
		  GLADE_TYPE_PROJECT, G_PARAM_READWRITE));

528
529
530
531
532
533
534
535
	g_object_class_install_property 
		(object_class, PROP_POINTER_MODE,
		 g_param_spec_enum 
		 ("pointer-mode", _("Pointer Mode"), 
		  _("Current mode for the pointer in the workspace"),
		  GLADE_TYPE_POINTER_MODE,
		  GLADE_POINTER_SELECT,
		  G_PARAM_READWRITE));
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
536
	
537
	g_type_class_add_private (klass, sizeof (GladeAppPrivate));
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
}

/*****************************************************************
 *                       Public API                              *
 *****************************************************************/
static void
on_project_selection_changed_cb (GladeProject *project, GladeApp *app)
{
	GList *list;
	gint num;

	g_return_if_fail (GLADE_IS_PROJECT (project));
	g_return_if_fail (GLADE_IS_APP (app));

	/* Only update the editor if the selection has changed on
	 * the currently active project.
	 */
	if (app->priv->editor &&
	    (project == glade_app_get_project ()))
	{
		list = glade_project_selection_get (project);
		num = g_list_length (list);
		if (num == 1 && !GLADE_IS_PLACEHOLDER (list->data))
			glade_editor_load_widget (app->priv->editor,
562
						  glade_widget_get_from_gobject (list->data));
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
563
564
565
566
567
		else
			glade_editor_load_widget (app->priv->editor, NULL);
	}
}

Tristan Van Berkom's avatar
Tristan Van Berkom committed
568
569
570
/**
 * glade_app_config_save
 *
571
 * Saves the GKeyFile to "g_get_user_config_dir()/GLADE_CONFIG_FILENAME"
Tristan Van Berkom's avatar
Tristan Van Berkom committed
572
573
574
575
 *
 * Return 0 on success.
 */
gint
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
576
glade_app_config_save ()
Tristan Van Berkom's avatar
Tristan Van Berkom committed
577
{
Tristan Van Berkom's avatar
Tristan Van Berkom committed
578
579
	GIOChannel *channel;
	GIOStatus   status;
580
	gchar *data=NULL, *filename;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
581
582
	const gchar *config_dir = g_get_user_config_dir ();
	GError *error = NULL;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
583
584
	gsize size, written, bytes_written = 0;
	static gboolean error_shown = FALSE;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
585
	GladeApp *app;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
586
587
588
589

	/* If we had any errors; wait untill next session to retry.
	 */
	if (error_shown) return -1;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
590
591

	app = glade_app_get ();
Tristan Van Berkom's avatar
Tristan Van Berkom committed
592
593
	
	/* Just in case... try to create the config directory */
594
595
596
597
598
	if (g_file_test (config_dir, G_FILE_TEST_IS_DIR) == FALSE)
	{
		if (g_file_test (config_dir, G_FILE_TEST_EXISTS))
		{
			/* Config dir exists but is not a directory */
Tristan Van Berkom's avatar
Tristan Van Berkom committed
599
			glade_util_ui_message
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
600
				(glade_app_get_window(),
601
				 GLADE_UI_ERROR, NULL,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
602
603
604
605
				 _("Trying to save private data to %s directory "
				   "but it is a regular file.\n"
				   "No private data will be saved in this session"), 
				 config_dir);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
606
			error_shown = TRUE;
607
608
609
610
611
			return -1;
		}
		else if (g_mkdir (config_dir, S_IRWXU) != 0)
		{
			/* Doesnt exist; failed to create */
Tristan Van Berkom's avatar
Tristan Van Berkom committed
612
			glade_util_ui_message
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
613
				(glade_app_get_window(),
614
				 GLADE_UI_ERROR, NULL,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
615
616
				 _("Failed to create directory %s to save private data.\n"
				   "No private data will be saved in this session"), config_dir);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
617
			error_shown = TRUE;
618
619
620
621
			return -1;
		}
	} 

Tristan Van Berkom's avatar
Tristan Van Berkom committed
622
	filename = g_build_filename (config_dir, GLADE_CONFIG_FILENAME, NULL);
623
	
Tristan Van Berkom's avatar
Tristan Van Berkom committed
624
	if ((channel = g_io_channel_new_file (filename, "w", &error)) != NULL)
Tristan Van Berkom's avatar
Tristan Van Berkom committed
625
	{
Tristan Van Berkom's avatar
Tristan Van Berkom committed
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
		if ((data = g_key_file_to_data (app->priv->config, &size, &error)) != NULL)
		{
			
			/* Implement loop here */
			while ((status = g_io_channel_write_chars
				(channel, 
				 data + bytes_written, /* Offset of write */
				 size - bytes_written, /* Size left to write */
				 &written, &error)) != G_IO_STATUS_ERROR &&
			       (bytes_written + written) < size)
				bytes_written += written;

			if (status == G_IO_STATUS_ERROR)
			{
				glade_util_ui_message
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
641
					(glade_app_get_window(),
642
					 GLADE_UI_ERROR, NULL,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
643
644
645
646
647
648
649
650
651
652
					 _("Error writing private data to %s (%s).\n"
					   "No private data will be saved in this session"), 
					 filename, error->message);
				 error_shown = TRUE;
			}
			g_free (data);
		} 
		else
		{
			glade_util_ui_message
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
653
				(glade_app_get_window(),
654
				 GLADE_UI_ERROR, NULL,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
655
656
657
658
659
660
661
				 _("Error serializing configuration data to save (%s).\n"
				   "No private data will be saved in this session"), 
				 error->message);
			error_shown = TRUE;
		}
		g_io_channel_shutdown(channel, TRUE, NULL);
		g_io_channel_unref (channel);
Tristan Van Berkom's avatar
Tristan Van Berkom committed
662
	}
Tristan Van Berkom's avatar
Tristan Van Berkom committed
663
	else
Tristan Van Berkom's avatar
Tristan Van Berkom committed
664
	{
Tristan Van Berkom's avatar
Tristan Van Berkom committed
665
		glade_util_ui_message
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
666
			(glade_app_get_window(),
667
			 GLADE_UI_ERROR, NULL,
Tristan Van Berkom's avatar
Tristan Van Berkom committed
668
669
670
671
			 _("Error opening %s to write private data (%s).\n"
			   "No private data will be saved in this session"), 
			 filename, error->message);
		error_shown = TRUE;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
672
673
674
	}
	g_free (filename);
	
Tristan Van Berkom's avatar
Tristan Van Berkom committed
675
676
677
678
679
680
	if (error)
	{
		g_error_free (error);
		return -1;
	}
	return 0;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
681
682
}

683
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
684
glade_app_set_transient_parent (GtkWindow *parent)
685
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
686
687
688
	GList     *projects, *objects;
	GladeApp  *app;
	
689
690
	g_return_if_fail (GTK_IS_WINDOW (parent));

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
691
	app = glade_app_get ();
692
693
694
695
	app->priv->transient_parent = parent;

	/* Loop over all projects/widgets and set_transient_for the toplevels.
	 */
696
	for (projects = glade_app_get_projects (); /* projects */
697
	     projects; projects = projects->next) 
698
		for (objects = (GList *) glade_project_get_objects (GLADE_PROJECT (projects->data));  /* widgets */
699
700
		     objects; objects = objects->next)
			if (GTK_IS_WINDOW (objects->data))
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
701
702
				gtk_window_set_transient_for
					(GTK_WINDOW (objects->data), parent);
703
704
705
}

GtkWindow *
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
706
glade_app_get_transient_parent (void)
707
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
708
709
	GtkWindow *parent;
	GladeApp  *app = glade_app_get ();
710

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
711
	parent = app->priv->transient_parent;
712
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
713
	return parent;
714
715
716
}

GladeApp *
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
717
glade_app_get (void)
718
{
719
	if (!singleton_app)
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
720
		g_critical ("No available GladeApp");
721
	return singleton_app;
722
723
724
}

void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
725
glade_app_update_ui (void)
726
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
727
728
	GladeApp *app = glade_app_get ();

729
	g_signal_emit (G_OBJECT (app),
730
731
		       glade_app_signals[UPDATE_UI], 0);
}
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
732

733
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
734
glade_app_set_window (GtkWidget *window)
735
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
736
737
	GladeApp *app = glade_app_get ();

738
739
740
	app->priv->window = window;
}

741
742
GladeCatalog *
glade_app_get_catalog (const gchar *name)
743
{
744
745
746
747
748
	GladeApp     *app = glade_app_get ();
	GList        *list;
	GladeCatalog *catalog;

	g_return_val_if_fail (name && name[0], NULL);
749
750
751

	for (list = app->priv->catalogs; list; list = list->next)
	{
752
753
754
		catalog = list->data;
		if (!strcmp (glade_catalog_get_name (catalog), name))
			return catalog;
755
	}
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
	return NULL;
}

gboolean
glade_app_get_catalog_version (const gchar *name, gint *major, gint *minor)
{
	GladeCatalog *catalog = glade_app_get_catalog (name);

	g_return_val_if_fail (catalog != NULL, FALSE);

	if (major)
		*major = glade_catalog_get_major_version (catalog);
	if (minor)
		*minor = glade_catalog_get_minor_version (catalog);
	
	return TRUE;
772
773
774
775
776
777
778
779
780
781
782
}

GList *
glade_app_get_catalogs (void)
{
	GladeApp *app = glade_app_get ();

	return app->priv->catalogs; 
}


Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
783
784
GtkWidget *
glade_app_get_window (void)
785
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
786
	GladeApp  *app = glade_app_get ();
787
788
789
	return app->priv->window;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
790
791
GladeEditor *
glade_app_get_editor (void)
792
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
793
	GladeApp *app    = glade_app_get ();
794
795
796
	return app->priv->editor;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
797
798
GladePalette *
glade_app_get_palette (void)
799
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
800
	GladeApp *app = glade_app_get ();
801
802
803
	return app->priv->palette;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
804
805
GladeClipboard *
glade_app_get_clipboard (void)
806
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
807
	GladeApp       *app       = glade_app_get ();
808
809
810
	return app->priv->clipboard;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
811
812
GtkWidget *
glade_app_get_clipboard_view (void)
813
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
814
	GladeApp *app = glade_app_get ();
815
816
817
	return app->priv->clipboard->view;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
818
819
GladeProject *
glade_app_get_project (void)
820
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
821
	GladeApp *app = glade_app_get ();
822
823
824
	return app->priv->active_project;
}

825
826
827
828
829
830
831
832
GladeProject *
glade_app_check_get_project (void)
{
	if (singleton_app)
		return glade_app_get_project ();
	return NULL;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
833
834
GList *
glade_app_get_projects (void)
835
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
836
	GladeApp *app = glade_app_get ();
837
838
839
	return app->priv->projects;
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
840
841
GKeyFile *
glade_app_get_config (void)
Tristan Van Berkom's avatar
Tristan Van Berkom committed
842
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
843
	GladeApp *app = glade_app_get ();
Tristan Van Berkom's avatar
Tristan Van Berkom committed
844
845
846
	return app->priv->config;
}

847
gboolean
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
848
glade_app_is_project_loaded (const gchar *project_path)
849
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
850
	GladeApp *app;
851
852
	GList    *list;
	gboolean  loaded = FALSE;
853

854
855
	if (project_path == NULL)
		return FALSE;
856

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
857
858
	app = glade_app_get ();

Tristan Van Berkom's avatar
Tristan Van Berkom committed
859
860
861
	for (list = app->priv->projects; list; list = list->next)
	{
		GladeProject *cur_project = GLADE_PROJECT (list->data);
862

863
864
		if ((loaded = glade_project_get_path (cur_project) && 
		     (strcmp (glade_project_get_path (cur_project), project_path) == 0)))
865
			break;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
866
867
	}

868
	return loaded;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
869
870
}

Tristan Van Berkom's avatar
Tristan Van Berkom committed
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
/**
 * glade_app_get_project_by_path:
 * @project_path: The path of an open project
 *
 * Finds an open project with @path
 *
 * Returns: A #GladeProject, or NULL if no such open project was found
 */
GladeProject*
glade_app_get_project_by_path (const gchar *project_path)
{
	GladeApp *app;
	GList    *l;
	gchar *canonical_path;

886
887
	if (project_path == NULL)
		return NULL;
Tristan Van Berkom's avatar
Tristan Van Berkom committed
888
889
890
891
892
893
894
895
896

	app = glade_app_get ();

	canonical_path = glade_util_canonical_path (project_path);

	for (l = app->priv->projects; l; l = l->next)
	{
		GladeProject *project = (GladeProject *) l->data;

897
		if (glade_project_get_path (project) && strcmp (canonical_path, glade_project_get_path (project)) == 0) {
Tristan Van Berkom's avatar
Tristan Van Berkom committed
898
899
900
901
902
903
904
905
906
			g_free (canonical_path);
			return project;
		}
	}

	g_free (canonical_path);

	return NULL;
}
907
908

void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
909
glade_app_show_properties (gboolean raise)
910
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
911
	GladeApp  *app  = glade_app_get ();
912
913
914
915

	if (GLADE_APP_GET_CLASS (app)->show_properties)
		GLADE_APP_GET_CLASS (app)->show_properties (app, raise);
	else 
916
		g_critical ("%s not implemented\n", G_STRFUNC);
917
918
919
}

void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
920
glade_app_hide_properties (void)
921
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
922
	GladeApp  *app  = glade_app_get ();
923
924
925
926

	if (GLADE_APP_GET_CLASS (app)->hide_properties)
		GLADE_APP_GET_CLASS (app)->hide_properties (app);
	else 
927
		g_critical ("%s not implemented\n", G_STRFUNC);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
928

929
930
}

931
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
932
glade_app_update_instance_count (GladeProject *project)
933
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
934
	GladeApp  *app;
935
	GList *l;
936
	gint temp, max = 0, i = 0, uncounted_projects = 0;
937
	gchar *project_name;
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
938
939

	g_return_if_fail (GLADE_IS_PROJECT (project));
940
		
941
942
943
944
	if (glade_project_get_instance_count (project) > 0)
		return;

	project_name = glade_project_get_name (project);
945

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
946
947
	app = glade_app_get ();

948
949
	for (l = app->priv->projects; l; l = l->next)
	{
950
951
		GladeProject *prj = GLADE_PROJECT (l->data);
		gchar *name = glade_project_get_name (project);
952

953
		if (prj != project && !g_utf8_collate (name, project_name))
954
955
		{
			i++;
956
			temp = MAX (glade_project_get_instance_count (prj) + 1, i);
957
			max  = MAX (temp, max);
958

959
			if (glade_project_get_instance_count (prj) < 1)
960
				uncounted_projects++;
961
		}
962
963
		
		g_free (name);
964
	}
965
966
	
	g_free (project_name);
967
968

	/* Dont reset the initially opened project */
969
970
971
972
	if (uncounted_projects > 1 || g_list_find (app->priv->projects, project) == NULL)
	{
		glade_project_set_instance_count (project, MAX (max, i));
	}
973
}
974

Tristan Van Berkom's avatar
Tristan Van Berkom committed
975
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
976
glade_app_add_project (GladeProject *project)
Tristan Van Berkom's avatar
Tristan Van Berkom committed
977
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
978
	GladeApp  *app;
979
980
981
	GladeDesignView *view;
	GladeDesignLayout *layout;

982
983
 	g_return_if_fail (GLADE_IS_PROJECT (project));

984
985
	app = glade_app_get ();

986
	/* If the project was previously loaded, don't re-load */
987
	if (g_list_find (app->priv->projects, project) != NULL)
988
	{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
989
		glade_app_set_project (project);
Tristan Van Berkom's avatar
Tristan Van Berkom committed
990
		return;
991
	}
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
992
	glade_app_update_instance_count (project);
993
	
994
995
996
	/* Take a reference for GladeApp here... */
	app->priv->projects = g_list_append (app->priv->projects, 
					     g_object_ref (project));
997
998
999
1000
	
	/* connect to the project signals so that the editor can be updated */
	g_signal_connect (G_OBJECT (project), "selection_changed",
			  G_CALLBACK (on_project_selection_changed_cb), app);
1001

1002
	
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1003
	glade_app_set_project (project);
1004

1005
	/* Select the first window in the project */
1006
1007
1008
	if (g_list_length (app->priv->projects) == 1 ||
	    !(view = glade_design_view_get_from_project (project)) ||
	    !(layout = glade_design_view_get_layout (view)) ||
1009
	    !gtk_bin_get_child (GTK_BIN (layout)))
1010
	{
1011
		const GList *node;
1012
1013
1014
1015
1016
		for (node = glade_project_get_objects (project);
		     node != NULL;
		     node = g_list_next (node))
		{
			GObject *obj = G_OBJECT (node->data);
1017

1018
			if (GTK_IS_WINDOW (obj))
1019
1020
			{
				glade_project_selection_set (project, obj, TRUE);
1021
				glade_widget_show (glade_widget_get_from_gobject (obj));
1022
1023
				break;
			}
1024
1025
1026
		}
	}

1027
	/* XXX I think the palette & editor should detect this by itself */
1028
	gtk_widget_set_sensitive (GTK_WIDGET (app->priv->palette), TRUE);
1029
	gtk_widget_set_sensitive (GTK_WIDGET (app->priv->editor), TRUE);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1030

1031
1032
1033
}

void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1034
glade_app_remove_project (GladeProject *project)
1035
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1036
	GladeApp *app;
1037
	g_return_if_fail (GLADE_IS_PROJECT (project));
1038

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1039
1040
	app = glade_app_get ();

1041
	app->priv->projects = g_list_remove (app->priv->projects, project);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1042

1043
	/* this is needed to prevent clearing the selection of a closed project 
1044
	 */
1045
1046
1047
1048
1049
	app->priv->active_project = NULL;
	
	/* If no more projects */
	if (app->priv->projects == NULL)
	{
1050
		/* XXX I think the palette & editor should detect this. */
1051
		gtk_widget_set_sensitive (GTK_WIDGET (app->priv->palette), FALSE);
1052
1053
1054
1055
1056
1057

		/* set loaded widget to NULL first so that we dont mess
		 * around with sensitivity of the editor children.
		 */
		glade_editor_load_widget (app->priv->editor, NULL);
		gtk_widget_set_sensitive (GTK_WIDGET (app->priv->editor), FALSE);
1058
1059
	} 
	else
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1060
		glade_app_set_project (g_list_last (app->priv->projects)->data);
1061

1062
1063
1064
	/* Its safe to just release the project as the project emits a
	 * "close" signal and everyone is responsable for cleaning up at
	 * that point.
1065
1066
	 */
	g_object_unref (project);
1067
1068
}

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1069
1070
1071
1072
1073
1074
1075

/**
 * glade_app_set_project:
 * @project: A #GladeProject
 *
 * Sets the active project in the #GladeApp to @project.
 */
1076
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1077
glade_app_set_project (GladeProject *project)
1078
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1079
	GladeApp *app = glade_app_get();
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

	g_return_if_fail (GLADE_IS_PROJECT (project));

	if (app->priv->active_project == project)
		return;

	if (!g_list_find (app->priv->projects, project))
	{
		g_warning ("Could not set project because it could not "
			   " be found in the app->priv->project list\n");
		return;
	}

	/* clear the selection in the previous project */
	if (app->priv->active_project)
		glade_project_selection_clear (app->priv->active_project, FALSE);

	app->priv->active_project = project;

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1099
	/* (XXX really ?) trigger the selection changed signal to update the editor */
1100
1101
	glade_project_selection_changed (project);
	
1102
1103
1104
	/* refresh palette for active project */
	glade_palette_refresh (glade_app_get_palette ());

1105
	/* Update UI */
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1106
1107
1108
	glade_app_update_ui ();

	g_object_notify (G_OBJECT (app), "active-project");
1109
1110
}

1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143

/**
 * glade_app_set_pointer_mode:
 * @mode: A #GladePointerMode
 *
 * Sets the #GladePointerMode
 */
void
glade_app_set_pointer_mode (GladePointerMode mode)
{
	GladeApp *app = glade_app_get();

	app->priv->pointer_mode = mode;

	g_object_notify (G_OBJECT (app), "pointer-mode");
}


/**
 * glade_app_get_pointer_mode:
 *
 * Gets the current #GladePointerMode
 * 
 * Returns: The #GladePointerMode
 */
GladePointerMode
glade_app_get_pointer_mode (void)
{
	GladeApp *app = glade_app_get();

	return app->priv->pointer_mode;
}

1144
1145
1146
1147
1148
1149
1150
1151
/**
 * glade_app_command_copy:
 * @app: A #GladeApp
 *
 * Copy the active project's selection (the new copies
 * will end up on the clipboard and will be set as
 * the clipboards selection).
 */
1152
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1153
glade_app_command_copy (void)
1154
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1155
	GladeApp           *app;
1156
1157
1158
1159
	GList              *widgets = NULL, *list;
	GladeWidget        *widget;
	gboolean            failed = FALSE;

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1160
1161
1162
1163
1164
	app = glade_app_get();
	if (app->priv->active_project == NULL)
	{
		return;
	}
1165

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1166
	for (list = glade_app_get_selection ();
1167
1168
	     list && list->data; list = list->next)
	{
1169
		widget  = glade_widget_get_from_gobject (list->data);
1170
1171
1172
1173
		widgets = g_list_prepend (widgets, widget);
	}

	if (failed == FALSE && widgets != NULL)
1174
	{
1175
		glade_command_copy (widgets);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1176
		glade_app_update_ui ();
1177
	}
1178
	else if (widgets == NULL)
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1179
		glade_util_ui_message (glade_app_get_window(),
1180
				       GLADE_UI_INFO, NULL,
1181
1182
1183
				       _("No widget selected."));

	if (widgets) g_list_free (widgets);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1184

1185
1186
}

1187
1188
1189
1190
1191
1192
1193
1194
/**
 * glade_app_command_cut:
 * @app: A #GladeApp
 *
 * Cut the active project's selection (the cut objects
 * will end up on the clipboard and will be set as
 * the clipboards selection).
 */
1195
void
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1196
glade_app_command_cut (void)
1197
{
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1198
	GladeApp           *app;
1199
1200
1201
1202
	GList              *widgets = NULL, *list;
	GladeWidget        *widget;
	gboolean            failed = FALSE;

Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1203
1204
1205
1206
1207
	app = glade_app_get();
	if (app->priv->active_project == NULL)
		return;
	
	for (list = glade_app_get_selection ();
1208
	     list && list->data; list = list->next)
1209
	{
1210
		widget  = glade_widget_get_from_gobject (list->data);
1211
1212
1213
1214
1215
1216
		widgets = g_list_prepend (widgets, widget);
	}

	if (failed == FALSE && widgets != NULL)
	{
		glade_command_cut (widgets);
Tristan Van Berkom's avatar
Updated    
Tristan Van Berkom committed
1217
		glade_app_update_ui ();
1218
	}
<