Merge branch 'master' into beta

This commit is contained in:
David Capello 2016-06-08 13:31:51 -03:00
commit e21b142305
26 changed files with 112 additions and 45 deletions

View File

@ -226,6 +226,8 @@ void App::run()
// Initialize Steam API // Initialize Steam API
#ifdef ENABLE_STEAM #ifdef ENABLE_STEAM
steam::SteamAPI steam; steam::SteamAPI steam;
if (steam.initialized())
she::instance()->activateApp();
#endif #endif
#ifdef ENABLE_UPDATER #ifdef ENABLE_UPDATER

View File

@ -50,7 +50,7 @@ protected:
Workspace* workspace = App::instance()->workspace(); Workspace* workspace = App::instance()->workspace();
WorkspaceView* view = workspace->activeView(); WorkspaceView* view = workspace->activeView();
if (view) if (view)
workspace->closeView(view); workspace->closeView(view, false);
} }
}; };
@ -60,12 +60,17 @@ public:
: Command("CloseAllFiles", : Command("CloseAllFiles",
"Close All Files", "Close All Files",
CmdRecordableFlag) { CmdRecordableFlag) {
m_quitting = false;
} }
Command* clone() const override { return new CloseAllFilesCommand(*this); } Command* clone() const override { return new CloseAllFilesCommand(*this); }
protected: protected:
void onLoadParams(const Params& params) override {
m_quitting = params.get_as<bool>("quitting");
}
void onExecute(Context* context) override { void onExecute(Context* context) override {
Workspace* workspace = App::instance()->workspace(); Workspace* workspace = App::instance()->workspace();
@ -78,11 +83,13 @@ protected:
} }
for (auto docView : docViews) { for (auto docView : docViews) {
if (!workspace->closeView(docView)) if (!workspace->closeView(docView, m_quitting))
break; break;
} }
} }
private:
bool m_quitting;
}; };
Command* CommandFactory::createCloseFileCommand() Command* CommandFactory::createCloseFileCommand()

View File

