Skip to content

Commit

Permalink
Also save window name and runtime set tab color. Using the renamewind…
Browse files Browse the repository at this point in the history
…ow action instead of storing a separate `name` property because that proved more difficult to insert into the lifecycle correctly when the window/peasant was created than afterwards.
  • Loading branch information
Rosefield committed Sep 3, 2021
1 parent a66809d commit a93d3b1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ void AppCommandlineArgs::_resetStateToDefault()
_swapPaneDirection = FocusDirection::None;

_focusPaneTarget = -1;
_loadPersistedLayoutIdx = -1;

// DON'T clear _launchMode here! This will get called once for every
// subcommand, so we don't want `wt -F new-tab ; split-pane` clearing out
Expand Down
17 changes: 14 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ namespace winrt::TerminalApp::implementation
if (auto terminalTab = _GetTerminalTabImpl(tab))
{
auto tabActions = terminalTab->BuildStartupActions();
actions.insert(actions.end(), tabActions.begin(), tabActions.end());
actions.insert(actions.end(), std::make_move_iterator(tabActions.begin()), std::make_move_iterator(tabActions.end()));
}
else if (tab.try_as<SettingsTab>())
{
Expand All @@ -1234,7 +1234,7 @@ namespace winrt::TerminalApp::implementation
OpenSettingsArgs args{ SettingsTarget::SettingsUI };
action.Args(args);

actions.push_back(action);
actions.emplace_back(std::move(action));
}
}

Expand All @@ -1247,7 +1247,18 @@ namespace winrt::TerminalApp::implementation
SwitchToTabArgs switchToTabArgs{ idx.value() };
action.Args(switchToTabArgs);

actions.push_back(action);
actions.emplace_back(std::move(action));
}

// If the user set a custom name, save it
if (_WindowName != L"")
{
ActionAndArgs action;
action.Action(ShortcutAction::RenameWindow);
RenameWindowArgs args{ _WindowName };
action.Args(args);

actions.emplace_back(std::move(action));
}

WindowLayout layout{};
Expand Down
23 changes: 18 additions & 5 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,25 @@ namespace winrt::TerminalApp::implementation
// 1 for the child after the first split.
auto state = _rootPane->BuildStartupActions(0, 1);

ActionAndArgs newTabAction{};
newTabAction.Action(ShortcutAction::NewTab);
NewTabArgs newTabArgs{ state.firstPane->GetTerminalArgsForPane() };
newTabAction.Args(newTabArgs);
{
ActionAndArgs newTabAction{};
newTabAction.Action(ShortcutAction::NewTab);
NewTabArgs newTabArgs{ state.firstPane->GetTerminalArgsForPane() };
newTabAction.Args(newTabArgs);

state.args.emplace(state.args.begin(), std::move(newTabAction));
}

state.args.emplace(state.args.begin(), std::move(newTabAction));
if (_runtimeTabColor)
{
ActionAndArgs setColorAction{};
setColorAction.Action(ShortcutAction::SetTabColor);

SetTabColorArgs setColorArgs{ _runtimeTabColor.value() };
setColorAction.Args(setColorArgs);

state.args.emplace_back(std::move(setColorAction));
}

// If we only have one arg, we only have 1 pane so we don't need any
// special focus logic
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
struct SetTabColorArgs : public SetTabColorArgsT<SetTabColorArgs>
{
SetTabColorArgs() = default;
SetTabColorArgs(Windows::UI::Color tabColor) :
_TabColor{ tabColor } {}
ACTION_ARG(Windows::Foundation::IReference<Windows::UI::Color>, TabColor, nullptr);

static constexpr std::string_view ColorKey{ "color" };
Expand Down Expand Up @@ -1574,6 +1576,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
struct RenameWindowArgs : public RenameWindowArgsT<RenameWindowArgs>
{
RenameWindowArgs() = default;
RenameWindowArgs(winrt::hstring name) :
_Name{ name } {};
ACTION_ARG(winrt::hstring, Name);
static constexpr std::string_view NameKey{ "name" };

Expand Down Expand Up @@ -1763,9 +1767,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
BASIC_FACTORY(NewTabArgs);
BASIC_FACTORY(MoveFocusArgs);
BASIC_FACTORY(MovePaneArgs);
BASIC_FACTORY(SetTabColorArgs);
BASIC_FACTORY(SwapPaneArgs);
BASIC_FACTORY(SplitPaneArgs);
BASIC_FACTORY(SetColorSchemeArgs);
BASIC_FACTORY(RenameWindowArgs);
BASIC_FACTORY(ExecuteCommandlineArgs);
BASIC_FACTORY(CloseOtherTabsArgs);
BASIC_FACTORY(CloseTabsAfterArgs);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ namespace Microsoft.Terminal.Settings.Model

[default_interface] runtimeclass SetTabColorArgs : IActionArgs
{
SetTabColorArgs(Windows.UI.Color tabColor);
Windows.Foundation.IReference<Windows.UI.Color> TabColor { get; };
};

Expand Down Expand Up @@ -286,6 +287,7 @@ namespace Microsoft.Terminal.Settings.Model

[default_interface] runtimeclass RenameWindowArgs : IActionArgs
{
RenameWindowArgs(String name);
String Name { get; };
};

Expand Down

0 comments on commit a93d3b1

Please sign in to comment.