|
|||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Click image for full screenshot - 306 KB Table of Contents
{ Automatically generated Table of Contents } IntroductionThis is a short article about an HTML editor I assembled with special support for writing articles at The Code Project. BackgroundOffice 2007 doesn't contain a version of Frontpage, which I used to use to write articles. I didn't want to install Frontpage 2003 over Office 2007 "just in case!" So, I had a look around for an HTML editor that can show a preview side-by-side with the raw HTML. Visual Studio was the best one I found, but the preview has to be below the HTML, which is not what I want on my widescreen monitors. So I decided to write one myself. Here it is and I hope you find it useful. Note: As Derek Bartram pointed out in the message board below, Visual Studio 2008 can split the source and design views vertically. The setting is: Tools | Options | HTML Designer | General | Split views vertically Assembly InstructionsIt's a basic Windows Forms application with Weifen Luo's DockPanel Suite [^], so you can arrange the panes just how you want them. The editor is part of Using BobBuilderWindow TypesThere are two types of windows in BobBuilder: editor and preview. You must have exactly one editor window open for each document, but you can have any number of preview windows open. Editor WindowsThe AutocompleteTo help prevent illegal HTML being rendered, there are a few "autocompleted" characters. Firstly, if you type a Preview WindowsThe preview windows update continuously while you use the editor. If you have a system sound set for the "Navigation Started" event, you might like to disable it! The preview windows attempt to remember their scroll positions at each update, but this is not possible if illegal HTML is rendered. ToolstripsThere are buttons for the standard formattings like bold and italic. There is also an Table of ContentsThere are a menu item and a toolstrip button to insert a Table of Contents. This command parses the HTML using Known IssuesLinksAny relative hyperlinks, for example to anchors, do not work in the preview windows. This is because the HTML is passed to the WebBrowser controls using their However, before the HTML is passed to the WebBrowser control, it is modified a bit. Some JavaScript is added to help maintain the scroll position and a Note: when you upload your article, the HTML will be put in one of the main directories, but all other files (images, ZIPs, ... ) will be put in a subdirectory named the same as the basename of the article. For example, BobBuilder.aspx is in /KB/cs/ and all other files are in /KB/cs/BobBuilder/. You might like to replicate this structure locally when you are writing your article. Points of InterestThere are a couple of points to highlight: Design PatternsI implemented the MVC pattern, but with a twist: I used the Observer pattern with the views subscribing to the ( A neat feature of the .NET partial class Controller
{
public static Document CurrentDocument
{
get
{
return Instance
.ExecuteCore( null, new Command.GetCurrentDocument() )
.Document;
}
}
}
This pattern made life easier than having the controller maintain a collection of some view interface. Now this is all taken care of by the built-in System.Windows.Forms.KeysI could not find a .NET way to determine the right member of this enumeration for a given [System.Runtime.InteropServices.DllImport( "user32.dll" )]
static extern short VkKeyScan( char ch );
static Keys ConvertToKeys( char c )
{
short vk = VkKeyScan( c );
int key = vk & 0x00FF;
int mod = vk & 0xFF00;
int iKeys = ( mod << 8 ) | key;
Keys eKeys = ( Keys ) iKeys;
return eKeys;
}
TODOThis is a short list of possible future enhancements. Please leave a comment below if you have any opinions or ideas.
References
History
|
||||||||||||||||||||||||||||||||||