Gorgon
Show / Hide Table of Contents

Class ContentEditorViewModelBase<T>

Common functionality for a content view model.

Inheritance
object
PropertyMonitor
ViewModelBase<T, IHostContentServices>
ContentEditorViewModelBase<T>
Implements
IEditorContent
IViewModel
INotifyPropertyChanged
INotifyPropertyChanging
Inherited Members
ViewModelBase<T, IHostContentServices>.WaitPanelActivated
ViewModelBase<T, IHostContentServices>.WaitPanelDeactivated
ViewModelBase<T, IHostContentServices>.ProgressUpdated
ViewModelBase<T, IHostContentServices>.ProgressDeactivated
ViewModelBase<T, IHostContentServices>.HostServices
ViewModelBase<T, IHostContentServices>.UpdateProgress(string, float, string, Action)
ViewModelBase<T, IHostContentServices>.UpdateProgress(ProgressPanelUpdateArgs)
ViewModelBase<T, IHostContentServices>.UpdateMarequeeProgress(string, string, Action)
ViewModelBase<T, IHostContentServices>.HideProgress()
ViewModelBase<T, IHostContentServices>.ShowWaitPanel(WaitPanelActivateArgs)
ViewModelBase<T, IHostContentServices>.ShowWaitPanel(string, string)
ViewModelBase<T, IHostContentServices>.HideWaitPanel()
ViewModelBase<T, IHostContentServices>.OnInitialize(T)
ViewModelBase<T, IHostContentServices>.OnLoad()
ViewModelBase<T, IHostContentServices>.OnUnload()
ViewModelBase<T, IHostContentServices>.Load()
ViewModelBase<T, IHostContentServices>.Unload()
ViewModelBase<T, IHostContentServices>.Initialize(T)
PropertyMonitor.PropertyChanged
PropertyMonitor.PropertyChanging
PropertyMonitor.UsePropertyNameValidation
PropertyMonitor.OnPropertyChanging(string)
PropertyMonitor.OnPropertyChanged(string)
PropertyMonitor.NotifyPropertyChanged(string)
PropertyMonitor.NotifyPropertyChanging(string)
PropertyMonitor.NotifyAllPropertiesChanging()
PropertyMonitor.NotifyAllPropertiesChanged()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Editor.UI
Assembly: Gorgon.Editor.API.dll
Syntax
public abstract class ContentEditorViewModelBase<T> : ViewModelBase<T, IHostContentServices>, IEditorContent, IViewModel, INotifyPropertyChanged, INotifyPropertyChanging where T : class, IContentViewModelInjection
Type Parameters
Name Description
T

The type of dependency injection object. Must be a class, and implement IContentViewModelInjection.

Remarks

