TIP #242 Version 1.2: Preselect Filter on tk_get*File Dialogs

This is not necessarily the current version of this TIP.


TIP:242
Title:Preselect Filter on tk_get*File Dialogs
Version:$Revision: 1.2 $
Author:Brian Griffin <bgriffin at model dot com>
State:Draft
Type:Project
Tcl-Version:8.5
Vote:Pending
Created:Thursday, 03 March 2005

Abstract

This TIP proposes adding an -typevariable option to the tk_getOpenFile and tk_getSaveFile dialog box commands. This option will preselect the filter from the -filetypes list based on the type name.

Rationale

The standard Open and Save dialog boxes currently allow you to seed the initial directory and the initial file, but selecting the initial filter should be supported as well. It is common to use a single dialog with a variety of filter options as a way for the user to select the import or export type, rather then having the user select a type before opening the dialog. By giving the application control over selecting the filter, the UI can be made friendlier to the user since the current operation is mostly similar to previous operations. For example, if you just opened a .txt file, the next open the user performs is most likely also a .txt file, so requiring the user to adjust the filter again is extra work and should be unnecessary.

Proposed Change

Add a -typevariable option to tk_getOpenFile and tk_getSaveFile. The variable referenced will be used as an in/out parameter. The variables value will be used to select a type from the -filetypes list. The variable will be updated when the call returns to the current filter selection. For example, given:

    set types {
        {{Text Files}       {.txt}        }
        {{TCL Scripts}      {.tcl}        }
        {{C Source Files}   {.c}      TEXT}
        {{GIF Files}        {.gif}        }
        {{GIF Files}        {}        GIFF}
        {{All Files}        *             }
    }
    tk_getOpenFile -filetypes $types -typevariable type

To preselect .c files for the filter, set type {C Source Files}. If the filter is changed to {TCL Scripts}, for example, the variable "type" is modified to the value {TCL Scripts}.

Reference Implementation

A reference implementation will be posted to Tk patches. I have modified tkfbox.tcl and tkWinDialog.c. I have not looked at MacOSX yet.

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows