Updated Spanish translation
[anjuta-git-plugin.git] / plugins / glade / anjuta-design-document.c
blobd7ec87ed0448ea76b33c2f4e4e5361c35530949b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) Johannes Schmid 2007 <jhs@gnome.org>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "anjuta-design-document.h"
27 #include <libanjuta/anjuta-debug.h>
28 #include <libanjuta/interfaces/ianjuta-file.h>
29 #include <libanjuta/interfaces/ianjuta-file-savable.h>
30 #include <libanjuta/interfaces/ianjuta-document.h>
32 #include <libgnomevfs/gnome-vfs-utils.h>
34 enum
36 PROP_0,
37 PROP_PLUGIN
40 struct _AnjutaDesignDocumentPrivate
42 GladePlugin* glade_plugin;
45 #define ADD_GET_PRIVATE(o) \
46 (G_TYPE_INSTANCE_GET_PRIVATE ((o), ANJUTA_TYPE_DESIGN_DOCUMENT, AnjutaDesignDocumentPrivate))
48 static void
49 anjuta_design_document_instance_init (AnjutaDesignDocument *object)
54 static void
55 anjuta_design_document_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
57 g_return_if_fail (ANJUTA_IS_DESIGN_DOCUMENT (object));
58 AnjutaDesignDocumentPrivate* priv = ADD_GET_PRIVATE(object);
60 switch (prop_id)
62 case PROP_PLUGIN:
63 priv->glade_plugin = g_value_get_object(value);
64 break;
65 default:
66 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
67 break;
71 static void
72 anjuta_design_document_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
74 g_return_if_fail (ANJUTA_IS_DESIGN_DOCUMENT (object));
77 switch (prop_id)
79 default:
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
81 break;
85 static void
86 anjuta_design_document_class_init (AnjutaDesignDocumentClass *klass)
88 GObjectClass* object_class = G_OBJECT_CLASS (klass);
90 object_class->set_property = anjuta_design_document_set_property;
91 object_class->get_property = anjuta_design_document_get_property;
93 g_type_class_add_private (klass, sizeof(ANJUTA_TYPE_DESIGN_DOCUMENT));
95 g_object_class_install_property (object_class,
96 PROP_PLUGIN,
97 g_param_spec_object ("plugin",
98 "",
99 "",
100 G_TYPE_OBJECT,
101 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
104 GtkWidget*
105 anjuta_design_document_new (GladePlugin* glade_plugin, GladeProject* project)
107 return GTK_WIDGET(g_object_new(ANJUTA_TYPE_DESIGN_DOCUMENT,
108 "plugin", glade_plugin,
109 "project", project,
110 NULL));
113 static void ifile_open(IAnjutaFile* file, const gchar* uri, GError **e)
115 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(file);
116 AnjutaDesignDocumentPrivate* priv = ADD_GET_PRIVATE(self);
118 ianjuta_file_open(IANJUTA_FILE(priv->glade_plugin), uri, e);
121 static gchar* ifile_get_uri(IAnjutaFile* file, GError **e)
123 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(file);
125 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
127 #if (GLADEUI_VERSION >= 330)
128 const gchar* path = glade_project_get_path(project);
129 if (path != NULL)
130 return gnome_vfs_get_uri_from_local_path(path);
131 else
132 return NULL;
133 #else
134 if (project && project->path)
135 return gnome_vfs_get_uri_from_local_path(project->path);
136 else
137 return NULL;
138 #endif
142 static void
143 ifile_iface_init(IAnjutaFileIface *iface)
145 iface->open = ifile_open;
146 iface->get_uri = ifile_get_uri;
149 static void ifile_savable_save (IAnjutaFileSavable* file, GError **e)
151 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(file);
152 AnjutaDesignDocumentPrivate* priv = ADD_GET_PRIVATE(self);
154 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
156 #if (GLADEUI_VERSION >= 330)
157 if (glade_project_get_path(project) != NULL) {
158 #else
159 if (project && project->path != NULL) {
160 #endif
161 AnjutaStatus *status;
163 status = anjuta_shell_get_status (ANJUTA_PLUGIN(priv->glade_plugin)->shell, NULL);
165 #if (GLADEUI_VERSION >= 330)
166 if (glade_project_save (project, glade_project_get_path(project),
167 NULL)) {
168 anjuta_status_set (status, _("Glade project '%s' saved"),
169 glade_project_get_name(project));
170 #else
171 if (glade_project_save (project, project->path, NULL)) {
172 anjuta_status_set (status, _("Glade project '%s' saved"),
173 project->name);
174 #endif
175 g_signal_emit_by_name(G_OBJECT(self), "save_point", TRUE);
177 else
179 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN(priv->glade_plugin)->shell),
180 _("Invalid glade file name"));
182 return;
184 DEBUG_PRINT("Invalid use of ifile_savable_save!");
187 static void ifile_savable_save_as(IAnjutaFileSavable* file, const gchar* uri, GError **e)
189 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(file);
190 AnjutaDesignDocumentPrivate* priv = ADD_GET_PRIVATE(self);
192 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
194 AnjutaStatus *status = anjuta_shell_get_status (ANJUTA_PLUGIN(priv->glade_plugin)->shell, NULL);
196 #if (GLADEUI_VERSION >= 330)
197 if (glade_project_save (project, gnome_vfs_get_local_path_from_uri(uri),
198 NULL))
200 anjuta_status_set (status, _("Glade project '%s' saved"),
201 glade_project_get_name(project));
202 #else
203 if (glade_project_save (project, gnome_vfs_get_local_path_from_uri(uri), NULL))
205 anjuta_status_set (status, _("Glade project '%s' saved"),
206 project->name);
207 #endif
208 g_signal_emit_by_name(G_OBJECT(self), "save_point", TRUE);
210 else
212 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN(priv->glade_plugin)->shell),
213 _("Invalid glade file name"));
215 return;
218 static void ifile_savable_set_dirty(IAnjutaFileSavable* file, gboolean dirty, GError **e)
220 /* FIXME */
223 static gboolean ifile_savable_is_dirty(IAnjutaFileSavable* file, GError **e)
225 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(file);
227 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
228 if (project == NULL)
229 return FALSE;
230 #if (GLADEUI_VERSION >= 330)
231 # if (GLADEUI_VERSION >= 331)
232 if (glade_project_get_modified (project))
233 # else
234 if (glade_project_get_has_unsaved_changes (project))
235 # endif
236 #else
237 if (project->changed)
238 #endif
240 return TRUE;
242 else
244 return FALSE;
248 static void
249 ifile_savable_iface_init(IAnjutaFileSavableIface *iface)
251 iface->save = ifile_savable_save;
252 iface->save_as = ifile_savable_save_as;
253 iface->set_dirty = ifile_savable_set_dirty;
254 iface->is_dirty = ifile_savable_is_dirty;
257 /* Return true if editor can redo */
258 static gboolean idocument_can_redo(IAnjutaDocument *editor, GError **e)
260 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(editor);
261 #if (GLADEUI_VERSION >= 330)
262 GladeCommand *redo_item;
263 #else
264 GList *prev_redo_item;
265 GList *redo_item;
266 #endif
267 const gchar *redo_description = NULL;
269 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
270 if (!project)
272 redo_item = NULL;
274 else
276 #if (GLADEUI_VERSION >= 330)
277 redo_item = glade_project_next_redo_item(project);
278 if (redo_item)
279 redo_description = redo_item->description;
280 #else
281 prev_redo_item = project->prev_redo_item;
282 redo_item = (prev_redo_item == NULL) ? project->undo_stack : prev_redo_item->next;
283 if (redo_item && redo_item->data)
284 redo_description = GLADE_COMMAND (redo_item->data)->description;
285 #endif
287 return (redo_description != NULL);
290 /* Return true if editor can undo */
291 static gboolean idocument_can_undo(IAnjutaDocument *editor, GError **e)
293 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(editor);
294 #if (GLADEUI_VERSION >= 330)
295 GladeCommand *undo_item;
296 #else
297 GList *prev_redo_item;
298 GList *undo_item;
299 #endif
300 const gchar *undo_description = NULL;
301 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
302 if (!project)
304 undo_item = NULL;
306 else
308 #if (GLADEUI_VERSION >= 330)
309 undo_item = glade_project_next_undo_item(project);
310 if (undo_item)
311 undo_description = undo_item->description;
312 #else
313 undo_item = prev_redo_item = project->prev_redo_item;
314 if (undo_item && undo_item->data)
315 undo_description = GLADE_COMMAND (undo_item->data)->description;
316 #endif
318 return (undo_description != NULL);
321 /* Return true if editor can undo */
322 static void idocument_begin_undo_action (IAnjutaDocument *editor, GError **e)
324 /* FIXME */
327 /* Return true if editor can undo */
328 static void idocument_end_undo_action (IAnjutaDocument *editor, GError **e)
330 /* FIXME */
334 static void
335 idocument_undo(IAnjutaDocument* edit, GError** ee)
337 glade_app_command_undo();
340 static void
341 idocument_redo(IAnjutaDocument* edit, GError** ee)
343 glade_app_command_redo();
346 /* Grab focus */
347 static void idocument_grab_focus (IAnjutaDocument *editor, GError **e)
349 gtk_widget_grab_focus (GTK_WIDGET(editor));
352 /* Return the opened filename */
353 static const gchar* idocument_get_filename(IAnjutaDocument *editor, GError **e)
355 AnjutaDesignDocument* self = ANJUTA_DESIGN_DOCUMENT(editor);
356 GladeProject* project = glade_design_view_get_project(GLADE_DESIGN_VIEW(self));
357 #if (GLADEUI_VERSION >= 330)
358 return glade_project_get_name(project);
359 #else
360 if (project)
361 return project->name;
362 else
363 return "Glade";
364 #endif
367 static void
368 idocument_cut(IAnjutaDocument* edit, GError** ee)
370 glade_app_command_cut();
373 static void
374 idocument_copy(IAnjutaDocument* edit, GError** ee)
376 glade_app_command_copy();
379 static void
380 idocument_paste(IAnjutaDocument* edit, GError** ee)
382 glade_app_command_paste(NULL);
385 static void
386 idocument_clear(IAnjutaDocument* edit, GError** ee)
388 glade_app_command_delete();
392 static void
393 idocument_iface_init (IAnjutaDocumentIface *iface)
395 iface->grab_focus = idocument_grab_focus;
396 iface->get_filename = idocument_get_filename;
397 iface->can_undo = idocument_can_undo;
398 iface->can_redo = idocument_can_redo;
399 iface->begin_undo_action = idocument_begin_undo_action;
400 iface->end_undo_action = idocument_end_undo_action;
401 iface->undo = idocument_undo;
402 iface->redo = idocument_redo;
403 iface->cut = idocument_cut;
404 iface->copy = idocument_copy;
405 iface->paste = idocument_paste;
406 iface->clear = idocument_clear;
409 ANJUTA_TYPE_BEGIN (AnjutaDesignDocument, anjuta_design_document, GLADE_TYPE_DESIGN_VIEW);
410 ANJUTA_TYPE_ADD_INTERFACE(idocument, IANJUTA_TYPE_DOCUMENT);
411 ANJUTA_TYPE_ADD_INTERFACE(ifile, IANJUTA_TYPE_FILE);
412 ANJUTA_TYPE_ADD_INTERFACE(ifile_savable, IANJUTA_TYPE_FILE_SAVABLE);
413 ANJUTA_TYPE_END;