All entries for Thursday 06 October 2005
October 06, 2005
I know I said I'd get an article together further detailing the document-view framework I've been creating, but I've been busy and am still unsure the best way to go about explaining it all.
After looking around the internet and finding nothing else similar I'm wondering 3 things:
- Is this maybe a commerically viable framework?
- Does no one care about or use a document-view architecture any more?
- Am I not Googling in the right places?
In the mean time I thought I'd post a little sample of how easy my framework makes setuping a doc-view app.
This is a simple TextDocument class that does nothing more than load and save it's Text property:
<DocumentTypeName("Text Document")> _
Public Class TextDocument
' Create new empty document
Public Sub New()
Text = String.Empty
' Create from filename
Public Sub New(ByVal filename As String)
Text = My.Computer.FileSystem.ReadAllText(filename)
' Save to filename
Protected Overrides Function SaveCore() As IDocument
My.Computer.FileSystem.WriteAllText(Filename, Text, False)
Private _text As String
Public Property Text() As String
Set(ByVal value As String)
If value Is Nothing Then value = String.Empty
If _text <> value Then
_text = value
Note it inherits from a base class FileDocument that takes care of implementing the IDocument interface and tracking the "is dirty" state and filename etc.
Cool things to note are the FileDocumentExtension and DocumentTypeName attributes applied to the class. These can be used to build a UI (e.g. Open file dialog filename filters).
The text document view takes the form of a custom control that inherits from ViewBaseUserControl (itself being a UserControl). This base class handles implementing the IView interface.
Due to the greatness of partial classes in .NET 2.0 the code for the text document view control is just:
Public Class TextDocumentView
Protected Overrides Sub DocumentSet(ByVal document As Equin.DocumentViewFramework.IDocument)
' Bind to the Text property of the TextDocument object.
TextDocumentBindingSource.DataSource = document
Public Overrides Function EndEdit() As Boolean
(I have placed a TextBox and BindingSource on the control's design surface and set properties accordingly – all that code is generated by the designer in the other source file.)
This custom control can then be placed on a form. In my test application I have a form, TextDocumentViewForm, that inherits from ViewBaseForm. So this is also an IView. I can then infact put two (or more) text view controls on to it and do things like split views. The only real code in the form is:
Protected Overrides Sub SetDocumentCore(ByVal document As Equin.DocumentViewFramework.IDocument)
rightView.Document = document
leftView.Document = document
This just hooks up the controls to the document when it is set.
I am in the process of XML-doc'ing the framework. I'm still not sure whether to just open source it or if there is commerical viability… any ideas?