mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
Timeline: we've to observe the Context to know if the Document is destroyed
In this way the timeline can stop observing the Document when it's closed.
This commit is contained in:
parent
d8fd4736d4
commit
c9ab56cf69
@ -115,23 +115,28 @@ Timeline::Timeline()
|
|||||||
, m_context(UIContext::instance())
|
, m_context(UIContext::instance())
|
||||||
, m_document(NULL)
|
, m_document(NULL)
|
||||||
{
|
{
|
||||||
|
m_context->addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timeline::~Timeline()
|
Timeline::~Timeline()
|
||||||
{
|
{
|
||||||
if (m_document)
|
detachDocument();
|
||||||
m_document->removeObserver(this);
|
|
||||||
|
m_context->removeObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timeline::updateUsingEditor(Editor* editor)
|
void Timeline::updateUsingEditor(Editor* editor)
|
||||||
{
|
{
|
||||||
if (m_document)
|
|
||||||
m_document->removeObserver(this);
|
|
||||||
|
|
||||||
DocumentView* view = editor->getDocumentView();
|
DocumentView* view = editor->getDocumentView();
|
||||||
DocumentLocation location;
|
DocumentLocation location;
|
||||||
view->getDocumentLocation(&location);
|
view->getDocumentLocation(&location);
|
||||||
|
|
||||||
|
// Do nothing, we've already viewing this document in the timeline.
|
||||||
|
if (m_document == location.document())
|
||||||
|
return;
|
||||||
|
|
||||||
|
detachDocument();
|
||||||
|
|
||||||
m_document = location.document();
|
m_document = location.document();
|
||||||
m_sprite = location.sprite();
|
m_sprite = location.sprite();
|
||||||
m_layer = location.layer();
|
m_layer = location.layer();
|
||||||
@ -147,8 +152,16 @@ void Timeline::updateUsingEditor(Editor* editor)
|
|||||||
|
|
||||||
setFocusStop(true);
|
setFocusStop(true);
|
||||||
regenerateLayers();
|
regenerateLayers();
|
||||||
|
}
|
||||||
|
|
||||||
m_document->addObserver(this);
|
void Timeline::detachDocument()
|
||||||
|
{
|
||||||
|
if (m_document) {
|
||||||
|
m_document->removeObserver(this);
|
||||||
|
m_document = NULL;
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Timeline::isMovingCel() const
|
bool Timeline::isMovingCel() const
|
||||||
@ -739,6 +752,12 @@ void Timeline::onPreferredSize(PreferredSizeEvent& ev)
|
|||||||
ev.setPreferredSize(Size(32, 32));
|
ev.setPreferredSize(Size(32, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Timeline::onRemoveDocument(Context* context, Document* document)
|
||||||
|
{
|
||||||
|
if (document == m_document)
|
||||||
|
detachDocument();
|
||||||
|
}
|
||||||
|
|
||||||
void Timeline::onAddLayer(DocumentEvent& ev)
|
void Timeline::onAddLayer(DocumentEvent& ev)
|
||||||
{
|
{
|
||||||
ASSERT(ev.layer() != NULL);
|
ASSERT(ev.layer() != NULL);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef APP_UI_TIMELINE_H_INCLUDED
|
#ifndef APP_UI_TIMELINE_H_INCLUDED
|
||||||
#define APP_UI_TIMELINE_H_INCLUDED
|
#define APP_UI_TIMELINE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "app/context_observer.h"
|
||||||
#include "app/document_observer.h"
|
#include "app/document_observer.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "raster/frame_number.h"
|
#include "raster/frame_number.h"
|
||||||
@ -40,6 +41,7 @@ namespace app {
|
|||||||
class Editor;
|
class Editor;
|
||||||
|
|
||||||
class Timeline : public ui::Widget
|
class Timeline : public ui::Widget
|
||||||
|
, public ContextObserver
|
||||||
, public DocumentObserver {
|
, public DocumentObserver {
|
||||||
public:
|
public:
|
||||||
enum State {
|
enum State {
|
||||||
@ -78,7 +80,11 @@ namespace app {
|
|||||||
void onRemoveFrame(DocumentEvent& ev) OVERRIDE;
|
void onRemoveFrame(DocumentEvent& ev) OVERRIDE;
|
||||||
void onTotalFramesChanged(DocumentEvent& ev) OVERRIDE;
|
void onTotalFramesChanged(DocumentEvent& ev) OVERRIDE;
|
||||||
|
|
||||||
|
// ContextObserver impl.
|
||||||
|
void onRemoveDocument(Context* context, Document* document) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void detachDocument();
|
||||||
void setCursor(int x, int y);
|
void setCursor(int x, int y);
|
||||||
void getDrawableLayers(const gfx::Rect& clip, int* first_layer, int* last_layer);
|
void getDrawableLayers(const gfx::Rect& clip, int* first_layer, int* last_layer);
|
||||||
void getDrawableFrames(const gfx::Rect& clip, FrameNumber* first_frame, FrameNumber* last_frame);
|
void getDrawableFrames(const gfx::Rect& clip, FrameNumber* first_frame, FrameNumber* last_frame);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user