34beb74
Index: mimeedit.sh
34beb74
===================================================================
5303c68
--- mimeedit.sh	(revision 1962)
34beb74
+++ mimeedit.sh	(working copy)
5303c68
@@ -63,11 +63,13 @@
5303c68
 # Build a list with registered apps for this mimetype.
5303c68
 #
5303c68
 function deflist (){
5303c68
-  if [ -e "$UTMP.avail" ]; then cleanup;fi
5303c68
+  TMP_AVAIL="`mktemp /tmp/gnome-commander.XXXXXX`"
5303c68
+  TMP_CHOSEN="`mktemp /tmp/gnome-commander.XXXXXX`"
5303c68
+  # if [ -e "$UTMP.avail" ]; then cleanup;fi
5303c68
   # Create the list in "$UTMP.avail" to be used by the zenity list-box
5303c68
   if [ "$NONEW" == 1 ]
5303c68
   then
5303c68
-   echo "FALSE Add_New_App New" > "$UTMP.avail"
5303c68
+   echo "FALSE Add_New_App New" > $TMP_AVAIL
5303c68
   fi
5303c68
   # Get all sub-mimetypes, one per row.
5303c68
   SUB="$(grep -hs "^$MTPE" $SUBC $G_CACHE $U_CACHE | awk -F= '{print $1}' | sed 's/ /\n/g')"
5303c68
@@ -77,14 +79,14 @@
5303c68
   then
5303c68
     for i in $(echo "$MTPEs" | sort -u); do
5303c68
       echo "FALSE $i $(grep -hs "^Name=" $GDATA_DIR/$i $DATA_DIR/$i | \
5303c68
-      sed 's/Name=//;s/ /_/g')" >> "$UTMP.avail"
5303c68
+      sed 's/Name=//;s/ /_/g')" >> $TMP_AVAIL
5303c68
     done
5303c68
   fi
5303c68
   # Change FALSE to TRUE for the default app. 
5303c68
-  if grep -q "desktop" "$UTMP.avail"
5303c68
+  if grep -q "desktop" $TMP_AVAIL
5303c68
   then
5303c68
     DEF_APP=$(gnomevfs-info -s "$ARGU" | grep "Default app" | sed 's/.*: //')
5303c68
-    sed -i "s|FALSE $DEF_APP|TRUE $DEF_APP|" "$UTMP.avail"
5303c68
+    sed -i "s|FALSE $DEF_APP|TRUE $DEF_APP|" $TMP_AVAIL
5303c68
   fi
5303c68
   # Show the list
5303c68
   zenity --height="350" --width="550" --list --radiolist --text \
5303c68
@@ -99,17 +101,17 @@
5303c68
 
5303c68
 Please select" \
5303c68
   --column "Pick" --column ".desktop file" --column "Application" \
5303c68
-  $(cat "$UTMP.avail") > "$UTMP.chosen" 
5303c68
+  $(cat $TMP_AVAIL ) > $TMP_CHOSEN 
5303c68
   retval=$?
5303c68
-  choice=$(cat "$UTMP.chosen")
5303c68
+  choice=$(cat $TMP_CHOSEN )
5303c68
   if grep -q "$MTPE=$choice" $U_DEF
5303c68
   then
5303c68
     retval=2
5303c68
   fi
5303c68
   case $retval in
5303c68
   0)
5303c68
-    DEF_CH=$(grep -s "$choice" "$UTMP.avail" | awk '{print $2}')
5303c68
-    DEF_NME=$(grep -s "$choice" "$UTMP.avail" | awk '{print $3}')
5303c68
+    DEF_CH=$(grep -s "$choice" $TMP_AVAIL | awk '{print $2}')
5303c68
+    DEF_NME=$(grep -s "$choice" $TMP_AVAIL | awk '{print $3}')
5303c68
     if [ "$DEF_CH" = Add_New_App ]
5303c68
     then
5303c68
       newmime
5303c68
@@ -305,8 +307,8 @@
5303c68
 # Remove tempfiles.
5303c68
 #
5303c68
 function cleanup (){
5303c68
-  rm -f "$UTMP.avail"
5303c68
-  rm -f "$UTMP.chosen"
5303c68
+  rm -f $TMP_AVAIL
5303c68
+  rm -f $TMP_CHOSEN
5303c68
 }
5303c68
 
5303c68
 #
5303c68
@@ -342,6 +344,7 @@
34beb74
 # The .desktop file editor
34beb74
 #
34beb74
 function dtfedit (){ 
34beb74
+  TMPFILE=`mktemp /tmp/gnome-commander.XXXXXX`
34beb74
   USER_DTF="$DT_FILE-$EXT"
34beb74
   if [ -n "$DT_FILE" ]
34beb74
   then 
5303c68
@@ -350,15 +353,22 @@
34beb74
     then
34beb74
       TO_EDIT="$DATA_DIR/$USER_DTF"
34beb74
     else
34beb74
-      TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
34beb74
+      DT_FILE_PREFIX=$(echo $DT_FILE | sed -e 's|-[0-9][0-9]*||')
34beb74
+      DT_FILE_SUFFIX=$(echo $DT_FILE | sed -n -e 's|^.*-\([0-9][0-9]*\)$|\1|p')
34beb74
+      if [ -e $DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop ]
34beb74
+      then
34beb74
+	TO_EDIT="$DATA_DIR/${DT_FILE_PREFIX}-usercreated-$DT_FILE_SUFFIX.desktop"
34beb74
+      else
34beb74
+        TO_EDIT="$GDATA_DIR/$DT_FILE.desktop"
34beb74
+      fi
34beb74
     fi
34beb74
     cat "$TO_EDIT" | zenity --height="350" --width="550" --text-info --editable \
34beb74
-    --title "Edititng the file: $USER_DTF" > $UTMP.$USER_DTF 
34beb74
-    if [ -s $UTMP.$USER_DTF ]
34beb74
+    --title "Edititng the file: $USER_DTF" > $TMPFILE
34beb74
+    if [ -s $TMPFILE ]
34beb74
     then 
34beb74
-      mv $UTMP.$USER_DTF $DATA_DIR/$USER_DTF 
34beb74
+      mv $TMPFILE $DATA_DIR/$USER_DTF
34beb74
     else 
34beb74
-      rm -f $UTMP.$USER_DTF 
34beb74
+      rm -f $TMPFILE
34beb74
       DT_FILE=""
34beb74
     fi
34beb74
   fi