nomad-software / tkd

GUI toolkit for the D programming language based on Tcl/Tk
MIT License
117 stars 16 forks source link

Posix file dialogs show hidden files and directories #38

Closed KarlHeesch closed 8 years ago

KarlHeesch commented 8 years ago

This is really a pain, as often these dialogs start at the home directory which is full of hidden files and directories in Linux.

There is a workaround for this unlucky default setup of file dialogs. Please see [(http://wiki.tcl.tk/1060)] when the discussion reaches June 2011: 'Is there a way to disable displaying of hidden directories in Linux (starting with a dot ".") when file sector dialog opens?'.

So I would like to put the following workaround for tkd into discussion. (I am new in D-programming, so there might well be a smarter approach.)

Background: As this workaround allocates resources (a dummy call to tk_getOpenFile is needed), it should be executed only once and only if the application uses DirectoryDialog, OpenFileDialog or SaveFileDialog.

  1. Add following member to Dialog:
/**
 * Workaround to fix default of file dialogs showing unwanted
 * hidden files and directories on Posix systems.
 *
 * To be called from constructor of FileDialog and of DirectoryDialog
 * when on version(Posix).
 */
protected final void fixFileOrDirDialog() {
    static bool fixed;
    if (!fixed) {
        fixed = true;
        this._tk.eval("catch {tk_getOpenFile foo bar}");   // Dummy that instanciates below variables.
        this._tk.eval("set ::tk::dialog::file::showHiddenVar 0");  // Don't show hidden entities.
        this._tk.eval("set ::tk::dialog::file::showHiddenBtn 1");  // Show switch for hiddent entities.
    }
}
  1. Modify the constructor of FileDialog (line 57ff) as follows:
this(Window parent, string title)
{
    this._typeVariable = format("variable-%s", this.generateHash("%s%s", this._elementId, this.id));
    super(parent, title);
    version(Posix) fixFileOrDirDialog();
}
  1. Modify the constructor of DirectoryDialog (54ff) as follows:
this(Window parent, string title = "Directory")
{
    super(parent, title);
    version(Posix) fixFileOrDirDialog();
}

Sorry, but I could not find a solution where to touch only one spot in the code while holding the background condition mentioned above.

Regards, Karl

nomad-software commented 8 years ago

Fixed in commit: https://github.com/nomad-software/tkd/commit/f13a7b1c676aee417d7d0d91c1e7447dcf4835ec

jordisayol commented 8 years ago

Usually Linux treats backup files/folders that ends with ~ "tilde" as hidden files. Can they be included as hidden on dialogs?

nomad-software commented 8 years ago

Probably not as it's Tcl/Tk taking care of this, not the D bindings.