Skip to content

Commit

Permalink
save this for later, we should only need ot look it up once
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 9, 2023
1 parent 434abc2 commit 1b59eb9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
38 changes: 25 additions & 13 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,19 @@ namespace winrt::TerminalApp::implementation
{
// Pass commandline args into the TerminalPage. If we were supposed to
// load from a persisted layout, do that instead.
auto foundLayout = false;

// layout will only ever be non-null if there were >0 tabs persisted in
// .TabLayout(). We can re-evaluate that as a part of TODO: GH#12633
if (const auto& layout = LoadPersistedLayout())
{
if (layout.TabLayout().Size() > 0)
std::vector<Settings::Model::ActionAndArgs> actions;
for (const auto& a : layout.TabLayout())
{
std::vector<Settings::Model::ActionAndArgs> actions;
for (const auto& a : layout.TabLayout())
{
actions.emplace_back(a);
}
_root->SetStartupActions(actions);
foundLayout = true;
actions.emplace_back(a);
}
_root->SetStartupActions(actions);
}
if (!foundLayout)
else
{
_root->SetStartupActions(_appArgs.GetStartupActions());
}
Expand Down Expand Up @@ -1095,6 +1093,7 @@ namespace winrt::TerminalApp::implementation
void TerminalWindow::SetPersistedLayoutIdx(const uint32_t idx)
{
_loadFromPersistedLayoutIdx = idx;
_cachedLayout = std::nullopt;
}

// Method Description;
Expand All @@ -1109,18 +1108,31 @@ namespace winrt::TerminalApp::implementation
return _settings.GlobalSettings().ShouldUsePersistedLayout() ? _loadFromPersistedLayoutIdx : std::nullopt;
}

WindowLayout TerminalWindow::LoadPersistedLayout() const
WindowLayout TerminalWindow::LoadPersistedLayout()
{
if (_cachedLayout.has_value())
{
return *_cachedLayout;
}

if (const auto idx = LoadPersistedLayoutIdx())
{
const auto i = idx.value();
const auto layouts = ApplicationState::SharedInstance().PersistedWindowLayouts();
if (layouts && layouts.Size() > i)
{
return layouts.GetAt(i);
auto layout = layouts.GetAt(i);

// TODO: GH#12633: Right now, we're manually making sure that we
// have at least one tab to restore. If we ever want to come
// back and make it so that you can persist position and size,
// but not the tabs themselves, we can revisit this assumption.
_cachedLayout = (layout.TabLayout().Size() > 0) ? layout : nullptr;
return *_cachedLayout;
}
}
return nullptr;
_cachedLayout = nullptr;
return *_cachedLayout;
}

void TerminalWindow::IdentifyWindow()
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace winrt::TerminalApp::implementation
void RenameFailed();

std::optional<uint32_t> LoadPersistedLayoutIdx() const;
winrt::Microsoft::Terminal::Settings::Model::WindowLayout LoadPersistedLayout() const;
winrt::Microsoft::Terminal::Settings::Model::WindowLayout LoadPersistedLayout();

void SetPersistedLayoutIdx(const uint32_t idx);
void SetNumberOfOpenWindows(const uint64_t num);
Expand Down Expand Up @@ -155,6 +155,7 @@ namespace winrt::TerminalApp::implementation
uint64_t _WindowId{ 0 };

std::optional<uint32_t> _loadFromPersistedLayoutIdx{};
std::optional<winrt::Microsoft::Terminal::Settings::Model::WindowLayout> _cachedLayout{ std::nullopt };

Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr };
TerminalApp::SettingsLoadEventArgs _initialLoadResult{ nullptr };
Expand Down

0 comments on commit 1b59eb9

Please sign in to comment.