Programmatically Change Save Window State Settings
Category Lotus Notes Notes Client Show-n-Tell ThursdayAlthough I'd much rather toss a few of my own Lotusphere wrap-up thoughts into the Blogosphere, I figure I'd at least get this one out now while it's fresh in my mind...pretend it's Thursday
My client is going through an upgrade to Notes 7, and one of the great new features is of course the ability to "Save Window State" such that when you restart Notes you see the same window tabs as when you shut down. A fine feature that we decided to turn on by default, but a few users had a problem with this. Specifically, the problem users were those who had, prior to the upgrade, figured out how to add windows to their "Startup" bookmark folder (found under "More Bookmarks"), allowing for instance your Inbox and Calendar to both launch automatically when you started Notes.
The "problem" was that under certain circumstances you might see duplicate window tabs on Notes startup, one for the "saved window state" and the same one again from the"startup". My solution was to give users two buttons so they could pick between the old or new approaches:
- BUTTON 1: Disable the save window state features and continue using the "Startup" option.
- BUTTON 2: Clear out the startup folder in order to rely solely on the newer "Save Window State" approach.
In both cases, the code involved affects the Notes.ini file and the Bookmarks database (bookmark.nsf). While the code isn't particularly complicated, it did take a fair bit of poking around in the design of the bookmarks database to understand what changes were required. Unfortunately the innards of the bookmarks database are not terribly well documented, so I thought I'd share my code here in case anyone found it useful.
Here's the code for BUTTON 1:
Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim bookmarkdb As NotesDatabase Dim outline As NotesOutline Dim entry As NotesOutlineEntry Dim childentry As NotesOutlineEntry Dim folder As NotesView Dim vec As NotesViewEntryCollection Set bookmarkdb = Session.GetDatabase("", "bookmark.nsf") Set outline = bookmarkdb.GetOutline("UserBookmarkOrder") Set entry = outline.GetFirst() 'This will find and delete the bookmark folder containing the links for the Last State, if they exist Do While Not entry Is Nothing If entry.Label = "Last State" Then Do While entry.HasChildren Set childentry = outline.GetNext(entry) Call outline.RemoveEntry(childentry) Loop Call outline.save() Goto ExitLoop Else Set entry = outline.GetNext(entry) End If Loop ExitLoop: 'Now we need to remove the "link" documents from the Last State folder Set folder = bookmarkdb.GetView("$LastState") Set vec = folder.AllEntries Call vec.RemoveAll(True) 'This will disable the "Save Window State on Exit" user preference Call session.SetEnvironmentVar( "SaveStateOnExit", "0", True) Messagebox "You will need to restart your Notes client for the settings to take effect", 48, "Finished" End Sub
provided by Julian Robichaux at nsftools.com.
And here's the code for BUTTON 2:
Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim bookmarkdb As NotesDatabase Dim outline As NotesOutline Dim entry As NotesOutlineEntry Dim childentry As NotesOutlineEntry Dim folder As NotesView Dim vec As NotesViewEntryCollection Set bookmarkdb = Session.GetDatabase("", "bookmark.nsf") Set outline = bookmarkdb.GetOutline("UserBookmarkOrder") Set entry = outline.GetFirst() 'This will find and delete the bookmark folder containing the links for the Last State, if they exist Do While Not entry Is Nothing If entry.Label = "Startup" Then Do While entry.HasChildren Set childentry = outline.GetNext(entry) Call outline.RemoveEntry(childentry) Loop Call outline.save() Goto ExitLoop Else Set entry = outline.GetNext(entry) End If Loop ExitLoop: 'We need to remove the "link" documents from the Startup folder Set folder = bookmarkdb.GetView("$Startup") Set vec = folder.AllEntries Call vec.RemoveAll(True) 'This will enable the "Save Window State on Exit" user preference Call session.SetEnvironmentVar( "SaveStateOnExit", "1", True) Messagebox "You will need to restart your Notes client for the settings to take effect", 48, "Finished" End Sub
provided by Julian Robichaux at nsftools.com.


- 

