mirror of
https://github.com/the-sane/lug-helper.git
synced 2024-12-28 15:54:19 +00:00
Use a checkbox menu for item deletions
This commit is contained in:
parent
2343bfb733
commit
6af87bb231
100
lug-helper.sh
100
lug-helper.sh
@ -355,10 +355,7 @@ message() {
|
|||||||
#
|
#
|
||||||
# How to call this function:
|
# How to call this function:
|
||||||
#
|
#
|
||||||
# Requires two arrays to be set: "menu_options" and "menu_actions"
|
# Requires the following variables:
|
||||||
# two string variables: "menu_text_zenity" and "menu_text_terminal"
|
|
||||||
# and one integer variable: "menu_height".
|
|
||||||
#
|
|
||||||
# - The array "menu_options" should contain the strings of each option.
|
# - The array "menu_options" should contain the strings of each option.
|
||||||
# - The array "menu_actions" should contain function names to be called.
|
# - The array "menu_actions" should contain function names to be called.
|
||||||
# - The strings "menu_text_zenity" and "menu_text_terminal" should contain
|
# - The strings "menu_text_zenity" and "menu_text_terminal" should contain
|
||||||
@ -366,6 +363,7 @@ message() {
|
|||||||
# This text will be displayed above the menu options.
|
# This text will be displayed above the menu options.
|
||||||
# Zenity supports Pango Markup for text formatting.
|
# Zenity supports Pango Markup for text formatting.
|
||||||
# - The integer "menu_height" specifies the height of the zenity menu.
|
# - The integer "menu_height" specifies the height of the zenity menu.
|
||||||
|
# - The string "menu_type" should contain either "radiolist" or "checklist".
|
||||||
# - The string "cancel_label" should contain the text of the cancel button.
|
# - The string "cancel_label" should contain the text of the cancel button.
|
||||||
#
|
#
|
||||||
# The final element in each array is expected to be a quit option.
|
# The final element in each array is expected to be a quit option.
|
||||||
@ -388,6 +386,8 @@ menu() {
|
|||||||
debug_print exit "Script error: The string 'menu_text_terminal' was not set\nbefore calling the menu function. Aborting."
|
debug_print exit "Script error: The string 'menu_text_terminal' was not set\nbefore calling the menu function. Aborting."
|
||||||
elif [ -z "$menu_height" ]; then
|
elif [ -z "$menu_height" ]; then
|
||||||
debug_print exit "Script error: The string 'menu_height' was not set\nbefore calling the menu function. Aborting."
|
debug_print exit "Script error: The string 'menu_height' was not set\nbefore calling the menu function. Aborting."
|
||||||
|
elif [ "$menu_type" != "radiolist" ] && [ "$menu_type" != "checklist" ]; then
|
||||||
|
debug_print exit "Script error: Unknown menu_type in menu() function. Aborting."
|
||||||
elif [ -z "$cancel_label" ]; then
|
elif [ -z "$cancel_label" ]; then
|
||||||
debug_print exit "Script error: The string 'cancel_label' was not set\nbefore calling the menu function. Aborting."
|
debug_print exit "Script error: The string 'cancel_label' was not set\nbefore calling the menu function. Aborting."
|
||||||
fi
|
fi
|
||||||
@ -399,28 +399,66 @@ menu() {
|
|||||||
# ie: "TRUE" "List item 1" "FALSE" "List item 2" "FALSE" "List item 3"
|
# ie: "TRUE" "List item 1" "FALSE" "List item 2" "FALSE" "List item 3"
|
||||||
for (( i=0; i<"${#menu_options[@]}"-1; i++ )); do
|
for (( i=0; i<"${#menu_options[@]}"-1; i++ )); do
|
||||||
if [ "$i" -eq 0 ]; then
|
if [ "$i" -eq 0 ]; then
|
||||||
# Select the first radio button by default
|
# Set the first element
|
||||||
zen_options=("TRUE")
|
if [ "$menu_type" = "radiolist" ]; then
|
||||||
zen_options+=("${menu_options[i]}")
|
# Select the first radio button by default
|
||||||
|
zen_options=("TRUE")
|
||||||
|
else
|
||||||
|
# Don't select the first checklist item
|
||||||
|
zen_options=("FALSE")
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
# Deselect all remaining items
|
||||||
zen_options+=("FALSE")
|
zen_options+=("FALSE")
|
||||||
zen_options+=("${menu_options[i]}")
|
|
||||||
fi
|
fi
|
||||||
|
# Add the menu list item
|
||||||
|
zen_options+=("${menu_options[i]}")
|
||||||
done
|
done
|
||||||
|
|
||||||
# Display the zenity radio button menu
|
# Display the zenity radio button menu
|
||||||
choice="$(zenity --list --radiolist --width="480" --height="$menu_height" --text="$menu_text_zenity" --title="Star Citizen LUG Helper" --hide-header --cancel-label "$cancel_label" --window-icon="$lug_logo" --column="" --column="Option" "${zen_options[@]}" 2>/dev/null)"
|
choice="$(zenity --list --"$menu_type" --width="480" --height="$menu_height" --text="$menu_text_zenity" --title="Star Citizen LUG Helper" --hide-header --cancel-label "$cancel_label" --window-icon="$lug_logo" --column="" --column="Option" "${zen_options[@]}" 2>/dev/null)"
|
||||||
|
|
||||||
# Loop through the options array to match the chosen option
|
# Match up choice with an element in menu_options
|
||||||
matched="false"
|
matched="false"
|
||||||
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
|
if [ "$menu_type" = "radiolist" ]; then
|
||||||
if [ "$choice" = "${menu_options[i]}" ]; then
|
# Loop through the options array to match the chosen option
|
||||||
# Execute the corresponding action
|
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
|
||||||
${menu_actions[i]}
|
if [ "$choice" = "${menu_options[i]}" ]; then
|
||||||
matched="true"
|
# Execute the corresponding action for a radiolist menu
|
||||||
break
|
${menu_actions[i]}
|
||||||
|
matched="true"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
elif [ "$menu_type" = "checklist" ]; then
|
||||||
|
# choice will be empty if no selection was made
|
||||||
|
# Unfortunately, it's also empty when the user presses cancel
|
||||||
|
# so we can't differentiate between those two states
|
||||||
|
|
||||||
|
# Convert choice string to array elements for checklists
|
||||||
|
ifsBAK="$IFS"
|
||||||
|
IFS='|' read -a choices <<< "$choice"
|
||||||
|
IFS="$ifsBAK"
|
||||||
|
|
||||||
|
# Fetch the function to be called
|
||||||
|
function_call="$(echo "${menu_actions[0]}" | awk '{print $1}')"
|
||||||
|
|
||||||
|
# Loop through the options array to match the chosen option(s)
|
||||||
|
unset arguments_array
|
||||||
|
for (( i=0; i<"${#menu_options[@]}"; i++ )); do
|
||||||
|
for (( j=0; j<"${#choices[@]}"; j++ )); do
|
||||||
|
if [ "${choices[j]}" = "${menu_options[i]}" ]; then
|
||||||
|
arguments_array+=("$(echo "${menu_actions[i]}" | awk '{print $2}')")
|
||||||
|
matched="true"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Call the function with all matched elements as arguments
|
||||||
|
if [ "$matched" = "true" ]; then
|
||||||
|
$function_call "${arguments_array[@]}"
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
|
|
||||||
# If no match was found, the user clicked cancel
|
# If no match was found, the user clicked cancel
|
||||||
if [ "$matched" = "false" ]; then
|
if [ "$matched" = "false" ]; then
|
||||||
@ -1016,10 +1054,19 @@ download_delete() {
|
|||||||
debug_print exit "Script error: The download_delete function expects an argument. Aborting."
|
debug_print exit "Script error: The download_delete function expects an argument. Aborting."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
item_to_delete="$1"
|
# Capture arguments and format a list of items
|
||||||
if message question "Are you sure you want to delete the following ${download_type}?\n\n${installed_items[$item_to_delete]}"; then
|
item_to_delete=("$@")
|
||||||
rm -r "${installed_items[$item_to_delete]}"
|
unset list_to_delete
|
||||||
debug_print continue "Deleted ${installed_items[$item_to_delete]}"
|
for (( i=0; i<"${#item_to_delete[@]}"; i++ )); do
|
||||||
|
list_to_delete+="\n${installed_items[${item_to_delete[i]}]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
if message question "Are you sure you want to delete the following ${download_type}(s)?\n$list_to_delete"; then
|
||||||
|
# Loop through the arguments
|
||||||
|
for (( i=0; i<"${#item_to_delete[@]}"; i++ )); do
|
||||||
|
rm -r "${installed_items[${item_to_delete[i]}]}"
|
||||||
|
debug_print continue "Deleted ${installed_items[${item_to_delete[i]}]}"
|
||||||
|
done
|
||||||
lutris_needs_restart="true"
|
lutris_needs_restart="true"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -1027,9 +1074,10 @@ download_delete() {
|
|||||||
# List installed items for deletion. Called by download_manage()
|
# List installed items for deletion. Called by download_manage()
|
||||||
download_select_delete() {
|
download_select_delete() {
|
||||||
# Configure the menu
|
# Configure the menu
|
||||||
menu_text_zenity="Select the $download_type you want to remove:"
|
menu_text_zenity="Select the $download_type(s) you want to remove:"
|
||||||
menu_text_terminal="Select the $download_type you want to remove:"
|
menu_text_terminal="Select the $download_type you want to remove:"
|
||||||
menu_text_height="60"
|
menu_text_height="60"
|
||||||
|
menu_type="checklist"
|
||||||
goback="Return to the $download_type management menu"
|
goback="Return to the $download_type management menu"
|
||||||
unset installed_items
|
unset installed_items
|
||||||
unset installed_item_names
|
unset installed_item_names
|
||||||
@ -1361,6 +1409,7 @@ download_select_install() {
|
|||||||
menu_text_zenity="Select the $download_type you want to install:"
|
menu_text_zenity="Select the $download_type you want to install:"
|
||||||
menu_text_terminal="Select the $download_type you want to install:"
|
menu_text_terminal="Select the $download_type you want to install:"
|
||||||
menu_text_height="60"
|
menu_text_height="60"
|
||||||
|
menu_type="radiolist"
|
||||||
goback="Return to the $download_type management menu"
|
goback="Return to the $download_type management menu"
|
||||||
unset menu_options
|
unset menu_options
|
||||||
unset menu_actions
|
unset menu_actions
|
||||||
@ -1492,6 +1541,7 @@ download_manage() {
|
|||||||
menu_text_zenity="<b><big>Manage Your $download_menu_heading</big>\n\n$download_menu_description</b>\n\nYou may choose from the following options:"
|
menu_text_zenity="<b><big>Manage Your $download_menu_heading</big>\n\n$download_menu_description</b>\n\nYou may choose from the following options:"
|
||||||
menu_text_terminal="Manage Your $download_menu_heading\n\n$download_menu_description\nYou may choose from the following options:"
|
menu_text_terminal="Manage Your $download_menu_heading\n\n$download_menu_description\nYou may choose from the following options:"
|
||||||
menu_text_height="$download_menu_height"
|
menu_text_height="$download_menu_height"
|
||||||
|
menu_type="radiolist"
|
||||||
|
|
||||||
# Configure the menu options
|
# Configure the menu options
|
||||||
delete="Remove an installed $download_type"
|
delete="Remove an installed $download_type"
|
||||||
@ -1516,8 +1566,8 @@ download_manage() {
|
|||||||
# Calculate the total height the menu should be
|
# Calculate the total height the menu should be
|
||||||
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
|
menu_height="$(($menu_option_height * ${#menu_options[@]} + $menu_text_height))"
|
||||||
|
|
||||||
# Set the label for the cancel button
|
# Set the label for the cancel button
|
||||||
cancel_label="Go Back"
|
cancel_label="Go Back"
|
||||||
|
|
||||||
# Call the menu function. It will use the options as configured above
|
# Call the menu function. It will use the options as configured above
|
||||||
menu
|
menu
|
||||||
@ -1843,6 +1893,7 @@ maintenance_menu() {
|
|||||||
menu_text_zenity="<b><big>Game Maintenance and Troubleshooting</big></b>\n\nYou may choose from the following options:"
|
menu_text_zenity="<b><big>Game Maintenance and Troubleshooting</big></b>\n\nYou may choose from the following options:"
|
||||||
menu_text_terminal="Game Maintenance and Troubleshooting\n\nYou may choose from the following options:"
|
menu_text_terminal="Game Maintenance and Troubleshooting\n\nYou may choose from the following options:"
|
||||||
menu_text_height="100"
|
menu_text_height="100"
|
||||||
|
menu_type="radiolist"
|
||||||
|
|
||||||
# Configure the menu options
|
# Configure the menu options
|
||||||
version_msg="Switch the Helper between LIVE and PTU (Currently: $live_or_ptu)"
|
version_msg="Switch the Helper between LIVE and PTU (Currently: $live_or_ptu)"
|
||||||
@ -2149,6 +2200,7 @@ while true; do
|
|||||||
menu_text_zenity="<b><big>Welcome, fellow Penguin, to the Star Citizen LUG Helper!</big>\n\nThis Helper is designed to help optimize your system for Star Citizen</b>\n\nYou may choose from the following options:"
|
menu_text_zenity="<b><big>Welcome, fellow Penguin, to the Star Citizen LUG Helper!</big>\n\nThis Helper is designed to help optimize your system for Star Citizen</b>\n\nYou may choose from the following options:"
|
||||||
menu_text_terminal="Welcome, fellow Penguin, to the Star Citizen Linux Users Group Helper!\n\nThis Helper is designed to help optimize your system for Star Citizen\nYou may choose from the following options:"
|
menu_text_terminal="Welcome, fellow Penguin, to the Star Citizen Linux Users Group Helper!\n\nThis Helper is designed to help optimize your system for Star Citizen\nYou may choose from the following options:"
|
||||||
menu_text_height="140"
|
menu_text_height="140"
|
||||||
|
menu_type="radiolist"
|
||||||
|
|
||||||
# Configure the menu options
|
# Configure the menu options
|
||||||
preflight_msg="Preflight Check (System Optimization)"
|
preflight_msg="Preflight Check (System Optimization)"
|
||||||
|
Loading…
Reference in New Issue
Block a user