Update desktop.template documentation
authorColin Clark <colin.clark@cclark.uk>
Mon, 27 Apr 2020 07:06:21 +0000 (08:06 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 27 Apr 2020 07:06:21 +0000 (08:06 +0100)
Also include a script to automatically update the menu "Valid sections"
of the template.
This needs to be run only when the menus have changed.

plugins/template.desktop.in
scripts/template-desktop.sh [new file with mode: 0755]

index d43690c..7af3121 100644 (file)
@@ -9,8 +9,13 @@ _Name=Template
 #Name[de]=Vorlage
 
 # Replace "command" with the actual command or script:
-Exec=command %f
+Exec=command <param>
 
+# Where <param> may be:
+# omitted      If no parameter is given the command will be executed in the
+#        current folder. If a parameter is given but the current folder
+#        does not contain any files, the command will not be run.
+#
 # %f    A single file name, even if multiple files are selected. The
 #        system reading the desktop entry should recognize that the program in
 #        question cannot handle multiple file arguments, and it should should
@@ -42,8 +47,8 @@ Icon=gtk-file
 Categories=X-Geeqie;
 OnlyShowIn=X-Geeqie;
 
-# Uncomment the following line to include in a Geeqie menu,
-# other than in the default path of EditMenu/ExternalMenu
+# Uncomment the following line to include in a Geeqie menu
+# other than in the default path of PluginsMenu
 #X-Geeqie-Menu-Path=<FileMenuPath>
 
 # e.g.
@@ -83,12 +88,16 @@ OnlyShowIn=X-Geeqie;
 #    ViewMenu/ViewSection
 #    ViewMenu/ToolsSection
 #    ViewMenu/SlideShowSection
+#    WindowsMenu
+#    WindowsMenu/NewWindow
 #    HelpMenu
 #    HelpMenu/HelpSection
 
 # This is a filter - see symlink.desktop and geeqie-symlink for an example
-# how to use this feature
+# of how to use this feature, or the Plugins section of the Help file.
 #X-Geeqie-Filter=true
 
 # It can be made verbose
 #X-Geeqie-Verbose=true
+
+# For other keys such as MimeType see https://developer.gnome.org/desktop-entry-spec/
diff --git a/scripts/template-desktop.sh b/scripts/template-desktop.sh
new file mode 100755 (executable)
index 0000000..c42a279
--- /dev/null
@@ -0,0 +1,83 @@
+#! /bin/bash
+
+# Insert updated menu "Valid sections" list into the desktop template file.
+# This needs to be run only when the menus have changed.
+
+tmp_file=$(mktemp)
+path=$(dirname $(realpath $0))
+srcpath=$(dirname $path)"/src/layout_util.c"
+templatepath=$(dirname $path)"/plugins/template.desktop.in"
+
+awk -v src_path=$srcpath 'BEGIN {
+menu_flag = 0
+template_flag = 0
+i = 0
+}
+
+function get_menus()
+{
+       {while ((getline line < src_path) > 0 )
+               {
+               if (line == "\"<ui>\"")
+                       {
+                       menu_flag = 1
+                       }
+               if (line == "\"<\057ui>\";")
+                       {
+                       menu_flag = 0
+                       }
+               if (menu_flag >= 1)
+                       {
+                       gsub(/\047|"|\/|<|>/, "", line)
+                       split(line, lineArr, "=")
+
+                       if (index(lineArr[1], "menu action") > 0)
+                               {
+                               i = i + 1
+                               menu[i] = lineArr[2]
+                               if ( i == 3)
+                                       {
+                                       print "#    " menu[1] "/" menu[2] "/"  lineArr[2]
+                                       }
+                               if ( i == 2)
+                                       {
+                                       print "#    " menu[1] "/"  lineArr[2]
+                                       }
+                               if (i == 1)
+                                       {
+                                       print "#    " lineArr[2]
+                                       }
+                               }
+                       if (index(lineArr[1], "placeholder name"))
+                               {
+                               if ( i == 2)
+                                       {
+                                       print "#    " menu[1] "/" menu[2] "/" lineArr[2]
+                                       }
+                               else
+                                       {
+                                       print "#    "   menu[1] "/" lineArr[2]
+                                       }
+                               }
+                       gsub(" ", "", line)
+                       if (line == "menu")
+                               {
+                               i = i - 1
+                               }
+                       }
+               }
+       }
+}
+
+/Valid sections/ {template_flag = 1; print; get_menus()}
+/This is a filter/ {template_flag = 0; print ""}
+(template_flag == 0) {print}
+'  $templatepath > $tmp_file
+
+zenity --text-info < $tmp_file
+if [ $? == 0 ]
+then
+       mv $tmp_file  $templatepath
+else
+       rm $tmp_file
+fi