Session Manager 1.0.1

A Plugin for Notepad++

Downloads  |  Notepad++ Home  |  Notepad++ Forums  |  Plugin Central

Contents

Installation

Use the Notepad++ Plugin Manager for easy installation or upgrade of Session Manager. New releases of Session Manager may be available here before they are available in the Plugin Manager. In that case use the following manual installation/upgrade procedure.

  1. Exit Notepad++.
  2. Optional when upgrading:
    • Rename the existing SessionMgr.dll file (located in the Notepad++ plugins folder) so that it does not have a .dll extension, for example: SessionMgr-0.7.1.dll.bak (assuming its version is 0.7.1).
    • Make a backup copy of all existing session files and the settings.ini file.
  3. Download the Session Manager plugin archive file.
  4. Extract the archive file (with subfolders) into the Notepad++ plugins folder.
  5. Start Notepad++.
  6. Open the Settings dialog and configure Session Manager as you wish.

That completes the manual installation/upgrade procedure, but please note...

Session Manager will create its configuration files, if they do not already exist, in the plugin configuration folder reported by Notepad++. For more information see the Installation Folder and Configuration Files Notepad++ wiki pages (search for "doLocalConf.xml" and "allowAppDataPlugins.xml").

Basic Concepts

  • Session: A Notepad++ session consists of the pathnames of all the currently open files, their containing view, their tab order, their language setting, their cursor position, and more. These properties are stored in an XML file referred to as a session file. Some of these properties can be synchronized across different session files. See Global Properties for details.
  • Selected: The selected session is the highlighted session in the list of session names on the Sessions dialog.
  • Current: The current session is the active session – the one most recently loaded.
  • Previous: The previous session is the prior current session.
  • Default: When there is no current session a default session is used. It is located in the Session Manager configuration folder.
  • Loading: In general when loading a session, the current session will be saved then all its files closed. The selected sessions' files will be opened and it then becomes the current session. See below for options that affect how a session is loaded.
  • Saving: Saving a session means saving information about the currently open files in a session file. Saving a session does not save the session's open files.

Plugin Menu

You can customize Session Manager's plugin menu items (see the settings.ini section). The default labels and shortcuts follow. You can also configure your own shortcuts with the Notepad++ Shortcut Mapper.

Main (Plugin) Menu Item

  • Session Manager (alt+p,s): Opens the Session Manager submenu.

Submenu Items

  • Sessions (alt+p,s,s): Opens the Sessions dialog.
  • Settings (alt+p,s,t): Opens the Settings dialog.
  • Save current (alt+p,s,v): Saves the current (or default) session.
  • Load previous (alt+p,s,p): Loads the previous session.
  • Help (alt+p,s,h): Opens this HTML help file in your default web browser.
  • About (alt+p,s,a): Displays Session Manager version and other information.

Sessions Dialog

Load (alt+l): To load a session double-click a session name in the list, or select it then click the Load button. It then becomes the current session.

Previous (alt+p): Loads the previous session.

Default: Loads the default session.

Save (alt+s): Saves the current (or default) session.

New: Creating a new session does not load the new session – it creates it, adds it to the list and selects it. You can then load it if you wish. There are three options for creating a new session.

  • As an empty session: Create a new, empty session. Note that an empty session contains no files, however Notepad++ always has at least one editor tab open. In this case it is a new buffer which has not yet been saved to a file. After opening other files you can simply close the new buffer if you do not need it.
  • As a copy of the current session: Create a new session by copying the current session.
  • As a copy of the selected session: Create a new session by copying the selected session.

Rename: Renames the selected session.

Delete: Deletes the selected session. This does not delete the session's files – only the session file itself, and it will be removed from the list. You will be asked for confirmation before the deletion.

Close: Press the ESCape key, or click the Close button, to close the Sessions dialog.

Options

