From 5f2ef63b65afb73b061fa23e9260fe77737de6a8 Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Fri, 2 Aug 2019 20:05:17 +0200 Subject: [PATCH] gschem: Switch to changed page before showing dialogs --- gschem/src/gschem_close_confirmation_dialog.c | 2 -- gschem/src/x_highlevel.c | 31 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gschem/src/gschem_close_confirmation_dialog.c b/gschem/src/gschem_close_confirmation_dialog.c index 5841ba11e..fa32073d5 100644 --- a/gschem/src/gschem_close_confirmation_dialog.c +++ b/gschem/src/gschem_close_confirmation_dialog.c @@ -743,7 +743,6 @@ x_dialog_close_changed_page (GschemToplevel *w_current, PAGE *page) case GTK_RESPONSE_YES: /* action selected: save */ - x_window_set_current_page (w_current, page); if (x_highlevel_save_page (w_current, page)) result = TRUE; /* no, user has cancelled the save and page has changes */ @@ -847,7 +846,6 @@ x_dialog_close_window (GschemToplevel *w_current) p_unsaved = g_list_next (p_unsaved)) { p_current = (PAGE *) p_unsaved->data; - x_window_set_current_page (w_current, p_current); if (!x_highlevel_save_page (w_current, p_current)) /* if user cancelled save, do not close window */ ret = FALSE; diff --git a/gschem/src/x_highlevel.c b/gschem/src/x_highlevel.c index 3bbf0c219..e0c029c99 100644 --- a/gschem/src/x_highlevel.c +++ b/gschem/src/x_highlevel.c @@ -24,7 +24,8 @@ * As opposed to the low-level page functions, the high-level page * functions do interact with the user. They switch to the newly * created / opened page, ask for confirmation for potentially - * destructive actions, and warn about major symbol changes. + * destructive actions (switching pages if necessary), and warn about + * major symbol changes. */ #include @@ -132,7 +133,8 @@ x_highlevel_open_pages (GschemToplevel *w_current, GSList *filenames) /*! \brief Save a page. * * Saves a page to its current filename. If the page is untitled, - * shows a file chooser dialog. + * makes it the current page of \a w_current and shows a file chooser + * dialog. * * \param [in] w_current the toplevel environment * \param [in] page the page to save, or \c NULL to save the @@ -150,8 +152,11 @@ x_highlevel_save_page (GschemToplevel *w_current, PAGE *page) g_return_val_if_fail (page != NULL, FALSE); } - if (page->is_untitled) + if (page->is_untitled) { + x_window_set_current_page (w_current, page); + return x_fileselect_save (w_current); + } return x_lowlevel_save_page (w_current, page, page->page_filename); } @@ -160,7 +165,8 @@ x_highlevel_save_page (GschemToplevel *w_current, PAGE *page) /*! \brief Reload a page from disk. * * Closes the page, creates a new page, and reads the file back from - * disk. If the page has been changed, asks the user for confirmation. + * disk. If the page has been changed, makes it the current page of + * \a w_current and asks the user for confirmation. * * \param [in] w_current the toplevel environment * \param [in] page the page to revert, or \c NULL to revert the @@ -182,6 +188,8 @@ x_highlevel_revert_page (GschemToplevel *w_current, PAGE *page) GtkWidget *dialog; int response; + x_window_set_current_page (w_current, page); + gchar *basename = g_path_get_basename (page->page_filename); dialog = gtk_message_dialog_new_with_markup ( GTK_WINDOW (w_current->main_window), @@ -222,7 +230,8 @@ x_highlevel_revert_page (GschemToplevel *w_current, PAGE *page) /*! \brief Close a page. * - * If the page has been changed, asks the user for confirmation. + * If the page has been changed, makes it the current page of \a + * toplevel and asks the user for confirmation. * * Switches to the next valid page if necessary. If this was the last * page of the toplevel, a new untitled page is created. @@ -243,8 +252,16 @@ x_highlevel_close_page (GschemToplevel *w_current, PAGE *page) g_return_val_if_fail (page != NULL, FALSE); } - if (page->CHANGED && !x_dialog_close_changed_page (w_current, page)) - return FALSE; + if (page->CHANGED) { + /* Setting the current page is redundant as the close confirmation + dialog switches to the current page (is has to, since it may be + called when the window is closed while there's a single changed + page in the background), but it doesn't hurt, either. */ + x_window_set_current_page (w_current, page); + + if (!x_dialog_close_changed_page (w_current, page)) + return FALSE; + } x_lowlevel_close_page (w_current, page); return TRUE; -- 2.11.4.GIT