public MainWindowViewModel(IPlatformSpecificServices services) { this.services = services; GenerationVM = new GenerationViewModel(services); TimeShiftVM = new TimeShifterViewModel(); ReplaceVM = new ReplaceViewModel(); StrobeEffectVM = new StrobeEffectViewModel(); LaserLightsVM = new LaserLightsViewModel(); UndoManager = new UndoManager <ShowLightViewModel>(); // Bind collection to UI Showlights.Connect() .AutoRefresh() .Sort(SortExpressionComparer <ShowLightViewModel> .Ascending(s => s.Time)) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var list) .Subscribe(); ObservableShowlights = list; // Subscribe to changes in the collection to set FileDirty Showlights.Connect() .AutoRefresh() .Subscribe(_ => { if (!FileDirty) { FileDirty = true; } }); CreateReactiveCommands(); UndoManager.FileIsClean .Subscribe(_ => FileDirty = false); this.WhenAnyValue(x => x.OpenFileName, x => x.FileDirty) .Subscribe(UpdateWindowTitle); // Update active colors when selected item changes or is edited this.WhenAnyValue(x => x.SelectedItem, x => x.SelectedItem.Note, (selected, _) => selected) .Where(selected => selected is not null) .Subscribe(sl => { MoveToTime = sl.Time / 1000f; InsertTime = sl.Time / 1000f; UpdateActiveColors(sl); }); this.WhenAnyValue(x => x.ActiveFogColor, x => x.ActiveBeamColor, (fog, beam) => $"Fog: {(fog == default ? "N/A" : fog.ToString())}\nBeam: {(beam == default ? "N/A" : beam.ToString())}") .ToPropertyEx(this, x => x.PreviewTooltip); }
public MainWindowViewModel(IPlatformSpecificServices services, ConfigurationWindowViewModel configViewModel) { // TODO: Remove? Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); this.services = services; CreateReactiveCommands(); SetupObservables(); // Reset "view log" text if user clears log files configViewModel.LogsCleared.Subscribe(_ => RemoveViewLogTexts()); // Ensure that application data and log directories exist Directory.CreateDirectory(Program.AppDataPath); Directory.CreateDirectory(Program.LogDirectory); }
public GenerationViewModel(IPlatformSpecificServices services) { this.services = services; var preferencesFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PrefFileName); if (File.Exists(preferencesFile)) { Preferences = GenerationPreferences.Load(preferencesFile); } else { Preferences = new GenerationPreferences(); } FogMethodRB = ReactiveCommand.Create <FogGenerationMethod>(method => Preferences.FogMethod = method); BeamMethodRB = ReactiveCommand.Create <BeamGenerationMethod>(method => Preferences.BeamMethod = method); SelectArrangement = ReactiveCommand.CreateFromTask <ShowLightType>(SelectArrangement_Impl); var canGenerate = this.WhenAnyValue( x => x.ShouldGenerateBeams, x => x.ShouldGenerateFog, x => x.ArrangementSelected, (beam, fog, selected) => selected && (beam || fog)); Generate = ReactiveCommand.CreateFromTask(Generate_Impl, canGenerate); Cancel = ReactiveCommand.Create(() => Hide(result: false), Generate.IsExecuting.Select(x => !x)); this.WhenAnyValue(x => x.ArrangementForFogFilename) .Where(str => str is not null) .Select(Path.GetFileName) .ToPropertyEx(this, x => x.ArrangementForFogText, "None Selected"); this.WhenAnyValue(x => x.ArrangementForBeamsFilename) .Where(str => str is not null) .Select(Path.GetFileName) .ToPropertyEx(this, x => x.ArrangementForBeamsText, "None Selected"); }