The following options affect how a session is loaded. See the Combining Sessions topic in the Tips section for more information on their usage.

  • Load into current (alt+i): If this option is checked the selected session will be loaded but it will not become the current session although the currently open files will be closed unless you check the next option. Your changes to this option are not saved.
  • Load without closing (alt+w): If this option is checked the currently open files will not be closed before the selected session is loaded. For convenience this option is checked automatically when the above option is checked. Your changes to this option are not saved.

The following options determine how the sessions list is sorted.

  • Sort by alpha (alt+a): Sorts alphabetically. Your changes to this option are saved.
  • Sort by date (alt+d): Sorts by most recently used. Sessions with the same last-modified time are sorted alphabetically. Your changes to this option are saved.

The Sessions dialog is resizable and remembers its size. Drag one of the corners or sides of the dialog to resize it.

Settings Dialog

  • Auto save: If this is enabled the current session is saved...
    • when any file is saved;
    • when a file's language changes;
    • when a file's bookmark margin is clicked;
    • before a new session is loaded;
    • when any file is opened, except when files are being opened due to a session being loaded;
    • when any file is closed, except when files are being closed due to a session being loaded or due to a Notepad++ shutdown.

    If Auto save is disabled sessions will only be saved when you select Save current from the plugin menu or click the Save button on the Sessions dialog. The default value for Auto save is 1 (enabled).

  • Auto load: If this is enabled the most recently opened session will be loaded when Notepad++ starts up. If you enable Auto load you should disable the Notepad++ Remember current session for next launch feature. The default value for Auto load is 0 (disabled).
  • Load into current: This setting is applied any time a session is loaded. It also determines the initial state of the Load into current checkbox on the Sessions dialog. The default value is 0 (disabled).
  • Load without closing: This setting is applied any time a session is loaded except on startup where it is considered enabled. It also determines the initial state of the Load without closing checkbox on the Sessions dialog. The default value is 0 (disabled).
  • Show in title bar: If this is enabled the current session name will be prepended to the text in the Notepad++ title bar. The default value is 0 (disabled).
  • Show in status bar: If this is enabled the current and previous session names will be displayed in the Notepad++ status bar. The default value is 0 (disabled).
  • Global bookmarks: This enables or disables the global bookmarks feature (see the Global Properties section). Note that if Auto save is disabled your global bookmarks will only get updated when you manually save the current session. The default value for Global bookmarks is 1 (enabled).
  • Session files folder: This specifies the location of the session files Session Manager will display in the Sessions dialog. Click the ... button to browse for a folder. Set to an empty string to get the default value: plugins\config\SessionMgr\sessions.
  • Session file extension: This specifies the file name extension of the session files Session Manager will display in the Sessions dialog. Think of it as a filter. Set to an empty string to get the default value: .npp-session.

Click the OK button to save and activate your changes. Press the ESCape key, or click the Cancel button, to cancel your changes and close the Settings dialog.

The Settings dialog is resizable and remembers its size. Drag one of the corners or sides of the dialog to resize it.

Tips & Tricks

Here are some tips for using Session Manager more efficiently.

  • Shortcuts: Get in the habit of using keyboard shortcuts, instead of the mouse, to open Session Manager dialogs.
  • Favorites: Make sessions containing favorite file(s). Any time you need those files just click the Load into current checkbox (which automatically checks Load without closing) then load the desired favorites session.
  • Categories: Name your sessions with categorized prefixes or suffixes. This will group related sessions together in the list when it is sorted alphabetically. For example, I prefix my "favorites" sessions with an underscore because I want those to appear at the top of the list. I have many web-related projects and I prefix those session names with "www_". An example of using a suffix is: "my-project_trunk", "my-project_rev-123", etc. That keeps them grouped together in the list.
  • Large Projects: Sometimes you may have a large project and end up creating many different sessions for it. Usually it's the type of project that may last for a relatively long time, but after the project is finished you don't want all those sessions cluttering the Sessions list – but you also may not want to delete all of them. Here's how Session Manager can help in this situation: use different session file name extensions. Using a different session file name extension keeps all session files in one folder and then the extension acts as a filter for what sessions are displayed in the Sessions list. Also, a different default session is created for each different extension. Changing the extension back to the default is easy – just leave the extension field blank, in the Settings dialog, and the default will be used.
  • Usage Scenarios: Here are two basic usage scenarios.
    • Enable the Auto load setting so some session is always current. Loaded sessions become current and change to always reflect the latest changes to that session. This scenario does not use the default session.
    • Disable the Auto load setting, enable the Load into current setting and disable the Load without closing setting. Open the Sessions dialog and click the Default button. In this scenario the default session is always current. When other sessions are loaded they are loaded into the default session. Other sessions do not change but always contain the same files, and the default session always represents the most recent editing session.
  • Combining Sessions: Let's say the Sessions dialog is open and you have two sessions, A and B. Session A is current and session B is selected.
    • Add B to A: Check the Load into current checkbox. The Load without closing checkbox is automatically checked. Load session B. Now session A is current and includes all of session B's files.
    • Add A to B: Uncheck the Load into current checkbox and check the Load without closing checkbox. Load session B. Now session B is current and includes all of session A's files.
    • Replace A with B: Check the Load into current checkbox and uncheck the Load without closing checkbox. Load session B. Now session A is current and only contains session B's files (it is now a copy of B).
  • Context Menu: This great tip was contributed by danrathbun. He shows us how to add a Session Manager submenu to the context (right-click) menu.
    • From the Notepad++ main menu select Settings then Edit Popup ContextMenu.
    • Insert the following. Where you insert it will determine the submenu's position in the Context Menu. The values of the PluginEntryName attributes must match the Session Manager main (plugin) menu item name. The values of the PluginCommandItemName attributes must match the Session Manager submenu item names. You can customize the values of the FolderName and ItemNameAs attributes.
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Sessions..." ItemNameAs="&Open..."/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Settings..." ItemNameAs="&Configure..."/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Save current" ItemNameAs="&Save current"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Load previous" ItemNameAs="&Load previous"/>
      <Item FolderName="Session &Manager" id="0"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Help" ItemNameAs="&Help"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="About..." ItemNameAs="&About..."/>
      The above assumes you are using the default Session Manager submenu item names. The following shows what to insert if you are using the example submenu items shown in the settings.ini section.
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Open..." ItemNameAs="&Open..."/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Configure..." ItemNameAs="&Configure..."/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Save current" ItemNameAs="&Save current"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Load previous" ItemNameAs="&Load previous"/>
      <Item FolderName="Session &Manager" id="0"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="Help" ItemNameAs="&Help"/>
      <Item FolderName="Session &Manager" PluginEntryName="Session Manager" PluginCommandItemName="About..." ItemNameAs="&About..."/>
    • Optionally you can make the following change so that right-click,s properly executes "Select All", since "Session Manager" also begins with an "S". Change this line:
      <Item MenuEntryName="Edit" MenuItemName="Select All"/>
      To this:
      <Item MenuEntryName="Edit" MenuItemName="Select All" ItemNameAs="&Select All"/>
    • Save your changes to the "contextMenu.xml" file and restart Notepad++. Now try right-click,m,o. Instead of right-clicking you can use the context menu key (if your keyboard has it): ctx-key,m,o. There are many possibilites. Configure it to what is most convenient for you.

Feedback

There is an ongoing discussion at the Notepad++ plugins forum. Join us!

Advanced

This section contains advanced and technical topics which are not necessary to understand for normal usage of Session Manager.

API

Session Manager provides an API which can be used by Notepad++ or other plugins. The "SessionMgrApi.h" file has complete documentation of this feature. A client sends an NPPM_MSGTOPLUGIN message to Notepad++ with wParam pointing to L"SessionMgr.dll" and lParam pointing to a SessionMgrApiData object. Clients can load sessions, save the current session, get the current session name, set the session directory and extension, and more.

settings.ini

