From 9966b48139a450a7da6dc8d9c432fd078bdcdf27 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 14 Aug 2015 13:06:26 -0300 Subject: [PATCH] Add support to drag the selection in other editor when the active one is in MovingPixels state --- src/app/commands/cmd_close_file.cpp | 3 ++- src/app/ui/document_view.cpp | 2 +- src/app/ui/editor/editor.cpp | 2 +- src/app/ui/editor/editor.h | 2 +- src/app/ui/editor/standby_state.cpp | 11 ++++++++++- src/app/ui_context.cpp | 30 +++++++++++++++++------------ src/app/ui_context.h | 3 ++- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/app/commands/cmd_close_file.cpp b/src/app/commands/cmd_close_file.cpp index 90ef38a13..5425a520b 100644 --- a/src/app/commands/cmd_close_file.cpp +++ b/src/app/commands/cmd_close_file.cpp @@ -70,7 +70,8 @@ protected: void onExecute(Context* context) override { Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); - std::vector docViews; + // Collect all document views + DocumentViews docViews; for (auto view : *workspace) { DocumentView* docView = dynamic_cast(view); if (docView) diff --git a/src/app/ui/document_view.cpp b/src/app/ui/document_view.cpp index 4ecf2c7da..ddfedd4a8 100644 --- a/src/app/ui/document_view.cpp +++ b/src/app/ui/document_view.cpp @@ -267,7 +267,7 @@ void DocumentView::onClonedFrom(WorkspaceView* from) bool DocumentView::onCloseView(Workspace* workspace) { if (m_editor->isMovingPixels()) - m_editor->cancelMovingPixels(); + m_editor->dropMovingPixels(); // If there is another view for this document, just close the view. for (auto view : *workspace) { diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index e6258972b..b23831cf6 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1604,7 +1604,7 @@ bool Editor::isMovingPixels() const return (dynamic_cast(m_state.get()) != nullptr); } -void Editor::cancelMovingPixels() +void Editor::dropMovingPixels() { ASSERT(isMovingPixels()); backToPreviousState(); diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index 16853f7da..88e6fac41 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -91,7 +91,7 @@ namespace app { EditorStatePtr getState() { return m_state; } bool isMovingPixels() const; - void cancelMovingPixels(); + void dropMovingPixels(); // Changes the state of the editor. void setState(const EditorStatePtr& newState); diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index cf71d6cd4..58ac8d074 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -21,6 +21,7 @@ #include "app/tools/ink.h" #include "app/tools/pick_ink.h" #include "app/tools/tool.h" +#include "app/ui/document_view.h" #include "app/ui/editor/drawing_state.h" #include "app/ui/editor/editor.h" #include "app/ui/editor/editor_customization_delegate.h" @@ -423,13 +424,21 @@ void StandbyState::startSelectionTransformation(Editor* editor, void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) { + Document* document = editor->document(); + + for (auto docView : UIContext::instance()->getAllDocumentViews(document)) { + if (docView->getEditor()->isMovingPixels()) { + // TODO Transfer moving pixels state to this editor + docView->getEditor()->dropMovingPixels(); + } + } + try { // Clear brush preview, as the extra cel will be replaced with the // transformed image. editor->brushPreview().hide(); EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); - Document* document = editor->document(); base::UniquePtr tmpImage(new_image_from_mask(editor->getSite())); PixelsMovementPtr pixelsMovement( diff --git a/src/app/ui_context.cpp b/src/app/ui_context.cpp index b8af071fa..bb54022c2 100644 --- a/src/app/ui_context.cpp +++ b/src/app/ui_context.cpp @@ -134,7 +134,7 @@ void UIContext::setActiveDocument(Document* document) notifyActiveSiteChanged(); } -DocumentView* UIContext::getFirstDocumentView(Document* document) const +DocumentView* UIContext::getFirstDocumentView(doc::Document* document) const { MainWindow* mainWindow = App::instance()->getMainWindow(); if (!mainWindow) // Main window can be null if we are in --batch mode @@ -153,6 +153,22 @@ DocumentView* UIContext::getFirstDocumentView(Document* document) const return nullptr; } +DocumentViews UIContext::getAllDocumentViews(doc::Document* document) const +{ + Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); + DocumentViews docViews; + + for (WorkspaceView* view : *workspace) { + if (DocumentView* docView = dynamic_cast(view)) { + if (docView->getDocument() == document) { + docViews.push_back(docView); + } + } + } + + return docViews; +} + Editor* UIContext::activeEditor() { DocumentView* view = activeView(); @@ -188,18 +204,8 @@ void UIContext::onRemoveDocument(doc::Document* doc) // We don't destroy views in batch mode. if (isUIAvailable()) { Workspace* workspace = App::instance()->getMainWindow()->getWorkspace(); - DocumentViews docViews; - // Collect all views related to the document. - for (WorkspaceView* view : *workspace) { - if (DocumentView* docView = dynamic_cast(view)) { - if (docView->getDocument() == doc) { - docViews.push_back(docView); - } - } - } - - for (DocumentView* docView : docViews) { + for (DocumentView* docView : getAllDocumentViews(doc)) { workspace->removeView(docView); delete docView; } diff --git a/src/app/ui_context.h b/src/app/ui_context.h index ad6404c32..586a5e8c6 100644 --- a/src/app/ui_context.h +++ b/src/app/ui_context.h @@ -31,7 +31,8 @@ namespace app { void setActiveView(DocumentView* documentView); void setActiveDocument(Document* document); - DocumentView* getFirstDocumentView(Document* document) const; + DocumentView* getFirstDocumentView(doc::Document* document) const; + DocumentViews getAllDocumentViews(doc::Document* document) const; // Returns the current editor. It can be null. Editor* activeEditor();