summaryrefslogtreecommitdiffstats
path: root/Source/CursesDialog
diff options
context:
space:
mode:
authorTushar Maheshwari <tushar27192@gmail.com>2019-09-21 14:17:23 (GMT)
committerTushar Maheshwari <tushar27192@gmail.com>2019-09-27 11:48:16 (GMT)
commit0833486d62e8ed3ae9f0219f9924c4e78d74f781 (patch)
tree78a5a7e62c1e23f9514b1c3228007913d533950c /Source/CursesDialog
parentbc71b253cb372cc6c0ae50406a11b81fe4259559 (diff)
downloadCMake-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')
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx32
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.h5
2 files changed, 13 insertions, 24 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;
diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h
index 021515b..a41f0e8 100644
--- a/Source/CursesDialog/cmCursesStringWidget.h
+++ b/Source/CursesDialog/cmCursesStringWidget.h
@@ -23,9 +23,6 @@ class cmCursesStringWidget : public cmCursesWidget
public:
cmCursesStringWidget(int width, int height, int left, int top);
- cmCursesStringWidget(cmCursesStringWidget const&) = delete;
- cmCursesStringWidget& operator=(cmCursesStringWidget const&) = delete;
-
/**
* Handle user input. Called by the container of this widget
* when this widget has focus. Returns true if the input was
@@ -65,7 +62,7 @@ public:
protected:
// true if the widget is in edit mode
bool InEdit;
- char* OriginalString;
+ std::string OriginalString;
bool Done;
};