summaryrefslogtreecommitdiffstats
path: root/ScreensPanel.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2022-12-13 00:34:57 +0100
committercgzones <cgzones@googlemail.com>2022-12-16 16:30:18 +0100
commitb4a4932f1fc53d75d88d8f54906acadfb3651a97 (patch)
treefc412637e1337738a749ce556c2e5dacb229bdca /ScreensPanel.c
parent2ca75625ee5c2ac0ef1571e6918d7c94f3aa011c (diff)
ScreenPanel: handle quitting panel while renaming
During renaming the ScreenPanel takes ownership of the text value of the screen entries ListItem (via its saved member) and replaces the pointer in the ListItem with a pointer to the ScreenPanel's static text buffer. Restore the ownership, similar to how it's done on ESC. Fixes: #1147
Diffstat (limited to 'ScreensPanel.c')
-rw-r--r--ScreensPanel.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ScreensPanel.c b/ScreensPanel.c
index 1fd4ae56..cb664ac4 100644
--- a/ScreensPanel.c
+++ b/ScreensPanel.c
@@ -55,6 +55,10 @@ static void ScreensPanel_delete(Object* object) {
item->ss = NULL;
}
+ /* during renaming the ListItem's value points to our static buffer */
+ if (this->renamingItem)
+ this->renamingItem->value = this->saved;
+
Panel_done(super);
free(this);
}
@@ -89,9 +93,10 @@ static HandlerResult ScreensPanel_eventHandlerRenaming(Panel* super, int ch) {
ListItem* item = (ListItem*) Panel_getSelected(super);
if (!item)
break;
+ assert(item == this->renamingItem);
free(this->saved);
item->value = xStrdup(this->buffer);
- this->renaming = false;
+ this->renamingItem = NULL;
super->cursorOn = false;
Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
ScreensPanel_update(super);
@@ -102,8 +107,9 @@ static HandlerResult ScreensPanel_eventHandlerRenaming(Panel* super, int ch) {
ListItem* item = (ListItem*) Panel_getSelected(super);
if (!item)
break;
+ assert(item == this->renamingItem);
item->value = this->saved;
- this->renaming = false;
+ this->renamingItem = NULL;
super->cursorOn = false;
Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
break;
@@ -119,7 +125,7 @@ static void startRenaming(Panel* super) {
ListItem* item = (ListItem*) Panel_getSelected(super);
if (item == NULL)
return;
- this->renaming = true;
+ this->renamingItem = item;
super->cursorOn = true;
char* name = item->value;
this->saved = name;
@@ -279,7 +285,7 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
static HandlerResult ScreensPanel_eventHandler(Panel* super, int ch) {
ScreensPanel* const this = (ScreensPanel*) super;
- if (this->renaming) {
+ if (this->renamingItem) {
return ScreensPanel_eventHandlerRenaming(super, ch);
} else {
return ScreensPanel_eventHandlerNormal(super, ch);
@@ -304,7 +310,7 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
this->settings = settings;
this->columns = ColumnsPanel_new(settings->screens[0], columns, &(settings->changed));
this->moving = false;
- this->renaming = false;
+ this->renamingItem = NULL;
super->cursorOn = false;
this->cursor = 0;
Panel_setHeader(super, "Screens");

© 2014-2024 Faster IT GmbH | imprint | privacy policy