From f4c91eca99ee68723150dd201358fa38b01ebca0 Mon Sep 17 00:00:00 2001 From: Timur Doumler Date: Thu, 13 Aug 2015 14:47:24 +0100 Subject: [PATCH] Fixed exporting global/fallback path settings for Android exporter by moving Android SDK/NDK DependencyPathValueSource ownership into the project. --- .../jucer_ProjectExport_Android.h | 29 +++++++++--- .../jucer_DependencyPathPropertyComponent.cpp | 43 +++++++++++------- .../jucer_DependencyPathPropertyComponent.h | 44 +++++++------------ 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h index 52e1abe207..fa54d1d05f 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h @@ -38,7 +38,8 @@ public: } //============================================================================== - AndroidProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t) + AndroidProjectExporter (Project& p, const ValueTree& t) + : ProjectExporter (p, t) { name = getNameAndroid(); @@ -62,6 +63,18 @@ public: if (getKeyAliasValue().getValue().isVoid()) getKeyAliasValue() = "androiddebugkey"; if (getKeyAliasPassValue().getValue().isVoid()) getKeyAliasPassValue() = "android"; if (getCPP11EnabledValue().getValue().isVoid()) getCPP11EnabledValue() = true; + + sdkPath = Value (new DependencyPathValueSource ( + getSetting (Ids::androidSDKPath), + DependencyPath::androidSdkKeyName, + DependencyPath::getThisOS() + )); + + ndkPath = Value (new DependencyPathValueSource ( + getSetting (Ids::androidNDKPath), + DependencyPath::androidNdkKeyName, + DependencyPath::getThisOS() + )); } //============================================================================== @@ -83,10 +96,10 @@ public: props.add (new TextPropertyComponent (getVersionCodeValue(), "Android Version Code", 32, false), "An integer value that represents the version of the application code, relative to other versions."); - props.add (new DependencyPathPropertyComponent (getSDKPathValue(), "Android SDK Path", DependencyPath::androidSdkKeyName), + props.add (new DependencyPathPropertyComponent (getSDKPathValue(), "Android SDK Path"), "The path to the Android SDK folder on the target build machine"); - props.add (new DependencyPathPropertyComponent (getNDKPathValue(), "Android NDK Path", DependencyPath::androidNdkKeyName), + props.add (new DependencyPathPropertyComponent (getNDKPathValue(), "Android NDK Path"), "The path to the Android NDK folder on the target build machine"); props.add (new TextPropertyComponent (getMinimumSDKVersionValue(), "Minimum SDK version", 32, false), @@ -132,10 +145,10 @@ public: String getActivitySubClassPath() const { return settings [Ids::androidActivitySubClassName]; } Value getVersionCodeValue() { return getSetting (Ids::androidVersionCode); } String getVersionCodeString() const { return settings [Ids::androidVersionCode]; } - Value getSDKPathValue() { return getSetting (Ids::androidSDKPath); } - String getSDKPathString() const { return settings [Ids::androidSDKPath]; } - Value getNDKPathValue() { return getSetting (Ids::androidNDKPath); } - String getNDKPathString() const { return settings [Ids::androidNDKPath]; } + Value getSDKPathValue() { return sdkPath; } + String getSDKPathString() const { return sdkPath.toString(); } + Value getNDKPathValue() { return ndkPath; } + String getNDKPathString() const { return ndkPath.toString(); } Value getNDKToolchainVersionValue() { return getSetting (Ids::toolset); } String getNDKToolchainVersionString() const { return settings [Ids::toolset]; } @@ -749,5 +762,7 @@ private: } //============================================================================== + Value sdkPath, ndkPath; + JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter) }; diff --git a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp index 251546cdcf..662a40b8cf 100644 --- a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.cpp @@ -22,6 +22,18 @@ const String DependencyPath::androidNdkKeyName = "androidNdkPath"; //============================================================================== +DependencyPathValueSource::DependencyPathValueSource (const Value& projectSettingsPath, + String globalSettingsKey, + DependencyPathOS osThisSettingAppliesTo) + : projectSettingsValue (projectSettingsPath), + globalKey (globalSettingsKey), + os (osThisSettingAppliesTo), + globalSettingsValue (PathSettingsTab::getPathByKey (globalKey, os)), + fallbackValue (PathSettingsTab::getFallbackPathByKey (globalKey, os)) +{ + globalSettingsValue.addListener (this); +} + bool DependencyPathValueSource::isValidPath() const { // if we are on another OS than the one which this path setting is for, @@ -34,16 +46,10 @@ bool DependencyPathValueSource::isValidPath() const //============================================================================== DependencyPathPropertyComponent::DependencyPathPropertyComponent (const Value& value, - const String& propertyName, - const String& globalKey, - DependencyPathOS os) - : TextPropertyComponent (propertyName, 1024, false), - pathValueSource (new DependencyPathValueSource (value, - PathSettingsTab::getPathByKey (globalKey, os), - PathSettingsTab::getFallbackPathByKey (globalKey, os), - globalKey, - os)), - pathValue (pathValueSource) + const String& propertyName) +try : TextPropertyComponent (propertyName, 1024, false), + pathValue (value), + pathValueSource (dynamic_cast (pathValue.getValueSource())) { bool initialValueIsEmpty = value.toString().isEmpty(); @@ -60,12 +66,19 @@ DependencyPathPropertyComponent::DependencyPathPropertyComponent (const Value& v else jassertfalse; } +catch (const std::bad_cast&) +{ + // a DependencyPathPropertyComponent must be initialised with a Value + // that is referring to a DependencyPathValueSource! + jassertfalse; + throw; +} void DependencyPathPropertyComponent::valueChanged (Value& value) { // this callback handles the update of this setting in case // the user changed the global preferences. - if (value.refersToSameSourceAs (pathValue) && pathValueSource->isUsingGlobalSettings()) + if (value.refersToSameSourceAs (pathValue) && pathValueSource.isUsingGlobalSettings()) textWasEdited(); } @@ -77,11 +90,11 @@ void DependencyPathPropertyComponent::textWasEdited() Colour DependencyPathPropertyComponent::getTextColourToDisplay() const { - if (! pathValueSource->isUsingProjectSettings()) - return pathValueSource->isValidPath() ? Colours::grey + if (! pathValueSource.isUsingProjectSettings()) + return pathValueSource.isValidPath() ? Colours::grey : Colours::lightpink; - return pathValueSource->isValidPath() ? Colours::black + return pathValueSource.isValidPath() ? Colours::black : Colours::red; } @@ -91,7 +104,7 @@ void DependencyPathPropertyComponent::labelTextChanged (Label*) void DependencyPathPropertyComponent::editorShown (Label* /*label*/, TextEditor& editor) { - if (! pathValueSource->isUsingProjectSettings()) + if (! pathValueSource.isUsingProjectSettings()) editor.setText (String::empty, dontSendNotification); } diff --git a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h index bb6b124bd0..fd897a7c33 100644 --- a/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h +++ b/extras/Introjucer/Source/Project/jucer_DependencyPathPropertyComponent.h @@ -54,18 +54,8 @@ class DependencyPathValueSource : public Value::ValueSource, { 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); - } + DependencyPathOS osThisSettingAppliesTo = DependencyPath::getThisOS()); /** This gets the currently used value, which may be either the project setting, the global setting, or the fallback value. */ @@ -142,6 +132,16 @@ private: /** the dependency path setting as set in this Introjucer project. */ Value projectSettingsValue; + /** 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). */ + DependencyPathOS os; + /** the dependency path global setting on this machine. used when there value set for this project is invalid. */ Value globalSettingsValue; @@ -150,16 +150,6 @@ private: whenever the latter doesn't apply, e.g. the setting is for another 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). */ - DependencyPathOS os; }; @@ -170,9 +160,7 @@ class DependencyPathPropertyComponent : public TextPropertyComponent, { public: DependencyPathPropertyComponent (const Value& value, - const String& propertyName, - const String& globalKey, - DependencyPathOS os = DependencyPath::getThisOS()); + const String& propertyName); private: @@ -186,12 +174,12 @@ private: /** This function handles path changes because the global path changed. */ void valueChanged (Value& value) override; - /** the value source of this dependency path setting. */ - DependencyPathValueSource* pathValueSource; - - /** the value object around the value source. */ + /** the value that represents this dependency path setting. */ Value pathValue; + /** a reference to the value source that this value refers to. */ + DependencyPathValueSource& pathValueSource; + // Label::Listener overrides: void labelTextChanged (Label* labelThatHasChanged) override; void editorShown (Label*, TextEditor&) override;