mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Add File > Reopen Closed File command
This commit is contained in:
parent
1b62515cd2
commit
cdb98d4cd5
@ -11,6 +11,7 @@
|
||||
<!-- File -->
|
||||
<key command="NewFile" shortcut="Ctrl+N" mac="Cmd+N" />
|
||||
<key command="OpenFile" shortcut="Ctrl+O" mac="Cmd+O" />
|
||||
<key command="ReopenClosedFile" shortcut="Ctrl+Shift+T" mac="Cmd+Shift+T" />
|
||||
<key command="SaveFile" shortcut="Ctrl+S" mac="Cmd+S" />
|
||||
<key command="SaveFileAs" shortcut="Ctrl+Shift+S" mac="Cmd+Shift+S" />
|
||||
<key command="SaveFileCopyAs" shortcut="Ctrl+Alt+Shift+S" mac="Cmd+Alt+Shift+S" />
|
||||
@ -591,6 +592,7 @@
|
||||
<item command="NewFile" text="@.file_new" />
|
||||
<item command="OpenFile" text="@.file_open" />
|
||||
<item id="recent_list" text="@.file_open_recent" />
|
||||
<item command="ReopenClosedFile" text="@.file_reopen_closed" />
|
||||
<separator />
|
||||
<item command="SaveFile" text="@.file_save" />
|
||||
<item command="SaveFileAs" text="@.file_save_as" />
|
||||
|
@ -372,6 +372,7 @@ RemoveFrame = Remove Frame
|
||||
RemoveFrameTag = Remove Frame Tag
|
||||
RemoveLayer = Remove Layer
|
||||
RemoveSlice = Remove Slice
|
||||
ReopenClosedFile = Reopen Closed File
|
||||
RepeatLastExport = Repeat Last Export
|
||||
ReplaceColor = Replace Color
|
||||
ReselectMask = Reselect Mask
|
||||
@ -691,6 +692,7 @@ file = &File
|
||||
file_new = &New...
|
||||
file_open = &Open...
|
||||
file_open_recent = Open &Recent
|
||||
file_reopen_closed = Reopen Close&d File
|
||||
file_save = &Save
|
||||
file_save_as = Save &As...
|
||||
file_export = Expor&t...
|
||||
|
@ -264,6 +264,7 @@ if(ENABLE_UI)
|
||||
commands/cmd_remove_frame.cpp
|
||||
commands/cmd_remove_frame_tag.cpp
|
||||
commands/cmd_remove_slice.cpp
|
||||
commands/cmd_reopen_closed_file.cpp
|
||||
commands/cmd_repeat_last_export.cpp
|
||||
commands/cmd_reselect_mask.cpp
|
||||
commands/cmd_reverse_frames.cpp
|
||||
|
57
src/app/commands/cmd_reopen_closed_file.cpp
Normal file
57
src/app/commands/cmd_reopen_closed_file.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/doc.h"
|
||||
#include "app/ui_context.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace app {
|
||||
|
||||
class ReopenClosedFileCommand : public Command {
|
||||
public:
|
||||
ReopenClosedFileCommand();
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
ReopenClosedFileCommand::ReopenClosedFileCommand()
|
||||
: Command(CommandId::ReopenClosedFile(), CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool ReopenClosedFileCommand::onEnabled(Context* ctx)
|
||||
{
|
||||
if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
|
||||
const auto& docs = uiCtx->closedDocs();
|
||||
return (!docs.empty());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReopenClosedFileCommand::onExecute(Context* ctx)
|
||||
{
|
||||
if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
|
||||
const auto& docs = uiCtx->closedDocs();
|
||||
if (!docs.empty())
|
||||
uiCtx->reopenClosedDoc(docs.front());
|
||||
}
|
||||
}
|
||||
|
||||
Command* CommandFactory::createReopenClosedFileCommand()
|
||||
{
|
||||
return new ReopenClosedFileCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -116,6 +116,7 @@ FOR_EACH_COMMAND(Refresh)
|
||||
FOR_EACH_COMMAND(RemoveFrame)
|
||||
FOR_EACH_COMMAND(RemoveFrameTag)
|
||||
FOR_EACH_COMMAND(RemoveSlice)
|
||||
FOR_EACH_COMMAND(ReopenClosedFile)
|
||||
FOR_EACH_COMMAND(RepeatLastExport)
|
||||
FOR_EACH_COMMAND(ReplaceColor)
|
||||
FOR_EACH_COMMAND(ReselectMask)
|
||||
|
@ -45,6 +45,11 @@ void Context::sendDocumentToTop(Doc* document)
|
||||
documents().move(document, 0);
|
||||
}
|
||||
|
||||
void Context::closeDocument(Doc* doc)
|
||||
{
|
||||
onCloseDocument(doc);
|
||||
}
|
||||
|
||||
Site Context::activeSite() const
|
||||
{
|
||||
Site site;
|
||||
@ -221,4 +226,11 @@ ActiveSiteHandler* Context::activeSiteHandler() const
|
||||
return m_activeSiteHandler.get();
|
||||
}
|
||||
|
||||
void Context::onCloseDocument(Doc* doc)
|
||||
{
|
||||
ASSERT(doc != nullptr);
|
||||
ASSERT(doc->context() == nullptr);
|
||||
delete doc;
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -77,7 +77,8 @@ namespace app {
|
||||
bool checkFlags(uint32_t flags) const { return m_flags.check(flags); }
|
||||
void updateFlags() { m_flags.update(this); }
|
||||
|
||||
void sendDocumentToTop(Doc* document);
|
||||
void sendDocumentToTop(Doc* doc);
|
||||
void closeDocument(Doc* doc);
|
||||
|
||||
Site activeSite() const;
|
||||
Doc* activeDocument() const;
|
||||
@ -110,6 +111,7 @@ namespace app {
|
||||
virtual void onSetActiveDocument(Doc* doc);
|
||||
virtual void onSetActiveLayer(doc::Layer* layer);
|
||||
virtual void onSetActiveFrame(const doc::frame_t frame);
|
||||
virtual void onCloseDocument(Doc* doc);
|
||||
|
||||
Doc* lastSelectedDoc() { return m_lastSelectedDoc; }
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -181,7 +182,7 @@ namespace app {
|
||||
}
|
||||
|
||||
void destroyDocument() {
|
||||
ASSERT(m_doc != NULL);
|
||||
ASSERT(m_doc != nullptr);
|
||||
|
||||
m_doc->close();
|
||||
Doc* doc = m_doc;
|
||||
@ -191,6 +192,18 @@ namespace app {
|
||||
m_doc = nullptr;
|
||||
}
|
||||
|
||||
void closeDocument() {
|
||||
ASSERT(m_doc != nullptr);
|
||||
|
||||
Context* ctx = (Context*)m_doc->context();
|
||||
m_doc->close();
|
||||
Doc* doc = m_doc;
|
||||
unlock();
|
||||
|
||||
ctx->closeDocument(doc);
|
||||
m_doc = nullptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class WeakDocReader : public DocAccess {
|
||||
|
@ -330,7 +330,9 @@ bool DocView::onCloseView(Workspace* workspace, bool quitting)
|
||||
->setStatusText(0, "Sprite '%s' closed.",
|
||||
m_document->name().c_str());
|
||||
|
||||
destroyer.destroyDocument();
|
||||
// Just close the document (so we can reopen it with
|
||||
// ReopenClosedFile command).
|
||||
destroyer.closeDocument();
|
||||
|
||||
// At this point the view is already destroyed
|
||||
return true;
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "base/mutex.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace app {
|
||||
|
||||
UIContext* UIContext::m_instance = nullptr;
|
||||
@ -223,6 +225,17 @@ Editor* UIContext::activeEditor()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void UIContext::reopenClosedDoc(Doc* doc)
|
||||
{
|
||||
auto it = std::find(m_closedDocs.begin(), m_closedDocs.end(), doc);
|
||||
ASSERT(it != m_closedDocs.end());
|
||||
if (it != m_closedDocs.end())
|
||||
m_closedDocs.erase(it);
|
||||
|
||||
// Put the document in the context again.
|
||||
doc->setContext(this);
|
||||
}
|
||||
|
||||
void UIContext::onAddDocument(Doc* doc)
|
||||
{
|
||||
app::Context::onAddDocument(doc);
|
||||
@ -295,4 +308,11 @@ void UIContext::onGetActiveSite(Site* site) const
|
||||
}
|
||||
}
|
||||
|
||||
void UIContext::onCloseDocument(Doc* doc)
|
||||
{
|
||||
ASSERT(doc != nullptr);
|
||||
ASSERT(doc->context() == nullptr);
|
||||
m_closedDocs.insert(m_closedDocs.begin(), doc);
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "app/context.h"
|
||||
#include "app/docs_observer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace app {
|
||||
class DocView;
|
||||
class Editor;
|
||||
@ -42,6 +44,10 @@ namespace app {
|
||||
// new one if it's necessary.
|
||||
Editor* getEditorFor(Doc* document);
|
||||
|
||||
// Returns the list of closed docs in this session.
|
||||
const std::vector<Doc*>& closedDocs() const { return m_closedDocs; }
|
||||
void reopenClosedDoc(Doc* doc);
|
||||
|
||||
protected:
|
||||
void onAddDocument(Doc* doc) override;
|
||||
void onRemoveDocument(Doc* doc) override;
|
||||
@ -49,9 +55,12 @@ namespace app {
|
||||
void onSetActiveDocument(Doc* doc) override;
|
||||
void onSetActiveLayer(doc::Layer* layer) override;
|
||||
void onSetActiveFrame(const doc::frame_t frame) override;
|
||||
void onCloseDocument(Doc* doc) override;
|
||||
|
||||
private:
|
||||
DocView* m_lastSelectedView;
|
||||
std::vector<Doc*> m_closedDocs;
|
||||
|
||||
static UIContext* m_instance;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user