Skip to content

Commit 86914bd

Browse files
committed
Merge branch 'dev/migrie/fhl/non-terminal-panes-2023' into dev/migrie/fhl/scratchpad-pane
2 parents a23c1a2 + e0b003a commit 86914bd

23 files changed

+926
-339
lines changed

doc/specs/#11000 - Marks/Shell-Integration-Marks.md

+499
Large diffs are not rendered by default.
201 KB
Loading
Loading

src/cascadia/TerminalApp/AppActionHandlers.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,16 @@ namespace winrt::TerminalApp::implementation
10221022
args.Handled(true);
10231023
}
10241024

1025+
void TerminalPage::_HandleDisplayWorkingDirectory(const IInspectable& /*sender*/,
1026+
const ActionEventArgs& args)
1027+
{
1028+
if (_settings.GlobalSettings().DebugFeaturesEnabled())
1029+
{
1030+
ShowTerminalWorkingDirectory();
1031+
args.Handled(true);
1032+
}
1033+
}
1034+
10251035
void TerminalPage::_HandleSearchForText(const IInspectable& /*sender*/,
10261036
const ActionEventArgs& args)
10271037
{

src/cascadia/TerminalApp/Resources/en-US/Resources.resw

+6-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
</data>
217217
<data name="SearchWebText" xml:space="preserve">
218218
<value>Web Search</value>
219-
</data>
219+
</data>
220220
<data name="TabColorChoose" xml:space="preserve">
221221
<value>Color...</value>
222222
</data>
@@ -836,4 +836,8 @@
836836
<data name="MoveTabToNewWindowToolTip" xml:space="preserve">
837837
<value>Moves tab to a new window </value>
838838
</data>
839-
</root>
839+
<data name="RunAsAdminFlyout.Text" xml:space="preserve">
840+
<value>Run as Administrator</value>
841+
<comment>This text is displayed on context menu for profile entries in add new tab button.</comment>
842+
</data>
843+
</root>

src/cascadia/TerminalApp/TerminalPage.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,15 @@ namespace winrt::TerminalApp::implementation
10571057
}
10581058
});
10591059

1060+
// Using the static method on the base class seems to do what we want in terms of placement.
1061+
WUX::Controls::Primitives::FlyoutBase::SetAttachedFlyout(profileMenuItem, _CreateRunAsAdminFlyout(profileIndex));
1062+
1063+
// Since we are not setting the ContextFlyout property of the item we have to handle the ContextRequested event
1064+
// and rely on the base class to show our menu.
1065+
profileMenuItem.ContextRequested([profileMenuItem](auto&&, auto&&) {
1066+
WUX::Controls::Primitives::FlyoutBase::ShowAttachedFlyout(profileMenuItem);
1067+
});
1068+
10601069
return profileMenuItem;
10611070
}
10621071

@@ -4113,6 +4122,33 @@ namespace winrt::TerminalApp::implementation
41134122
}
41144123
}
41154124

