Esempio n. 1
0
 public static void SetApplicationClosing(Window element, ApplicationExitingDelegate value)
 {
     element.SetValue(ApplicationClosingProperty, value);
 }
Esempio n. 2
0
 public static void SetApplicationClosing(Window element, ApplicationExitingDelegate value)
 {
     element.SetValue(ApplicationClosingProperty, value);
 }
Esempio n. 3
0
        public WindowViewModel(IObjectProvider objectProvider,
                               IWindowFactory windowFactory,
                               ILogger logger,
                               IWindowsController windowsController,
                               RecentFilesViewModel recentFilesViewModel,
                               GeneralOptionsViewModel generalOptionsViewModel,
                               ISchedulerProvider schedulerProvider,
                               IApplicationStatePublisher applicationStatePublisher)
        {
            _logger            = logger;
            _windowsController = windowsController;
            RecentFiles        = recentFilesViewModel;
            GeneralOptions     = generalOptionsViewModel;
            _schedulerProvider = schedulerProvider;
            _objectProvider    = objectProvider;
            InterTabClient     = new InterTabClient(windowFactory);
            OpenFileCommand    = new Command(OpenFile);

            ShowInGitHubCommand  = new Command(() => Process.Start("https://github.com/RolandPheasant"));
            ZoomOutCommand       = new Command(() => { GeneralOptions.Scale = GeneralOptions.Scale + 5; });
            ZoomInCommand        = new Command(() => { GeneralOptions.Scale = GeneralOptions.Scale - 5; });
            CollectMemoryCommand = new Command(() =>
            {
                //Diagnostics [useful for memory testing]
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            });
            ExitCommmand = new Command(() =>
            {
                applicationStatePublisher.Publish(ApplicationState.ShuttingDown);
                Application.Current.Shutdown();
            });
            WindowExiting = () =>
            {
                applicationStatePublisher.Publish(ApplicationState.ShuttingDown);
            };

            Version = $"v{Assembly.GetEntryAssembly().GetName().Version.ToString(3)}";

            var fileDropped = DropMonitor.Dropped.Subscribe(OpenFile);

            var isEmptyChecker = Views.ToObservableChangeSet()
                                 .ToCollection()
                                 .Select(items => items.Count)
                                 .StartWith(0)
                                 .Select(count => count == 0)
                                 .LogErrors(logger)
                                 .Subscribe(isEmpty => IsEmpty = isEmpty);

            var openRecent = recentFilesViewModel.OpenFileRequest
                             .LogErrors(logger)
                             .Subscribe(file =>
            {
                MenuIsOpen = false;
                OpenFile(file);
            });

            var selectedChange = this.WhenValueChanged(vm => vm.Selected)
                                 .Subscribe(selected =>
            {
                var currentSelection = selected?.Content as ISelectedAware;

                Views.Where(hv => !hv.Equals(selected))
                .Select(hv => hv.Content)
                .OfType <ISelectedAware>()
                .ForEach(selectedAware => selectedAware.IsSelected = false);

                if (currentSelection != null)
                {
                    currentSelection.IsSelected = true;
                }
            });


            _cleanUp = new CompositeDisposable(recentFilesViewModel,
                                               isEmptyChecker,
                                               fileDropped,
                                               DropMonitor,
                                               openRecent,
                                               selectedChange,
                                               Disposable.Create(() =>
            {
                Views.Select(vc => vc.Content)
                .OfType <IDisposable>()
                .ForEach(d => d.Dispose());
            }));
        }
Esempio n. 4
0
        public WindowViewModel(IObjectProvider objectProvider,
                               IWindowFactory windowFactory,
                               ILogger logger,
                               IWindowsController windowsController,
                               RecentFilesViewModel recentFilesViewModel,
                               GeneralOptionsViewModel generalOptionsViewModel,
                               ISchedulerProvider schedulerProvider,
                               IApplicationStatePublisher applicationStatePublisher)
        {
            _logger            = logger;
            _windowsController = windowsController;
            RecentFiles        = recentFilesViewModel;
            GeneralOptions     = generalOptionsViewModel;
            _schedulerProvider = schedulerProvider;
            _objectProvider    = objectProvider;
            InterTabClient     = new InterTabClient(windowFactory);
            OpenFileCommand    = new Command(OpenFile);

            ShowInGitHubCommand = new Command(() => Process.Start("https://github.com/RolandPheasant"));
            ZoomOutCommand      = new Command(() => { GeneralOptions.Scale = GeneralOptions.Scale + 5; });
            ZoomInCommand       = new Command(() => { GeneralOptions.Scale = GeneralOptions.Scale - 5; });
            ExitCommmand        = new Command(() =>
            {
                applicationStatePublisher.Publish(ApplicationState.ShuttingDown);
                Application.Current.Shutdown();
            });
            WindowExiting = () =>
            {
                applicationStatePublisher.Publish(ApplicationState.ShuttingDown);
            };

            Version = $"v{Assembly.GetEntryAssembly().GetName().Version.ToString(3)}";

            var fileDropped = DropMonitor.Dropped.Subscribe(OpenFile);

            var isEmptyChecker = Views.ToObservableChangeSet()
                                 .ToCollection()
                                 .Select(items => items.Count)
                                 .StartWith(0)
                                 .Select(count => count == 0)
                                 .LogErrors(logger)
                                 .Subscribe(isEmpty => IsEmpty = isEmpty);

            var openRecent = recentFilesViewModel.OpenFileRequest
                             .LogErrors(logger)
                             .Subscribe(file =>
            {
                MenuIsOpen = false;
                OpenFile(file);
            });


            _cleanUp = new CompositeDisposable(recentFilesViewModel,
                                               isEmptyChecker,
                                               fileDropped,
                                               DropMonitor,
                                               openRecent,
                                               Disposable.Create(() =>
            {
                Views.Select(vc => vc.Content)
                .OfType <IDisposable>()
                .ForEach(d => d.Dispose());
            }));
        }