diff --git a/Explorer++/Explorer++/Explorer++.cpp b/Explorer++/Explorer++/Explorer++.cpp index a91fc49fa..d2ef47c39 100644 --- a/Explorer++/Explorer++/Explorer++.cpp +++ b/Explorer++/Explorer++/Explorer++.cpp @@ -43,7 +43,8 @@ Explorerplusplus *Explorerplusplus::Create(App *app, const WindowStorageData *st Explorerplusplus::Explorerplusplus(App *app, const WindowStorageData *storageData) : m_id(idCounter++), m_app(app), - m_hContainer(CreateMainWindow(storageData)), + m_hContainer(CreateMainWindow(storageData, + app->GetFeatureList()->IsEnabled(Feature::MultipleWindowsPerSession))), m_commandController(this), m_tabBarBackgroundBrush(CreateSolidBrush(TAB_BAR_DARK_MODE_BACKGROUND_COLOR)), m_pluginMenuManager(m_hContainer, MENU_PLUGIN_START_ID, MENU_PLUGIN_END_ID), @@ -95,8 +96,10 @@ Explorerplusplus::~Explorerplusplus() m_pDirMon->Release(); } -HWND Explorerplusplus::CreateMainWindow(const WindowStorageData *storageData) +HWND Explorerplusplus::CreateMainWindow(const WindowStorageData *storageData, + const bool multipleWindowsPerSession) { + bool isFirstInstance = IsFirstInstance(); static bool mainWindowClassRegistered = false; if (!mainWindowClassRegistered) @@ -118,13 +121,23 @@ HWND Explorerplusplus::CreateMainWindow(const WindowStorageData *storageData) CHECK(res); placement.showCmd = SW_HIDE; - placement.rcNormalPosition = - storageData ? storageData->bounds : LayoutDefaults::GetDefaultMainWindowBounds(); + if (multipleWindowsPerSession) + placement.rcNormalPosition = + storageData ? storageData->bounds : LayoutDefaults::GetDefaultMainWindowBounds(); + else + placement.rcNormalPosition = + storageData && isFirstInstance ? storageData->bounds : LayoutDefaults::GetDefaultMainWindowBounds(); SetWindowPlacement(hwnd, &placement); return hwnd; } +bool Explorerplusplus::IsFirstInstance() +{ + HWND hPrev = FindWindow(WINDOW_CLASS_NAME, nullptr); + return (hPrev == nullptr); +} + ATOM Explorerplusplus::RegisterMainWindowClass(HINSTANCE instance) { WNDCLASSEX windowClass = {}; diff --git a/Explorer++/Explorer++/Explorer++.h b/Explorer++/Explorer++/Explorer++.h index 581fa9b28..e5b2572ec 100644 --- a/Explorer++/Explorer++/Explorer++.h +++ b/Explorer++/Explorer++/Explorer++.h @@ -210,7 +210,9 @@ class Explorerplusplus : Explorerplusplus(App *app, const WindowStorageData *storageData); - static HWND CreateMainWindow(const WindowStorageData *storageData); + static HWND CreateMainWindow(const WindowStorageData *storageData, + const bool multipleWindowsPerSession); + static bool IsFirstInstance(); static ATOM RegisterMainWindowClass(HINSTANCE instance); LRESULT WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); diff --git a/Explorer++/Explorer++/Explorer++.rc b/Explorer++/Explorer++/Explorer++.rc index 2ce2972a7..53fb886c2 100644 Binary files a/Explorer++/Explorer++/Explorer++.rc and b/Explorer++/Explorer++/Explorer++.rc differ diff --git a/Explorer++/Explorer++/TabContainerImpl.cpp b/Explorer++/Explorer++/TabContainerImpl.cpp index 74e58be8b..28e4f41ea 100644 --- a/Explorer++/Explorer++/TabContainerImpl.cpp +++ b/Explorer++/Explorer++/TabContainerImpl.cpp @@ -443,6 +443,10 @@ void TabContainerImpl::ProcessTabCommand(UINT uMenuID, Tab &tab) DuplicateTab(tab); break; + case IDM_TAB_MOVETABNEWWINDOW: + MoveTabToNewWindow(tab); + break; + case IDM_TAB_OPENPARENTINNEWTAB: OnOpenParentInNewTab(tab); break; @@ -1309,6 +1313,13 @@ void TabContainerImpl::DuplicateTab(const Tab &tab) CreateNewTab(navigateParams, {}, &folderSettings, &folderColumns); } +void TabContainerImpl::MoveTabToNewWindow(const Tab &tab) +{ + tab.GetBrowser()->OpenItem(tab.GetShellBrowserImpl()->GetDirectoryIdl().get(), + OpenFolderDisposition::NewWindow); + CloseTab(tab); +} + int TabContainerImpl::GetDropTargetItem(const POINT &pt) { POINT ptClient = pt; diff --git a/Explorer++/Explorer++/TabContainerImpl.h b/Explorer++/Explorer++/TabContainerImpl.h index f5e3eabde..4d98b1267 100644 --- a/Explorer++/Explorer++/TabContainerImpl.h +++ b/Explorer++/Explorer++/TabContainerImpl.h @@ -114,6 +114,7 @@ class TabContainerImpl : public TabContainer, public ShellDropTargetWindow int GetNumTabs() const; int MoveTab(const Tab &tab, int newIndex); void DuplicateTab(const Tab &tab); + void MoveTabToNewWindow(const Tab &tab); bool CloseTab(const Tab &tab); // Eventually, this should be removed. diff --git a/Explorer++/Explorer++/resource.h b/Explorer++/Explorer++/resource.h index f0d4caecd..f57ca27c8 100644 --- a/Explorer++/Explorer++/resource.h +++ b/Explorer++/Explorer++/resource.h @@ -753,6 +753,7 @@ #define IDM_VIEW_SORTBY 40285 #define IDM_TOOLBARS_MAINTOOLBAR 40291 #define IDM_TOOLBARS_BOOKMARKSTOOLBAR 40292 +#define IDM_TAB_MOVETABNEWWINDOW 40316 #define IDM_TAB_OPENPARENTINNEWTAB 40319 #define IDM_TAB_RENAMETAB 40321 #define IDM_VIEW_SETDEFAULTCOLUMNS 40323