[glade3] * gladeui/glade-project.c: Added "parse-began" signal
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade3] * gladeui/glade-project.c: Added "parse-began" signal
- Date: Wed, 22 Dec 2010 08:08:51 +0000 (UTC)
commit 3f04cb3e4deb60b2bbb3c8db1506e94a61e75006
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Wed Dec 22 17:13:41 2010 +0900
* gladeui/glade-project.c: Added "parse-began" signal
* gladeui/glade-design-view.c: Hide workspace and show load progress
while loading so that one cannot access project widgets during the load
(insensitive workspace was problematic and causing some loaded project
windows to be permanently insensitive).
* src/glade-window.c: Avoid any messups during project load, cannot close
projects while they are loading, etc.
ChangeLog | 10 ++++
gladeui/glade-design-view.c | 77 +++++++++++++++++++++++++++++----
gladeui/glade-project.c | 35 +++++++++++++--
gladeui/glade-utils.c | 97 ++++++++++++++++++++++--------------------
gladeui/glade-utils.h | 4 +-
src/glade-window.c | 94 +++++++++++++----------------------------
6 files changed, 190 insertions(+), 127 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0e3bff5..5f26e2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,16 @@
* src/glade-window.c: Added load progressbar to notebook tabs.
+ * gladeui/glade-project.c: Added "parse-began" signal
+
+ * gladeui/glade-design-view.c: Hide workspace and show load progress
+ while loading so that one cannot access project widgets during the load
+ (insensitive workspace was problematic and causing some loaded project
+ windows to be permanently insensitive).
+
+ * src/glade-window.c: Avoid any messups during project load, cannot close
+ projects while they are loading, etc.
+
2010-12-21 Tristan Van Berkom <tristanvb openismus com>
Added loading objects dialog with progress and cancel.
diff --git a/gladeui/glade-design-view.c b/gladeui/glade-design-view.c
index e7689f9..d50052f 100644
--- a/gladeui/glade-design-view.c
+++ b/gladeui/glade-design-view.c
@@ -57,6 +57,11 @@ struct _GladeDesignViewPrivate
GtkWidget *layout;
GladeProject *project;
+
+ GtkWidget *scrolled_window;
+
+ GtkWidget *progress;
+ GtkWidget *progress_window;
};
static GtkVBoxClass *parent_class = NULL;
@@ -64,15 +69,53 @@ static GtkVBoxClass *parent_class = NULL;
G_DEFINE_TYPE(GladeDesignView, glade_design_view, GTK_TYPE_VBOX)
+
+static void
+glade_design_view_parse_began (GladeProject *project,
+ GladeDesignView *view)
+{
+ gtk_widget_hide (view->priv->scrolled_window);
+ gtk_widget_show (view->priv->progress_window);
+}
+
+static void
+glade_design_view_parse_finished (GladeProject *project,
+ GladeDesignView *view)
+{
+ gtk_widget_hide (view->priv->progress_window);
+ gtk_widget_show (view->priv->scrolled_window);
+}
+
+static void
+glade_design_view_load_progress (GladeProject *project,
+ gint total,
+ gint step,
+ GladeDesignView *view)
+{
+ gchar *path;
+ gchar *str;
+
+ path = glade_utils_replace_home_dir_with_tilde (glade_project_get_path (project));
+ str = g_strdup_printf (_("Loading %s: loaded %d of %d objects"), path, step, total);
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (view->priv->progress), str);
+ g_free (str);
+ g_free (path);
+
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (view->priv->progress), step * 1.0 / total);
+}
+
static void
glade_design_view_set_project (GladeDesignView *view, GladeProject *project)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
view->priv->project = project;
-
- g_object_set_data (G_OBJECT (view->priv->project), GLADE_DESIGN_VIEW_KEY, view);
+ g_signal_connect (project, "parse-began", G_CALLBACK (glade_design_view_parse_began), view);
+ g_signal_connect (project, "parse-finished", G_CALLBACK (glade_design_view_parse_finished), view);
+ g_signal_connect (project, "load-progress", G_CALLBACK (glade_design_view_load_progress), view);
+
+ g_object_set_data (G_OBJECT (view->priv->project), GLADE_DESIGN_VIEW_KEY, view);
}
static void
@@ -112,28 +155,42 @@ glade_design_view_get_property (GObject *object,
static void
glade_design_view_init (GladeDesignView *view)
{
- GtkWidget *sw;
- GtkWidget *viewport;
+ GtkWidget *viewport, *filler;
view->priv = GLADE_DESIGN_VIEW_GET_PRIVATE (view);
view->priv->project = NULL;
view->priv->layout = glade_design_layout_new ();
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
+ view->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->priv->scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->priv->scrolled_window),
+ GTK_SHADOW_IN);
viewport = gtk_viewport_new (NULL, NULL);
gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
gtk_container_add (GTK_CONTAINER (viewport), view->priv->layout);
- gtk_container_add (GTK_CONTAINER (sw), viewport);
+ gtk_container_add (GTK_CONTAINER (view->priv->scrolled_window), viewport);
- gtk_widget_show (sw);
+ gtk_widget_show (view->priv->scrolled_window);
gtk_widget_show (viewport);
gtk_widget_show (view->priv->layout);
- gtk_box_pack_start (GTK_BOX (view), sw, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (view), view->priv->scrolled_window, TRUE, TRUE, 0);
+
+ /* The progress window */
+ view->priv->progress_window = gtk_vbox_new (FALSE, 0);
+ filler = gtk_label_new (NULL);
+ gtk_widget_show (filler);
+ gtk_box_pack_start (GTK_BOX (view->priv->progress_window), filler, TRUE, TRUE, 0);
+ view->priv->progress = gtk_progress_bar_new ();
+ gtk_widget_show (view->priv->progress);
+ gtk_box_pack_start (GTK_BOX (view->priv->progress_window), view->priv->progress, FALSE, TRUE, 0);
+ filler = gtk_label_new (NULL);
+ gtk_widget_show (filler);
+ gtk_box_pack_start (GTK_BOX (view->priv->progress_window), filler, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (view), view->priv->progress_window, TRUE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (view), 0);
}
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 7ab7b37..a778f4c 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -61,7 +61,8 @@ enum
SELECTION_CHANGED,
CLOSE,
CHANGED,
- PARSE_FINISHED,
+ PARSE_BEGAN,
+ PARSE_FINISHED,
CONVERT_FINISHED,
TARGETS_CHANGED,
LOAD_PROGRESS,
@@ -874,6 +875,21 @@ glade_project_class_init (GladeProjectClass *klass)
GLADE_TYPE_COMMAND, G_TYPE_BOOLEAN);
/**
+ * GladeProject::parse-began:
+ * @gladeproject: the #GladeProject which received the signal.
+ *
+ * Emitted when @gladeproject parsing starts.
+ */
+ glade_project_signals[PARSE_BEGAN] =
+ g_signal_new ("parse-began",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ /**
* GladeProject::parse-finished:
* @gladeproject: the #GladeProject which received the signal.
*
@@ -1527,6 +1543,8 @@ glade_project_load_internal (GladeProject *project)
return FALSE;
}
+ project->priv->mtime = glade_util_get_file_mtime (project->priv->path, NULL);
+
doc = glade_xml_context_get_doc (context);
root = glade_xml_doc_get_root (doc);
@@ -1542,6 +1560,9 @@ glade_project_load_internal (GladeProject *project)
return FALSE;
}
+ /* Emit "parse-began" signal */
+ g_signal_emit (project, glade_project_signals [PARSE_BEGAN], 0);
+
/* XXX Need to load project->priv->comment ! */
glade_project_read_comment (project, doc);
@@ -1591,8 +1612,6 @@ glade_project_load_internal (GladeProject *project)
if (glade_util_file_is_writeable (project->priv->path) == FALSE)
glade_project_set_readonly (project, TRUE);
- project->priv->mtime = glade_util_get_file_mtime (project->priv->path, NULL);
-
/* Reset project status here too so that you get a clean
* slate after calling glade_project_open().
*/
@@ -1604,15 +1623,16 @@ glade_project_load_internal (GladeProject *project)
*/
glade_project_fix_object_props (project);
-
/* Emit "parse-finished" signal */
g_signal_emit (project, glade_project_signals [PARSE_FINISHED], 0);
-
/* Update ui with versioning info
*/
glade_project_verify_project_for_ui (project);
+ /* Update various things in the UI */
+ glade_app_update_ui ();
+
return TRUE;
}
@@ -1921,6 +1941,11 @@ glade_project_save (GladeProject *project, const gchar *path, GError **error)
gchar *canonical_path;
gint ret;
+ g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
+
+ if (glade_project_is_loading (project))
+ return FALSE;
+
if (!glade_project_verify (project, TRUE))
return FALSE;
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 0f08b1d..aa928c2 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -2201,52 +2201,6 @@ glade_utils_hijack_key_press (GtkWindow *win,
}
-/* copied from gedit */
-gchar *
-glade_utils_replace_home_dir_with_tilde (const gchar *uri)
-{
- gchar *tmp;
- gchar *home;
-
- g_return_val_if_fail (uri != NULL, NULL);
-
- /* Note that g_get_home_dir returns a const string */
- tmp = (gchar *)g_get_home_dir ();
-
- if (tmp == NULL)
- return g_strdup (uri);
-
- home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
- if (home == NULL)
- return g_strdup (uri);
-
- if (strcmp (uri, home) == 0)
- {
- g_free (home);
-
- return g_strdup ("~");
- }
-
- tmp = home;
- home = g_strdup_printf ("%s/", tmp);
- g_free (tmp);
-
- if (g_str_has_prefix (uri, home))
- {
- gchar *res;
-
- res = g_strdup_printf ("~/%s", uri + strlen (home));
-
- g_free (home);
-
- return res;
- }
-
- g_free (home);
-
- return g_strdup (uri);
-}
-
void
glade_utils_cairo_draw_line (cairo_t *cr,
@@ -2291,3 +2245,54 @@ glade_utils_cairo_draw_rectangle (cairo_t *cr,
cairo_stroke (cr);
}
}
+
+
+/* copied from gedit */
+gchar *
+glade_utils_replace_home_dir_with_tilde (const gchar *path)
+{
+#ifdef G_OS_UNIX
+ gchar *tmp;
+ gchar *home;
+
+ g_return_val_if_fail (path != NULL, NULL);
+
+ /* Note that g_get_home_dir returns a const string */
+ tmp = (gchar *) g_get_home_dir ();
+
+ if (tmp == NULL)
+ return g_strdup (path);
+
+ home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
+ if (home == NULL)
+ return g_strdup (path);
+
+ if (strcmp (path, home) == 0)
+ {
+ g_free (home);
+
+ return g_strdup ("~");
+ }
+
+ tmp = home;
+ home = g_strdup_printf ("%s/", tmp);
+ g_free (tmp);
+
+ if (g_str_has_prefix (path, home))
+ {
+ gchar *res;
+
+ res = g_strdup_printf ("~/%s", path + strlen (home));
+
+ g_free (home);
+
+ return res;
+ }
+
+ g_free (home);
+
+ return g_strdup (path);
+#else
+ return g_strdup (path);
+#endif
+}
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index 0d1b1e5..104a5c8 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -155,8 +155,6 @@ gint glade_utils_hijack_key_press (GtkWindow *win,
gpointer user_data);
-gchar *glade_utils_replace_home_dir_with_tilde (const gchar *uri);
-
void glade_utils_cairo_draw_line (cairo_t *cr,
GdkColor *color,
gint x1,
@@ -173,6 +171,8 @@ void glade_utils_cairo_draw_rectangle (cairo_t *cr,
gint width,
gint height);
+gchar *glade_utils_replace_home_dir_with_tilde (const gchar *path);
+
G_END_DECLS
#endif /* __GLADE_UTILS_H__ */
diff --git a/src/glade-window.c b/src/glade-window.c
index a86ce53..a72d21d 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -283,54 +283,6 @@ get_formatted_project_name_for_display (GladeProject *project, FormatNameFlags f
return pass3;
}
-static gchar *
-replace_home_dir_with_tilde (const gchar *path)
-{
-#ifdef G_OS_UNIX
- gchar *tmp;
- gchar *home;
-
- g_return_val_if_fail (path != NULL, NULL);
-
- /* Note that g_get_home_dir returns a const string */
- tmp = (gchar *) g_get_home_dir ();
-
- if (tmp == NULL)
- return g_strdup (path);
-
- home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
- if (home == NULL)
- return g_strdup (path);
-
- if (strcmp (path, home) == 0)
- {
- g_free (home);
-
- return g_strdup ("~");
- }
-
- tmp = home;
- home = g_strdup_printf ("%s/", tmp);
- g_free (tmp);
-
- if (g_str_has_prefix (path, home))
- {
- gchar *res;
-
- res = g_strdup_printf ("~/%s", path + strlen (home));
-
- g_free (home);
-
- return res;
- }
-
- g_free (home);
-
- return g_strdup (path);
-#else
- return g_strdup (path);
-#endif
-}
static void
refresh_title (GladeWindow *window)
@@ -555,7 +507,7 @@ format_project_list_item_tooltip (GladeProject *project)
if (glade_project_get_path (project))
{
- path = replace_home_dir_with_tilde (glade_project_get_path (project));
+ path = glade_utils_replace_home_dir_with_tilde (glade_project_get_path (project));
if (glade_project_get_readonly (project))
{
@@ -1120,6 +1072,22 @@ open_cb (GtkAction *action, GladeWindow *window)
g_free (path);
}
+static gboolean
+check_loading_project_for_save (GladeProject *project)
+{
+ if (glade_project_is_loading (project))
+ {
+ gchar *name = glade_project_get_name (project);
+
+ glade_util_ui_message (glade_app_get_window(),
+ GLADE_UI_INFO, NULL,
+ _("Project %s is still loading."), name);
+ g_free (name);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static void
save (GladeWindow *window, GladeProject *project, const gchar *path)
{
@@ -1130,6 +1098,9 @@ save (GladeWindow *window, GladeProject *project, const gchar *path)
GtkWidget *button;
gint response;
+ if (check_loading_project_for_save (project))
+ return;
+
/* check for external modification to the project file */
mtime = glade_util_get_file_mtime (glade_project_get_path (project), NULL);
@@ -1221,6 +1192,9 @@ save_as (GladeWindow *window)
if (project == NULL)
return;
+ if (check_loading_project_for_save (project))
+ return;
+
filechooser = glade_util_file_dialog_new (_("Save As\342\200\246"), project,
GTK_WINDOW (window),
GLADE_FILE_DIALOG_ACTION_SAVE);
@@ -2494,15 +2468,12 @@ project_load_progress_cb (GladeProject *project,
gint step,
GtkProgressBar *progress)
{
- gchar *text;
gchar *name;
name = glade_project_get_name (project);
/* translators: "project name (objects loaded in total objects)" */
- text = g_strdup_printf (_("%s (%d of %d)"), name, step, total);
- gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), text);
- g_free (text);
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), name);
g_free (name);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), step * 1.0 / total);
@@ -2554,6 +2525,8 @@ create_notebook_tab (GladeWindow *window, GladeProject *project, gboolean for_fi
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
progress = gtk_progress_bar_new ();
+ gtk_widget_add_events (progress,
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
gtk_widget_set_name (progress, "glade-tab-label-progress");
gtk_box_pack_start (GTK_BOX (hbox), progress, FALSE, FALSE, 0);
g_signal_connect (project, "load-progress",
@@ -2594,14 +2567,10 @@ add_project (GladeWindow *window, GladeProject *project, gboolean for_file)
view = glade_design_view_new (project);
gtk_widget_show (view);
- if (for_file)
- {
- g_object_set_data (G_OBJECT (view), "view-added-while-loading", GINT_TO_POINTER (1));
+ g_object_set_data (G_OBJECT (view), "view-added-while-loading", GINT_TO_POINTER (for_file));
- gtk_widget_set_sensitive (view, FALSE);
- g_signal_connect (project, "parse-finished",
- G_CALLBACK (set_widget_sensitive_on_load), view);
- }
+ /* Update preview button */
+ gtk_widget_set_sensitive (GTK_WIDGET (window->priv->preview_button), FALSE);
/* Pass ownership of the project to the app */
glade_app_add_project (project);
@@ -2614,10 +2583,6 @@ add_project (GladeWindow *window, GladeProject *project, gboolean for_file)
gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook), -1);
refresh_notebook_tab_for_project (window, project);
-
- /* Update preview button */
- gtk_widget_set_sensitive (GTK_WIDGET (window->priv->preview_button),
- glade_project_get_previewable (project));
}
void
@@ -3535,6 +3500,7 @@ glade_window_class_init (GladeWindowClass *klass)
" { \n"
" GtkProgressBar::min-horizontal-bar-height = 1\n"
" GtkProgressBar::yspacing = 0\n"
+ " GtkProgressBar::xspacing = 0\n"
" xthickness = 0\n"
" ythickness = 0\n"
" }\n"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]