1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-18 00:54:19 +00:00

Refactoring: moved isValidPath() check to the DependencyPathValueSource, to make the DependencyPathPropertyComponent responsible for GUI only.

This commit is contained in:
Timur Doumler 2015-08-13 12:53:22 +01:00
parent d9cd459032
commit af9762885b
2 changed files with 31 additions and 27 deletions

View file

@ -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*)

View file

@ -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;