Skip to content

Commit

Permalink
Don't close the Preview window if we close an unrelated Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed May 19, 2015
1 parent e106f6f commit e973aa0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/app/ui/document_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,25 @@ class AppEditor : public Editor,

// EditorObserver implementation
void dispose() override {
App::instance()->getMainWindow()->getPreviewEditor()->updateUsingEditor(NULL);
PreviewEditorWindow* preview =
App::instance()->getMainWindow()->getPreviewEditor();

if (preview->relatedEditor() == this)
updatePreviewEditor(nullptr);
}

void onScrollChanged(Editor* editor) override {
if (current_editor == this)
App::instance()->getMainWindow()->getPreviewEditor()->updateUsingEditor(this);
updatePreviewEditor(this);
}

void onAfterFrameChanged(Editor* editor) override {
App::instance()->getMainWindow()->getPreviewEditor()->updateUsingEditor(this);
updatePreviewEditor(this);

set_current_palette(editor->sprite()->palette(editor->frame()), true);
}

void onAfterLayerChanged(Editor* editor) override {
App::instance()->getMainWindow()->getPreviewEditor()->updateUsingEditor(this);
updatePreviewEditor(this);
}

// EditorCustomizationDelegate implementation
Expand Down Expand Up @@ -161,6 +164,11 @@ class AppEditor : public Editor,
}

private:

void updatePreviewEditor(Editor* editor) {
App::instance()->getMainWindow()->getPreviewEditor()->updateUsingEditor(editor);
}

bool isKeyActionPressed(KeyAction action) {
if (Key* key = KeyboardShortcuts::instance()->action(action))
return key->checkFromAllegroKeyArray();
Expand Down
6 changes: 5 additions & 1 deletion src/app/ui/preview_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ PreviewEditorWindow::PreviewEditorWindow()
, m_playButton(new MiniPlayButton())
, m_refFrame(0)
, m_aniSpeed(1.0)
, m_relatedEditor(nullptr)
{
child_spacing = 0;
setAutoRemap(false);
Expand Down Expand Up @@ -297,12 +298,15 @@ void PreviewEditorWindow::updateUsingEditor(Editor* editor)
{
if (!m_isEnabled || !editor) {
hideWindow();
m_relatedEditor = nullptr;
return;
}

if (editor != current_editor)
if (!editor->isActive())
return;

m_relatedEditor = editor;

Document* document = editor->document();
Editor* miniEditor = (m_docView ? m_docView->getEditor(): NULL);

Expand Down
3 changes: 3 additions & 0 deletions src/app/ui/preview_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace app {
void updateUsingEditor(Editor* editor);
void uncheckCenterButton();

Editor* relatedEditor() const { return m_relatedEditor; }

protected:
bool onProcessMessage(ui::Message* msg) override;
void onClose(ui::CloseEvent& ev) override;
Expand All @@ -45,6 +47,7 @@ namespace app {
MiniPlayButton* m_playButton;
doc::frame_t m_refFrame;
double m_aniSpeed;
Editor* m_relatedEditor;
};

} // namespace app
Expand Down

0 comments on commit e973aa0

Please sign in to comment.