Remember last frame/layer visited for each document (fix #486)

This commit is contained in:
David Capello 2015-06-15 11:29:12 -03:00
parent 09bfa3e61b
commit 1af22f1ab7
3 changed files with 20 additions and 0 deletions

View File

@ -114,6 +114,10 @@
</tool>
<document>
<section id="site">
<option id="frame" type="doc::frame_t" default="doc::frame_t(0)" />
<option id="layer" type="doc::LayerIndex" />
</section>
<section id="tiled">
<option id="mode" type="filters::TiledMode" default="filters::TiledMode::NONE" migrate="Tools.Tiled" />
</section>

View File

@ -19,6 +19,7 @@
#include "doc/brush_pattern.h"
#include "doc/documents_observer.h"
#include "doc/frame.h"
#include "doc/layer_index.h"
#include "filters/tiled_mode.h"
#include "gfx/rect.h"

View File

@ -181,6 +181,14 @@ Editor::Editor(Document* document, EditorFlags flags)
DocumentPreferences& docPref = Preferences::instance().document(m_document);
// Restore last site in preferences
frame_t preferredFrame = docPref.site.frame();
Layer* preferredLayer = m_sprite->indexToLayer(docPref.site.layer());
if (preferredFrame >= 0 && preferredFrame <= m_sprite->lastFrame())
setFrame(preferredFrame);
if (preferredLayer)
setLayer(preferredLayer);
m_tiledConn = docPref.tiled.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridConn = docPref.grid.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_pixelGridConn = docPref.pixelGrid.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
@ -193,6 +201,13 @@ Editor::Editor(Document* document, EditorFlags flags)
Editor::~Editor()
{
if (m_document && m_sprite) {
DocumentPreferences& docPref = Preferences::instance()
.document(m_document);
docPref.site.frame(frame());
docPref.site.layer(m_sprite->layerToIndex(layer()));
}
m_observers.notifyDestroyEditor(this);
m_document->removeObserver(this);