Merge pull request #81 from gergelypolonkai/bug-65

Chart import doesn’t open a new window upon import, unless necessary
This commit is contained in:
Gergely Polonkai 2014-09-21 13:35:05 +02:00
commit 5665ed6ae9
3 changed files with 51 additions and 1 deletions

View File

@ -60,6 +60,36 @@ ag_app_create_window(AgApp *app)
return window;
}
static GtkWidget *
ag_app_get_usable_window(AgApp *app)
{
GtkWidget *window;
GList *l;
// Favour current window
window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(app)));
if (AG_IS_WINDOW(window) && ag_window_is_usable(AG_WINDOW(window))) {
return window;
}
// Otherwise, lets use the first existing, usable window
for (
l = gtk_application_get_windows(GTK_APPLICATION(app));
l;
l = g_list_next(l)
) {
if (AG_IS_WINDOW(l->data) && ag_window_is_usable(AG_WINDOW(l->data))) {
return l->data;
}
}
// If we are still here, no usable windows were found. Lets create one
window = ag_app_create_window(app);
return window;
}
static void
new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
@ -165,11 +195,12 @@ ag_app_import_file(AgApp *app, GFile *file, AgAppImportType type)
return;
}
window = ag_app_create_window(app);
window = ag_app_get_usable_window(app);
ag_window_set_chart(AG_WINDOW(window), chart);
ag_window_update_from_chart(AG_WINDOW(window));
g_action_group_activate_action(G_ACTION_GROUP(window), "save", NULL);
ag_window_change_tab(AG_WINDOW(window), "chart");
gtk_window_present(GTK_WINDOW(window));
}
static void

View File

@ -2767,3 +2767,20 @@ ag_window_load_chart_list(AgWindow *window)
return TRUE;
}
/**
* ag_window_is_usable:
* @window: an #AgWindow to test
*
* Checks if the given window is usable for new charts. Usability is
* currently means that it has no charts open.
*
* Returns: TRUE if @window is usable, FALSE otherwise
*/
gboolean
ag_window_is_usable(AgWindow *window)
{
AgWindowPrivate *priv = ag_window_get_instance_private(window);
return (priv->current_tab == priv->tab_list);
}

View File

@ -59,6 +59,8 @@ void ag_window_change_tab(AgWindow *window, const gchar *tab_name);
gboolean ag_window_load_chart_list(AgWindow *window);
gboolean ag_window_is_usable(AgWindow *window);
#define AG_WINDOW_ERROR (ag_window_error_quark())
GQuark ag_window_error_quark(void);