GUI: Add ListWidget commands: single click and edit start

These commands allow greater control over editable ListWidgets, although
the save dialog's list is currently the only one.

kListItemSingleClickedCmd allows clients to respond to selection changes
based on the method used (mouse vs keyboard) and allows responding to
clicking on an already selected item. In the next commit, this will fix
multiple save issues.

kListItemEditModeStartedCmd allows clients to initialize edit mode
consistently. The save dialog has been doing custom initialization after
calling startEditMode, but this is incorrect because ListWidget calls
startEditMode in response to Enter, so the initialization is skipped.
This commit is contained in:
sluicebox 2024-05-15 08:10:50 -07:00
parent 7fb6052aa7
commit 4308849811
2 changed files with 9 additions and 2 deletions

View File

@ -262,11 +262,15 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
sendCommand(kListSelectionChangedCmd, _selectedItem);
}
// Notify clients if an item was clicked
if (newSelectedItem >= 0) {
sendCommand(kListItemSingleClickedCmd, _selectedItem);
}
// TODO: Determine where inside the string the user clicked and place the
// caret accordingly.
// See _editScrollOffset and EditTextWidget::handleMouseDown.
markAsDirty();
}
void ListWidget::handleMouseUp(int x, int y, int button, int clickCount) {
@ -685,6 +689,7 @@ void ListWidget::startEditMode() {
_editColor = ThemeEngine::kFontColorNormal;
markAsDirty();
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
sendCommand(kListItemEditModeStartedCmd, _selectedItem);
}
}

View File

@ -39,9 +39,11 @@ enum NumberingMode {
/// Some special commands
enum {
kListItemDoubleClickedCmd = 'LIdb', ///< double click on item - 'data' will be item index
kListItemSingleClickedCmd = 'LIsc', ///< single click on item (sent on mouse down) - 'data' will be item index
kListItemDoubleClickedCmd = 'LIdc', ///< double click on item (sent on mouse up) - 'data' will be item index
kListItemActivatedCmd = 'LIac', ///< item activated by return/enter - 'data' will be item index
kListItemRemovalRequestCmd = 'LIrm', ///< request to remove the item with the delete/backspace keys - 'data' will be item index
kListItemEditModeStartedCmd = 'LIes', ///< edit mode started - 'data' will be item index
kListSelectionChangedCmd = 'Lsch' ///< selection changed - 'data' will be item index
};