Documentation and launching much nicer now when using the yad interface.
This commit is contained in:
@@ -83,6 +83,82 @@ agm_menu() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Specialized game launcher menu with "Read Documentation" button
|
||||
# Usage: agm_game_menu "title" "backtitle" "text" option1 "description1" option2 "description2" ...
|
||||
# Returns: exit code 0=Launch, 1=Cancel, 2/3=Documentation (yad/dialog)
|
||||
agm_game_menu() {
|
||||
local title="$1"
|
||||
local backTitle="$2"
|
||||
local text="$3"
|
||||
shift 3
|
||||
|
||||
if [[ "$dialogType" == "yad" ]]; then
|
||||
# Use custom buttons to match dialog behavior (launch/doc/cancel)
|
||||
local yadList=""
|
||||
declare -A valueMap
|
||||
while [[ $# -gt 0 ]]; do
|
||||
local option="$1"
|
||||
local description="$2"
|
||||
valueMap["$description"]="$option"
|
||||
if [[ -n "$yadList" ]]; then
|
||||
yadList="$yadList\n"
|
||||
fi
|
||||
yadList="${yadList}${description}"
|
||||
shift 2
|
||||
done
|
||||
|
||||
local selectedDescription
|
||||
selectedDescription=$(echo -e "$yadList" | yad --list \
|
||||
--title="$title" \
|
||||
--text="$text" \
|
||||
--column="Option" \
|
||||
--no-headers \
|
||||
--selectable-labels \
|
||||
--search-column=1 \
|
||||
--height=400 \
|
||||
--width=600 \
|
||||
--button="Launch:0" \
|
||||
--button="Read Documentation:2" \
|
||||
--button="Cancel:1")
|
||||
local menuCode=$?
|
||||
|
||||
# Strip trailing pipes and return the mapped value
|
||||
if [[ -n "$selectedDescription" ]]; then
|
||||
selectedDescription="${selectedDescription%|}"
|
||||
echo "${valueMap["$selectedDescription"]}"
|
||||
fi
|
||||
return $menuCode
|
||||
else
|
||||
# Build dialog menu format with mapping (same approach as yad)
|
||||
local dialogArgs=()
|
||||
declare -A valueMap
|
||||
while [[ $# -gt 0 ]]; do
|
||||
local option="$1"
|
||||
local description="$2"
|
||||
valueMap["$description"]="$option"
|
||||
dialogArgs+=("$description" "$description")
|
||||
shift 2
|
||||
done
|
||||
|
||||
local selectedDescription
|
||||
selectedDescription=$(dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--extra-button \
|
||||
--extra-label "Read Documentation" \
|
||||
--no-tags \
|
||||
--menu "$text" 0 0 0 \
|
||||
"${dialogArgs[@]}" \
|
||||
--stdout)
|
||||
local menuCode=$?
|
||||
|
||||
# Return the mapped value
|
||||
if [[ -n "$selectedDescription" ]]; then
|
||||
echo "${valueMap["$selectedDescription"]}"
|
||||
fi
|
||||
return $menuCode
|
||||
fi
|
||||
}
|
||||
|
||||
# Wrapper function for checklist selection
|
||||
# Usage: agm_checklist "title" "backtitle" "text" option1 "description1" "status1" option2 "description2" "status2" ...
|
||||
agm_checklist() {
|
||||
@@ -181,24 +257,41 @@ agm_msgbox() {
|
||||
}
|
||||
|
||||
# Wrapper function for yes/no dialog
|
||||
# Usage: agm_yesno "title" "backtitle" "text"
|
||||
# Usage: agm_yesno "title" "backtitle" "text" ["yes_label"] ["no_label"]
|
||||
agm_yesno() {
|
||||
local title="$1"
|
||||
local backTitle="$2"
|
||||
local text="$3"
|
||||
|
||||
local yesLabel="${4:-Yes}"
|
||||
local noLabel="${5:-No}"
|
||||
|
||||
if [[ "$dialogType" == "yad" ]]; then
|
||||
echo -e "$text" | yad --text-info \
|
||||
--title="$title" \
|
||||
--show-cursor \
|
||||
--button="Yes:0" \
|
||||
--button="No:1" \
|
||||
--button="$yesLabel:0" \
|
||||
--button="$noLabel:1" \
|
||||
--width=600 \
|
||||
--height=400
|
||||
else
|
||||
dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--yesno "$text" 0 0
|
||||
# dialog --yesno doesn't support custom labels, use menu instead
|
||||
if [[ "$yesLabel" != "Yes" ]] || [[ "$noLabel" != "No" ]]; then
|
||||
# Custom labels requested, use menu
|
||||
local choice
|
||||
choice=$(dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--no-tags \
|
||||
--menu "$text" 0 0 0 \
|
||||
"1" "$yesLabel" \
|
||||
"2" "$noLabel" \
|
||||
--stdout)
|
||||
[[ "$choice" == "1" ]]
|
||||
else
|
||||
# Default Yes/No
|
||||
dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--yesno "$text" 0 0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -441,4 +534,4 @@ agm_dselect() {
|
||||
--dselect "$defaultPath" 0 0 \
|
||||
--stdout
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user