[aseprite] 04/51: Ask to save each file when we're quitting

Tobias Hansen thansen at moszumanska.debian.org
Mon Jul 11 21:35:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 165d3af112db6ab581158024b541ec9e066de259
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Jun 8 13:27:36 2016 -0300

    Ask to save each file when we're quitting
---
 src/app/commands/cmd_close_file.cpp | 11 +++++++++--
 src/app/commands/cmd_exit.cpp       | 26 +++++++++++---------------
 src/app/context.cpp                 | 10 +++++++++-
 src/app/context.h                   |  3 ++-
 src/app/ui/data_recovery_view.cpp   |  2 +-
 src/app/ui/data_recovery_view.h     |  4 ++--
 src/app/ui/devconsole_view.cpp      |  4 ++--
 src/app/ui/devconsole_view.h        |  2 +-
 src/app/ui/document_view.cpp        | 10 +++++++---
 src/app/ui/document_view.h          |  2 +-
 src/app/ui/home_view.cpp            |  2 +-
 src/app/ui/home_view.h              |  4 ++--
 src/app/ui/main_window.cpp          |  2 +-
 src/app/ui/workspace.cpp            |  6 +++---
 src/app/ui/workspace.h              |  4 ++--
 src/app/ui/workspace_view.h         |  4 ++--
 16 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/src/app/commands/cmd_close_file.cpp b/src/app/commands/cmd_close_file.cpp
index 93095d8..cd34b8f 100644
--- a/src/app/commands/cmd_close_file.cpp
+++ b/src/app/commands/cmd_close_file.cpp
@@ -50,7 +50,7 @@ protected:
     Workspace* workspace = App::instance()->workspace();
     WorkspaceView* view = workspace->activeView();
     if (view)
-      workspace->closeView(view);
+      workspace->closeView(view, false);
   }
 };
 
@@ -60,12 +60,17 @@ public:
     : Command("CloseAllFiles",
               "Close All Files",
               CmdRecordableFlag) {
+    m_quitting = false;
   }
 
   Command* clone() const override { return new CloseAllFilesCommand(*this); }
 
 protected:
 
+  void onLoadParams(const Params& params) override {
+    m_quitting = params.get_as<bool>("quitting");
+  }
+
   void onExecute(Context* context) override {
     Workspace* workspace = App::instance()->workspace();
 
@@ -78,11 +83,13 @@ protected:
     }
 
     for (auto docView : docViews) {
-      if (!workspace->closeView(docView))
+      if (!workspace->closeView(docView, m_quitting))
         break;
     }
   }
 
+private:
+  bool m_quitting;
 };
 
 Command* CommandFactory::createCloseFileCommand()
diff --git a/src/app/commands/cmd_exit.cpp b/src/app/commands/cmd_exit.cpp
index 53e57ed..852918e 100644
--- a/src/app/commands/cmd_exit.cpp
+++ b/src/app/commands/cmd_exit.cpp
@@ -11,6 +11,7 @@
 
 #include "app/app.h"
 #include "app/commands/command.h"
+#include "app/commands/commands.h"
 #include "app/context.h"
 #include "app/document.h"
 #include "app/ui/main_window.h"
@@ -34,22 +35,17 @@ ExitCommand::ExitCommand()
 {
 }
 
