summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2010-10-12 17:49:14 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2010-10-12 17:49:14 +0900
commit0b6f713fbbddbc51c556418b3145b6c46a5df23c (patch)
tree52782e750d115e017017a41c73af152376e29436 /src
parent649c798eecd2e0d3c081ac70e4b62af14f205d9f (diff)
downloadglade-0b6f713fbbddbc51c556418b3145b6c46a5df23c.tar.gz
2010-10-12 Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Implemented preview feature for Glade. * gladeui/Makefile.am, gladeui/glade-previewer.c: Added program to preview glade files. * gladeui/glade-project.[ch]: Implemented glade_project_preview() to spawn a child preview process, reap it when it dies and close all previews when project closes. * src/glade-window.c: Added toolbar button to spawn the preview. * gladeui/glade-xml-utils.[ch]: Added glade_xml_dump_from_context(). * plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Added actions to preview a widget. * gladeui/glade-app.[ch]: Added glade_app_get_bin_dir() for resolving of previewer path.
Diffstat (limited to 'src')
-rw-r--r--src/glade-window.c87
1 files changed, 85 insertions, 2 deletions
diff --git a/src/glade-window.c b/src/glade-window.c
index f88c55ef..2ddfdbc7 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -33,6 +33,8 @@
#include <gladeui/glade-popup.h>
#include <gladeui/glade-inspector.h>
+#include <gladeui/glade-project.h>
+
#include <string.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
@@ -117,6 +119,7 @@ struct _GladeWindowPrivate
gchar *default_path; /* the default path for open/save operations */
GtkToggleToolButton *selector_button; /* the widget selector button (replaces the one in the palette) */
+ GtkToolButton *preview_button; /* the project preview button (replaces the one in the palette) */
GtkToggleToolButton *drag_resize_button; /* sets the pointer to drag/resize mode */
gboolean setting_pointer_mode; /* avoid feedback signal loops */
@@ -782,6 +785,50 @@ on_selector_button_toggled (GtkToggleToolButton *button, GladeWindow *window)
}
static void
+on_preview_button_clicked (GtkToggleToolButton *button, GladeWindow *window)
+{
+ GladeProject *project;
+
+ const GList *objects;
+
+ GtkWidget *widget = NULL;
+ GtkWidget *window_to_preview = NULL;
+ GladeWidget *glade_widget = NULL;
+
+ project = glade_design_view_get_project (window->priv->active_view);
+
+ if (project == NULL)
+ return;
+
+ objects = glade_project_get_objects (project);
+
+ while (objects != NULL)
+ {
+ if (GTK_IS_WIDGET (objects->data))
+ {
+ widget = GTK_WIDGET(objects->data);
+ if (GTK_IS_WINDOW (widget))
+ {
+ window_to_preview = widget;
+ break;
+ }
+ }
+ objects = objects->next;
+ }
+
+ if (widget != NULL)
+ {
+ glade_widget = glade_widget_get_from_gobject (G_OBJECT (widget));
+ }
+
+ if (window_to_preview != NULL) widget = window_to_preview;
+ glade_project_preview (project,
+ glade_widget_get_from_gobject((gpointer)widget)
+ );
+}
+
+
+static void
on_drag_resize_button_toggled (GtkToggleToolButton *button, GladeWindow *window)
{
if (window->priv->setting_pointer_mode)
@@ -2355,6 +2402,24 @@ create_selector_tool_button (GtkToolbar *toolbar)
}
static GtkWidget *
+create_preview_tool_button (GtkToolbar *toolbar)
+{
+ GtkToolItem *button;
+ button = gtk_tool_button_new_from_stock (GTK_STOCK_EXECUTE);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON(button), _("Preview snapshot"));
+
+ gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (button),
+ toolbar->tooltips,
+ _("Previews snapshot of project"),
+ NULL);
+
+ gtk_widget_show (GTK_WIDGET (button));
+
+ return GTK_WIDGET (button);
+}
+
+
+static GtkWidget *
create_drag_resize_tool_button (GtkToolbar *toolbar)
{
GtkToolItem *button;
@@ -2466,6 +2531,10 @@ add_project (GladeWindow *window, GladeProject *project)
/* Kick the inspector in the balls here... */
glade_project_selection_changed (project);
+
+ /* Update preview button */
+ gtk_widget_set_sensitive ( GTK_WIDGET (window->priv->preview_button),
+ glade_project_get_previewable (project));
}
void
@@ -2704,9 +2773,15 @@ refresh_undo_redo (GladeWindow *window)
static void
update_ui (GladeApp *app, GladeWindow *window)
-{
+{
+ GladeProject *project;
if (window->priv->active_view)
+ {
+ project = glade_design_view_get_project (window->priv->active_view);
+ gtk_widget_set_sensitive ( GTK_WIDGET (window->priv->preview_button),
+ glade_project_get_previewable (project));
gtk_widget_queue_draw (GTK_WIDGET (window->priv->active_view));
+ }
refresh_undo_redo (window);
@@ -3267,10 +3342,16 @@ glade_window_init (GladeWindow *window)
gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), GTK_TOOL_ITEM (sep), -1);
priv->selector_button =
- GTK_TOGGLE_TOOL_BUTTON (create_selector_tool_button (GTK_TOOLBAR (priv->toolbar)));
+ GTK_TOGGLE_TOOL_BUTTON (create_selector_tool_button (GTK_TOOLBAR (priv->toolbar)));
gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar),
GTK_TOOL_ITEM (priv->selector_button), -1);
+ priv->preview_button =
+ GTK_TOOL_BUTTON (create_preview_tool_button (GTK_TOOLBAR (priv->toolbar)));
+ gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar),
+ GTK_TOOL_ITEM (priv->preview_button), -1);
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->preview_button), FALSE);
+
priv->drag_resize_button =
GTK_TOGGLE_TOOL_BUTTON (create_drag_resize_tool_button
(GTK_TOOLBAR (priv->toolbar)));
@@ -3282,6 +3363,8 @@ glade_window_init (GladeWindow *window)
g_signal_connect (G_OBJECT (priv->selector_button), "toggled",
G_CALLBACK (on_selector_button_toggled), window);
+ g_signal_connect (G_OBJECT (priv->preview_button), "clicked",
+ G_CALLBACK (on_preview_button_clicked), window);
g_signal_connect (G_OBJECT (priv->drag_resize_button), "toggled",
G_CALLBACK (on_drag_resize_button_toggled), window);
g_signal_connect (G_OBJECT (glade_app_get()), "notify::pointer-mode",