mirror of
https://github.com/microsoft/terminal.git
synced 2026-07-08 18:16:28 +00:00
move startup actions to the window itself, rather than being parsed in AppLogic on startup
This commit is contained in:
@@ -228,27 +228,6 @@ namespace winrt::TerminalApp::implementation
|
||||
_warnings.push_back(newSettings.Warnings().GetAt(i));
|
||||
}
|
||||
|
||||
_hasSettingsStartupActions = false;
|
||||
const auto startupActions = newSettings.WindowSettingsDefaults().StartupActions();
|
||||
if (!startupActions.empty())
|
||||
{
|
||||
_settingsAppArgs.FullResetState();
|
||||
|
||||
ExecuteCommandlineArgs args{ newSettings.WindowSettingsDefaults().StartupActions() };
|
||||
auto result = _settingsAppArgs.ParseArgs(args);
|
||||
if (result == 0)
|
||||
{
|
||||
_hasSettingsStartupActions = true;
|
||||
|
||||
// Validation also injects new-tab command if implicit new-tab was provided.
|
||||
_settingsAppArgs.ValidateStartupCommands();
|
||||
}
|
||||
else
|
||||
{
|
||||
_warnings.push_back(SettingsLoadWarnings::FailedToParseStartupActions);
|
||||
}
|
||||
}
|
||||
|
||||
_settings = std::move(newSettings);
|
||||
|
||||
hr = _warnings.empty() ? S_OK : S_FALSE;
|
||||
@@ -267,11 +246,6 @@ namespace winrt::TerminalApp::implementation
|
||||
return hr;
|
||||
}
|
||||
|
||||
bool AppLogic::HasSettingsStartupActions() const noexcept
|
||||
{
|
||||
return _hasSettingsStartupActions;
|
||||
}
|
||||
|
||||
// Call this function after loading your _settings.
|
||||
// It handles any CPU intensive settings updates (like updating the Jumplist)
|
||||
// which should thus only occur if the settings file actually changed.
|
||||
@@ -494,13 +468,36 @@ namespace winrt::TerminalApp::implementation
|
||||
return _settings.GlobalSettings().ActionMap().GlobalHotkeys();
|
||||
}
|
||||
|
||||
TerminalApp::TerminalWindow AppLogic::CreateNewWindow()
|
||||
TerminalApp::TerminalWindow AppLogic::CreateNewWindow(const winrt::hstring& windowName)
|
||||
{
|
||||
auto warnings{ winrt::multi_threaded_vector<SettingsLoadWarnings>() };
|
||||
for (auto&& warn : _warnings)
|
||||
{
|
||||
warnings.Append(warn);
|
||||
}
|
||||
|
||||
// Look up the StartupActions for _this_ window's settings (which
|
||||
// may differ from the defaults if the user has per-window-name
|
||||
// overrides). Parse them here, per-window, rather than once globally,
|
||||
// so that each window can have its own startupActions.
|
||||
::TerminalApp::AppCommandlineArgs settingsAppArgs;
|
||||
auto hasSettingsStartupActions = false;
|
||||
const auto startupActions = _settings.WindowSettings(windowName).StartupActions();
|
||||
if (!startupActions.empty())
|
||||
{
|
||||
ExecuteCommandlineArgs cmdlineArgs{ startupActions };
|
||||
if (settingsAppArgs.ParseArgs(cmdlineArgs) == 0)
|
||||
{
|
||||
hasSettingsStartupActions = true;
|
||||
// Validation also injects new-tab command if implicit new-tab was provided.
|
||||
settingsAppArgs.ValidateStartupCommands();
|
||||
}
|
||||
else
|
||||
{
|
||||
warnings.Append(SettingsLoadWarnings::FailedToParseStartupActions);
|
||||
}
|
||||
}
|
||||
|
||||
auto ev = winrt::make_self<SettingsLoadEventArgs>(false,
|
||||
_settingsLoadedResult,
|
||||
_settingsLoadExceptionText,
|
||||
@@ -509,9 +506,9 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
auto window = winrt::make_self<implementation::TerminalWindow>(*ev, _contentManager);
|
||||
|
||||
if (_hasSettingsStartupActions)
|
||||
if (hasSettingsStartupActions)
|
||||
{
|
||||
window->SetSettingsStartupArgs(_settingsAppArgs.GetStartupActions());
|
||||
window->SetSettingsStartupArgs(settingsAppArgs.GetStartupActions());
|
||||
}
|
||||
return *window;
|
||||
}
|
||||
|
||||
@@ -39,13 +39,11 @@ namespace winrt::TerminalApp::implementation
|
||||
void ReloadSettingsThrottled();
|
||||
void NotifyRootInitialized();
|
||||
|
||||
bool HasSettingsStartupActions() const noexcept;
|
||||
|
||||
Microsoft::Terminal::Settings::Model::CascadiaSettings Settings() const noexcept;
|
||||
|
||||
Windows::Foundation::Collections::IMapView<Microsoft::Terminal::Control::KeyChord, Microsoft::Terminal::Settings::Model::Command> GlobalHotkeys();
|
||||
|
||||
TerminalApp::TerminalWindow CreateNewWindow();
|
||||
TerminalApp::TerminalWindow CreateNewWindow(const winrt::hstring& windowName);
|
||||
|
||||
winrt::TerminalApp::ContentManager ContentManager();
|
||||
|
||||
@@ -62,9 +60,6 @@ namespace winrt::TerminalApp::implementation
|
||||
HRESULT _settingsLoadedResult = S_OK;
|
||||
bool _loadedInitialSettings = false;
|
||||
|
||||
bool _hasSettingsStartupActions{ false };
|
||||
::TerminalApp::AppCommandlineArgs _settingsAppArgs;
|
||||
|
||||
std::shared_ptr<ThrottledFunc<>> _reloadSettings;
|
||||
|
||||
std::vector<Microsoft::Terminal::Settings::Model::SettingsLoadWarnings> _warnings{};
|
||||
|
||||
@@ -22,13 +22,11 @@ namespace TerminalApp
|
||||
|
||||
ContentManager ContentManager { get; };
|
||||
|
||||
Boolean HasSettingsStartupActions();
|
||||
|
||||
void ReloadSettings();
|
||||
void ReloadSettingsThrottled();
|
||||
Microsoft.Terminal.Settings.Model.CascadiaSettings Settings { get; };
|
||||
|
||||
TerminalWindow CreateNewWindow();
|
||||
TerminalWindow CreateNewWindow(String windowName);
|
||||
|
||||
IMapView<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();
|
||||
|
||||
|
||||
@@ -130,7 +130,10 @@ void AppHost::_HandleCommandlineArgs(const winrt::TerminalApp::WindowRequestedAr
|
||||
{
|
||||
// We did want to make a window, so let's instantiate it here.
|
||||
// We don't have XAML yet, but we do have other stuff.
|
||||
_windowLogic = _appLogic.CreateNewWindow();
|
||||
//
|
||||
// Pass the WindowName along to CreateNewWindow, so that the AppLogic can
|
||||
// pick up per-window startupActions (rather than just the defaults).
|
||||
_windowLogic = _appLogic.CreateNewWindow(windowArgs.WindowName());
|
||||
|
||||
if (const auto content = windowArgs.Content(); !content.empty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user