コード例 #1
0
ファイル: Workspace.cs プロジェクト: junelp01/sbaproject
        internal void Close(FileBaseViewModel doc)
        {
            {
                FileViewModel fileToClose = doc as FileViewModel;

                if (fileToClose != null)
                {
                    if (fileToClose.IsDirty)
                    {
                        var res = MessageBox.Show(string.Format("Save changes for file '{0}'?", fileToClose.FileName), "AvalonDock Test App", MessageBoxButton.YesNoCancel);
                        if (res == MessageBoxResult.Cancel)
                        {
                            return;
                        }

                        if (res == MessageBoxResult.Yes)
                        {
                            Save(fileToClose);
                        }
                    }

                    _files.Remove(fileToClose);

                    return;
                }
            }

            {
                StartPageViewModel s = doc as StartPageViewModel;
                if (s != null)
                {
                    _files.Remove(doc);

                    if (this._files.Count == 0)
                    {
                        this.ActiveDocument = null;
                    }
                    else
                    {
                        this.ActiveDocument = this._files[0];
                    }

                    return;
                }
            }
        }
コード例 #2
0
ファイル: Workspace.cs プロジェクト: junelp01/sbaproject
        /// <summary>
        /// Construct and add a new <seealso cref="StartPageViewModel"/> to intenral
        /// list of documents, if none is already present, otherwise return already
        /// present <seealso cref="StartPageViewModel"/> from internal document collection.
        /// </summary>
        /// <param name="CreateNewViewModelIfNecessary"></param>
        /// <returns></returns>
        internal StartPageViewModel GetStartPage(bool CreateNewViewModelIfNecessary)
        {
            List <StartPageViewModel> l = this._files.OfType <StartPageViewModel>().ToList();

            if (l.Count == 0)
            {
                if (CreateNewViewModelIfNecessary == false)
                {
                    return(null);
                }
                else
                {
                    StartPageViewModel s = new StartPageViewModel();
                    this._files.Add(s);

                    return(s);
                }
            }

            return(l[0]);
        }
コード例 #3
0
ファイル: Workspace.cs プロジェクト: junelp01/sbaproject
        /// <summary>
        /// Bind a window to some commands to be executed by the viewmodel.
        /// </summary>
        /// <param name="win"></param>
        public void InitCommandBinding(Window win)
        {
            win.CommandBindings.Add(new CommandBinding(ApplicationCommands.New,
                                                       (s, e) =>
            {
                this.OnNew(null);
            }));

            win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open,
                                                       (s, e) =>
            {
                this.OnOpen(null);
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.LoadFile,
                                                       (s, e) =>
            {
                if (e == null)
                {
                    return;
                }

                string filename = e.Parameter as string;

                if (filename == null)
                {
                    return;
                }

                this.Open(filename);
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.PinUnpin,
                                                       (s, e) =>
            {
                this.PinCommand_Executed(e.Parameter, e);
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.RemoveMruEntry,
                                                       (s, e) =>
            {
                this.RemoveMRUEntry_Executed(e.Parameter, e);
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.AddMruEntry,
                                                       (s, e) =>
            {
                this.AddMRUEntry_Executed(e.Parameter, e);
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.BrowseURL,
                                                       (s, e) =>
            {
                Process.Start(new ProcessStartInfo("http://Edi.codeplex.com"));
            }));

            win.CommandBindings.Add(new CommandBinding(AppCommand.ShowStartPage,
                                                       (s, e) =>
            {
                StartPageViewModel spage = this.GetStartPage(true);

                if (spage != null)
                {
                    this.ActiveDocument = spage;
                }
            }));
        }