Enhance "Refresh Scripts" in favor of "Install" and "Remove" entries
This discusses design for an enhanced feature. The feature lets users install and remove scripts.
Current Feature
Scripts live in a known directory. Users know that directory. Users use a file manager to move a script to that directory, or delete a file. Then they:
- restart GIMP
- OR choose "Refresh Scripts"
There are actually two directories:
- user-specific : belong to a user and persist pass re-installation of GIMP
- system-wide : shared by all users of the machine, installed by GIMP, and may be deleted when GIMP is re-installed.
"Refresh Scripts" is actually broken now (see #10596 (closed).)
New Feature
GIMP will have menu items:
- "Filters>Install Script..."
- "Filters>Remove Script..."
A user won't need to know the directory where scripts are installed.
A user can install or remove scripts one at a time.
Changes take effect immediately in the running GIMP app. A script's menu item will appear immediately.
The script's procedures will be in the PDB immediately, but any open PDB Browsers will not show them.
Changes persist to the next session of GIMP, even if GIMP does not close properly (it doesn't depend on GIMP writing to a RC file on closing.)
A user who knows the directories and has permissions can still use the old method of restarting GIMP.
The feature will not help download scripts from web repositories.
The feature will not guard against obsolete, faulty, or malicious scripts.
The feature will not guard against dependency problems between scripts. A user can remove scripts that other scripts need. A user can add scripts that depend on a missing script or other language plugin.
The feature will understand the difference between old-style scripts and new-style scripts, and install to the appropriate place. (Old style scripts live in /scripts. New-style scripts have a shebang and live in /plug-ins.)
#249)
Install (somewhat implementsA user will choose "Install Script". A dialog will appear to choose a file (e.g. from Downloads directory.) The script will be installed as a user-specific script. The script will persist through a re-installation of GIMP.
A user cannot install a system-wide script (using this feature.) Such a change might not persist through a re-installation of GIMP.
Remove
A user will choose "Remove Script." They will see a list of scripts eligible for deletion. They will select a script and then choose "OK." The list will show file names of scripts.
A file is one-to-zero-or-many with PDB procedures and their menu items. Deleting a file removes all the plugin procedures the file implements. Deleting a file may cause zero or many menu items to dissappear.
No confirmation will be required. Only the file in GIMP directories will be deleted. We will assume that the user has the original in a safe place.
The list will only show user-specific scripts. A user can not remove system-wide scripts (using this feature.)
Benefits
The new feature saves a user from knowing directory names and moving files.
Knowing the directory name is especially difficult because it varies by platform and sandboxed environment.
The word "Refresh" is obscure while "Install" and "Remove" have more intuitive meaning. The word "Refresh" means either install or remove, depending on what files the user moved earlier.
Implementation
The feature will be implemented by an old-style ScriptFu script. This is so that extension-script-fu will load the script in real time. In the future, when extension-script-fu and old-style scripts go away, and when the API is changed, the feature can be implemented in a new-style script.
Future API for query and create
Currently, a script is queried during a query phase. Querying is executing (or interpreting a file) with an arg that designates the query phase. A file is queried. Querying returns a list of procedure names implemented by the file. The PDB knows the file that implements a procedure.
There is also a create phase. The create phase also requires executing a file. During the create phase, a plugin registers its procedures in the PDB.
The plugin manager queries plugins and creates its procedures at GIMP startup, for new-style scripts and other language plugins.
For old-style scripts, the extension-script-fu queries plugin scripts and creates its temporary procedures in the PDB. That is why this feature can now only be implemented in an old-style script, and why it only installs/removes Scheme scripts. (extension-script-fu as a running interpreter process can interpret new-style scripts and register them into the PDB, but a new-style script interpreted independently cannot load scripts into the extension-script-fu.)
In the future, the querying and creating capability can be exposed in the API. Then a plugin in any language can implement the feature and install/remove plugins written in any language. For now, the capability is not exposed but hidden in the plugin manager.
(Note the PDB API now has procedures named like "gimp..query" but they are for a database query of the PDB, and not for querying a file.)
The signature of the new API is:
list-of-procedure-names gimp-plugin-query ( filename)
The method executes a file in query phase and returns a list of procedure names. The file must be a plugin, else the method returns an empty list.
This method is needed to remove i.e. uninstall plugins: to first remove every procedure from the PDB, and then the file is deleted from the filesystem.
void gimp-plugin-create-procedures ( filename )
The method executes a file in create phase. The executing file creates its procedures in the PDB, as a side-effect.
GUI is built in real time if the GIMP GUI is active at the time of the call and the plugin file properly commits the procedures. (Older plugins lacking a call to commit would continue to work.)
The file must be in one of the known directories for plugins and must remain there while the procedure is in the PDB. The method will fail if the given filename is in the wrong directory.
Steps
-
Eliminate "Refresh Scripts" menu item. (As stated earlier, it is broken.) This would close: #169
-
Fix the protocol for building GUI for scripts in real-time. (Trigger menu changes on a "commit" of changes to the PDB rather than the registration of a partially specified PDB procedure.)
-
Implement this feature as a ScriptFu plugin (or just reinstate "Refresh Scripts.")
-
Future: generalize to the management of plugins in any language by adding API for query and create
-
Future: fold into a general "Resource Manager" that would also install/remove resources like brushes.