Monday, March 30, 2009

FileSelect, a re-usable document centric WinForm File menu (one less wheel to re-invent…)

CodeProject - FileSelect - hassle free implementation of the File menu

“FileSelect is a WinForms user control for a default implementation of the "File" menu. All you need to do is to implement opening, saving and closing a document and sending change notifications:

fileselect

This will give you:

  • Correct behavior of Save, Save As and Close - whether this document is new or opened, and whether it was modified.
    this includes asking if the file should be saved, asking for a file name, etc.
  • Correct handling of file modified / not modified.
  • Disabling menu items when they can't be used
  • a Recent Files list - in place or as a popup menu
  • An automatically updating form title, including the current file name and an "is modified" marker
  • Customizable OpenFile / SaveFile dialogs included.

Most of the functionality can be activated selectively, I've tried to keep you in control with the individual features.

The download contains a sample (FileSelectDemo) that implements a basic text editor - or rather, the file handling part -  where you can explore the available functionality. It shows all commands available, including two styles of recent files. Of course, in your application you can add only the items you need.

Motivation

I want to share some thoughts that are not directly related to using that control. Why did I write that? Surely, this is a spare time project and way to much time went into it than could ever be justified for commercial development.

First, it is a common pattern, and I get annoyed when I see something not only I have to do over and over, but also everyone else. When learning Windows Forms, I was missing some simplicity here. I did not really (read: "totally not at all") miss the Document / View - Architecture of MFC, as it was to inflexible and stubborn for my taste - you could use either all of it, or none, or you were in for a rough ride. That's one reason this component only handles the "UI side" of providing a document-centric application.

…”

While I’m moving away from WinForm and to WPF, and were I’m still doing WinForms I’m moving toward a Ribbon UI, I still think this project is officially cool.

How many times have we all re-invented the “File” menu in our app’s? Like a billion or two? Yeah. That’s why this project reached out of my notebook screen and smacked me on my forehead (a whole V8 moment thing). In hindsight this is pretty darn logical. Investing a few extra minutes so you don’t have to re-invent the File menu every time for every project seems like a no brainer doesn’t it? Especially when Peter’s done much the grunt work for us!  :)

1 comment:

  1. I've implemented something similar, as part of my TC WinForms library. It's just a different implementation. I use an IDocumentContainer-interface and commands that can be bound to buttons and menu-items.

    You can find the source code on http://tcwinforms.codeplex.com/

    ReplyDelete

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...