@ -11,6 +11,7 @@
#include "app/app.h" #include "app/app.h"
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/context.h" #include "app/context.h"
#include "app/document.h" #include "app/document.h"
#include "app/ui/main_window.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(); if (ctx->hasModifiedDocuments()) {
bool modifiedFiles = false; 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) { // The user didn't save all documents (canceled the exit)
const Document* document = static_cast<Document*>(*it); if (ctx->hasModifiedDocuments())
if (document->isModified()) { return;
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
} }
// Close the window // Close the window

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // 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()); 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) void Context::executeCommand(const char* commandName)
{ {
Command* cmd = CommandsModule::instance()->getCommandByName(commandName); Command* cmd = CommandsModule::instance()->getCommandByName(commandName);

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -63,6 +63,7 @@ namespace app {
void sendDocumentToTop(doc::Document* document); void sendDocumentToTop(doc::Document* document);
app::Document* activeDocument() const; app::Document* activeDocument() const;
bool hasModifiedDocuments() const;
void executeCommand(const char* commandName); void executeCommand(const char* commandName);
virtual void executeCommand(Command* command, const Params& params = Params()); virtual void executeCommand(Command* command, const Params& params = Params());

View File

@ -218,7 +218,7 @@ void DataRecoveryView::onWorkspaceViewSelected()
{ {
} }
bool DataRecoveryView::onCloseView(Workspace* workspace) bool DataRecoveryView::onCloseView(Workspace* workspace, bool quitting)
{ {
workspace->removeView(this); workspace->removeView(this);
return true; return true;

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -34,7 +34,7 @@ namespace app {
// WorkspaceView implementation // WorkspaceView implementation
ui::Widget* getContentWidget() override { return this; } ui::Widget* getContentWidget() override { return this; }
void onWorkspaceViewSelected() override; void onWorkspaceViewSelected() override;
bool onCloseView(Workspace* workspace) override; bool onCloseView(Workspace* workspace, bool quitting) override;
void onTabPopup(Workspace* workspace) override; void onTabPopup(Workspace* workspace) override;
// Triggered when the list is empty (because the user deleted all // Triggered when the list is empty (because the user deleted all

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -109,7 +109,7 @@ void DevConsoleView::onWorkspaceViewSelected()
m_entry->requestFocus(); m_entry->requestFocus();
} }
bool DevConsoleView::onCloseView(Workspace* workspace) bool DevConsoleView::onCloseView(Workspace* workspace, bool quitting)
{ {
workspace->removeView(this); workspace->removeView(this);
return true; return true;

View File

@ -36,7 +36,7 @@ namespace app {
bool canCloneWorkspaceView() override { return true; } bool canCloneWorkspaceView() override { return true; }
WorkspaceView* cloneWorkspaceView() override; WorkspaceView* cloneWorkspaceView() override;
void onWorkspaceViewSelected() override; void onWorkspaceViewSelected() override;
bool onCloseView(Workspace* workspace) override; bool onCloseView(Workspace* workspace, bool quitting) override;
void onTabPopup(Workspace* workspace) override; void onTabPopup(Workspace* workspace) override;
// EngineDelegate impl // EngineDelegate impl

View File

@ -220,7 +220,7 @@ void DocumentView::onClonedFrom(WorkspaceView* from)
->setViewScroll(View::getView(srcEditor)->viewScroll()); ->setViewScroll(View::getView(srcEditor)->viewScroll());
} }
bool DocumentView::onCloseView(Workspace* workspace) bool DocumentView::onCloseView(Workspace* workspace, bool quitting)
{ {
if (m_editor->isMovingPixels()) if (m_editor->isMovingPixels())
m_editor->dropMovingPixels(); m_editor->dropMovingPixels();
@ -247,8 +247,12 @@ bool DocumentView::onCloseView(Workspace* workspace)
// see if the sprite has changes // see if the sprite has changes
while (m_document->isModified()) { while (m_document->isModified()) {
// ask what want to do the user with the changes in the sprite // 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", int ret = Alert::show("Warning"
m_document->name().c_str()); "<<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) { if (ret == 1) {
// "save": save the changes // "save": save the changes

View File

@ -67,7 +67,7 @@ namespace app {
WorkspaceView* cloneWorkspaceView() override; WorkspaceView* cloneWorkspaceView() override;
void onWorkspaceViewSelected() override; void onWorkspaceViewSelected() override;
void onClonedFrom(WorkspaceView* from) override; void onClonedFrom(WorkspaceView* from) override;
bool onCloseView(Workspace* workspace) override; bool onCloseView(Workspace* workspace, bool quitting) override;
void onTabPopup(Workspace* workspace) override; void onTabPopup(Workspace* workspace) override;
InputChainElement* onGetInputChainElement() override { return this; } InputChainElement* onGetInputChainElement() override { return this; }

View File

@ -89,7 +89,7 @@ TabIcon HomeView::getTabIcon()
return TabIcon::HOME; return TabIcon::HOME;
} }
bool HomeView::onCloseView(Workspace* workspace) bool HomeView::onCloseView(Workspace* workspace, bool quitting)
{ {
workspace->removeView(this); workspace->removeView(this);
return true; return true;

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@ -50,7 +50,7 @@ namespace app {
// WorkspaceView implementation // WorkspaceView implementation
ui::Widget* getContentWidget() override { return this; } ui::Widget* getContentWidget() override { return this; }
bool onCloseView(Workspace* workspace) override; bool onCloseView(Workspace* workspace, bool quitting) override;
void onTabPopup(Workspace* workspace) override; void onTabPopup(Workspace* workspace) override;
void onWorkspaceViewSelected() override; void onWorkspaceViewSelected() override;

View File

@ -298,7 +298,7 @@ void MainWindow::onCloseTab(Tabs* tabs, TabView* tabView)
WorkspaceView* view = dynamic_cast<WorkspaceView*>(tabView); WorkspaceView* view = dynamic_cast<WorkspaceView*>(tabView);
ASSERT(view); ASSERT(view);
if (view) if (view)
m_workspace->closeView(view); m_workspace->closeView(view, false);
} }
void MainWindow::onCloneTab(Tabs* tabs, TabView* tabView, int pos) void MainWindow::onCloneTab(Tabs* tabs, TabView* tabView, int pos)

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // 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); 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() WorkspaceView* Workspace::activeView()

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // 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 // Closes the given view. Returns false if the user cancels the
// operation. // operation.
bool closeView(WorkspaceView* view); bool closeView(WorkspaceView* view, bool quitting);
WorkspaceView* activeView(); WorkspaceView* activeView();
void setActiveView(WorkspaceView* view); void setActiveView(WorkspaceView* view);

View File

@ -1,5 +1,5 @@
// Aseprite // 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 // 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 // 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 // Returns true if the view was closed successfully or false if
// the user cancels the operation. // 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; virtual void onTabPopup(Workspace* workspace) = 0;

View File

@ -144,6 +144,10 @@ public:
delete this; delete this;
} }
void activateApp() override {
// Do nothing
}
void finishLaunching() override { void finishLaunching() override {
// Do nothing // Do nothing
} }

View File

@ -22,6 +22,7 @@ namespace she {
~OSXApp(); ~OSXApp();
bool init(); bool init();
void activateApp();
void finishLaunching(); void finishLaunching();
private: private:

View File

@ -27,11 +27,25 @@ public:
[m_app setActivationPolicy:NSApplicationActivationPolicyRegular]; [m_app setActivationPolicy:NSApplicationActivationPolicyRegular];
[m_app setDelegate:m_appDelegate]; [m_app setDelegate:m_appDelegate];
[m_app activateIgnoringOtherApps:YES];
// Don't activate the application ignoring other apps. This is
// called by OS X when the application is launched by the user
// from the application bundle. In this way, we can execute
// aseprite from the command line/bash scripts and the app will
// not be activated.
//[m_app activateIgnoringOtherApps:YES];
return true; return true;
} }
// We might need to call this function when the app is launched from
// Steam. It appears that there is a bug on OS X Steam client where
// the app is launched, activated, and then the Steam client is
// activated again.
void activateApp() {
[m_app activateIgnoringOtherApps:YES];
}
void finishLaunching() { void finishLaunching() {
[m_app finishLaunching]; [m_app finishLaunching];
} }
@ -67,6 +81,11 @@ bool OSXApp::init()
return m_impl->init(); return m_impl->init();
} }
void OSXApp::activateApp()
{
m_impl->activateApp();
}
void OSXApp::finishLaunching() void OSXApp::finishLaunching()
{ {
m_impl->finishLaunching(); m_impl->finishLaunching();

View File

@ -91,7 +91,8 @@ bool is_key_pressed(KeyScancode scancode)
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
{ {
m_nsCursor = [NSCursor arrowCursor]; // We start without the system mouse cursor
m_nsCursor = nil;
m_visibleMouse = true; m_visibleMouse = true;
m_pointerType = she::PointerType::Unknown; m_pointerType = she::PointerType::Unknown;

View File

@ -57,6 +57,12 @@ public:
delete this; delete this;
} }
void activateApp() override {
#if __APPLE__
OSXApp::instance()->activateApp();
#endif
}
void finishLaunching() override { void finishLaunching() override {
#if __APPLE__ #if __APPLE__
// Start processing NSApplicationDelegate events. (E.g. after // Start processing NSApplicationDelegate events. (E.g. after

View File

@ -32,6 +32,7 @@ namespace she {
public: public:
virtual ~System() { } virtual ~System() { }
virtual void dispose() = 0; virtual void dispose() = 0;
virtual void activateApp() = 0;
virtual void finishLaunching() = 0; virtual void finishLaunching() = 0;
virtual Capabilities capabilities() const = 0; virtual Capabilities capabilities() const = 0;
virtual Logger* logger() = 0; virtual Logger* logger() = 0;

View File

@ -35,16 +35,20 @@ typedef void (*SteamAPI_Shutdown_Func)();
class SteamAPI::Impl { class SteamAPI::Impl {
public: public:
Impl() { Impl() : m_initialized(false) {
m_steamLib = base::load_dll( m_steamLib = base::load_dll(
base::join_path(base::get_file_path(base::get_app_path()), base::join_path(base::get_file_path(base::get_app_path()),
STEAM_API_DLL_FILENAME)); STEAM_API_DLL_FILENAME));
if (!m_steamLib) if (!m_steamLib) {
LOG("Steam library not found...\n");
return; return;
}
auto SteamAPI_Init = base::get_dll_proc<SteamAPI_Init_Func>(m_steamLib, "SteamAPI_Init"); auto SteamAPI_Init = base::get_dll_proc<SteamAPI_Init_Func>(m_steamLib, "SteamAPI_Init");
if (!SteamAPI_Init) if (!SteamAPI_Init) {
LOG("SteamAPI_Init not found...\n");
return; return;
}
if (!SteamAPI_Init()) { if (!SteamAPI_Init()) {
LOG("Steam is not initialized...\n"); LOG("Steam is not initialized...\n");
@ -52,6 +56,7 @@ public:
} }
LOG("Steam initialized...\n"); LOG("Steam initialized...\n");
m_initialized = true;
} }
~Impl() { ~Impl() {
@ -67,8 +72,13 @@ public:
base::unload_dll(m_steamLib); base::unload_dll(m_steamLib);
} }
bool initialized() const {
return m_initialized;
}
private: private:
base::dll m_steamLib; base::dll m_steamLib;
bool m_initialized;
}; };
SteamAPI::SteamAPI() SteamAPI::SteamAPI()
@ -81,4 +91,9 @@ SteamAPI::~SteamAPI()
delete m_impl; delete m_impl;
} }
bool SteamAPI::initialized() const
{
return m_impl->initialized();
}
} // namespace steam } // namespace steam

View File

@ -15,6 +15,8 @@ public:
SteamAPI(); SteamAPI();
~SteamAPI(); ~SteamAPI();
bool initialized() const;
private: private:
class Impl; class Impl;
Impl* m_impl; Impl* m_impl;

@ -1 +1 @@
Subproject commit 27e2f011ebef85144724c30f63285852612aafa0 Subproject commit 8529e84fb4bb22abfc5c4d9cafbb06025a8b909d