diff options
author | Tushar Maheshwari <tushar27192@gmail.com> | 2019-09-21 14:17:23 (GMT) |
---|---|---|
committer | Tushar Maheshwari <tushar27192@gmail.com> | 2019-09-27 11:48:16 (GMT) |
commit | 0833486d62e8ed3ae9f0219f9924c4e78d74f781 (patch) | |
tree | 78a5a7e62c1e23f9514b1c3228007913d533950c /Source/CursesDialog/cmCursesStringWidget.cxx | |
parent | bc71b253cb372cc6c0ae50406a11b81fe4259559 (diff) | |
download | CMake-0833486d62e8ed3ae9f0219f9924c4e78d74f781.zip CMake-0833486d62e8ed3ae9f0219f9924c4e78d74f781.tar.gz CMake-0833486d62e8ed3ae9f0219f9924c4e78d74f781.tar.bz2 |
cmCursesStringWidget: remove manual delete
- Relpace `char*` operations with `std::string`
Diffstat (limited to 'Source/CursesDialog/cmCursesStringWidget.cxx')
-rw-r--r-- | Source/CursesDialog/cmCursesStringWidget.cxx | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx index 3fc1858..d3a05e8 100644 --- a/Source/CursesDialog/cmCursesStringWidget.cxx +++ b/Source/CursesDialog/cmCursesStringWidget.cxx @@ -9,7 +9,6 @@ #include "cmStateTypes.h" #include <cstdio> -#include <cstring> inline int ctrl(int z) { @@ -35,13 +34,13 @@ void cmCursesStringWidget::OnTab(cmCursesMainForm* /*unused*/, void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) { - FORM* form = fm->GetForm(); if (this->InEdit) { cmCursesForm::LogMessage("String widget leaving edit."); this->InEdit = false; fm->PrintKeys(); - delete[] this->OriginalString; + this->OriginalString.clear(); // trick to force forms to update the field buffer + FORM* form = fm->GetForm(); form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); this->Done = true; @@ -49,9 +48,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) cmCursesForm::LogMessage("String widget entering edit."); this->InEdit = true; fm->PrintKeys(); - char* buf = field_buffer(this->Field, 0); - this->OriginalString = new char[strlen(buf) + 1]; - strcpy(this->OriginalString, buf); + this->OriginalString = field_buffer(this->Field, 0); } } @@ -75,7 +72,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, return false; } - this->OriginalString = nullptr; + this->OriginalString.clear(); this->Done = false; char debugMessage[128]; @@ -113,7 +110,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') || key == KEY_PPAGE || key == ctrl('u')) { this->InEdit = false; - delete[] this->OriginalString; + this->OriginalString.clear(); // trick to force forms to update the field buffer form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); @@ -125,7 +122,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, this->InEdit = false; fm->PrintKeys(); this->SetString(this->OriginalString); - delete[] this->OriginalString; + this->OriginalString.clear(); touchwin(w); wrefresh(w); return true; @@ -188,23 +185,18 @@ bool cmCursesStringWidget::PrintKeys() } if (this->InEdit) { char fmt_s[] = "%s"; - char firstLine[512]; // Clean the toolbar - memset(firstLine, ' ', sizeof(firstLine)); - firstLine[511] = '\0'; curses_move(y - 4, 0); - printw(fmt_s, firstLine); - curses_move(y - 3, 0); - printw(fmt_s, firstLine); - curses_move(y - 2, 0); - printw(fmt_s, firstLine); - curses_move(y - 1, 0); - printw(fmt_s, firstLine); - + clrtoeol(); curses_move(y - 3, 0); printw(fmt_s, "Editing option, press [enter] to confirm"); + clrtoeol(); curses_move(y - 2, 0); printw(fmt_s, " press [esc] to cancel"); + clrtoeol(); + curses_move(y - 1, 0); + clrtoeol(); + return true; } return false; |