Repository: microsoft/terminal (language: cpp)

Issue:
Add the "Move Tab to New Window" item to the context menu of the tabs
              Is it supposed to add the "Move Tab to New Window" item to the context menu of the tabs
![Screenshot_2023-04-06_08-54-54](https://user-images.githubusercontent.com/3509797/230285656-909af440-5b8a-4d98-91cd-e72b8d4feaf4.png)
like Mozilla Firefox
![Screenshot_2023-04-06_08-55-44](https://user-images.githubusercontent.com/3509797/230285863-db1a8f4d-f1ca-44b5-96d3-eca158e30f37.png)
in the context of this task?

Screenshots of Windows Terminal Preview 1.17.1023 and Mozilla Firefox 111.0.1 (64-bit), Microsoft Windows 10.0.19045.2788.

_Originally posted by @Korb in https://github.com/microsoft/terminal/issues/1256#issuecomment-1498541375_
            


Discussion / hints:
Want to tackle my first issue for this project. 
Having trouble getting the project build in visual studio which I need to Run & Debug. 

I installed all the prerequisites as described in README as far as I know. 
And am able to build it with Powershell.

Had some trouble with Configuration manager when first opening the project in Visual Studio.
https://stackoverflow.com/questions/72852490/current-solution-contains-incorrect-configuration-mappings

Cleared everything between
 `GlobalSection(ProjectConfigurationPlatforms) = postSolution`
 and
 `EndGlobalSection`
 
 For the OpenConsole.sln file.
 
 Properties for Cascadia Package have been set in the Debug menu to "Native Only"  for "Application process" and "Background task process". 
 
 x64 Platform has been selected. 

This is what I get: 
![image](https://github.com/microsoft/terminal/assets/15957528/e70c8464-6336-4f87-a760-73fe3b389ad8)


I tried x86 , makes no difference. 
Turned off Windows Defender, doesn't make a difference
https://stackoverflow.com/questions/16680717/error-msb6006-mt-exe-exited-with-code-31


 
 
Oh you can almost certainly ignore the warning that VS shows about the incorrect configurations. I'd revert all your changes to `OpenConsole.sln`, then make sure you pick:

![](https://github.com/microsoft/terminal/assets/18356694/e656f2da-0584-46c7-a30a-1f230ceb7555)


And that should just work.

Our sln is a crazy hodgepodge of c++ and C# code and unsurprisingly, VS _does not care for that_ 😅

Lemme know if you run into any other issues
@zadjii-msft 

Reverted all changes to OpenConsole.sln by removing and recloning the project. 

Picked: 
![image](https://github.com/microsoft/terminal/assets/15957528/ca89bc94-5d40-44a2-90ec-b8788920fa89)

Restored and updated submodules
`git submodule update --init --recursive`

Ignored warning about incorrect configurations. 
In the Debug menu,  I changed "Application process" and "Background task process" to "Native Only".

Build it, had an issue with nuget packages: 

![Nuget Package Restore 2023-05-12 114632](https://github.com/microsoft/terminal/assets/15957528/bb571cc4-d0e2-4dc8-af4f-a2bdbaa517f3)

Solved that by building with Powershell. This installed the packages, but this time build ended with errors. 
Afterwards I deleted the Obj and Bin folder of the project and build it with visual studio, getting the same erros as before, but getting similar errors with PowerShell now as well:

![Same Errors ](https://github.com/microsoft/terminal/assets/15957528/756c0f6f-9c8f-4a97-a0cb-4a8826c9b832)


![image](https://github.com/microsoft/terminal/assets/15957528/86c86eb9-a103-4084-8717-b56e4724855f)

![image](https://github.com/microsoft/terminal/assets/15957528/181aca8a-fd23-40a9-b211-b2b3726711a4)






```
(_ConsoIeGenerateAdditionaIWinmdManifests target) —>
    mt.exe: command line error c1010007: Unexpected/ Unknown option "...\Microsoft.Termina1.Control\Microsoft.Terminal.Control.winmd". Use the / ? option for help on usage and samples. 
    The command `mt.exe -winmd:...\Termina1.Control\Microsoft.Terminal.Control.winmd -dll:Microsoft.Terminal.Control.dll -out:...WindowsTerminal\Microsoft.Terminal.Control.manifest exited with code 31
```

Huh. I've literally never seen that before. That'll require some searching. 

When you built it from the command-line the first time, it worked and you didn't run into that? 

Utterly bewildering. 
Silly question - does the username covered up with the blue splodge contain any odd characters - like a space?
@ianjoneill 

Yes It contains a space.

Update 1:
I tried building with Powershell in two separate locations one in my User folder, the other in C:. 
In C: I don't get the mt.exe errors Getting Nuget package restore errors so that's an improvement :)
Thanks.

Update 2 : 

![image](https://github.com/microsoft/terminal/assets/15957528/9ede8f1e-5898-4c3e-ab1e-3a9505ab1ed3)


@ianjoneill  @zadjii-msft 

Got it running in VS thanks very much to @ianjoneill !
and @zadjii-msft  for the configuration Manager ignore tip. 
![image](https://github.com/microsoft/terminal/assets/15957528/1e92ed1a-0611-49fb-93d7-9690c1c16a28)




@[zadjii-msft](https://github.com/zadjii-msft)  @[ianjoneill](https://github.com/ianjoneill)

“That'll require some searching.”
Would you have done that? What is like protocol in this Open Source project in terms of help you can expect from Members ?

Can I expect you to do the searching. Or is it more like you expect me to do the searching and try various different things. And I can expect a small hint here and there?

PS: I'll get to picking up this issue now I got Debugger working. 
> “That'll require some searching.”
> Would you have done that?

I mean, yea? I was planning on trying to look into that error myself if you couldn't figure it out. Pretty much my biggest priority is helping keep folks unblocked. I'm all for giving hints - heck, I've got an entire project board full of "walkthroughs" I've written for issues: https://aka.ms/terminal-walkthroughs. 

Speaking of which, I should probably write one for this issue too!

> **Note**
> ## Walkthrough

* I'd start by looking at `TerminalTab::_CreateContextMenu`. That's where we set up the tab context menu. 
* Almost all the buttons work by triggering a `WINRT_CALLBACK`, which is ultimately handled by a handler set up in `TerminalPage::_InitializeTab` (in `TabManagement.cpp`)
* To actually do the moving, you'll want to build a `MoveTabArgs` with the `Window` set to `"new"`.
  * You'll want to then call `TerminalPage._MoveTab` 
* The trick here will be being able to move an unfocused tab. "Find" has a similar issue. It might be a sensible place to do a `page->_SetFocusedTab(*tab);` first, to manually focus that tab. 
@zadjii-msft Your walkthroughs look really cool, in the sense that you build it like a game!! I love that. 

Btw, the software not being able to be build when someone has a username that contains a space.  This may be a new issue? If so, I could make a new issue for it. 
Can't help but being bugged by not having the project in my preferable location.
Made some progress, got the UI part done. 
![UI_Part_done_mostly](https://github.com/microsoft/terminal/assets/15957528/edefc48a-a109-4de2-a6f7-7182e2b45558)

Button will need a new Glyph though. I assume you have like an artist for that? 

Still need to build the functionality, currently duplicates duplicate tab functionality. 




I started exploring the code base a bit and have some questions: 

Where are cpp files inside solution explorer, like where is TerminalTab.cpp? 
Can find it in file explorer, but not solution explorer. Is this a cpp thing or? (more used to c#)
And if it is there, how can I find it? I remember something about shortcuts for that, but not sure. 

![where_are_cpp_files_inside_solution_explorer](https://github.com/microsoft/terminal/assets/15957528/9a42810e-68ff-472e-aac1-868976d36c08)
![but_inside_file_explorer](https://github.com/microsoft/terminal/assets/15957528/48807902-fc3e-4a51-a31c-0509806b38e3)


Functionality added, here's the preview: 
![Functionality_done_onto_commit](https://github.com/microsoft/terminal/assets/15957528/79e81d54-3600-42d2-9cf6-8bc00ad828ac)


Will be working towards pull request. 

That looks great!

Presumably you figured it out, but the .cpp files are nested under the .h files (usually). Some of them are nested under the .idl's or .xaml's. Honestly, I don't know why VS chooses to do it that way 🤷 I've honestly only ever used the "Go to files" shortcut (which I think is sound to <kbd>ctrl+shift+t</kbd>) in VS. **Way** easier than trying to navigate the project structure. Just type bits of the file name and go. But then again, I'm more of a Sublime / VsCode user than a VS one - I just use big VS for building and debugging 😆 
@zadjii-msft 

![image](https://github.com/microsoft/terminal/assets/15957528/879f5a87-d458-456f-876d-687bd1d9617a)

What do you mean with TerminalApp? The code files named TerminalApp? Like TerminalApp.h, TerminalApp.cs 
Or files in the TerminalApp Project inside the VS Solution?
This one, see below
![image](https://github.com/microsoft/terminal/assets/15957528/4b850dcd-efb1-47d2-897b-6ba7c7e89218)



@zadjii-msft 

!! Making sure you notice it needs a different Glyph, currently uses the Duplicate glyph. 
I assume you have like an artist for that?
Ah yea - those are probably a little out of date. But yea `TerminalApp` in that context means "The `TerminalApp` project". Which these days is probably more accurately "anything that uses C++/WinRT".

I'd honestly just use one of the following two icons from the built-in [Segoe Fluent Icons](https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font)

Glyph | Unicode point | Description
-- | -- | --
![image](https://github.com/microsoft/terminal/assets/18356694/df036f97-0996-4090-a003-f2adf2ad42de) | e8a7 | OpenInNewWindow
![image](https://github.com/microsoft/terminal/assets/18356694/c1e1a82d-48ab-4e11-b6b5-5c3810270d57) | e78b | NewWindow

`OpenInNewWindow` looks good to me. 

Fix patch:
diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw
index e670f5a5d2f..e33bc405dd8 100644
--- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw
+++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw
@@ -827,4 +827,10 @@
     <value>Reset tab color</value>
     <comment>Text used to identify the reset button</comment>
   </data>
+  <data name="MoveTabToNewWindowText" xml:space="preserve">
+    <value>Move Tab to New Window</value>
+  </data>
+  <data name="MoveTabToNewWindowToolTip" xml:space="preserve">
+    <value>Moves tab to a new window </value>
+  </data>
 </root>
\ No newline at end of file
diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp
index 2e3ea91fe7c..f1ad6671b92 100644
--- a/src/cascadia/TerminalApp/TabManagement.cpp
+++ b/src/cascadia/TerminalApp/TabManagement.cpp
@@ -188,6 +188,18 @@ namespace winrt::TerminalApp::implementation
             }
         });
 
+        newTabImpl->MoveTabToNewWindowRequested([weakTab, weakThis{ get_weak() }]() {
+            auto page{ weakThis.get() };
+            auto tab{ weakTab.get() };
+
+            if (page && tab)
+            {
+                MoveTabArgs args{ hstring{ L"new" }, MoveTabDirection::Forward };
+                page->_SetFocusedTab(*tab);
+                page->_MoveTab(args);
+            }
+        });
+
         newTabImpl->ExportTabRequested([weakTab, weakThis{ get_weak() }]() {
             auto page{ weakThis.get() };
             auto tab{ weakTab.get() };
diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp
index 28f9152794b..39a7f4a93fd 100644
--- a/src/cascadia/TerminalApp/TerminalTab.cpp
+++ b/src/cascadia/TerminalApp/TerminalTab.cpp
@@ -1336,6 +1336,28 @@ namespace winrt::TerminalApp::implementation
             Automation::AutomationProperties::SetHelpText(splitTabMenuItem, splitTabToolTip);
         }
 
+        Controls::MenuFlyoutItem moveTabToNewWindowMenuItem;
+        {
+            // "Move Tab to New Window Tab"
+            Controls::FontIcon moveTabToNewWindowTabSymbol;
+            moveTabToNewWindowTabSymbol.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
+            moveTabToNewWindowTabSymbol.Glyph(L"\xE8A7");
+
+            moveTabToNewWindowMenuItem.Click([weakThis](auto&&, auto&&) {
+                if (auto tab{ weakThis.get() })
+                {
+                    tab->_MoveTabToNewWindowRequestedHandlers();
+                }
+            });
+            moveTabToNewWindowMenuItem.Text(RS_(L"MoveTabToNewWindowText"));
+            moveTabToNewWindowMenuItem.Icon(moveTabToNewWindowTabSymbol);
+
+            const auto moveTabToNewWindowToolTip = RS_(L"MoveTabToNewWindowToolTip");
+
+            WUX::Controls::ToolTipService::SetToolTip(moveTabToNewWindowMenuItem, box_value(moveTabToNewWindowToolTip));
+            Automation::AutomationProperties::SetHelpText(moveTabToNewWindowMenuItem, moveTabToNewWindowToolTip);
+        }
+
         Controls::MenuFlyoutItem closePaneMenuItem = _closePaneMenuItem;
         {
             // "Close Pane"
@@ -1404,7 +1426,7 @@ namespace winrt::TerminalApp::implementation
         contextMenuFlyout.Items().Append(renameTabMenuItem);
         contextMenuFlyout.Items().Append(duplicateTabMenuItem);
         contextMenuFlyout.Items().Append(splitTabMenuItem);
-
+        contextMenuFlyout.Items().Append(moveTabToNewWindowMenuItem);
         contextMenuFlyout.Items().Append(exportTabMenuItem);
         contextMenuFlyout.Items().Append(findMenuItem);
         contextMenuFlyout.Items().Append(menuSeparator);
diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h
index a4cc9aa8eca..e2a225e2c63 100644
--- a/src/cascadia/TerminalApp/TerminalTab.h
+++ b/src/cascadia/TerminalApp/TerminalTab.h
@@ -100,6 +100,7 @@ namespace winrt::TerminalApp::implementation
         WINRT_CALLBACK(TabRaiseVisualBell, winrt::delegate<>);
         WINRT_CALLBACK(DuplicateRequested, winrt::delegate<>);
         WINRT_CALLBACK(SplitTabRequested, winrt::delegate<>);
+        WINRT_CALLBACK(MoveTabToNewWindowRequested, winrt::delegate<>);
         WINRT_CALLBACK(FindRequested, winrt::delegate<>);
         WINRT_CALLBACK(ExportTabRequested, winrt::delegate<>);
         WINRT_CALLBACK(ColorPickerRequested, winrt::delegate<>);


Test patch: