mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-15 15:14:16 +00:00
Ask to save each file when we're quitting
This commit is contained in:
parent
46e9ece20a
commit
165d3af112
@ -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()
|
||||
|
@ -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;
|
||||
if (ctx->hasModifiedDocuments()) {
|
||||
Command* closeAll = CommandsModule::instance()->getCommandByName(CommandId::CloseAllFiles);
|
||||
Params params;
|
||||
params.set("quitting", "1");
|
||||
ctx->executeCommand(closeAll, params);
|
||||
|
||||
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
|
||||
// The user didn't save all documents (canceled the exit)
|
||||
if (ctx->hasModifiedDocuments())
|
||||
return;
|
||||
}
|
||||
|
||||
// Close the window
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -218,7 +218,7 @@ void DataRecoveryView::onWorkspaceViewSelected()
|
||||
{
|
||||
}
|
||||
|
||||
bool DataRecoveryView::onCloseView(Workspace* workspace)
|
||||
bool DataRecoveryView::onCloseView(Workspace* workspace, bool quitting)
|
||||
{
|
||||
workspace->removeView(this);
|
||||
return true;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user