This base class provides functionality needed to communicate the state of the content (i.e. if it's been updated), a handler for manipulating the internal application clipboard, and commands to persist the content data and close the content UI.

Content is what the editor defines as the items that users will create/edit with the editor, this could be images, sprites, music, sound, scripts, etc... Developers of content plug ins must inherit from this type so that their content model data is updated from the UI, and returns feedback to the UI.

As an example, if you wanted to create a very simple text editor, you would define a view with a multi-line textbox control on it, and then create a TextEditorContent view model based on this type and add a command to recieve updates from the UI (e.g. when text is entered), and a property to return the current text stored in the data.

Views that are associated with view models derived from this type must inherit from the ContentBaseControl. And developers must register their content views using the ViewFactory.Register<T>(Func<Control>) method so that the host editor application can present the UI to the end user.

Constructors

| Edit this page View Source

ContentEditorViewModelBase()

Initializes a new instance of the EditorContentCommon class.

Declaration
protected ContentEditorViewModelBase()
See Also
ViewFactory
ContentBaseControl

Properties

| Edit this page View Source

Clipboard

Property to return the clipboard handler for this view model.

Declaration
public IClipboardHandler Clipboard { get; protected set; }
Property Value
Type Description
IClipboardHandler
Remarks

This gives access to the application clipboard functionality to copy, cut and paste data. If this is assigned, then your view should have some means to execute the required commands for the copy, cut and paste operations.

important

The application clipboard is not the same as the Windows clipboard. Data copied to the application clipboard is not accessible by other applications.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

CloseContentCommand

Property to return the command used to close the content.

Declaration
public IEditorAsyncCommand<CloseContentArgs> CloseContentCommand { get; protected set; }
Property Value
Type Description
IEditorAsyncCommand<CloseContentArgs>
Remarks

This command will be executed when the user shuts down the content via some UI element (e.g. the 'X' in a window).

Plug in developers may override this command by setting the property in their own view model. If it is not assigned by the developer, then an internal command is executed. This internal command should cover most use cases, so overriding the command should only be done in unique circumstances.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

CommandContext

Property to set or return the current context for commands from this content.

Declaration
public IEditorContext CommandContext { get; set; }
Property Value
Type Description
IEditorContext
Remarks

This is used in UI interactions where the context of the operations may change depending on state. An example would be a context for an MS Office ribbon control, where activating a tool would then show a new set of commands that were previously hidden. These commands would appear under a context heading on the ribbon.

If the UI does not support contexts, then this property would be ignored.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

ContentFileManager

Property to return the file manager used to manage content files.

Declaration
protected IContentFileManager ContentFileManager { get; }
Property Value
Type Description
IContentFileManager
See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

ContentState

Property to return the current content state.

Declaration
public ContentState ContentState { get; set; }
Property Value
Type Description
ContentState
Remarks

Changing this value will update the File and mark it as changed if the value is New, or Modified.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

ContentType

Property to return the type of content.

Declaration
public abstract string ContentType { get; }
Property Value
Type Description
string
Remarks

The content type is a user defined string that indicates what the data for the content represents. For example, for an image editor, this could return "Image".

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

File

Property to return the file for the content.

Declaration
public IContentFile File { get; protected set; }
Property Value
Type Description
IContentFile
Remarks

This is the file that contains the content data. Useful in cases where the path for the file is required, or other file properties are needed.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

FilesAreSelected

Property to return whether there are files selected by the user in project file system.

Declaration
public bool FilesAreSelected { get; }
Property Value
Type Description
bool
Remarks

This property is useful for enabling or disabling UI elements based on file selection.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

SaveContentCommand

Property to set or return the command used to save the content.

Declaration
public IEditorAsyncCommand<SaveReason> SaveContentCommand { get; set; }
Property Value
Type Description
IEditorAsyncCommand<SaveReason>
Remarks

This command will be executed when the user wants to persist the content data back to the project file system. Developers must assign a command here in order to persist the data back to the file system.

See Also
ViewFactory
ContentBaseControl

Methods

| Edit this page View Source

OnCloseContentTaskAsync()

Function to determine the action to take when this content is closing.

Declaration
protected virtual Task<bool> OnCloseContentTaskAsync()
Returns
Type Description
Task<bool>

true to continue with closing, false to cancel the close request.

Remarks

Content plug in developers should override this method so that users are given a chance to save their content data (if it has changed) prior to closing the content.

This is set up as an asynchronous method so that users may save their data asynchronously to keep the UI usable.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

OnInitialize(T)

Function to initialize the content.

Declaration
protected override void OnInitialize(T injectionParameters)
Parameters
Type Name Description
T injectionParameters

Common view model dependency injection parameters from the application.

Overrides
ViewModelBase<T, IHostContentServices>.OnInitialize(T)
Remarks

This is required in order to inject initialization data for the view model from an external source (i.e. the editor host application). Developers will use this area to perform setup of the content view model, and validate any information being injected.

Ideally this can be used to create resources, child view models, and other objects that need to be initialized when the view model is created.

This method is only ever called after the view model has been created, and never again during the lifetime of the view model.

Exceptions
Type Condition
ArgumentNullException

Thrown when the injectionParameters parameter is null.

ArgumentException

Thrown if the File parameter is null.

See Also
ViewFactory
ContentBaseControl
| Edit this page View Source

OnUnload()

Function called when the associated view is unloaded.

Declaration
protected override void OnUnload()
Overrides
ViewModelBase<T, IHostContentServices>.OnUnload()
Remarks

This method is used to perform tear down and clean up of resources.

See Also
Load()
| Edit this page View Source

SaveContentFileAsync(IGorgonVirtualFile)

Function to save the content from a working file to the actual file on the file system.

Declaration
protected Task SaveContentFileAsync(IGorgonVirtualFile workFile)
Parameters
Type Name Description
IGorgonVirtualFile workFile

The working file for the content.

Returns
Type Description
Task

A task for asynchronous operation.

Remarks

The workFile is a copy of the original file in the project file system. This working file is managed by a scratch file system passed to the content plug in. By handling files in this manner, we can ensure that the original file can remain intact should something go wrong, or an undesirable change is included in the content by reverting to the original file.

See Also
ViewFactory
ContentBaseControl

Implements

IEditorContent
IViewModel
INotifyPropertyChanged
INotifyPropertyChanging

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

ViewFactory
ContentBaseControl
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author