Skip to content

Commit 6dc0af3

Browse files
committed
Add "Move Tab to a New Window" in tab context menu
And open new windows in the default bounds, not in the stored bounds, avoiding that confusing behavior when the new window is created in the same exact position of the previous one. The stored bounds are used for the first instance.
1 parent 47bcbd4 commit 6dc0af3

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

Explorer++/Explorer++/Explorer++.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Explorerplusplus::~Explorerplusplus()
100100

101101
HWND Explorerplusplus::CreateMainWindow(const WindowStorageData *storageData)
102102
{
103+
bool isFirstInstance = IsFirstInstance();
103104
static bool mainWindowClassRegistered = false;
104105

105106
if (!mainWindowClassRegistered)
@@ -121,12 +122,19 @@ HWND Explorerplusplus::CreateMainWindow(const WindowStorageData *storageData)
121122
CHECK(res);
122123

123124
placement.showCmd = SW_HIDE;
124-
placement.rcNormalPosition = storageData ? storageData->bounds : GetDefaultMainWindowBounds();
125+
placement.rcNormalPosition =
126+
storageData && isFirstInstance ? storageData->bounds : GetDefaultMainWindowBounds();
125127
SetWindowPlacement(hwnd, &placement);
126128

127129
return hwnd;
128130
}
129131

132+
bool Explorerplusplus::IsFirstInstance()
133+
{
134+
HWND hPrev = FindWindow(WINDOW_CLASS_NAME, nullptr);
135+
return (hPrev == nullptr);
136+
}
137+
130138
ATOM Explorerplusplus::RegisterMainWindowClass(HINSTANCE instance)
131139
{
132140
WNDCLASSEX windowClass = {};

Explorer++/Explorer++/Explorer++.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class Explorerplusplus :
207207
Explorerplusplus(App *app, const WindowStorageData *storageData);
208208

209209
static HWND CreateMainWindow(const WindowStorageData *storageData);
210+
static bool IsFirstInstance();
210211
static ATOM RegisterMainWindowClass(HINSTANCE instance);
211212
static RECT GetDefaultMainWindowBounds();
212213

148 Bytes
Binary file not shown.

Explorer++/Explorer++/TabContainer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ void TabContainer::ProcessTabCommand(UINT uMenuID, Tab &tab)
440440
DuplicateTab(tab);
441441
break;
442442

443+
case IDM_TAB_MOVETABNEWWINDOW:
444+
MoveTabToNewWindow(tab);
445+
break;
446+
443447
case IDM_TAB_OPENPARENTINNEWTAB:
444448
OnOpenParentInNewTab(tab);
445449
break;
@@ -1339,6 +1343,13 @@ void TabContainer::DuplicateTab(const Tab &tab)
13391343
CreateNewTab(navigateParams, {}, &folderSettings, &folderColumns);
13401344
}
13411345

1346+
void TabContainer::MoveTabToNewWindow(const Tab &tab)
1347+
{
1348+
tab.GetBrowser()->OpenItem(tab.GetShellBrowserImpl()->GetDirectoryIdl().get(),
1349+
OpenFolderDisposition::NewWindow);
1350+
CloseTab(tab);
1351+
}
1352+
13421353
int TabContainer::GetDropTargetItem(const POINT &pt)
13431354
{
13441355
POINT ptClient = pt;

Explorer++/Explorer++/TabContainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class TabContainer : public ShellDropTargetWindow<int>
111111
int GetNumTabs() const;
112112
int MoveTab(const Tab &tab, int newIndex);
113113
void DuplicateTab(const Tab &tab);
114+
void MoveTabToNewWindow(const Tab &tab);
114115
bool CloseTab(const Tab &tab);
115116

116117
// Eventually, this should be removed.

Explorer++/Explorer++/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@
748748
#define IDM_VIEW_SORTBY 40285
749749
#define IDM_TOOLBARS_MAINTOOLBAR 40291
750750
#define IDM_TOOLBARS_BOOKMARKSTOOLBAR 40292
751+
#define IDM_TAB_MOVETABNEWWINDOW 40316
751752
#define IDM_TAB_OPENPARENTINNEWTAB 40319
752753
#define IDM_TAB_RENAMETAB 40321
753754
#define IDM_VIEW_SETDEFAULTCOLUMNS 40323

0 commit comments

Comments
 (0)