mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Replace ContextObserver::onActiveDocumentChange() with onActiveSiteChange()
This commit is contained in:
parent
14d369404e
commit
c3d7a96a87
@ -41,7 +41,9 @@ using namespace app::tools;
|
||||
class ToolsConfigurationWindow : public app::gen::ToolsConfiguration,
|
||||
public doc::ContextObserver {
|
||||
public:
|
||||
ToolsConfigurationWindow(Context* ctx) : m_ctx(ctx) {
|
||||
ToolsConfigurationWindow(Context* ctx)
|
||||
: m_ctx(ctx)
|
||||
, m_lastDocument(nullptr) {
|
||||
m_ctx->addObserver(this);
|
||||
|
||||
// Slots
|
||||
@ -58,7 +60,7 @@ public:
|
||||
centerWindow();
|
||||
load_window_pos(this, "ConfigureTool");
|
||||
|
||||
onActiveDocumentChange(m_ctx->activeDocument());
|
||||
updateUI();
|
||||
}
|
||||
|
||||
~ToolsConfigurationWindow() {
|
||||
@ -79,7 +81,12 @@ private:
|
||||
return preferences().document(m_ctx->activeDocument());
|
||||
}
|
||||
|
||||
void onActiveDocumentChange(doc::Document* document) override {
|
||||
void onActiveSiteChange(const doc::Site& site) override {
|
||||
if (m_lastDocument != site.document())
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void updateUI() {
|
||||
DocumentPreferences& docPref = this->docPref();
|
||||
|
||||
tiled()->setSelected(docPref.tiled.mode() != filters::TiledMode::NONE);
|
||||
@ -88,6 +95,8 @@ private:
|
||||
snapToGrid()->setSelected(docPref.grid.snap());
|
||||
viewGrid()->setSelected(docPref.grid.visible());
|
||||
pixelGrid()->setSelected(docPref.pixelGrid.visible());
|
||||
|
||||
m_lastDocument = m_ctx->activeDocument();
|
||||
}
|
||||
|
||||
void onWindowClose() {
|
||||
@ -155,6 +164,7 @@ private:
|
||||
}
|
||||
|
||||
Context* m_ctx;
|
||||
Document* m_lastDocument;
|
||||
};
|
||||
|
||||
class ConfigureTools : public Command {
|
||||
|
@ -86,6 +86,7 @@ ColorBar::ColorBar(int align)
|
||||
, m_bgColor(app::Color::fromRgb(0, 0, 0), IMAGE_RGB)
|
||||
, m_lock(false)
|
||||
, m_remap(nullptr)
|
||||
, m_lastDocument(nullptr)
|
||||
{
|
||||
m_instance = this;
|
||||
|
||||
@ -195,9 +196,12 @@ void ColorBar::setPaletteEditorButtonState(bool state)
|
||||
m_paletteButton.setSelected(state);
|
||||
}
|
||||
|
||||
void ColorBar::onActiveDocumentChange(doc::Document* document)
|
||||
void ColorBar::onActiveSiteChange(const doc::Site& site)
|
||||
{
|
||||
destroyRemap();
|
||||
if (m_lastDocument != site.document()) {
|
||||
m_lastDocument = site.document();
|
||||
destroyRemap();
|
||||
}
|
||||
}
|
||||
|
||||
// Switches the palette-editor
|
||||
|
@ -51,7 +51,7 @@ namespace app {
|
||||
void setPaletteEditorButtonState(bool state);
|
||||
|
||||
// ContextObserver impl
|
||||
void onActiveDocumentChange(doc::Document* document) override;
|
||||
void onActiveSiteChange(const doc::Site& site) override;
|
||||
|
||||
// Signals
|
||||
Signal1<void, const app::Color&> FgColorChange;
|
||||
@ -91,6 +91,7 @@ namespace app {
|
||||
ColorButton m_bgColor;
|
||||
bool m_lock;
|
||||
doc::Remap* m_remap;
|
||||
const doc::Document* m_lastDocument;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -109,15 +109,27 @@ void UIContext::setActiveView(DocumentView* docView)
|
||||
App::instance()->updateDisplayTitleBar();
|
||||
|
||||
m_lastSelectedView = docView;
|
||||
|
||||
// TODO all the calls to functions like updateUsingEditor(),
|
||||
// setPixelFormat(), app_refresh_screen(), updateDisplayTitleBar()
|
||||
// Can be replaced with a ContextObserver listening to the
|
||||
// onActiveSiteChange() event.
|
||||
notifyActiveSiteChanged();
|
||||
}
|
||||
|
||||
void UIContext::setActiveDocument(Document* document)
|
||||
{
|
||||
bool notify = (m_lastSelectedDoc != document);
|
||||
m_lastSelectedDoc = document;
|
||||
|
||||
DocumentView* docView = getFirstDocumentView(document);
|
||||
if (docView) // The view can be null if we are in --batch mode
|
||||
if (docView) { // The view can be null if we are in --batch mode
|
||||
setActiveView(docView);
|
||||
notify = false;
|
||||
}
|
||||
|
||||
if (notify)
|
||||
notifyActiveSiteChanged();
|
||||
}
|
||||
|
||||
DocumentView* UIContext::getFirstDocumentView(Document* document) const
|
||||
|
@ -40,14 +40,10 @@ Document* Context::activeDocument() const
|
||||
return site.document();
|
||||
}
|
||||
|
||||
void Context::notifyActiveDocumentChanged(Document* doc)
|
||||
void Context::notifyActiveSiteChanged()
|
||||
{
|
||||
notifyObservers(&ContextObserver::onActiveDocumentChange, doc);
|
||||
}
|
||||
|
||||
void Context::notifyActiveSiteChanged(Site* site)
|
||||
{
|
||||
notifyObservers(&ContextObserver::onActiveSiteChange, site);
|
||||
Site site = activeSite();
|
||||
notifyObservers<const Site&>(&ContextObserver::onActiveSiteChange, site);
|
||||
}
|
||||
|
||||
void Context::onGetActiveSite(Site* site) const
|
||||
|
@ -31,10 +31,9 @@ namespace doc {
|
||||
Site activeSite() const;
|
||||
Document* activeDocument() const;
|
||||
|
||||
protected:
|
||||
void notifyActiveDocumentChanged(Document* doc);
|
||||
void notifyActiveSiteChanged(Site* site);
|
||||
void notifyActiveSiteChanged();
|
||||
|
||||
protected:
|
||||
virtual void onGetActiveSite(Site* site) const;
|
||||
virtual void onAddDocument(Document* doc) override;
|
||||
virtual void onRemoveDocument(Document* doc) override;
|
||||
|
@ -16,8 +16,7 @@ namespace doc {
|
||||
class ContextObserver {
|
||||
public:
|
||||
virtual ~ContextObserver() { }
|
||||
virtual void onActiveDocumentChange(Document* document) { }
|
||||
virtual void onActiveSiteChange(Site* site) { }
|
||||
virtual void onActiveSiteChange(const Site& site) { }
|
||||
};
|
||||
|
||||
} // namespace doc
|
||||
|
@ -36,12 +36,15 @@ namespace doc {
|
||||
}
|
||||
|
||||
void onAddDocument(Document* doc) override {
|
||||
this->notifyActiveDocumentChanged(m_activeDoc = doc);
|
||||
m_activeDoc = doc;
|
||||
notifyActiveSiteChanged();
|
||||
}
|
||||
|
||||
void onRemoveDocument(Document* doc) override {
|
||||
if (m_activeDoc == doc)
|
||||
this->notifyActiveDocumentChanged(m_activeDoc = nullptr);
|
||||
if (m_activeDoc == doc) {
|
||||
m_activeDoc = nullptr;
|
||||
notifyActiveSiteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user