make remove_files() actually invert sel., etc.

- remove_files(): this had an 'Invert all' button which didn't
    entirely work, as it simply toggled all on/off rather than
    reflecting selection state (it was more 'Select/Deselect All'). By
    changing the order of the buttons and using selection_state(), it
    now can now 'Invert Sel'ections. The button order had to be juggled
    because dialog only outputs a list on 0/3. So now it asks to delete
    and defaults to Cancel with '--defaultno' rather than asking to keep
    and defaulting to OK. Also cleaned up the dialog invocation in
    general and cleaned up the sed/redirect creation of
    $FILES_CHECKLIST. Also changed the 'ERROR' title for not finding
    anything to 'NOTICE' since it's not an error to, e.g., not have any
    obsolete sources.
  - reverse_choices(): deleted since it was no longer used.
  - remove_obsolete_sources(), browse_categories(): similar sed cleanups
    as above.
  - selection_state(): clarified comments, remembered to add LINE as a
    local var, and anchored a regex whose $ got lost.
This commit is contained in:
slakmagik 2011-03-07 01:26:50 +00:00
parent 9677e0ebf9
commit 511ef6f26f

View File

@ -443,12 +443,13 @@ selection_state() {
# may reverse the selected items in the checklist. The first argument # may reverse the selected items in the checklist. The first argument
# determines which is done ('reverse' to reverse, anything else to # determines which is done ('reverse' to reverse, anything else to
# preserve the selection state) while the second argument is the file the # preserve the selection state) while the second argument is the file the
# widget uses for input and the third is the file which reflects the # widget uses for input (to display the widget items) and the third is the
# user's selections. # file the widget uses for output (which reflects the user's selections).
local ACTION=$1 local ACTION=$1
local MENU_FILE=$2 local MENU_FILE=$2
local SELECTION_FILE=$3 local SELECTION_FILE=$3
local LINE
sed -i 's/ON$/OFF/' $MENU_FILE sed -i 's/ON$/OFF/' $MENU_FILE
while read LINE; do while read LINE; do
@ -456,7 +457,7 @@ selection_state() {
done < $SELECTION_FILE done < $SELECTION_FILE
if [[ $1 == reverse ]]; then if [[ $1 == reverse ]]; then
sed -i 's/ON$/HOLD/;s/OFF/ON/' $MENU_FILE sed -i 's/ON$/HOLD/;s/OFF$/ON/' $MENU_FILE
sed -i 's/HOLD$/OFF/' $MENU_FILE sed -i 's/HOLD$/OFF/' $MENU_FILE
fi fi
} }
@ -1463,8 +1464,7 @@ browse_categories() {
view_cache_dir() { view_cache_dir() {
# This function displays the contents of $SRCDIR. # This function displays the contents of $SRCDIR.
ls -A $SRCDIR | sed "s/^\(.*\)$/\"\\1\"/g" \ ls -A $SRCDIR | sed 's/.*/"&"/g' > $SBOPKGTMP/sbopkg_app_sources
> $SBOPKGTMP/sbopkg_app_sources
remove_files $SRCDIR "sources" $SBOPKGTMP/sbopkg_app_sources OFF remove_files $SRCDIR "sources" $SBOPKGTMP/sbopkg_app_sources OFF
} }
@ -3102,7 +3102,7 @@ remove_obsolete_sources() {
fi fi
# Quote file names # Quote file names
sed -i "s/^\(.*\)$/\"\\1\"/" $SOURCES sed -i 's/.*/"&"/' $SOURCES
remove_files $SRCDIR "obsolete sources" $SOURCES ON remove_files $SRCDIR "obsolete sources" $SOURCES ON
} }
@ -3124,29 +3124,6 @@ remove_uninstalled_packages() {
remove_files $OUTPUT "uninstalled packages" $PACKAGES ON remove_files $OUTPUT "uninstalled packages" $PACKAGES ON
} }
reverse_choices() {
# Reverses ON or OFF setting in a file for dialog purposes.
# $1 is the file
local REVERSE_FILE="$1"
local TMPREVERSE=$SBOPKGTMP/sbopkg_tmp_reverse
local PICK ONOFF
rm -f $TMPREVERSE
# Reading from $REVERSE_FILE
while read PICK; do
ONOFF=$(sed 's:^.* \([^ ]*\)$:\1:' <<< "$PICK")
if [[ $ONOFF =~ [oO][nN] ]]; then
PICK=${PICK/%[oO][nN]/OFF}
echo $PICK >> $TMPREVERSE
else
PICK=${PICK/%[oO][fF][fF]/ON}
echo $PICK >> $TMPREVERSE
fi
done < $REVERSE_FILE
mv $TMPREVERSE $REVERSE_FILE
}
remove_files() { remove_files() {
# Selectively remove files, after showing a checklist of them. # Selectively remove files, after showing a checklist of them.
# The file names (specified in $3) _must_ be quoted. # The file names (specified in $3) _must_ be quoted.
@ -3165,33 +3142,29 @@ remove_files() {
cd $FILESPATH cd $FILESPATH
if [[ -s $FILES ]]; then if [[ -s $FILES ]]; then
sed "s/^\(.*\)$/\\1 \"\" $ONOFF/g" < $FILES | sed "s/.*/& \"\" $ONOFF/g" $FILES | sort > $FILES_CHECKLIST
sort > $FILES_CHECKLIST
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
while :; do while :; do
dialog --title "$(crunch "Displaying $TOPIC")" \ dialog --separate-output --defaultno \
--ok-label "OK" --extra-label "Delete selected" \ --title "Displaying $TOPIC" \
--cancel-label "Invert all" --extra-button \ --extra-button --extra-label "Invert Sel" \
--separate-output --checklist "$(crunch "Would you like \ --checklist "Delete the $TOPIC in $FILESPATH?" \
to keep the $TOPIC in $FILESPATH?")"\ 20 60 12 --file $FILES_CHECKLIST 2> $FILES_DELETING
20 60 12 \ CHOICE=$? # 0=Ok, 3=Invert Sel
--file $FILES_CHECKLIST 2> $FILES_DELETING selection_state preserve $FILES_CHECKLIST $FILES_DELETING
CHOICE=$? # 0=Ok, 1=Invert all, 3=Delete
case $CHOICE in case $CHOICE in
255|-1) # ESC
rm -f $FILES_CHECKLIST $FILES_DELETING
return 0
;;
0) 0)
return 0
;;
1)
reverse_choices $FILES_CHECKLIST
;;
3)
DELETE=1 DELETE=1
break break
;; ;;
3)
selection_state reverse $FILES_CHECKLIST \
$FILES_DELETING
;;
*)
rm -f $FILES_CHECKLIST $FILES_DELETING
return 0
;;
esac esac
done done
else else
@ -3223,7 +3196,7 @@ remove_files() {
fi fi
else else
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
dialog --title "ERROR" --msgbox "$(crunch "It appears there are \ dialog --title "NOTICE" --msgbox "$(crunch "It appears there are \
no $TOPIC in $FILESPATH.")" 8 30 no $TOPIC in $FILESPATH.")" 8 30
else else
echo "$(crunch "It appears there are no $TOPIC in $FILESPATH.")" echo "$(crunch "It appears there are no $TOPIC in $FILESPATH.")"