mirror of
https://github.com/reactos/CMake.git
synced 2024-11-24 12:09:48 +00:00
cmCursesStringWidget: remove manual delete
- Relpace `char*` operations with `std::string`
This commit is contained in:
parent
bc71b253cb
commit
0833486d62
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user