The following properties are not accessible via the Settings dialog but must be edited directly in the "settings.ini" file. Close Notepad++ and use some other editor to edit this file. Note that you must save this file as UTF-16LE.

  • saveDelay: You probably will not need to change this property. See the Shutdown section for details. The default value is 3.
  • sessionsW, sessionsH, settingsW and settingsH: These properties are in the [dialog] section. They store the sizes of the Sessions and Settings dialogs. You can set these to 0 to reset their sizes to the defaults.
  • main, sub1, sub2, etc.: These properties are in the [menu] section. They optionally define the labels for the Session Manager plugin menu. Session Manager will use default values (see the Plugin Menu section) for any items not defined here. Here is an example of customizing the menu items:
    [menu]
    main=Session &Manager
    sub1=&Open...
    sub2=&Configure...
    sub3=&Save current
    sub4=&Load previous
    sub5=&Help
    sub6=&About...
  • debug: This property is in the [debug] section. This is probably not useful unless you are debugging SessionMgr itself. The default value is 0. If you are curious, set it to 30 and specify a logFile.
  • logFile: This property is in the [debug] section and is used only if debug > 0. The value must be an absolute pathname of a file to which debug messages will be printed.

Global Properties

Notepad++ saves a file's bookmarks (and other properties) in the session file, so the same file in different sessions will not have the same bookmarks. Session Manager can keep files' bookmarks (and a little more) synchronized across different sessions (See Global bookmarks in the Settings Dialog section).

The file "global.xml", in the Session Manager configuration directory, stores bookmarks, firstVisibleLine and language for each unique pathname in all your sessions. There are 3 cases where these global properties are used...

  • After a session is saved, the global bookmarks, firstVisibleLine and language are updated from the session properties.
  • When a session is about to be loaded, the session bookmarks and language are updated from the global properties, then the session is loaded.
  • When an existing document is added to a session, its bookmarks and firstVisibleLine are updated from the global properties, then the session is saved.

File nodes are never removed from the global properties file (except when the file no longer exists) so if you remove a certain file from all sessions then later add it to a session it will have bookmarks and firstVisibleLine restored from the last time it was part of a session.

The global properties feature was introduced in Session Manager 0.8, so if you have been using version <= 0.7.1 and you install version >= 0.8, the global properties file will be initially empty. Your global bookmarks will get updated as you load different sessions. You can speed up this process by loading all your sessions, one by one, in order from earliest to latest last-modified time, or in order from least to most important.

Shutdown

Session Manager does not immediately save the current session when a file is closed. It must determine if a shutdown is in progress in which case all files will be closed. We don't want to save the session if files are being closed due to a shutdown. When Notepad++ is about to shutdown it closes all files before it sends the shutdown notification to plugins. To work around this, when a file is closed Session Manager waits for saveDelay seconds (see the settings.ini section). If the shutdown notification has not been received at the end of that time then the current session is saved.

This is not an ideal solution but it is very rare for a session to be saved incorrectly. When you initiate a shutdown Notepad++ first checks all open files. If a file is modified Notepad++ will offer to let you save the file, not save the file, or cancel the shutdown. If you choose to save the file then the plugin will receive NPPN_FILEBEFORESAVE, SCN_SAVEPOINTREACHED and then NPPN_FILESAVED, as usual. Notepad++ then continues checking open files and prompting you if any are modified. Only after all files have been checked does Notepad++ begin closing files.

So far, there is only one scenario I have found where Session Manager will save the session incorrectly. If you close one or more files and then quit Notepad++ before saveDelay seconds have elapsed then those closed files will still be part of that session.

Ideally, Notepad++ would issue NPPN_BEFORESHUTDOWN, then close all files, then issue NPPN_SHUTDOWN. In the case where the user cancels the shutdown it would issue NPPN_CANCELSHUTDOWN.

Revision History

1.0.1, 15Nov2014

  • Fixed a regression bug reported by Bernd G (thanks!). Now, on startup, regardless of these options in the settings file, it considers Load into current to be false because there is no current session on startup, and it considers Load without closing to be true so it doesn't close files opened via the NPP command line.
  • Removed global properties support for the "encoding" attribute. It seems NPP doesn't use it, it's always -1.
  • Updated the help file.

1.0, 06Nov2014

  • After three years Session Manager is finally released as version 1.0!

0.8.4.1, 06Nov2014 (binary not released)

  • Unicode-related fixes and improvements:
    • Modified TinyXml2's load/save to support unicode file names.
    • Adds an XML declaration if it is missing from the global properties file. However, NPP saves session files without a declaration.
    • Rewrote the 'pth' functions to be more unicode safe.
    • The debug log file name and messages can now be unicode.
    • No longer includes 'tchar.h' and no longer uses _T, TCHAR and related macros. Uses wide chars and wide stdlib and Win32 functions explicitly. Still defines UNICODE and _UNICODE.
    • Session files are read/written as UTF-8. The 'settings.ini' file is still read/written as UTF-16LE – keep that in mind if you edit the file manually. I may eventually change that file to XML format and UTF-8 encoding.
    • Writes pathnames in session files (using UTF8-CPP) in the format NPP requires: all chars < 32 or > 126 are converted to entities.
  • Renamed 'file-properties.xml' to 'global.xml'. Sorry for the non-back-compat change. You can just rename the old file to the new name.
  • Improved error handling and messages, but it needs more testing.
  • Using dynamic allocation in many places instead of static buffers.
  • Using newer style for BrowseForFolder (should be supported by 98, ME and above).
  • On startup, cleans the global file properties file by removing File elements whose files do not exist on disk.
  • Implemented an API that can be called by NPP or other plugins. Documented in 'SessionMgrApi.h'.

0.8.3, 28Oct2014 (binary not released)

  • Bug fix: Now properly updates current and previous session names on delete or rename.
  • Now will not let you delete the current session.
  • Moved the global properties functions to their own file.
  • Made misc minor improvements to the code.
  • Experimenting with doxygen notation.
  • Made big improvements to the help page.

0.8.2, 19Oct2014

  • Fixed a bug reported by Pavel (thanks!): When about to load a new session, do not save the current session if Auto save is disabled.
  • In the "Create New Session" dialog, renamed "From the currently open files" to "As a copy of the current session" and renamed "By copying the selected session" to "As a copy of the selected session".
  • Renamed some Config class methods.
  • Tweaked some button positions.
  • Made improvements to the help page.

0.8.1, 12Oct2014

  • Added an option to sort the sessions list by the session files' last-modified times in addition to alphabetically.
  • Improved the algorithm for resizing/repositioning controls when the dialog is resized by the user. Fixed a bug related to saving/restoring the dialog size.
  • Added a checkbox on the Settings dialog for the global bookmarks feature.
  • Some controls on the Sessions dialog now have keyboard shortcuts. Hold Alt then hit: l = Load, p = Previous, s = Save, i = Load into current, w = Load without closing, a = Sort by alpha, d = Sort by date.
  • Improved debug logging. Current and active buffer IDs are logged for notifications.
  • Changed the About text.
  • Made big improvements to the help page.

0.8, 05Oct2014

  • Global bookmarks! Uses TinyXml2.
  • Saves the session when the bookmark margin is clicked.
  • Writes messages to a log file when in debug mode.
  • Uses Windows SDK v7.1, was v7.0a. Still uses MSVS2010 command-line tool chain.
  • Updated header files from NPP 6.6.9.

0.7.1, 20Jan2013

  • Issue reported by light2some: When a file is first changed the titlebar text does not get the session prefix. Fix: Update the titlebar text one second after the SCN_SAVEPOINTLEFT Scintilla event (NPP doesn't prepend the "*" until after the event).
  • Upgraded header files from NPP v6.2.3: menuCmdID.h, Notepad_plus_msgs.h, PluginInterface.h and Scintilla.h.
  • [Minor NPP bug?] It's not a problem but I noticed that, in Notepad_plus_msgs.h, NPPN_DOCORDERCHANGED and NPPN_READONLYCHANGED have the same value (NPPN_FIRST + 16). Also, I cannot detect either of these events in my plugin code, even tho NPPM_INTERNAL_DOCORDERCHANGED seems to be handled correctly in the NPP source code.

0.7, 13Jan2013

  • The Sessions dialog and the Settings dialog now remember their sizes after being resized.
  • The previous session is now remembered and can be loaded via a new menu option, "Load previous", and a new button on the Sessions dialog, "Previous".
  • The name of the current session is now prepended to the text in the Notepad++ title bar. This is enabled by a new option on the Settings dialog, "Show in title bar".
  • The names of the current and previous sessions are now displayed in the Notepad++ status bar. This is enabled by a new option on the Settings dialog, "Show in status bar".
  • The labels for the Session Manager plugin menu are now optionally defined in the settings.ini file.
  • The setting "Enable 'Load into current'" was renamed to "Load into current". The setting "Disable 'Load without closing'" was simplified to "Load without closing".
  • There is now a folder browse button next to the "Session files folder" edit control on the Settings dialog.

0.6.0.1, 17Jun2012

  • Added danrathbun's Context Menu tip to the Help file. There were no code changes.

0.6, 21Mar2012

  • The bugfix in the previous release has been confirmed.
  • In the New Session dialog box, clicking one of the options (when the edit field is empty) will populate the edit field with the selected session name.

0.4.1, 20Mar2012

  • Possible bugfix (strange characters in names): I think I have found and corrected this problem.
  • Changed button name from Cancel to Close on the Session Manager dialog.
  • If the session directory specified in the Settings dialog does not exist then it is created.

0.4, 29Nov2011

  • Changed Sessions and Settings dialogs to have TOOLWINDOW style.
  • Bugfix: When the Sessions listbox was displayed the focused item and selected item were not always the same.
  • Added getLbIdxByData and dbgBox in Util.cpp.
  • Added enableLIC and disableLWC to DEFAULT_INI_CONTENTS.
  • Commented-out saving of current session on NPPN_DOCORDERCHANGED - this event never occurs?
  • Moved definition of unicode constants from System.h to Makefile.

0.3, 03Oct2011

  • The 0.2 source archive did not include the build files. They are included now.
  • Session template files are no longer used.
  • Previously, upgrading Session Manager would cause the existing configuration files to be over-written. Now that does not happen. Session Manager creates default configuration files only if they do not already exist.
  • Session Manager now uses a default session (located in the config folder) if there is no current session. The default session can be loaded by clicking the newly added Default button on the Sessions dialog.
  • A Save button has been added to the Sessions dialog. It saves the current (or default) session.
  • Sessions are auto-saved on two additional NPP events: NPPN_LANGCHANGED and NPPN_DOCORDERCHANGED.
  • The second option for creating a new session has changed to "From the currently open files", which basically is a session "save as" feature.
  • Previously if you opened files by passing them on the Notepad++ command line and Auto load was enabled then Session Manager would close the file(s) Notepad++ had just opened (passed on the command line). This has been corrected. Now Session Manager will not close open files when auto-loading.
  • Increased the initial width of the Settings dialog. Removed all debug properties except one, named "debug". Added two more boolean properties: enableLIC and disableLWC.
  • Add a trailing slash, if needed, to the user-entered session folder. Add a leading dot, if needed, to the user-entered session file extension.
  • Made general improvements to the code. Fixed a dependency-related bug in the Makefile. Made big improvements to the help file.

0.2, 24Sep2011

  • Compile with /MT so the crt library is linked statically.
  • Display a warning if no file name is supplied for New or Rename dialogs.
  • If the config and sessions folders do not exist then create them. If config and template files are not present then default files are created.
  • An empty session folder will not cause an error.
  • Build with an nmake makefile. Still uses the VC++ v10 toolchain, but now is not dependent on any IDE.
  • Removed saveDelay from Settings dialog, but it is still in the .ini file.
  • Sessions and Settings dialogs are sizable but do not yet save user size/position.
  • The session list is read from disk every time the Sessions dialog is displayed. Removed "Refresh Session List" from the menu.

0.1, 03Aug2011

  • Initial release. Compiled with VC++ 2010. Tested with Notepad++ v5.9.2 on WinXP-SP3. Unicode only.