diff options
author | Martin Duffy <martin.duffy@kitware.com> | 2022-05-12 20:43:15 (GMT) |
---|---|---|
committer | Martin Duffy <martin.duffy@kitware.com> | 2022-05-12 20:43:15 (GMT) |
commit | 2defe9ff95016fd72e9a16b4a8fa8b8d0ec5a45f (patch) | |
tree | 5cf1d6aaf994622b6e21921dd7e027984b8ff922 /Source/CursesDialog | |
parent | e1c85e29f4a09b45fa3cb29e4f225e68c32d9932 (diff) | |
download | CMake-2defe9ff95016fd72e9a16b4a8fa8b8d0ec5a45f.zip CMake-2defe9ff95016fd72e9a16b4a8fa8b8d0ec5a45f.tar.gz CMake-2defe9ff95016fd72e9a16b4a8fa8b8d0ec5a45f.tar.bz2 |
ccmake: Fix crash when deleting all cache entries
Prevents crash when deleting all cache entries.
Additionally, if advanced entries are hidden, no longer show the first advanced
entry when deleting all visible entries.
Fixes: #23499
Diffstat (limited to 'Source/CursesDialog')
-rw-r--r-- | Source/CursesDialog/cmCursesMainForm.cxx | 19 | ||||
-rw-r--r-- | Source/CursesDialog/cmCursesMainForm.h | 1 |
2 files changed, 11 insertions, 9 deletions
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index cd0a4bd..3e254e0 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -93,13 +93,13 @@ void cmCursesMainForm::InitializeUI() int entrywidth = this->InitialWidth - 35; - if (count == 0) { - // If cache is empty, display a label saying so and a - // dummy entry widget (does not respond to input) - cmCursesCacheEntryComposite comp("EMPTY CACHE", 30, 30); - comp.Entry = cm::make_unique<cmCursesDummyWidget>(1, 1, 1, 1); - newEntries.emplace_back(std::move(comp)); - } else { + // Add a label to display when cache is empty + // dummy entry widget (does not respond to input) + cmCursesCacheEntryComposite comp("EMPTY CACHE", 30, 30); + comp.Entry = cm::make_unique<cmCursesDummyWidget>(1, 1, 1, 1); + newEntries.emplace_back(std::move(comp)); + + if (count > 0) { // Create the composites. // First add entries which are new @@ -190,7 +190,8 @@ void cmCursesMainForm::RePost() this->Fields.push_back(entry.Entry->Field); } // if no cache entries there should still be one dummy field - if (this->Fields.empty()) { + this->IsEmpty = this->Fields.empty(); + if (this->IsEmpty) { const auto& front = this->Entries.front(); this->Fields.push_back(front.Label->Field); this->Fields.push_back(front.IsNewLabel->Field); @@ -869,7 +870,7 @@ void cmCursesMainForm::HandleInput() } } // delete cache entry - else if (key == 'd' && this->NumberOfVisibleEntries) { + else if (key == 'd' && this->NumberOfVisibleEntries && !this->IsEmpty) { this->OkToGenerate = false; FIELD* cur = current_field(this->Form); size_t findex = field_index(cur); diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index 9eb6418..fb44a45 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -161,6 +161,7 @@ protected: bool OkToGenerate = false; // Number of pages displayed int NumberOfPages = 0; + bool IsEmpty = false; int InitialWidth; std::unique_ptr<cmake> CMakeInstance; |