Destroy "remap" data in ColorBar when we change to another document

At the moment this "remap" data is temporal in ColorBar, but maybe it
should be inside app::Document.
This commit is contained in:
David Capello 2015-03-23 14:55:34 -03:00
parent fd62a60472
commit d6ecdefe22
2 changed files with 30 additions and 8 deletions

View File

@ -135,10 +135,14 @@ ColorBar::ColorBar(int align)
m_paletteButton.DropDownClick.connect(Bind<void>(&ColorBar::onPaletteButtonDropDownClick, this));
onColorButtonChange(getFgColor());
UIContext::instance()->addObserver(this);
}
ColorBar::~ColorBar()
{
UIContext::instance()->removeObserver(this);
set_config_color("ColorBar", "FG", getFgColor());
set_config_color("ColorBar", "BG", getBgColor());
}
@ -181,6 +185,11 @@ void ColorBar::setPaletteEditorButtonState(bool state)
m_paletteButton.setSelected(state);
}
void ColorBar::onSetActiveDocument(doc::Document* document)
{
destroyRemap();
}
// Switches the palette-editor
void ColorBar::onPaletteButtonClick()
{
@ -217,19 +226,13 @@ void ColorBar::onRemapButtonClick()
Transaction transaction(writer.context(), "Remap Colors", ModifyDocument);
transaction.execute(new cmd::RemapColors(sprite, *m_remap));
transaction.commit();
delete m_remap;
m_remap = nullptr;
}
update_screen_for_document(writer.document());
destroyRemap();
}
catch (base::Exception& e) {
Console::showException(e);
}
m_remapButton.setVisible(false);
layout();
}
void ColorBar::onPaletteViewIndexChange(int index, ui::MouseButtons buttons)
@ -301,4 +304,16 @@ void ColorBar::onColorButtonChange(const app::Color& color)
m_paletteView.selectColor(color.getIndex());
}
void ColorBar::destroyRemap()
{
if (!m_remap)
return;
delete m_remap;
m_remap = nullptr;
m_remapButton.setVisible(false);
layout();
}
} // namespace app

View File

@ -16,6 +16,7 @@
#include "app/ui/palette_view.h"
#include "base/signal.h"
#include "base/unique_ptr.h"
#include "doc/context_observer.h"
#include "doc/pixel_format.h"
#include "ui/box.h"
#include "ui/button.h"
@ -27,7 +28,8 @@ namespace app {
class PaletteIndexChangeEvent;
class ColorBar : public ui::Box
, public PaletteViewDelegate {
, public PaletteViewDelegate
, public doc::ContextObserver {
static ColorBar* m_instance;
public:
static ColorBar* instance() { return m_instance; }
@ -48,6 +50,9 @@ namespace app {
// when the visibility of the dialog changes.
void setPaletteEditorButtonState(bool state);
// ContextObserver impl
void onSetActiveDocument(doc::Document* document) override;
// Signals
Signal1<void, const app::Color&> FgColorChange;
Signal1<void, const app::Color&> BgColorChange;
@ -67,6 +72,8 @@ namespace app {
void onPaletteViewChangeSize(int boxsize) override;
private:
void destroyRemap();
class ScrollableView : public ui::View {
public:
ScrollableView();