From 90a635d5f39239bf4a2e17feffa38021e7eafeb3 Mon Sep 17 00:00:00 2001 From: Fang Xiaohui Date: Thu, 24 Mar 2022 09:30:07 +0800 Subject: [PATCH] [NUI][Xaml] Remove unused method --- .../src/internal/XamlBinding/BindingExpression.cs | 2 +- .../src/public/BaseComponents/TextEditor.cs | 44 ++--- .../BaseComponents/TextEditorBindableProperty.cs | 2 + .../src/public/BaseComponents/TextField.cs | 46 ++---- .../BaseComponents/TextFieldBindableProperty.cs | 2 + src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs | 2 +- .../src/public/XamlBinding/BindableObject.cs | 181 +++++++++------------ .../src/public/XamlBinding/TypedBinding.cs | 2 +- 8 files changed, 111 insertions(+), 170 deletions(-) diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs index 7eb889a..a239617 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs @@ -186,7 +186,7 @@ namespace Tizen.NUI.Binding return; } - target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false); + target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted); } else if (needsSetter && part.LastSetter != null && current != null) { diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index a63a90f..b338296 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -37,6 +37,7 @@ namespace Tizen.NUI.BaseComponents private InputMethodContext inputMethodContext = null; private float fontSizeScale = 1.0f; private bool hasFontSizeChangedCallback = false; + private bool isSettingTextInCSharp = false; static TextEditor() { } @@ -77,6 +78,8 @@ namespace Tizen.NUI.BaseComponents { SetVisible(false); } + + TextChanged += TextEditorTextChanged; } internal TextEditor(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true, TextEditorStyle style = null) : base(cPtr, cMemoryOwn, style) @@ -85,6 +88,8 @@ namespace Tizen.NUI.BaseComponents { SetVisible(false); } + + TextChanged += TextEditorTextChanged; } /// @@ -1843,32 +1848,6 @@ namespace Tizen.NUI.BaseComponents } } - internal override bool IsBinded - { - get - { - return base.IsBinded; - } - set - { - base.IsBinded = value; - - if (value == true) - { - TextChanged += TextEditorTextChanged; - } - else - { - TextChanged -= TextEditorTextChanged; - } - } - } - - private void TextEditorTextChanged(object sender, TextChangedEventArgs e) - { - ForceNotifyBindedInstance(TextProperty); - } - /// /// The FontSizeScale property.
/// The default value is 1.0.
@@ -2119,10 +2098,7 @@ namespace Tizen.NUI.BaseComponents } } - if (IsBinded) - { - TextChanged -= TextEditorTextChanged; - } + TextChanged -= TextEditorTextChanged; base.Dispose(type); } @@ -2209,6 +2185,14 @@ namespace Tizen.NUI.BaseComponents } } + private void TextEditorTextChanged(object sender, TextChangedEventArgs e) + { + if (!isSettingTextInCSharp) + { + ForceNotifyBindedInstance(TextProperty); + } + } + internal new class Property { internal static readonly int TEXT = Interop.TextEditor.TextGet(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs index 2ded6c4..06deef4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs @@ -33,7 +33,9 @@ namespace Tizen.NUI.BaseComponents var textEditor = (TextEditor)bindable; if (newValue != null) { + textEditor.isSettingTextInCSharp = true; Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textEditor.SwigCPtr, TextEditor.Property.TEXT, new Tizen.NUI.PropertyValue((string)newValue)); + textEditor.isSettingTextInCSharp = false; } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index acc4180..bc460b0 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -38,6 +38,7 @@ namespace Tizen.NUI.BaseComponents private InputMethodContext inputMethodCotext = null; private float fontSizeScale = 1.0f; private bool hasFontSizeChangedCallback = false; + private bool isSettingTextInCSharp = false; static TextField() { } @@ -77,6 +78,8 @@ namespace Tizen.NUI.BaseComponents { SetVisible(false); } + + TextChanged += TextEditorTextChanged; } internal TextField(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null) @@ -85,6 +88,8 @@ namespace Tizen.NUI.BaseComponents { SetVisible(false); } + + TextChanged += TextEditorTextChanged; } internal TextField(TextField handle, bool shown = true) : this(Interop.TextField.NewTextField(TextField.getCPtr(handle)), true) @@ -95,6 +100,8 @@ namespace Tizen.NUI.BaseComponents { SetVisible(false); } + + TextChanged += TextEditorTextChanged; } internal enum ExceedPolicyType @@ -2017,32 +2024,6 @@ namespace Tizen.NUI.BaseComponents } } - internal override bool IsBinded - { - get - { - return base.IsBinded; - } - set - { - base.IsBinded = value; - - if (value == true) - { - TextChanged += TextEditorTextChanged; - } - else - { - TextChanged -= TextEditorTextChanged; - } - } - } - - private void TextEditorTextChanged(object sender, TextChangedEventArgs e) - { - ForceNotifyBindedInstance(TextProperty); - } - /// /// Get the InputMethodContext instance. /// @@ -2165,10 +2146,7 @@ namespace Tizen.NUI.BaseComponents } } - if (IsBinded) - { - TextChanged -= TextEditorTextChanged; - } + TextChanged -= TextEditorTextChanged; base.Dispose(type); } @@ -2259,6 +2237,14 @@ namespace Tizen.NUI.BaseComponents } } + private void TextEditorTextChanged(object sender, TextChangedEventArgs e) + { + if (!isSettingTextInCSharp) + { + ForceNotifyBindedInstance(TextProperty); + } + } + internal new class Property { internal static readonly int TEXT = Interop.TextField.TextGet(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs index 9ba8fd2..3db6918 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs @@ -84,7 +84,9 @@ namespace Tizen.NUI.BaseComponents var textField = (TextField)bindable; if (newValue != null) { + textField.isSettingTextInCSharp = true; Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textField.SwigCPtr, TextField.Property.TEXT, new Tizen.NUI.PropertyValue((string)newValue)); + textField.isSettingTextInCSharp = false; } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => diff --git a/src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs b/src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs index 9ec42de..e7c0855 100755 --- a/src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs +++ b/src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs @@ -667,7 +667,7 @@ namespace Tizen.NUI if (bindable == null) throw new ArgumentNullException(nameof(bindable)); - bindable.SetValueCore(property, value, SetValueFlags.None, SetValuePrivateFlags.ManuallySet, false); + bindable.SetValueCore(property, value, SetValueFlags.None, SetValuePrivateFlags.ManuallySet); } internal static void OnChildPropertyChanged(Binding.BindableObject bindable, object oldValue, object newValue) { diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs b/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs index 426fb55..3f5a40a 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs @@ -217,6 +217,51 @@ namespace Tizen.NUI.Binding set; } + /// This will be public opened in next ACR. + [EditorBrowsable(EditorBrowsableState.Never)] + public void ForceNotifyBindedInstance(BindableProperty property) + { + if (null != property) + { + BindablePropertyContext context = GetOrCreateContext(property); + BindingBase binding = context.Binding; + + var currentlyApplying = applying; + + if (binding != null && !currentlyApplying) + { + applying = true; + binding.Apply(true); + applying = false; + } + + OnPropertyChanged(property.PropertyName); + + PropertyToGroup.TryGetValue(property, out HashSet propertyGroup); + + if (null != propertyGroup) + { + foreach (var relativeProperty in propertyGroup) + { + if (relativeProperty != property) + { + var relativeContext = GetOrCreateContext(relativeProperty); + var relativeBinding = relativeContext.Binding; + + if (null != relativeBinding) + { + applying = true; + relativeBinding.Apply(true); + applying = false; + } + + OnPropertyChanged(relativeProperty.PropertyName); + } + } + } + } + } + /// /// Sets the value of the specified property. /// @@ -260,48 +305,6 @@ namespace Tizen.NUI.Binding } } - /// This will be public opened in next ACR. - [EditorBrowsable(EditorBrowsableState.Never)] - public void ForceNotifyBindedInstance(BindableProperty property) - { - if (null != property) - { - BindablePropertyContext context = GetOrCreateContext(property); - - if (null != context?.Binding) - { - applying = true; - context.Binding.Apply(true); - applying = false; - } - - OnPropertyChanged(property.PropertyName); - - PropertyToGroup.TryGetValue(property, out HashSet propertyGroup); - - if (null != propertyGroup) - { - foreach (var relativeProperty in propertyGroup) - { - if (relativeProperty != property) - { - var relativeContext = GetOrCreateContext(relativeProperty); - var relativeBinding = relativeContext.Binding; - - if (null != relativeBinding) - { - applying = true; - relativeBinding.Apply(true); - applying = false; - } - - OnPropertyChanged(relativeProperty.PropertyName); - } - } - } - } - } - /// /// Sets the value of the propertyKey. /// @@ -643,7 +646,7 @@ namespace Tizen.NUI.Binding internal void SetValueCore(BindablePropertyKey propertyKey, object value, SetValueFlags attributes = SetValueFlags.None) { - SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None, false); + SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None); } /// @@ -655,10 +658,10 @@ namespace Tizen.NUI.Binding [EditorBrowsable(EditorBrowsableState.Never)] internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes = SetValueFlags.None) { - SetValueCore(property, value, attributes, SetValuePrivateFlags.Default, false); + SetValueCore(property, value, attributes, SetValuePrivateFlags.Default); } - internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal) + internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) { bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0; bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0; @@ -716,7 +719,7 @@ namespace Tizen.NUI.Binding else { context.Attributes |= BindableContextAttributes.IsBeingSet; - SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent); + SetValueActual(property, context, value, currentlyApplying, attributes, silent); Queue delayQueue = context.DelayedSetters; if (delayQueue != null) @@ -724,7 +727,7 @@ namespace Tizen.NUI.Binding while (delayQueue.Count > 0) { SetValueArgs s = delayQueue.Dequeue(); - SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes); + SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, s.Attributes); } context.DelayedSetters = null; @@ -752,7 +755,7 @@ namespace Tizen.NUI.Binding } } - internal virtual bool IsBinded + internal bool IsBinded { get; set; @@ -890,11 +893,10 @@ namespace Tizen.NUI.Binding return; SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource, - (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0), - false); + (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0)); } - void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false) + void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent = false) { object original = context.Value; bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0; @@ -933,71 +935,36 @@ namespace Tizen.NUI.Binding PropertyToGroup.TryGetValue(property, out HashSet propertyGroup); - if (!silent) + if (!silent && (!same || raiseOnEqual)) { - if ((!same || raiseOnEqual)) - { - property.PropertyChanged?.Invoke(this, original, value); + property.PropertyChanged?.Invoke(this, original, value); - if (binding != null && !currentlyApplying) - { - applying = true; - binding.Apply(true); - applying = false; - } - - OnPropertyChanged(property.PropertyName); - - if (null != propertyGroup) - { - foreach (var relativeProperty in propertyGroup) - { - if (relativeProperty != property) - { - var relativeContext = GetOrCreateContext(relativeProperty); - var relativeBinding = relativeContext.Binding; - - if (null != relativeBinding) - { - applying = true; - relativeBinding.Apply(true); - applying = false; - } - - OnPropertyChanged(relativeProperty.PropertyName); - } - } - } - } - else if (true == same && true == forceSendChangeSignal) + if (binding != null && !currentlyApplying) { - if (binding != null && !currentlyApplying) - { - applying = true; - binding.Apply(true); - applying = false; - } + applying = true; + binding.Apply(true); + applying = false; + } - OnPropertyChanged(property.PropertyName); + OnPropertyChanged(property.PropertyName); - if (null != propertyGroup) + if (null != propertyGroup) + { + foreach (var relativeProperty in propertyGroup) { - foreach (var relativeProperty in propertyGroup) + if (relativeProperty != property) { - if (relativeProperty != property) - { - var relativeContext = GetOrCreateContext(relativeProperty); - var relativeBinding = relativeContext.Binding; - - if (null != relativeBinding) - { - applying = true; - relativeBinding.Apply(true); - applying = false; - } + var relativeContext = GetOrCreateContext(relativeProperty); + var relativeBinding = relativeContext.Binding; - OnPropertyChanged(relativeProperty.PropertyName); + if (null != relativeBinding) + { + applying = true; + relativeBinding.Apply(true); + applying = false; } + + OnPropertyChanged(relativeProperty.PropertyName); } } } diff --git a/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs b/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs index 7061209..6c68f43 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs @@ -247,7 +247,7 @@ namespace Tizen.NUI.Binding.Internals // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType); return; } - target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false); + target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted); return; } -- 2.7.4