Autoimport-export of files based on extension
Not logged in

On 24Aug04, Roger asks at Tkoutline discussion:

''I would like to see some import filters applied automatically if this program is associated with certain extensions, and such a file is opened. I mean, if I click a .txt file, and I have associated txt files with this program, then it should import rather than trying to open the file.

This would allow me to build up a system of txt files, or html files, and have them opened (imported) by this program.

This would allow us to choose what file format we want to use to save our outlines, as html files, or txt files, or tkoutline format, etc..

It would make the program a lot more versatile and useful for creating notes systems with a preferred file format. It could also make tkoutline useful as a general txt editor, for example.

I would like to be able to invent my own extensions also, like .text and associate them with tkoutliner, so it imports them as txt files when I click on a .text file in my computer.''

Brian Theado - for text format this should be possible to do right now with version 0.93, by adding some code to your startup script (Edit->Edit startup script). See below for some code that will achieve what I think you are asking. Just add it to your startup script and restart tkoutline. It will work for .txt and .text extensions. Adding something like .opml for the only other import format that tkoutline supports is slightly harder because nothing like ::tkoutline::editTextFileAsOutline exists for opml files. Html files are even harder, because html importing functionality doesn't exist yet.

Warning: only lightly tested.

 # The open method isn't very well factored out and has a lot of functionality in it,
 # so "wrap" the existing implementation by renaming the normal command and redefining
 # a new one in its place that will call the original version for non-text files
 ::tkoutline::browser rename Open Open.bak
 ::tkoutline::browser proc Open {{fname ""} {tree ""}} {
    if {string length $fname == 0} {
        set fname tk_getOpenFile
        } else {
        set fname file join [pwd $fname]
    if {string length $fname == 0} return
    if {string length $tree == 0} {
        switch -- file extension $fname {
            .txt - .text {
                ::tkoutline::editTextFileAsOutline $fname
            default {
                Open.bak $fname
        } else {
        Open.bak $fname $tree

Another idea extending this even further has been posted at [bad-link: <a href="">1</a>]1 by Auriel Manolson. He proposes automatically detecting from the contents of the file whether or not it is plain text our a tkoutline file.

There is nothing in the tkoutline file format that can be used to determine for sure whether or not it is a tkoutline file. Currently the file is in the format of a nested Tcl list. Being a nested Tcl list means that the first few characters will be open curly braces. So if these braces are present and the file parses as a proper Tcl list, then it is a good guess that it is a tkoutline file (no guarantees, though).