public void AddRemovePathsTest() { var setting = new PreferenceSettings() { CustomPackageFolders = { @"Z:\" } }; var vm = new PackagePathViewModel(setting); var path = string.Empty; vm.RequestShowFileDialog += (sender, args) => { args.Path = path; }; path = @"C:\"; vm.AddPathCommand.Execute(null); path = @"D:\"; vm.AddPathCommand.Execute(null); Assert.AreEqual(0, vm.SelectedIndex); Assert.AreEqual(@"C:\", vm.RootLocations[1]); Assert.AreEqual(@"D:\", vm.RootLocations[2]); vm.SelectedIndex = 2; vm.DeletePathCommand.Execute(0); Assert.AreEqual(1, vm.SelectedIndex); Assert.AreEqual(@"C:\", vm.RootLocations[0]); Assert.AreEqual(@"D:\", vm.RootLocations[1]); }
internal PackagePathView(PackagePathViewModel viewModel) { if (viewModel == null) throw new ArgumentNullException("viewModel"); InitializeComponent(); this.DataContext = viewModel; viewModel.RequestShowFileDialog += OnRequestShowFileDialog; viewModel.PropertyChanged += OnPropertyChanged; UpdateVisualToReflectSelectionState(); }
public void CannotDeletePathIfThereIsOnlyOne() { var setting = new PreferenceSettings { CustomPackageFolders = { @"C:\" } }; var vm = new PackagePathViewModel(setting); Assert.AreEqual(1, vm.RootLocations.Count); Assert.IsFalse(vm.DeletePathCommand.CanExecute(null)); }
public void ReorderingPathsTest() { var setting = new PreferenceSettings { CustomPackageFolders = { @"C:\", @"D:\", @"E:\" } }; var vm = new PackagePathViewModel(setting); Assert.AreEqual(0, vm.SelectedIndex); Assert.IsTrue(vm.MovePathDownCommand.CanExecute(null)); Assert.IsFalse(vm.MovePathUpCommand.CanExecute(null)); vm.SelectedIndex = 2; Assert.AreEqual(2, vm.SelectedIndex); Assert.IsTrue(vm.MovePathUpCommand.CanExecute(null)); Assert.IsFalse(vm.MovePathDownCommand.CanExecute(null)); vm.SelectedIndex = 1; Assert.AreEqual(1, vm.SelectedIndex); Assert.IsTrue(vm.MovePathUpCommand.CanExecute(null)); Assert.IsTrue(vm.MovePathDownCommand.CanExecute(null)); vm.MovePathUpCommand.Execute(vm.SelectedIndex); Assert.AreEqual(0, vm.SelectedIndex); Assert.AreEqual(@"D:\", vm.RootLocations[0]); Assert.AreEqual(@"C:\", vm.RootLocations[1]); Assert.AreEqual(@"E:\", vm.RootLocations[2]); vm.SelectedIndex = 1; vm.MovePathDownCommand.Execute(vm.SelectedIndex); Assert.AreEqual(2, vm.SelectedIndex); Assert.AreEqual(@"D:\", vm.RootLocations[0]); Assert.AreEqual(@"E:\", vm.RootLocations[1]); Assert.AreEqual(@"C:\", vm.RootLocations[2]); }
private void DynamoViewModelRequestPackagePaths(object sender, EventArgs e) { var viewModel = new PackagePathViewModel(dynamoViewModel.PreferenceSettings); var view = new PackagePathView(viewModel) { Owner = this }; view.ShowDialog(); }
private void DynamoViewModelRequestPackagePaths(object sender, EventArgs e) { var loadPackagesParams = new LoadPackageParams { Preferences = dynamoViewModel.PreferenceSettings, PathManager = dynamoViewModel.Model.PathManager, }; var customNodeManager = dynamoViewModel.Model.CustomNodeManager; var packageLoader = dynamoViewModel.Model.GetPackageManagerExtension().PackageLoader; var viewModel = new PackagePathViewModel(packageLoader,loadPackagesParams,customNodeManager); var view = new PackagePathView(viewModel) { Owner = this }; view.ShowDialog(); }
/// <summary> /// The PreferencesViewModel constructor basically initialize all the ItemsSource for the corresponding ComboBox in the View (PreferencesView.xaml) /// </summary> public PreferencesViewModel(DynamoViewModel dynamoViewModel) { this.preferenceSettings = dynamoViewModel.PreferenceSettings; this.pythonScriptEditorTextOptions = dynamoViewModel.PythonScriptEditorTextOptions; this.runPreviewEnabled = dynamoViewModel.HomeSpaceViewModel.RunSettingsViewModel.RunButtonEnabled; this.homeSpace = dynamoViewModel.HomeSpace; this.dynamoViewModel = dynamoViewModel; this.installedPackagesViewModel = new InstalledPackagesViewModel(dynamoViewModel, dynamoViewModel.PackageManagerClientViewModel.PackageManagerExtension.PackageLoader); // Scan for engines AddPythonEnginesOptions(); PythonEngineManager.Instance.AvailableEngines.CollectionChanged += PythonEnginesChanged; //Sets SelectedPythonEngine. //If the setting is empty it corresponds to the default python engine var engine = PythonEnginesList.FirstOrDefault(x => x.Equals(preferenceSettings.DefaultPythonEngine)); SelectedPythonEngine = string.IsNullOrEmpty(engine) ? Res.DefaultPythonEngineNone : preferenceSettings.DefaultPythonEngine; string languages = Wpf.Properties.Resources.PreferencesWindowLanguages; LanguagesList = new ObservableCollection <string>(languages.Split(',')); SelectedLanguage = languages.Split(',').First(); FontSizeList = new ObservableCollection <string>(); FontSizeList.Add(Wpf.Properties.Resources.ScalingSmallButton); FontSizeList.Add(Wpf.Properties.Resources.ScalingMediumButton); FontSizeList.Add(Wpf.Properties.Resources.ScalingLargeButton); FontSizeList.Add(Wpf.Properties.Resources.ScalingExtraLargeButton); SelectedFontSize = Wpf.Properties.Resources.ScalingMediumButton; NumberFormatList = new ObservableCollection <string>(); NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber0); NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber00); NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber000); NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber0000); NumberFormatList.Add(Wpf.Properties.Resources.DynamoViewSettingMenuNumber00000); SelectedNumberFormat = preferenceSettings.NumberFormat; runSettingsIsChecked = preferenceSettings.DefaultRunType; RunPreviewIsChecked = preferenceSettings.ShowRunPreview; //By Default the warning state of the Visual Settings tab (Group Styles section) will be disabled isWarningEnabled = false; StyleItemsList = LoadStyles(preferenceSettings.GroupStyleItemsList); //When pressing the "Add Style" button some controls will be shown with some values by default so later they can be populated by the user AddStyleControl = new StyleItem() { GroupName = "", HexColorString = "#" + GetRandomHexStringColor() }; //This piece of code will populate all the description text for the RadioButtons in the Geometry Scaling section. optionsGeometryScale = new GeometryScalingOptions(); UpdateGeoScaleRadioButtonSelected(dynamoViewModel.ScaleFactorLog); optionsGeometryScale.DescriptionScaleRange = new ObservableCollection <string>(); optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Small].Item2, scaleRanges[GeometryScaleSize.Small].Item3)); optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Medium].Item2, scaleRanges[GeometryScaleSize.Medium].Item3)); optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Large].Item2, scaleRanges[GeometryScaleSize.Large].Item3)); optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.ExtraLarge].Item2, scaleRanges[GeometryScaleSize.ExtraLarge].Item3)); SavedChangesLabel = string.Empty; SavedChangesTooltip = string.Empty; preferencesTabs = new Dictionary <string, TabSettings>(); preferencesTabs.Add("General", new TabSettings() { Name = "General", ExpanderActive = string.Empty }); preferencesTabs.Add("Features", new TabSettings() { Name = "Features", ExpanderActive = string.Empty }); preferencesTabs.Add("VisualSettings", new TabSettings() { Name = "VisualSettings", ExpanderActive = string.Empty }); preferencesTabs.Add("Package Manager", new TabSettings() { Name = "Package Manager", ExpanderActive = string.Empty }); //create a packagePathsViewModel we'll use to interact with the package search paths list. var loadPackagesParams = new LoadPackageParams { Preferences = preferenceSettings }; var customNodeManager = dynamoViewModel.Model.CustomNodeManager; var packageLoader = dynamoViewModel.Model.GetPackageManagerExtension()?.PackageLoader; PackagePathsViewModel = new PackagePathViewModel(packageLoader, loadPackagesParams, customNodeManager); WorkspaceEvents.WorkspaceSettingsChanged += PreferencesViewModel_WorkspaceSettingsChanged; PropertyChanged += Model_PropertyChanged; }