Skip to content

Commit

Permalink
Analytics Change for Preferences View (#11696)
Browse files Browse the repository at this point in the history
* Analytics Change for Preferences View

* Code Clean up
  • Loading branch information
QilongTang authored May 20, 2021
1 parent 36d79c6 commit fa2a9e9
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 60 deletions.
9 changes: 0 additions & 9 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,6 @@ You will get a chance to save your work.</value>
<value>Number Format</value>
<comment>Setting menu | Number format</comment>
</data>
<data name="DynamoViewSettingMenuRenderPrecision" xml:space="preserve">
<value>Render Precision</value>
<comment>Setting menu | Render precision</comment>
</data>
<data name="DynamoViewSettingMenuSquareCentimeter" xml:space="preserve">
<value>Square Centimeter</value>
<comment>Setting menu | Square centimeter</comment>
Expand Down
4 changes: 0 additions & 4 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,6 @@
<value>Number Format</value>
<comment>Setting menu | Number format</comment>
</data>
<data name="DynamoViewSettingMenuRenderPrecision" xml:space="preserve">
<value>Render Precision</value>
<comment>Setting menu | Render precision</comment>
</data>
<data name="DynamoViewSettingMenuSquareCentimeter" xml:space="preserve">
<value>Square Centimeter</value>
<comment>Setting menu | Square centimeter</comment>
Expand Down
101 changes: 71 additions & 30 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dynamo.Configuration;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Wpf.ViewModels.Core.Converters;
using System;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class PreferencesViewModel : ViewModelBase, INotifyPropertyChanged
private HomeWorkspaceModel homeSpace;
private DynamoViewModel dynamoViewModel;
private bool isWarningEnabled;
private GeometryScalingOptions optionsGeometryScal = null;
private GeometryScalingOptions optionsGeometryScale = null;
#endregion Private Properties

public GeometryScaleSize ScaleSize { get; set; }
Expand Down Expand Up @@ -108,6 +109,7 @@ public string SavedChangesTooltip

}
}

//This includes all the properties that can be set on the General tab
#region General Properties
/// <summary>
Expand Down Expand Up @@ -310,16 +312,16 @@ public StyleItem AddStyleControl
/// <summary>
/// This property is used as a container for the description text (GeometryScalingOptions.DescriptionScaleRange) for each radio button (Visual Settings -> Geometry Scaling section)
/// </summary>
public GeometryScalingOptions OptionsGeometryScal
public GeometryScalingOptions OptionsGeometryScale
{
get
{
return optionsGeometryScal;
return optionsGeometryScale;
}
set
{
optionsGeometryScal = value;
RaisePropertyChanged(nameof(OptionsGeometryScal));
optionsGeometryScale = value;
RaisePropertyChanged(nameof(OptionsGeometryScale));
}
}

Expand Down Expand Up @@ -604,52 +606,91 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
AddStyleControl = new StyleItem() { GroupName = "", HexColorString = "#" + GetRandomHexStringColor() };

//This piece of code will populate all the description text for the RadioButtons in the Geometry Scaling section.
optionsGeometryScal = new GeometryScalingOptions();
optionsGeometryScale = new GeometryScalingOptions();

//This will set the default option for the Geometry Scaling Radio Buttons, the value is comming from the DynamoViewModel
optionsGeometryScal.EnumProperty = (GeometryScaleSize)GeometryScalingOptions.ConvertScaleFactorToUI(dynamoViewModel.ScaleFactorLog);
optionsGeometryScale.EnumProperty = (GeometryScaleSize)GeometryScalingOptions.ConvertScaleFactorToUI(dynamoViewModel.ScaleFactorLog);

optionsGeometryScal.DescriptionScaleRange = new ObservableCollection<string>();
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Small].Item2,
optionsGeometryScale.DescriptionScaleRange = new ObservableCollection<string>();
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Small].Item2,
scaleRanges[GeometryScaleSize.Small].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Medium].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Medium].Item2,
scaleRanges[GeometryScaleSize.Medium].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Large].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Large].Item2,
scaleRanges[GeometryScaleSize.Large].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.ExtraLarge].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.ExtraLarge].Item2,
scaleRanges[GeometryScaleSize.ExtraLarge].Item3));

SavedChangesLabel = string.Empty;
SavedChangesTooltip = string.Empty;

this.PropertyChanged += model_PropertyChanged;
this.PropertyChanged += Model_PropertyChanged;
}

