Пример #1
0
        public async Task <bool> Close(bool force = false)
        {
            using (await asyncCriticalSection.EnterAsync()) {
                if (closed)
                {
                    return(true);
                }

                bool wasActive = documentManager.ActiveDocument == this;

                // Raise the closing event. Handlers have a chance to cancel the save operation

                var args = new DocumentCloseEventArgs(this, force, wasActive);
                args.Cancel = false;
                await OnClosing(args);

                if (!force && args.Cancel)
                {
                    return(false);
                }

                // Show the File not Saved UI

                if (!await ShowSaveUI(force))
                {
                    return(false);
                }

                closed = true;

                ClearTasks();

                Closed?.SafeInvoke(this, args);

                // Reset the root view before closing the view, otherwise shell.CloseView will destroy it.
                // We need the view to be functional until after the window is closed. The Dispose() method
                // already takes care of disposing the view, which will destroy the widget it contains
                window.SetRootView(null);

                shell.CloseView(window, true);

                Counters.OpenDocuments--;

                Dispose();

                return(true);
            }
        }
Пример #2
0
        public async Task <bool> Close(bool force = false)
        {
            using (await asyncCriticalSection.EnterAsync()) {
                if (closed)
                {
                    return(true);
                }

                bool wasActive = documentManager.ActiveDocument == this;

                // Raise the closing event. Handlers have a chance to cancel the save operation

                var args = new DocumentCloseEventArgs(this, force, wasActive);
                args.Cancel = false;
                await OnClosing(args);

                if (!force && args.Cancel)
                {
                    return(false);
                }

                // Show the File not Saved UI

                if (!await ShowSaveUI(force))
                {
                    return(false);
                }

                closed = true;

                ClearTasks();

                try {
                    Closed?.Invoke(this, args);
                } catch (Exception ex) {
                    LoggingService.LogError("Exception while calling Closed event.", ex);
                }

                shell.CloseView(window, true);

                Counters.OpenDocuments--;

                Dispose();

                return(true);
            }
        }
Пример #3
0
 public ToolsViewModel(IShell shell)
 {
     ShowMainViewCommand = ReactiveCommand.Create(() =>
     {
         shell.ShowView <MainView>(
             new ViewRequest("main-view"),
             new UiShowOptions {
             Title = nameof(MainView)
         }
             );
     });
     ShowMainViewNamedCommand = ReactiveCommand.Create(() =>
     {
         shell.ShowView(
             c => c.ResolveNamed <IView>("main_view"),
             new ViewRequest("main-view-named"),
             new UiShowOptions {
             Title = nameof(MainView)
         }
             );
     });
     ShowFlyoutDemoViewCommand = ReactiveCommand.Create(() =>
     {
         shell.ShowView <FlyoutDemoView>(
             new ViewRequest("flyout-demo-view"),
             new UiShowOptions {
             Title = nameof(FlyoutDemoView)
         }
             );
     });
     ShowChildWindowViewCommand = ReactiveCommand.Create(() =>
     {
         shell.ShowView <ChildWindowDemoView>(
             new ViewRequest("child-window-demo-view"),
             new UiShowOptions {
             Title = nameof(ChildWindowDemoView)
         }
             );
     });
     CloseMainViewCommand = ReactiveCommand.Create(() =>
     {
         shell.CloseView("main-view");
     });
 }