Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Shell&lt;TViewModel, TController, TModel&gt;"/> class.
        /// </summary>
        public Shell()
        {
            // Bind visual properties of the window to the persistent settings
            this.BindSettings();

            this.MinHeight = 600;
            this.MinWidth  = 1000;
            this.Width     = 1000;

            // Initialize the view model
            try
            {
                this.viewModel = new TViewModel();
            }
            catch (Exception e)
            {
                Utilities.HandleException(e);
            }

            // Subscribe to view model events
            this.ViewModel.CurrentFileContentChanged += this.OnCurrentFileContentChanged;

            // Subscribe to controller events
            this.ViewModel.Controller.Opening += this.OnOpening;
            this.ViewModel.Controller.Opened  += this.OnOpened;
            this.ViewModel.Controller.Saving  += this.OnSaving;
            this.ViewModel.Controller.Saved   += this.OnSaved;
            this.ViewModel.Controller.Closing += this.OnClosing;

            // Set the data context to the shell. This sets the stage for simple
            // data binding in the skins (xaml) that can access the wpf specific
            // shell features, the view model, and the data model.
            this.DataContext = this;

            // Attach any available services to make them easily accessible to child UI elements
            if (this.ViewModel.IsUndoRedoAvailable)
            {
                EditorServices.SetUndoManager(this, this.ViewModel.UndoManager);
            }

            if (this.ViewModel.IsSearchAvailable)
            {
                EditorServices.SetSearchEngine(this, this.ViewModel.SearchEngine);
            }

            if (this.ViewModel.IsValidationAvailable)
            {
                EditorServices.SetValidationManager(this, this.ViewModel.ValidationManager);
            }

            // Set a dynamic resource reference for the window's content and the window's style.
            // This allows editor applications to switch out the "skin" at compile time or runtime.
            this.SetResourceReference(Window.ContentProperty, "ShellContent");
            this.SetResourceReference(Window.StyleProperty, "ShellStyle");

            // Initialize the command bindings
            this.InitializeCommandBindings();
        }
Пример #2
0
        /// <summary>
        /// Creates an undoable region.
        /// </summary>
        /// <param name="obj">The object from which the UndoManager is retrieved.</param>
        /// <returns>An undoable region.</returns>
        //public static UndoableRegion CreateUndoableRegion (this DependencyObject obj) ** Uncomment when we have C# 3.0 support **
        public static UndoableRegion CreateUndoableRegion(DependencyObject obj)
        {
            UndoableRegion undoableRegion = null;
            //UndoableGroup undoManager = obj.GetUndoManager () as UndoableGroup; ** Uncomment when we have C# 3.0 support **
            UndoableGroup undoManager = EditorServices.GetUndoManager(obj) as UndoableGroup;

            if (undoManager != null)
            {
                undoableRegion = new UndoableRegion(undoManager);
            }
            return(undoableRegion);
        }