/// <summary>
/// Listen for the PropertyChanged event and updates the saved changes label accordingly
/// </summary>
private void model_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
string description = string.Empty;
// C# does not support going through all cases when one of the case is true
switch (e.PropertyName)
{
case "SelectedLanguage":
case "SelectedFontSize":
case "SelectedNumberFormat":
case "RunSettingsIsChecked":
case "RunPreviewIsChecked":
case "StyleItemsList":
case "OptionsGeometryScal":
case "ShowEdges":
case "IsolateSelectedGeometry":
case "TessellationDivisions":
case "SelectedPythonEngine":
case "HideIronPythonAlertsIsChecked":
case "ShowWhitespaceIsChecked":
case "NodeAutocompleteIsChecked":
case "EnableTSplineIsChecked":
UpdateSavedChangesLabel();
case nameof(SelectedLanguage):
// Do nothing for now
break;
case nameof(SelectedFontSize):
// Do nothing for now
break;
case nameof(SelectedNumberFormat):
description = Res.DynamoViewSettingMenuNumberFormat;
goto default;
case nameof(RunSettingsIsChecked):
description = Res.PreferencesViewRunSettingsLabel;
goto default;
case nameof(RunPreviewIsChecked):
description = Res.DynamoViewSettingShowRunPreview;
goto default;
case nameof(StyleItemsList):
// Do nothing for now
break;
case nameof(OptionsGeometryScale):
description = Res.DynamoViewSettingsMenuChangeScaleFactor;
goto default;
case nameof(ShowEdges):
description = Res.PreferencesViewVisualSettingShowEdges;
goto default;
case nameof(IsolateSelectedGeometry):
description = Res.PreferencesViewVisualSettingsIsolateSelectedGeo;
goto default;
case nameof(TessellationDivisions):
description = Res.PreferencesViewVisualSettingsRenderPrecision;
goto default;
case nameof(SelectedPythonEngine):
description = Res.PreferencesViewDefaultPythonEngine;
goto default;
case nameof(HideIronPythonAlertsIsChecked):
description = Res.PreferencesViewIsIronPythonDialogDisabled;
goto default;
case nameof(ShowWhitespaceIsChecked):
description = Res.PreferencesViewShowWhitespaceInPythonEditor;
goto default;
case nameof(NodeAutocompleteIsChecked):
description = Res.PreferencesViewEnableNodeAutoComplete;
goto default;
case nameof(EnableTSplineIsChecked):
description = Res.PreferencesViewEnableTSplineNodes;
goto default;
default:
if (!string.IsNullOrEmpty(description))
{
// Log switch on each setting and use description equals to label name
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
description);
UpdateSavedChangesLabel();
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
<!--Geometry Scaling Expander-->
<Expander x:Name="Scale"
Grid.Row="1"
DataContext="{Binding OptionsGeometryScal}"
DataContext="{Binding OptionsGeometryScale}"
Style="{StaticResource MenuExpanderStyle}"
Expanded="Expander_Expanded"
Header="{x:Static p:Resources.PreferencesViewVisualSettingsGeoScaling}">
Expand Down
49 changes: 38 additions & 11 deletions src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using Dynamo.Configuration;
using System.Windows.Media;
using Dynamo.Logging;
using Dynamo.ViewModels;
using Res = Dynamo.Wpf.Properties.Resources;
using System.Linq;
using Dynamo.Logging;

namespace Dynamo.Wpf.Views
{
Expand All @@ -18,16 +16,23 @@ namespace Dynamo.Wpf.Views
/// </summary>
public partial class PreferencesView : Window
{
private PreferencesViewModel viewModel;
private DynamoViewModel dynViewModel;
private readonly PreferencesViewModel viewModel;
private readonly DynamoViewModel dynViewModel;

/// <summary>
/// Constructor of Preferences View
/// </summary>
/// <param name="dynamoViewModel"> Dynamo ViewModel</param>
public PreferencesView(DynamoViewModel dynamoViewModel)
{
DataContext = new PreferencesViewModel(dynamoViewModel);
dynViewModel = dynamoViewModel;


InitializeComponent();
Dynamo.Logging.Analytics.TrackEvent(
Actions.Open,
Categories.Preferences);

//If we want the PreferencesView window to be modal, we need to assign the owner (since we created a new Style and not following the common Style)
this.Owner = Application.Current.MainWindow;
Expand All @@ -40,30 +45,48 @@ public PreferencesView(DynamoViewModel dynamoViewModel)
InitRadioButtonsDescription();
}

/// <summary>
/// Add inline description for each geometry scalling radio button
/// </summary>
private void InitRadioButtonsDescription()
{
RadioSmallDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[0]);
RadioSmallDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[0]);

RadioMediumDesc.Inlines.Add(new Run(Res.ChangeScaleFactorPromptDescriptionDefaultSetting) { FontWeight = FontWeights.Bold });
RadioMediumDesc.Inlines.Add(" " + viewModel.OptionsGeometryScal.DescriptionScaleRange[1]);
RadioMediumDesc.Inlines.Add(" " + viewModel.OptionsGeometryScale.DescriptionScaleRange[1]);

RadioLargeDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[1]);
RadioLargeDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[1]);

RadioExtraLargeDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[2]);
RadioExtraLargeDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[2]);
}

/// <summary>
/// Dialog close button handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Dynamo.Logging.Analytics.TrackEvent(
Actions.Close,
Categories.Preferences);
this.Close();
}

//When the TitleBar is clicked this method will be executed
/// <summary>
/// handler for preferences dialog dragging action. When the TitleBar is clicked this method will be executed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PreferencesPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
//Drag functionality when the TitleBar is clicked with the left button and dragged to another place
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
Dynamo.Logging.Analytics.TrackEvent(
Actions.Move,
Categories.Preferences);
}
}

Expand Down Expand Up @@ -190,6 +213,10 @@ private void Geometry_Scaling_Checked(object sender, RoutedEventArgs e)
{
Log(String.Format("Geometry working range changed to {0} ({1}, {2})",
viewModel.ScaleRange.Item1, viewModel.ScaleRange.Item2, viewModel.ScaleRange.Item3));
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
Res.PreferencesViewVisualSettingsGeoScaling);
}

var allNodes = dynViewModel.HomeSpace.Nodes;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeServices/IAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum Actions
Delete,

/// <summary>
/// Move Event, such as Node move
/// Move Event, such as Node move, dialog move
/// </summary>
Move,

Expand Down

0 comments on commit fa2a9e9

Please sign in to comment.