Revision: 2383
          http://synfig.svn.sourceforge.net/synfig/?rev=2383&view=rev
Author:   gballintijn
Date:     2009-06-20 11:59:12 +0000 (Sat, 20 Jun 2009)

Log Message:
-----------
#2602803: "Patch: Improve UI on crash recovery dialog."
Simplified version of the patch that Bombe added to SourceForge.net on 
2009-02-15. Based on suggestions by Pabs, I cleaned up and shortened the code a 
bit, making it more consistent with surrounding code.

Modified Paths:
--------------
    synfig-studio/trunk/src/gtkmm/app.cpp
    synfig-studio/trunk/src/gtkmm/canvasview.cpp
    synfig-studio/trunk/src/synfigapp/uimanager.cpp
    synfig-studio/trunk/src/synfigapp/uimanager.h

Modified: synfig-studio/trunk/src/gtkmm/app.cpp
===================================================================
--- synfig-studio/trunk/src/gtkmm/app.cpp       2009-06-19 08:53:38 UTC (rev 
2382)
+++ synfig-studio/trunk/src/gtkmm/app.cpp       2009-06-20 11:59:12 UTC (rev 
2383)
@@ -322,6 +322,34 @@
 {
 public:
 
+       virtual Response confirmation(const std::string &title,
+                       const std::string &primaryText,
+                       const std::string &secondaryText,
+                       const std::string &confirmPhrase,
+                       const std::string &cancelPhrase,
+                       Response defaultResponse)
+       {
+               Gtk::MessageDialog dialog(
+                       primaryText,            // Message
+                       false,                  // Markup
+                       Gtk::MESSAGE_WARNING,   // Type
+                       Gtk::BUTTONS_NONE,      // Buttons
+                       true                    // Modal
+               );
+
+               if (! title.empty())
+                       dialog.set_title(title);
+               if (! secondaryText.empty())
+                       dialog.set_secondary_text(secondaryText);
+
+               dialog.add_button(cancelPhrase, RESPONSE_CANCEL);
+               dialog.add_button(confirmPhrase, RESPONSE_OK);
+               dialog.set_default_response(defaultResponse);
+
+               dialog.show_all();
+               return (Response) dialog.run();
+       }
+
        virtual Response yes_no(const std::string &title, const std::string 
&message,Response dflt=RESPONSE_YES)
        {
                Gtk::Dialog dialog(
@@ -1290,12 +1318,13 @@
                if(auto_recover->recovery_needed())
                {
                        splash_screen.hide();
-                       if (get_ui_interface()->yes_no(_("Auto Recovery"),
-                                                                               
   _("Synfig Studio seems to have crashed\n"
-                                                                               
         "before you could save all your files.\n"
-                                                                               
         "Would you like to re-open those files\n"
-                                                                               
         "and recover your unsaved changes?")) ==
-                               synfigapp::UIInterface::RESPONSE_YES)
+                       if (get_ui_interface()->confirmation("Crash Recovery",
+                                       _("Auto recovery file found"),
+                                       _("Synfig Studio seems to have 
crashed\n"
+                                         "before you could save all your 
files.\n"
+                                         "Recover unsaved changes?"),
+                                       _("Recover"), _("Ignore"))
+                               == synfigapp::UIInterface::RESPONSE_OK)
                        {
                                int number_recovered;
                                if(!auto_recover->recover(number_recovered))

Modified: synfig-studio/trunk/src/gtkmm/canvasview.cpp
===================================================================
--- synfig-studio/trunk/src/gtkmm/canvasview.cpp        2009-06-19 08:53:38 UTC 
(rev 2382)
+++ synfig-studio/trunk/src/gtkmm/canvasview.cpp        2009-06-20 11:59:12 UTC 
(rev 2383)
@@ -248,6 +248,37 @@
                //view->progressbar->set_fraction(0);
        }
 
+       virtual Response confirmation(const std::string &title,
+                       const std::string &primaryText,
+                       const std::string &secondaryText,
+                       const std::string &confirmPhrase,
+                       const std::string &cancelPhrase,
+                       Response defaultResponse=RESPONSE_OK)
+       {
+               view->present();
+               
//while(studio::App::events_pending())studio::App::iteration(false);
+               Gtk::MessageDialog dialog(
+                       *view,                  // Parent
+                       primaryText,            // Message
+                       false,                  // Markup
+                       Gtk::MESSAGE_WARNING,   // Type
+                       Gtk::BUTTONS_NONE,      // Buttons
+                       true                    // Modal
+               );
+
+               if (! title.empty())
+                       dialog.set_title(title);
+               if (! secondaryText.empty())
+                       dialog.set_secondary_text(secondaryText);
+
+               dialog.add_button(cancelPhrase, RESPONSE_CANCEL);
+               dialog.add_button(confirmPhrase, RESPONSE_OK);
+               dialog.set_default_response(defaultResponse);
+
+               dialog.show_all();
+               return (Response) dialog.run();
+       }
+
        virtual Response yes_no(const std::string &title, const std::string 
&message,Response dflt=RESPONSE_YES)
        {
                view->present();

Modified: synfig-studio/trunk/src/synfigapp/uimanager.cpp
===================================================================
--- synfig-studio/trunk/src/synfigapp/uimanager.cpp     2009-06-19 08:53:38 UTC 
(rev 2382)
+++ synfig-studio/trunk/src/synfigapp/uimanager.cpp     2009-06-20 11:59:12 UTC 
(rev 2383)
@@ -49,6 +49,33 @@
 /* === M E T H O D S ======================================================= */
 
 UIInterface::Response
+ConsoleUIInterface::confirmation(const std::string &title, const std::string 
&primaryText,
+               const std::string &secondaryText, const std::string 
&confirmPhrase,
+               const std::string &cancelPhrase, Response dflt)
+{
+       cout << title << ": " << primaryText << endl;
+       cout << secondaryText;
+
+       if (dflt == RESPONSE_OK)
+               cout << "(" << confirmPhrase << "/" << cancelPhrase << ")" << 
endl;
+       else
+               cout << "(" << cancelPhrase << "/" << confirmPhrase << ")" << 
endl;
+
+       string resp;
+       cin >> resp;
+
+       if (dflt == RESPONSE_OK)
+       {
+               if (resp == cancelPhrase)
+                       return RESPONSE_CANCEL;
+               return RESPONSE_OK;
+       }
+       if (resp == confirmPhrase)
+               return RESPONSE_OK;
+       return RESPONSE_CANCEL;
+}
+
+UIInterface::Response
 ConsoleUIInterface::yes_no(const std::string &title, const std::string 
&message,Response dflt)
 {
        cout<<title<<": "<<message<<' ';

Modified: synfig-studio/trunk/src/synfigapp/uimanager.h
===================================================================
--- synfig-studio/trunk/src/synfigapp/uimanager.h       2009-06-19 08:53:38 UTC 
(rev 2382)
+++ synfig-studio/trunk/src/synfigapp/uimanager.h       2009-06-20 11:59:12 UTC 
(rev 2383)
@@ -51,6 +51,9 @@
                RESPONSE_OK=2
        };
        virtual ~UIInterface() { }
+       virtual Response confirmation(const std::string &title, const 
std::string &primaryText,
+                                       const std::string &secondaryText, const 
std::string &confirmPhrase,
+                                       const std::string &cancelPhrase, 
Response dflt=RESPONSE_OK)=0;
        virtual Response yes_no(const std::string &title, const std::string 
&message,Response dflt=RESPONSE_YES)=0;
        virtual Response yes_no_cancel(const std::string &title, const 
std::string &message,Response dflt=RESPONSE_YES)=0;
        virtual Response ok_cancel(const std::string &title, const std::string 
&message,Response dflt=RESPONSE_OK)=0;
@@ -59,6 +62,10 @@
 class DefaultUIInterface : public UIInterface
 {
 public:
+       Response confirmation(const std::string &/*title*/, const std::string 
&/*primaryText*/,
+                               const std::string &/*secondaryText*/, const 
std::string &/*confirmPhrase*/,
+                               const std::string &/*cancelPhrase*/, Response 
dflt)
+               { return dflt; }
        Response yes_no(const std::string &/*title*/, const std::string 
&/*message*/,Response dflt)
                { return dflt; }
        Response yes_no_cancel(const std::string &/*title*/, const std::string 
&/*message*/,Response dflt)
@@ -79,6 +86,10 @@
 class ConfidentUIInterface : public UIInterface
 {
 public:
+       Response confirmation(const std::string &/*title*/, const std::string 
&/*primaryText*/,
+                               const std::string &/*secondaryText*/, const 
std::string &/*confirmPhrase*/,
+                               const std::string &/*cancelPhrase*/, Response 
/*dflt*/)
+               { return RESPONSE_OK; }
        Response yes_no(const std::string &/*title*/, const std::string 
&/*message*/,Response /*dflt*/)
                { return RESPONSE_YES; }
        Response yes_no_cancel(const std::string &/*title*/, const std::string 
&/*message*/,Response /*dflt*/)
@@ -99,6 +110,9 @@
 class ConsoleUIInterface : public UIInterface
 {
 public:
+       Response confirmation(const std::string &title, const std::string 
&primaryText,
+                               const std::string &secondaryText, const 
std::string &confirmPhrase,
+                               const std::string &cancelPhrase, Response dflt);
        Response yes_no(const std::string &title, const std::string 
&message,Response dflt);
        Response yes_no_cancel(const std::string &title, const std::string 
&message,Response dflt);
        Response ok_cancel(const std::string &title, const std::string 
&message,Response dflt);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to