-void ExitCommand::onExecute(Context* context)
+void ExitCommand::onExecute(Context* ctx)
 {
-  const doc::Documents& docs = context->documents();
-  bool modifiedFiles = false;
-
-  for (doc::Documents::const_iterator it=docs.begin(), end=docs.end(); it!=end; ++it) {
-    const Document* document = static_cast<Document*>(*it);
-    if (document->isModified()) {
-      modifiedFiles = true;
-      break;
-    }
-  }
-
-  if (modifiedFiles) {
-    if (ui::Alert::show("Warning<<There are sprites with changes.<<Do you want to quit anyway?||&Yes||&No") != 1)
-      return; // In this case the user doesn't want to close with modified files
+  if (ctx->hasModifiedDocuments()) {
+    Command* closeAll = CommandsModule::instance()->getCommandByName(CommandId::CloseAllFiles);
+    Params params;
+    params.set("quitting", "1");
+    ctx->executeCommand(closeAll, params);
+
+    // The user didn't save all documents (canceled the exit)
+    if (ctx->hasModifiedDocuments())
+      return;
   }
 
   // Close the window
diff --git a/src/app/context.cpp b/src/app/context.cpp
index f2e0139..21d906d 100644
--- a/src/app/context.cpp
+++ b/src/app/context.cpp
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -38,6 +38,14 @@ app::Document* Context::activeDocument() const
   return static_cast<app::Document*>(doc::Context::activeDocument());
 }
 
+bool Context::hasModifiedDocuments() const
+{
+  for (auto doc : documents())
+    if (static_cast<app::Document*>(doc)->isModified())
+      return true;
+  return false;
+}
+
 void Context::executeCommand(const char* commandName)
 {
   Command* cmd = CommandsModule::instance()->getCommandByName(commandName);
diff --git a/src/app/context.h b/src/app/context.h
index 44edec9..e0463ce 100644
--- a/src/app/context.h
+++ b/src/app/context.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -63,6 +63,7 @@ namespace app {
     void sendDocumentToTop(doc::Document* document);
 
     app::Document* activeDocument() const;
+    bool hasModifiedDocuments() const;
 
     void executeCommand(const char* commandName);
     virtual void executeCommand(Command* command, const Params& params = Params());
diff --git a/src/app/ui/data_recovery_view.cpp b/src/app/ui/data_recovery_view.cpp
index 4bfa092..8f9bc1f 100644
--- a/src/app/ui/data_recovery_view.cpp
+++ b/src/app/ui/data_recovery_view.cpp
@@ -218,7 +218,7 @@ void DataRecoveryView::onWorkspaceViewSelected()
 {
 }
 
-bool DataRecoveryView::onCloseView(Workspace* workspace)
+bool DataRecoveryView::onCloseView(Workspace* workspace, bool quitting)
 {
   workspace->removeView(this);
   return true;
diff --git a/src/app/ui/data_recovery_view.h b/src/app/ui/data_recovery_view.h
index f27207d..039d7bf 100644
--- a/src/app/ui/data_recovery_view.h
+++ b/src/app/ui/data_recovery_view.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -34,7 +34,7 @@ namespace app {
     // WorkspaceView implementation
     ui::Widget* getContentWidget() override { return this; }
     void onWorkspaceViewSelected() override;
-    bool onCloseView(Workspace* workspace) override;
+    bool onCloseView(Workspace* workspace, bool quitting) override;
     void onTabPopup(Workspace* workspace) override;
 
     // Triggered when the list is empty (because the user deleted all
diff --git a/src/app/ui/devconsole_view.cpp b/src/app/ui/devconsole_view.cpp
index 1e97389..f329baa 100644
--- a/src/app/ui/devconsole_view.cpp
+++ b/src/app/ui/devconsole_view.cpp
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -109,7 +109,7 @@ void DevConsoleView::onWorkspaceViewSelected()
   m_entry->requestFocus();
 }
 
-bool DevConsoleView::onCloseView(Workspace* workspace)
+bool DevConsoleView::onCloseView(Workspace* workspace, bool quitting)
 {
   workspace->removeView(this);
   return true;
diff --git a/src/app/ui/devconsole_view.h b/src/app/ui/devconsole_view.h
index 3fd60de..eaefc64 100644
--- a/src/app/ui/devconsole_view.h
+++ b/src/app/ui/devconsole_view.h
@@ -36,7 +36,7 @@ namespace app {
     bool canCloneWorkspaceView() override { return true; }
     WorkspaceView* cloneWorkspaceView() override;
     void onWorkspaceViewSelected() override;
-    bool onCloseView(Workspace* workspace) override;
+    bool onCloseView(Workspace* workspace, bool quitting) override;
     void onTabPopup(Workspace* workspace) override;
 
     // EngineDelegate impl
diff --git a/src/app/ui/document_view.cpp b/src/app/ui/document_view.cpp
index 48f9af2..267ac24 100644
--- a/src/app/ui/document_view.cpp
+++ b/src/app/ui/document_view.cpp
@@ -220,7 +220,7 @@ void DocumentView::onClonedFrom(WorkspaceView* from)
     ->setViewScroll(View::getView(srcEditor)->viewScroll());
 }
 
-bool DocumentView::onCloseView(Workspace* workspace)
+bool DocumentView::onCloseView(Workspace* workspace, bool quitting)
 {
   if (m_editor->isMovingPixels())
     m_editor->dropMovingPixels();
@@ -247,8 +247,12 @@ bool DocumentView::onCloseView(Workspace* workspace)
       // see if the sprite has changes
       while (m_document->isModified()) {
         // ask what want to do the user with the changes in the sprite
-        int ret = Alert::show("Warning<<Saving changes in:<<%s||&Save||Do&n't Save||&Cancel",
-          m_document->name().c_str());
+        int ret = Alert::show("Warning"
+                              "<<Saving changes to the sprite"
+                              "<<\"%s\" before %s?"
+                              "||&Save||Do&n't Save||&Cancel",
+                              m_document->name().c_str(),
+                              quitting ? "quitting": "closing");
 
         if (ret == 1) {
           // "save": save the changes
diff --git a/src/app/ui/document_view.h b/src/app/ui/document_view.h
index 7d9ef3b..c45e24f 100644
--- a/src/app/ui/document_view.h
+++ b/src/app/ui/document_view.h
@@ -67,7 +67,7 @@ namespace app {
     WorkspaceView* cloneWorkspaceView() override;
     void onWorkspaceViewSelected() override;
     void onClonedFrom(WorkspaceView* from) override;
-    bool onCloseView(Workspace* workspace) override;
+    bool onCloseView(Workspace* workspace, bool quitting) override;
     void onTabPopup(Workspace* workspace) override;
     InputChainElement* onGetInputChainElement() override { return this; }
 
diff --git a/src/app/ui/home_view.cpp b/src/app/ui/home_view.cpp
index 690b5b9..1897bdb 100644
--- a/src/app/ui/home_view.cpp
+++ b/src/app/ui/home_view.cpp
@@ -89,7 +89,7 @@ TabIcon HomeView::getTabIcon()
   return TabIcon::HOME;
 }
 
-bool HomeView::onCloseView(Workspace* workspace)
+bool HomeView::onCloseView(Workspace* workspace, bool quitting)
 {
   workspace->removeView(this);
   return true;
diff --git a/src/app/ui/home_view.h b/src/app/ui/home_view.h
index 691510d..a07dffc 100644
--- a/src/app/ui/home_view.h
+++ b/src/app/ui/home_view.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -50,7 +50,7 @@ namespace app {
 
     // WorkspaceView implementation
     ui::Widget* getContentWidget() override { return this; }
-    bool onCloseView(Workspace* workspace) override;
+    bool onCloseView(Workspace* workspace, bool quitting) override;
     void onTabPopup(Workspace* workspace) override;
     void onWorkspaceViewSelected() override;
 
diff --git a/src/app/ui/main_window.cpp b/src/app/ui/main_window.cpp
index 818ea79..627a557 100644
--- a/src/app/ui/main_window.cpp
+++ b/src/app/ui/main_window.cpp
@@ -298,7 +298,7 @@ void MainWindow::onCloseTab(Tabs* tabs, TabView* tabView)
   WorkspaceView* view = dynamic_cast<WorkspaceView*>(tabView);
   ASSERT(view);
   if (view)
-    m_workspace->closeView(view);
+    m_workspace->closeView(view, false);
 }
 
 void MainWindow::onCloneTab(Tabs* tabs, TabView* tabView, int pos)
diff --git a/src/app/ui/workspace.cpp b/src/app/ui/workspace.cpp
index c13e012..70f4dd0 100644
--- a/src/app/ui/workspace.cpp
+++ b/src/app/ui/workspace.cpp
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -75,9 +75,9 @@ void Workspace::removeView(WorkspaceView* view)
     panel->removeView(view);
 }
 
-bool Workspace::closeView(WorkspaceView* view)
+bool Workspace::closeView(WorkspaceView* view, bool quitting)
 {
-  return view->onCloseView(this);
+  return view->onCloseView(this, quitting);
 }
 
 WorkspaceView* Workspace::activeView()
diff --git a/src/app/ui/workspace.h b/src/app/ui/workspace.h
index 25dcecc..65803fe 100644
--- a/src/app/ui/workspace.h
+++ b/src/app/ui/workspace.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -39,7 +39,7 @@ namespace app {
 
     // Closes the given view. Returns false if the user cancels the
     // operation.
-    bool closeView(WorkspaceView* view);
+    bool closeView(WorkspaceView* view, bool quitting);
 
     WorkspaceView* activeView();
     void setActiveView(WorkspaceView* view);
diff --git a/src/app/ui/workspace_view.h b/src/app/ui/workspace_view.h
index 15d0e63..e6084ea 100644
--- a/src/app/ui/workspace_view.h
+++ b/src/app/ui/workspace_view.h
@@ -1,5 +1,5 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// Copyright (C) 2001-2016  David Capello
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 2 as
@@ -37,7 +37,7 @@ namespace app {
 
     // Returns true if the view was closed successfully or false if
     // the user cancels the operation.
-    virtual bool onCloseView(Workspace* workspace) = 0;
+    virtual bool onCloseView(Workspace* workspace, bool quitting) = 0;
 
     virtual void onTabPopup(Workspace* workspace) = 0;
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list