Version 7 of Accessing the help pages without changing the default directory

Updated 2011-11-10 01:07:16 by AMG

Didier (2011-02-09] I wonder if I can work around this difficulty. I thought I coded a very clever piece of code. In my program, if I click on a file in Directory A, A becomes a default directory. Now the problem started when I had to code the Help. If I call the Help page, the directory will be changed to the Help directory. Which is what I don't want. What I'd like is to stay in the current directory and to view the Help pages which are in another directory without changing the default directory. Is this possible?

GJS (2011-02-09) You need to use the full path of the help files. Sometimes it helps to store important directories in some sort of variable when your application starts up. One method of getting the directory your script is running from would be to use [file dirname [info script]]]. If you are developing a starkit you may choose to use $::starkit::topdir to get the directory that main.tcl is in. To get the directory the starkit is in you can use [file dirname $::starkit::topdir]. Once you have saved the main directory of the app, lets say you used a variable name dir, you can use [file join $dir help] to get the a directory named help, or [file join $dir help myhelp.txt] to get the help file. Hopefully this answers your question.

Didier (2011-02-10) It does. Thanks Gary! And thank you again for the Set windows side by side suggestion. It was for me the beginning of a new computing adventure! Working with two files in two different directories.

I thought of a more barbarian approach to the above-mentioned problem. I thought of writing some code that would work this way:

  • Change the default directory according to the file loaded
  • But Do not do this if the directory has the word User's Help in its path

It's not a very orthodox way to proceed, I agree but it's less complicated. What do you think? How should I proceed if I use this simpler approach?

Tx again!

GJS I am not really sure how to proceed in a situation like this. I always leave [pwd] alone and store full directory paths in variables. When I need to access a file or directory in one of those directories, I simply use [file join]. For your application, I guess I would store the help directory for access to the help files. Then you can still cd to what ever directory, and access your help files. It always helps to store directories that are important to your application so that you can access them easily. This will also allow you to work with different system configurations more easily. Here is a rough proc, it won't run on it's own, but it may give you an idea.

proc changeD {dir} {
  variable helpdir
  switch -exact -- [file tail $dir] {
    "User's Help" {
      display $helpdir
    }
    default {
      cd [file normalize $dir]
      display [pwd]
    }
  }
}