示例#1
0
        /// <summary>
        /// Initializes a new diagram editor.
        /// </summary>
        /// <param name="diagram">The diagram being edited</param>
        /// <param name="codeEditor">The code editor</param>
        /// <param name="notifications">Creates objects that report progress</param>
        /// <param name="diagramRenderers">Responsible for converting diagram data to images</param>
        /// <param name="diagramIO">Saves diagrams</param>
        /// <param name="compiler">Compiles diagrams</param>
        /// <param name="autoSaveTimer">Determines how soon after a change a diagram will be autosaved</param>
        /// <param name="refreshTimer">Determines how long after the last code modification was made to automatically refresh a diagram's image</param>
        /// <param name="uiScheduler">A task scheduler for executing UI tasks</param>
        public DiagramEditorViewModel(Diagram diagram, ICodeEditor codeEditor, INotifications notifications,
                                      IIndex <ImageFormat, IDiagramRenderer> diagramRenderers, IDiagramIOService diagramIO, IDiagramCompiler compiler,
                                      ITimer autoSaveTimer, ITimer refreshTimer, TaskScheduler uiScheduler)
        {
            _diagram = Property.New(this, p => p.Diagram, OnPropertyChanged);
            Diagram  = diagram;

            _notifications    = notifications;
            _diagramRenderers = diagramRenderers;
            _diagramIO        = diagramIO;
            _compiler         = compiler;
            _autoSaveTimer    = autoSaveTimer;
            _refreshTimer     = refreshTimer;
            _uiScheduler      = uiScheduler;

            CodeEditor                  = codeEditor;
            CodeEditor.Content          = Diagram.Content;
            CodeEditor.PropertyChanged += codeEditor_PropertyChanged;                   // Subscribe after setting the content the first time.

            _imageFormat = Property.New(this, p => p.ImageFormat, OnPropertyChanged);
            ImageFormat  = Diagram.ImageFormat;

            _diagramImage = Property.New(this, p => p.DiagramImage, OnPropertyChanged);

            _isIdle = Property.New(this, p => p.IsIdle, OnPropertyChanged)
                      .AlsoChanges(p => p.CanSave)
                      .AlsoChanges(p => p.CanRefresh)
                      .AlsoChanges(p => p.CanClose);
            IsIdle = true;

            _autoSave         = Property.New(this, p => p.AutoSave, OnPropertyChanged);
            _autoSaveInterval = Property.New(this, p => p.AutoSaveInterval, OnPropertyChanged);

            _saveCommand    = Command.For(this).DependsOn(p => p.CanSave).Asynchronously().Executes(SaveAsync);
            _refreshCommand = Command.For(this).DependsOn(p => p.CanRefresh).Asynchronously().Executes(RefreshAsync);
            _closeCommand   = Command.For(this).DependsOn(p => p.CanClose).Executes(Close);

            // The document has been opened first time. So, any changes
            // made to the document will require creating a backup.
            _firstSaveAfterOpen = true;

            _autoSaveTimer.Elapsed += autoSaveTimerElapsed;
            _refreshTimer.Elapsed  += refreshTimer_Elapsed;
        }
        /// <summary>
        /// Initializes a new diagram editor.
        /// </summary>
        /// <param name="diagram">The diagram being edited</param>
        /// <param name="codeEditor">The code editor</param>
        /// <param name="notifications">Creates objects that report progress</param>
        /// <param name="diagramRenderers">Responsible for converting diagram data to images</param>
        /// <param name="diagramIO">Saves diagrams</param>
        /// <param name="compiler">Compiles diagrams</param>
        /// <param name="autoSaveTimer">Determines how soon after a change a diagram will be autosaved</param>
        /// <param name="refreshTimer">Determines how long after the last code modification was made to automatically refresh a diagram's image</param>
        /// <param name="uiScheduler">A task scheduler for executing UI tasks</param>
        public DiagramEditorViewModel(Diagram diagram,
                                      ICodeEditor codeEditor,
                                      INotifications notifications,
                                      IReadOnlyDictionary <ImageFormat, IDiagramRenderer> diagramRenderers,
                                      IDiagramIOService diagramIO,
                                      IDiagramCompiler compiler,
                                      ITimer autoSaveTimer,
                                      ITimer refreshTimer,
                                      TaskScheduler uiScheduler) : this()
        {
            Diagram = diagram;

            _notifications    = notifications;
            _diagramRenderers = diagramRenderers;
            _diagramIO        = diagramIO;
            _compiler         = compiler;
            _autoSaveTimer    = autoSaveTimer;
            _refreshTimer     = refreshTimer;
            _uiScheduler      = uiScheduler;

            CodeEditor                  = codeEditor;
            CodeEditor.Content          = Diagram.Content;
            CodeEditor.PropertyChanged += codeEditor_PropertyChanged;                   // Subscribe after setting the content the first time.

            ImageFormat = Diagram.ImageFormat;

            IsIdle = true;
            Errors = new List <DiagramErrorViewModel>(0);

            // The document has been opened first time. So, any changes
            // made to the document will require creating a backup.
            _firstSaveAfterOpen = true;

            _autoSaveTimer.Elapsed += AutoSaveTimerElapsed;
            _refreshTimer.Elapsed  += RefreshTimerElapsed;
        }