4125+
winrt::fire_and_forget TerminalPage::ShowTerminalWorkingDirectory()
4126+
{
4127+
auto weakThis{ get_weak() };
4128+
co_await wil::resume_foreground(Dispatcher());
4129+
if (auto page{ weakThis.get() })
4130+
{
4131+
// If we haven't ever loaded the TeachingTip, then do so now and
4132+
// create the toast for it.
4133+
if (page->_windowCwdToast == nullptr)
4134+
{
4135+
if (auto tip{ page->FindName(L"WindowCwdToast").try_as<MUX::Controls::TeachingTip>() })
4136+
{
4137+
page->_windowCwdToast = std::make_shared<Toast>(tip);
4138+
// Make sure to use the weak ref when setting up this
4139+
// callback.
4140+
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl });
4141+
}
4142+
}
4143+
_UpdateTeachingTipTheme(WindowCwdToast().try_as<winrt::Windows::UI::Xaml::FrameworkElement>());
4144+
4145+
if (page->_windowCwdToast != nullptr)
4146+
{
4147+
page->_windowCwdToast->Open();
4148+
}
4149+
}
4150+
}
4151+
41164152
// Method Description:
41174153
// - Called when the user hits the "Ok" button on the WindowRenamer TeachingTip.
41184154
// - Will raise an event that will bubble up to the monarch, asking if this
@@ -4940,4 +4976,42 @@ namespace winrt::TerminalApp::implementation
49404976
// _RemoveTab will make sure to null out the _stashed.draggedTab
49414977
_RemoveTab(*_stashed.draggedTab);
49424978
}
4979+
4980+
/// <summary>
4981+
/// Creates a sub flyout menu for profile items in the split button menu that when clicked will show a menu item for
4982+
/// Run as Administrator
4983+
/// </summary>
4984+
/// <param name="profileIndex">The index for the profileMenuItem</param>
4985+
/// <returns>MenuFlyout that will show when the context is request on a profileMenuItem</returns>
4986+
WUX::Controls::MenuFlyout TerminalPage::_CreateRunAsAdminFlyout(int profileIndex)
4987+
{
4988+
// Create the MenuFlyout and set its placement
4989+
WUX::Controls::MenuFlyout profileMenuItemFlyout{};
4990+
profileMenuItemFlyout.Placement(WUX::Controls::Primitives::FlyoutPlacementMode::BottomEdgeAlignedRight);
4991+
4992+
// Create the menu item and an icon to use in the menu
4993+
WUX::Controls::MenuFlyoutItem runAsAdminItem{};
4994+
WUX::Controls::FontIcon adminShieldIcon{};
4995+
4996+
adminShieldIcon.Glyph(L"\xEA18");
4997+
adminShieldIcon.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
4998+
4999+
runAsAdminItem.Icon(adminShieldIcon);
5000+
runAsAdminItem.Text(RS_(L"RunAsAdminFlyout/Text"));
5001+
5002+
// Click handler for the flyout item
5003+
runAsAdminItem.Click([profileIndex, weakThis{ get_weak() }](auto&&, auto&&) {
5004+
if (auto page{ weakThis.get() })
5005+
{
5006+
NewTerminalArgs args{ profileIndex };
5007+
args.Elevate(true);
5008+
page->_OpenNewTerminalViaDropdown(args);
5009+
}
5010+
});
5011+
5012+
profileMenuItemFlyout.Items().Append(runAsAdminItem);
5013+
5014+
return profileMenuItemFlyout;
5015+
}
5016+
49435017
}

src/cascadia/TerminalApp/TerminalPage.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ namespace winrt::TerminalApp::implementation
147147

148148
winrt::fire_and_forget IdentifyWindow();
149149
winrt::fire_and_forget RenameFailed();
150+
winrt::fire_and_forget ShowTerminalWorkingDirectory();
150151

151152
winrt::fire_and_forget ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions,
152153
const bool initial,
@@ -256,6 +257,7 @@ namespace winrt::TerminalApp::implementation
256257

257258
std::shared_ptr<Toast> _windowIdToast{ nullptr };
258259
std::shared_ptr<Toast> _windowRenameFailedToast{ nullptr };
260+
std::shared_ptr<Toast> _windowCwdToast{ nullptr };
259261

260262
winrt::Windows::UI::Xaml::Controls::TextBox::LayoutUpdated_revoker _renamerLayoutUpdatedRevoker;
261263
int _renamerLayoutCount{ 0 };
@@ -530,7 +532,7 @@ namespace winrt::TerminalApp::implementation
530532
void _ContextMenuOpened(const IInspectable& sender, const IInspectable& args);
531533
void _SelectionMenuOpened(const IInspectable& sender, const IInspectable& args);
532534
void _PopulateContextMenu(const IInspectable& sender, const bool withSelection);
533-
535+
winrt::Windows::UI::Xaml::Controls::MenuFlyout _CreateRunAsAdminFlyout(int profileIndex);
534536
#pragma region ActionHandlers
535537
// These are all defined in AppActionHandlers.cpp
536538
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);

src/cascadia/TerminalApp/TerminalPage.xaml

+6
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,11 @@
205205
Text="{x:Bind WindowProperties.WindowName, Mode=OneWay}" />
206206
</mux:TeachingTip.Content>
207207
</mux:TeachingTip>
208+
209+
<mux:TeachingTip x:Name="WindowCwdToast"
210+
x:Uid="WindowCwdToast"
211+
Title="{x:Bind WindowProperties.VirtualWorkingDirectory, Mode=OneWay}"
212+
x:Load="False"
213+
IsLightDismissEnabled="True" />
208214
</Grid>
209215
</Page>

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static constexpr std::string_view IdentifyWindowKey{ "identifyWindow" };
7272
static constexpr std::string_view IdentifyWindowsKey{ "identifyWindows" };
7373
static constexpr std::string_view RenameWindowKey{ "renameWindow" };
7474
static constexpr std::string_view OpenWindowRenamerKey{ "openWindowRenamer" };
75+
static constexpr std::string_view DisplayWorkingDirectoryKey{ "debugTerminalCwd" };
7576
static constexpr std::string_view SearchForTextKey{ "searchWeb" };
7677
static constexpr std::string_view GlobalSummonKey{ "globalSummon" };
7778
static constexpr std::string_view QuakeModeKey{ "quakeMode" };
@@ -405,6 +406,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
405406
{ ShortcutAction::IdentifyWindows, RS_(L"IdentifyWindowsCommandKey") },
406407
{ ShortcutAction::RenameWindow, RS_(L"ResetWindowNameCommandKey") },
407408
{ ShortcutAction::OpenWindowRenamer, RS_(L"OpenWindowRenamerCommandKey") },
409+
{ ShortcutAction::DisplayWorkingDirectory, RS_(L"DisplayWorkingDirectoryCommandKey") },
408410
{ ShortcutAction::GlobalSummon, MustGenerate },
409411
{ ShortcutAction::SearchForText, MustGenerate },
410412
{ ShortcutAction::QuakeMode, RS_(L"QuakeModeCommandKey") },

src/cascadia/TerminalSettingsModel/AllShortcutActions.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
ON_ALL_ACTIONS(IdentifyWindows) \
8686
ON_ALL_ACTIONS(RenameWindow) \
8787
ON_ALL_ACTIONS(OpenWindowRenamer) \
88+
ON_ALL_ACTIONS(DisplayWorkingDirectory) \
8889
ON_ALL_ACTIONS(SearchForText) \
8990
ON_ALL_ACTIONS(GlobalSummon) \
9091
ON_ALL_ACTIONS(QuakeMode) \

src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw

+3
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@
511511
<data name="OpenWindowRenamerCommandKey" xml:space="preserve">
512512
<value>Rename window...</value>
513513
</data>
514+
<data name="DisplayWorkingDirectoryCommandKey" xml:space="preserve">
515+
<value>Display Terminal's current working directory</value>
516+
</data>
514517
<data name="GlobalSummonCommandKey" xml:space="preserve">
515518
<value>Show/Hide the Terminal window</value>
516519
</data>

src/cascadia/WindowsTerminal/AppHost.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ winrt::fire_and_forget AppHost::_peasantNotifyActivateWindow()
962962
// - The window layout as a json string.
963963
winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> AppHost::_GetWindowLayoutAsync()
964964
{
965-
winrt::apartment_context peasant_thread;
966-
967965
winrt::hstring layoutJson = L"";
968966
// Use the main thread since we are accessing controls.
969967
co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher());
@@ -974,9 +972,6 @@ winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> AppHost::_GetWindowL
974972
}
975973
CATCH_LOG()
976974

977-
// go back to give the result to the peasant.
978-
co_await peasant_thread;
979-
980975
co_return layoutJson;
981976
}
982977

@@ -1052,9 +1047,6 @@ void AppHost::_DisplayWindowId(const winrt::Windows::Foundation::IInspectable& /
10521047
winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Foundation::IInspectable /*sender*/,
10531048
const winrt::TerminalApp::RenameWindowRequestedArgs args)
10541049
{
1055-
// Capture calling context.
1056-
winrt::apartment_context ui_thread;
1057-
10581050
// Switch to the BG thread - anything x-proc must happen on a BG thread
10591051
co_await winrt::resume_background();
10601052

@@ -1064,12 +1056,9 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou
10641056

10651057
_peasant.RequestRename(requestArgs);
10661058

1067-
// Switch back to the UI thread. Setting the WindowName needs to happen
1068-
// on the UI thread, because it'll raise a PropertyChanged event
1069-
co_await ui_thread;
1070-
10711059
if (requestArgs.Succeeded())
10721060
{
1061+
co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher());
10731062
_windowLogic.WindowName(args.ProposedName());
10741063
}
10751064
else

0 commit comments

Comments
 (0)