File powerbox for Gtk applications
Implemented in gtk-powerbox-hook/gtk-powerbox.c
The powerbox/Gtk integration reimplements Gtk's GtkFileChooserDialog interface so that it opens a file powerbox for choosing files or directories. This means that existing, unmodified Gtk applications can use the powerbox.
GtkFileChooserDialog is replaced using an LD_PRELOADed shared object (powerbox-for-gtk.so), which replaces the gtk_file_chooser_dialog_*() functions. This shared object will work across different versions of Gtk. (Perhaps in the future, it could be compiled into Gtk.)
The powerbox/Gtk integration does not change the older GtkFileSelection interface, which is deprecated and exposes too many internal details to change.
How it works
The replacement GtkFileChooserDialog class inherits from GtkDialog, and hence from GtkWindow etc. However, it must prevent GtkWindow from ever opening a window on the screen; this is done by the powerbox manager instead. GtkFileChooserDialog achieves this by overriding the GtkWidget "map" method with code that does not pass the call on to GtkWindow. Instead, the "map" method invokes the powerbox API.
Limitations
- Selecting multiple files in one go is not implemented yet.
- The dialog's "extra widget" is not supported: it does not get displayed at all. This is a serious problem, as it means file type selection widgets (as used by, e.g., Gimp) are not displayed. To fix this requires doing inter-client widget embedding. A temporary fix would be to display the extra widget in a separate top-level window.
- The preview widget is not supported. It does not get displayed.
Filters are not yet implemented. GtkFileChooserDialog does not pass file type filter parameters to the powerbox manager. This is not a serious problem; it is just a convenience.
GtkDialog offers the application an unconstrained choice over the action buttons that appear in the dialog box, while the powerbox always displays Open/Save and Cancel buttons. GtkFileChooserDialog must make a guess at which of GtkDialog's actions to map the powerbox's Open/Save action to. If GtkDialog has more than one action besides Cancel, only one will be usable.
- Confirmation and warning dialog boxes:
- Some applications implement file overwrite confirmation dialog boxes themselves. In this case, two confirmation boxes will appear sequentially, because the powerbox also asks for confirmation.
- Usually, when choosing a file results in the application opening a confirmation or warning box, the file chooser stays open, and the user can then pick a different file. However, with powerbox/Gtk, the file chooser is closed when the user chooses a file.
The GtkFileChooserIface interface allows applications to interact with the file chooser widget while it is open -- for example, to find out which file is currently selected. This will not work with the powerbox/Gtk integration, because the powerbox API is a simple call-return interface, and it does not give the application any way to interact with the file chooser while it is open.
GtkFileChooserButton and GtkFileChooserWidget are not replaced.
The following GtkFileChooser API functions are currently missing:
- gtk_file_chooser_{set,get}_show_hidden
- gtk_file_chooser_{set,get}_do_overwrite_confirmation
- gtk_file_chooser_get_current_folder
- gtk_file_chooser_{set,get}_current_folder_uri
- gtk_file_chooser_{set,get}_preview_widget
- gtk_file_chooser_{set,get}_preview_widget_active
- gtk_file_chooser_{set,get}_use_preview_label
- gtk_file_chooser_list_shortcut_folders
- gtk_file_chooser_add_shortcut_folder_uri
- gtk_file_chooser_remove_shortcut_folder_uri
- gtk_file_chooser_list_shortcut_folder_uris
Earlier version of the GtkFileChooserDialog replacement
My first attempt at a replacement GtkFileChooserDialog class did not inherit from the GtkDialog class, on the grounds that it did not need to open a GtkDialog window itself. It inherited from GtkObject and nothing else.
This caused some problems, because applications expect GtkFileChooserDialog to inherit from GtkDialog (and so, indirectly, from GtkWindow, GtkWidget, etc.) as documented. This did not cause applications to crash: the Gtk API functions just print a warning and return if passed objects that don't belong to the expected class.
The old version is still included, as src/gtk-powerbox-noninherit.c.
