Skip to content

Add "Move Tab to a New Window" in tab context menu #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Explorer++/Explorer++/Explorer++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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 = {};
Expand Down
4 changes: 3 additions & 1 deletion Explorer++/Explorer++/Explorer++.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified Explorer++/Explorer++/Explorer++.rc
Binary file not shown.
11 changes: 11 additions & 0 deletions Explorer++/Explorer++/TabContainerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Explorer++/Explorer++/TabContainerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class TabContainerImpl : public TabContainer, public ShellDropTargetWindow<int>
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.
Expand Down
1 change: 1 addition & 0 deletions Explorer++/Explorer++/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down