All entries for Thursday 06 October 2005

October 06, 2005

Document–View Framework Update

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:

  1. Is this maybe a commerically viable framework?
  2. Does no one care about or use a document-view architecture any more?
  3. 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:

Imports Equin.DocumentViewFramework
Imports Equin.DocumentViewFramework.Base

<FileDocumentExtension("txt")> _
<DocumentTypeName("Text Document")> _
Public Class TextDocument
Inherits FileDocument

' Create new empty document
Public Sub New()
MyBase.New()
Text = String.Empty
End Sub

' Create from filename
Public Sub New(ByVal filename As String)
MyBase.New(filename)
Text = My.Computer.FileSystem.ReadAllText(filename)
MarkOld()
End Sub

' Save to filename
Protected Overrides Function SaveCore() As IDocument
My.Computer.FileSystem.WriteAllText(Filename, Text, False)
Return Me
End Function

Private _text As String

Public Property Text() As String
Get
Return _text
End Get
Set(ByVal value As String)
If value Is Nothing Then value = String.Empty
If _text <> value Then
_text = value
OnPropertyChanged("Text")
MarkDirty()
End If
End Set
End Property
End Class

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
End Sub

Public Overrides Function EndEdit() As Boolean
TextDocumentBindingSource.EndEdit()
Return True
End Function
End Class

(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
End Sub

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?


Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help http://www.webmd.com/eye–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry

Tags

October 2005

Mo Tu We Th Fr Sa Su
Sep |  Today  | Nov
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31                  

Galleries

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXIV