Reopening same folder in single instance mode

Discuss development issues and submit patches here
Post Reply
twinsen
Posts: 109
Joined: Mon Dec 27, 2010 3:17 pm

Reopening same folder in single instance mode

Post by twinsen »

Previously if you opened the same folder multiple times from the command line in single instance mode, you would get lots of duplicates of the same folder (and it wouldn't even restore the window). Windows explorer has the nice ability that when you open the same folder twice from the command line it just makes the existing window in focus, you don't get redundant window clutter (it also brings the window in focus).

Now when opening a folder from the command line in single instance mode, if the folder is already open it makes that tab in focus instead of creating a new tab.

I also needed to apply the restore fix on http://www.explorerplusplus.com/phpBB3/ ... 96&start=0
Simply search for the two "SW_SHOW" occurrences and replace with "SW_RESTORE" (unless Davids already applied that fix).

Together with the "new/last instance argument" patch, you can even control an existing explorer++ window in multiple instance mode, eg "explorer++ -last_instance d:\" would tell the last instance to focus its d drive tab.

Demo exe: http://members.iinet.net.au/~bertdb/rya ... sen_2.3.7z

I haven't made a patch yet, but here are the changes if any one is interested...

In 1.2 its Explorer.cpp, WindowProcedure where WM_COPYDATA is handled, this is the extra code.

Code: Select all

				if(pcds->lpData != NULL)
				{
					TCHAR szBrowseDirectory[MAX_PATH];
					StringCchCopy(szBrowseDirectory,SIZEOF_ARRAY(szBrowseDirectory),(TCHAR*)pcds->lpData);
					if (szBrowseDirectory[lstrlen(szBrowseDirectory)-1] == '\\')
					{
						// Remove slash.
						PathRemoveFileSpec(szBrowseDirectory);
					}

					// Check if the dir is already open, if so just make that active
					// a bit like what windows explorer does if you open the same folder twice 
					// from the command line.

					bool alreadyOpen = false;
					int nTabs = TabCtrl_GetItemCount(m_hTabCtrl);
					for (int i=0;i<nTabs;++i)
					{
						TCITEM tcItem;
						TCHAR szTabDirectory[MAX_PATH];

						tcItem.mask	= TCIF_PARAM;
						TabCtrl_GetItem(m_hTabCtrl,i,&tcItem);
						m_pShellBrowser[(int)tcItem.lParam]->QueryCurrentDirectory(MAX_PATH,szTabDirectory);
						if (szTabDirectory[lstrlen(szTabDirectory)-1] == '\\')
						{
							// Remove slash.
							PathRemoveFileSpec(szTabDirectory);
						}
	
						if (lstrcmpi(szTabDirectory,szBrowseDirectory) == 0)
						{
							alreadyOpen = true;

							// Put tab in focus instead.
							TabCtrl_SetCurSel(m_hTabCtrl,i);
							OnTabSelectionChange();

							// Now focus the list view so don't need to click the mouse.
							SetFocus(m_hActiveListView);
						}
					}

					if (!alreadyOpen)
					{
						BrowseFolder(szBrowseDirectory,SBSP_ABSOLUTE,TRUE,TRUE,FALSE);
					}
				}
Post Reply