Skip to content

Conversation

@mg-dev25
Copy link
Contributor

@mg-dev25 mg-dev25 commented Dec 4, 2025

Add --select-row Option for List Dialog Pre-selection

Summary

Adds --select-row=ROW[,ROW...] option to list dialogs for pre-selecting rows by their 1-based index. Scripts can now restore previous user selections when reopening dialogs.

Problem

List dialogs lack row pre-selection. Users cannot:

  • Restore previous choices when reopening dialogs
  • Set default selections in configuration interfaces
  • Highlight specific items on dialog open

Checklist/radiolist support pre-selection via TRUE/FALSE values, but regular lists do not.

Solution

New option --select-row=ROW[,ROW...]:

  • 1-based row numbers for readability
  • Comma-separated values for multiple selections (with --multiple)
  • Auto-scrolls to first selected row
  • Blocks select-action during initial selection

Examples

Single selection:

yad --list --column="Items" --select-row=3 \
    "Apple" "Banana" "Cherry" "Date"

Multiple selection:

yad --list --column="Items" --select-row=1,3,5 --multiple \
    "Apple" "Banana" "Cherry" "Date" "Elderberry"

Restore previous choice:

LAST=$(cat /tmp/last.txt 2>/dev/null || echo "1")
RESULT=$(yad --list --column="Option" --select-row=$LAST \
    "Option A" "Option B" "Option C")
echo "$RESULT" | grep -n . | cut -d: -f1 > /tmp/last.txt

Changes

File Change
src/yad.h Add select_row field to YadListData
src/option.c Register option, initialize to NULL
src/list.c Selection logic after fill_data()

Implementation

Option registration (option.c):

  • GOption entry with G_OPTION_ARG_STRING type

Selection logic (list.c):

  • Parse comma-separated row numbers
  • Convert 1-based to 0-based GTK tree paths
  • Validate row existence before selecting
  • Handle single vs multiple selection modes
  • Block select-action handler during setup
  • Scroll to first selected row

Safety:

  • Skip invalid rows (0, negative, out of range)
  • Respect --no-selection option
  • Works with tree mode

Testing

Test Command Result
Single --select-row=2 Row 2 highlighted
Multiple --select-row=1,3,5 --multiple Rows 1,3,5 highlighted
Invalid --select-row=999 No selection
Mixed --select-row=1,999,3 Rows 1,3 selected
Disabled --select-row=2 --no-selection No selection

Backward Compatibility

Fully compatible. Without --select-row, behavior unchanged.

Related Issues

Adds --select-row=ROW[,ROW...] option to list dialog that allows
pre-selecting one or more rows by their 1-based index.

Features:
- Single row selection: --select-row=3 selects the third row
- Multiple row selection: --select-row=1,3,5 with --multiple flag
- Automatically scrolls to first selected row
- Works with both single and multi-selection modes
- Blocks select-action callback during initial selection

Resolves: v1cont#47, v1cont#131 (upstream)
@mg-dev25 mg-dev25 closed this Dec 7, 2025
@mg-dev25 mg-dev25 deleted the feat/select-row branch December 7, 2025 10:52
@mg-dev25 mg-dev25 restored the feat/select-row branch December 7, 2025 23:15
@mg-dev25 mg-dev25 reopened this Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant