From 153071f082b54c95c8d5bf5dea79aeee6d80a671 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 14 Jun 2014 01:35:04 -0300 Subject: [PATCH] Fix issue 406: persist ISelectionSettings --- src/app/settings/ui_settings_impl.cpp | 5 +++-- src/app/ui/context_bar.cpp | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/settings/ui_settings_impl.cpp b/src/app/settings/ui_settings_impl.cpp index d1c310fd5..bb17a3f2e 100644 --- a/src/app/settings/ui_settings_impl.cpp +++ b/src/app/settings/ui_settings_impl.cpp @@ -183,7 +183,7 @@ class UISelectionSettingsImpl , public base::Observable { public: UISelectionSettingsImpl(); - ~UISelectionSettingsImpl(); + virtual ~UISelectionSettingsImpl(); SelectionMode getSelectionMode(); app::Color getMoveTransparentColor(); @@ -827,6 +827,8 @@ UISelectionSettingsImpl::UISelectionSettingsImpl() : UISelectionSettingsImpl::~UISelectionSettingsImpl() { + set_config_int("Tools", "SelectionMode", (int)m_selectionMode); + set_config_int("Tools", "RotAlgorithm", (int)m_rotationAlgorithm); } SelectionMode UISelectionSettingsImpl::getSelectionMode() @@ -859,7 +861,6 @@ void UISelectionSettingsImpl::setMoveTransparentColor(app::Color color) void UISelectionSettingsImpl::setRotationAlgorithm(RotationAlgorithm algorithm) { m_rotationAlgorithm = algorithm; - set_config_int("Tools", "RotAlgorithm", m_rotationAlgorithm); notifyObservers(&SelectionSettingsObserver::onSetRotationAlgorithm, algorithm); } diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index ca84b0f59..d80431fc8 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -395,16 +395,23 @@ class ContextBar::RotAlgorithmField : public ComboBox { public: RotAlgorithmField() { + // We use "m_lockChange" variable to avoid setting the rotation + // algorithm when we call ComboBox::addItem() (because the first + // addItem() generates an onChange() event). + m_lockChange = true; addItem(new Item("Fast Rotation", kFastRotationAlgorithm)); addItem(new Item("RotSprite", kRotSpriteRotationAlgorithm)); + m_lockChange = false; - setSelectedItemIndex((int) - UIContext::instance()->settings()->selection() - ->getRotationAlgorithm()); + setSelectedItemIndex((int)UIContext::instance()->settings() + ->selection()->getRotationAlgorithm()); } protected: void onChange() OVERRIDE { + if (m_lockChange) + return; + UIContext::instance()->settings()->selection() ->setRotationAlgorithm(static_cast(getSelectedItem())->algo()); } @@ -426,6 +433,8 @@ private: private: RotationAlgorithm m_algo; }; + + bool m_lockChange; }; class ContextBar::FreehandAlgorithmField : public CheckBox @@ -457,6 +466,9 @@ public: PART_SELECTION_REPLACE, PART_SELECTION_ADD, PART_SELECTION_SUBTRACT) { + setSelectedItem( + (int)UIContext::instance()->settings() + ->selection()->getSelectionMode()); } void setupTooltips(TooltipManager* tooltipManager)