From af9762885bf2ec71d14138740c78eea3f8fa15c7 Mon Sep 17 00:00:00 2001 From: Timur Doumler Date: Thu, 13 Aug 2015 12:53:22 +0100 Subject: [PATCH] Refactoring: moved isValidPath() check to the DependencyPathValueSource, to make the DependencyPathPropertyComponent responsible for GUI only. --- .../jucer_DependencyPathPropertyComponent.cpp | 38 ++++++++++--------- .../jucer_DependencyPathPropertyComponent.h | 20 +++++----- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp index 1295867c7d..251546cdcf 100644 --- a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp @@ -20,16 +20,28 @@ const String DependencyPath::aaxKeyName = "aaxPath"; const String DependencyPath::androidSdkKeyName = "androidSdkPath"; const String DependencyPath::androidNdkKeyName = "androidNdkPath"; +//============================================================================== + +bool DependencyPathValueSource::isValidPath() const +{ + // if we are on another OS than the one which this path setting is for, + // we have no way of knowing whether the path is valid - so just assume it is: + if (! appliesToThisOS()) + return true; + + return PathSettingsTab::checkPathByKey (globalKey, getValue().toString()); +} + //============================================================================== DependencyPathPropertyComponent::DependencyPathPropertyComponent (const Value& value, const String& propertyName, - const String& globalKeyName, + const String& globalKey, DependencyPathOS os) : TextPropertyComponent (propertyName, 1024, false), - globalKey (globalKeyName), pathValueSource (new DependencyPathValueSource (value, - PathSettingsTab::getPathByKey (globalKeyName, os), - PathSettingsTab::getFallbackPathByKey (globalKeyName, os), + PathSettingsTab::getPathByKey (globalKey, os), + PathSettingsTab::getFallbackPathByKey (globalKey, os), + globalKey, os)), pathValue (pathValueSource) { @@ -66,21 +78,11 @@ void DependencyPathPropertyComponent::textWasEdited() Colour DependencyPathPropertyComponent::getTextColourToDisplay() const { if (! pathValueSource->isUsingProjectSettings()) - return isValidPath() ? Colours::grey - : Colours::lightpink; + return pathValueSource->isValidPath() ? Colours::grey + : Colours::lightpink; - return isValidPath() ? Colours::black - : Colours::red; -} - -bool DependencyPathPropertyComponent::isValidPath() const -{ - // if we are on another OS than the one which this path setting is for, - // we have no way of knowing whether the path is valid - so just assume it is: - if (! pathValueSource->appliesToThisOS()) - return true; - - return PathSettingsTab::checkPathByKey (globalKey, getValue().toString()); + return pathValueSource->isValidPath() ? Colours::black + : Colours::red; } void DependencyPathPropertyComponent::labelTextChanged (Label*) diff --git a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h index 62642c29e1..bb6b124bd0 100644 --- a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h +++ b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h @@ -56,10 +56,12 @@ public: DependencyPathValueSource (const Value& projectSettingsPath, const Value& globalSettingsPath, const String& fallbackPath, + String globalSettingsKey, DependencyPathOS osThisSettingAppliesTo) : projectSettingsValue (projectSettingsPath), globalSettingsValue (globalSettingsPath), fallbackValue (fallbackPath), + globalKey (globalSettingsKey), os (osThisSettingAppliesTo) { globalSettingsValue.addListener (this); @@ -106,6 +108,8 @@ public: return os == DependencyPath::getThisOS(); } + bool isValidPath() const; + private: void valueChanged (Value& value) override { @@ -147,10 +151,14 @@ private: OS than the ome this machine is running. */ String fallbackValue; + /** the global key used in the application settings for the global setting value. + needed for checking whether the path is valid. */ + String globalKey; + /** on what operating system should this dependency path be used? - note that this is *not* the os that is targeted by the project, - but rather the os on which the project will be compiled - (= on which the path settings need to be set correctly). */ + note that this is *not* the os that is targeted by the project, + but rather the os on which the project will be compiled + (= on which the path settings need to be set correctly). */ DependencyPathOS os; }; @@ -178,12 +186,6 @@ private: /** This function handles path changes because the global path changed. */ void valueChanged (Value& value) override; - /** Check if the current value is a valid path. */ - bool isValidPath() const; - - /** the property key of the global property that this component is tracking. */ - String globalKey; - /** the value source of this dependency path setting. */ DependencyPathValueSource* pathValueSource;