Via Tool button I would like to Change File Open Directory

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Via Tool button I would like to Change File Open Directory

Post by Ed Grossheim »

6/27/2007 8:33:02 PM

I haven't given up yet..... but I would accept charity-help as I would like to change the File Open Directory, at the click of a tool button.

In Microsoft Word, I do this in VbScript with a command called ChangeFileOpenDirectory.

This is critcial as I will work in folders far removed from eachother.

When I click on Open File I would like to open the exact folder I want (After I clicked the button which would make this happen).

Any clues?

Thanks, Ed :?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,
I would like to change the File Open Directory, at the click of a tool button.
In the Zeus zScript directory there is the file_open.lua macro script which will display the file open dialog using the directory of the current file (i.e. the directory is configurable).

You should be able to use a similar macro code to achieve the result you are after ;)
When I click on Open File I would like to open the exact folder I want (After I clicked the button which would make this happen).
Rather than making this a two step process I would suggest making it a single step where by you just bind your file_open macro directly to the toolbar button.

If you use the Options, Toolbar Options menu you will see several Run this macro script buttons. Just add the first few of these to the toolbar.

The only tricky part is to remember these button line up with same order as the Macros menu and because this menu is document type dependent, the toolbar buttons can change depending on the file (i.e. document type) being edited.

So to work around this you need to make sure you add the changes to the default document type. For example after adding the first macro button to the toolbar you will notice the first button runs the Welcome to Zeus macro item which is also shown as the first item of the Macros menu.

So all you need do edit the default document type and change this macro to now run your special file_open macro.

Because you are changing the default document type, this means the buttons will be effectively constant for all other document types ;)

Cheers Jussi

PS: FWIW the Alt+Shift+E is bound to FileOpenEx function which will display the file open dialog using the directory of the currently active document. You might also want to bind this function to some other key.
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

While I continueon with the help of your ans. - More details

Post by Ed Grossheim »

6/28/2007 9:49:24 AM

I am trying to work with your answer... In the mean time I am sending a couple further details about where I am trying to go.

I am trying to understand the nature of the Default Directory of the Current Document.

e.g. I have three files open, each in different folders.

If I go to any tab, making that file my current document, and then (as if I want to Open a fourth file )
Using the menu I click on File Open, for File Open, Zeus pulls a file open dialog on the chronologically last folder (file) I imported.
So for File Open, Zeus thinks this is the "Default Folder".

Now if I go to any tab, making that file my current document, and then (as if I want to Save the file)
Using the menu I click on File Save, Zeus knows the Default Folder is the folder This File came from.

So a Zeus "File Open Dialog", Zeus thinks either of two folders is the Zeus default and opens that folder in the File Open Dialog.

Which folder opens depends on whether I am saving a file, or Opening a file..


===========================================================================================

My situation is that I will be operating in say 5 widely separated folders. I will want to quickly open any one of them. I will want to
quickly Save the Current document to any one of my five folders (each may even be on a different drive).

So when I do either the menu File Open, or File Save (or Save As) .... I want to immediately see the Open File Dialog on the folder I desire, without indexing through many levels and drives to adjust the Dialog Box to be on the desired folder. I want one macro that once run makes all of this so.

In Microsoft Word (2002), my macro uses the FileOpenDirectory command, when I run this macro on a button ..... no matter how many documents I have open in Word, no matter which document I am currently on:
If I chose File Open, or File Save (or Save as) .... the File Dialog box that opens is right there "on my desired folder".

In Word, this is my macro:

Public Sub CHOOSEDIR4()
' PROCEDURE WRITTEN 6/29/04 by ED GROSSHEIM
ChangeFileOpenDirectory _
"C:\Documents and Settings\Ed\Application Data\Microsoft\Templates\"
End Sub

I have added a Custom Toolbar with five buttons bound to five macros similar to the one above.

==============================================================================================

Will get back, Ed
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

I think I am out of ideas !

Post by Ed Grossheim »

6/28/2007 3:20:03 PM

Sorry,

I am afraid I need another clue. I tried.

:cry: - Ed
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,

Currently Zeus does not have a way to set the file open default directory.

The Zeus FileOpen function default directory is always the last used directory.

The Zeus FileSaveAs function will always save to the directory of the currently active file and if no file is active it then uses the default directory.

The FileOpenEx function can be used to indirectly change the default directory.

For example if you use the Macros, Execute Scripts menu:

and type in FileOpen - you get the last used directory.

and type in FileOpenEx - you will get the directory of the currently active file.

If you edit the file_open.lua macro script and change this line of code:

Code: Select all

-- the starting directory
--local dir = macro_tag("$FDD")
-- use this as the file open directory
local dir = "c:\my\directory"
and then use the Macros, Execute Scripts menu and type in file_open.lua the file open dialog will open in the c:\my\directory.

You can bind this macro to the toolbar as described earlier.

Cheers Jussi
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Final Thought

Post by Ed Grossheim »

6/28/2007 9:53:51 PM
Hi Jussi

Well call me crude, but I have a work-around that is sufficient for me.

e.g. I want to change the directory to "text notes temp".
In this desired directory I placed an empty file "x.vbs"

I set a tool up under Tools/Options/Default doc type/Tools

Calling the Tool "Pick Dir Text Notes Temp"
Dos Command, Run hidden.
Arguments: zeus "C:\Documents and Settings\ED\Desktop\TEXT NOTES TEMP\x.vbs"

I run the tool, I choose the x.vbs tab click on File Save As and save it (choosing replace it if it asks).


Then File Open or File Save/or As buttons show me my Text Notes Temp Dir.

Not pretty, but good enough.


Part of my confusion is that I cannot find sufficient examples of functions being scripted to understand what I am doing.

The examples that are there are mostly in lua, and I am not very interested in grasping the idiosyncrasies of lua.

e.g. Knowing vbscript fairly well, I still can't even figure out how to use the "fileopen function" that you say is scriptable in vbs.

I would like to be able to look at ten example vbs scripts that each refered to a different scriptable function (five that referred to built in Editor functions and five that referred to Keyboard functions).

In Zeus Help, under functions it says:
"The functions listed below are built-in to the Zeus editor itself and can be used by all of the supported scripting languages. In addition to these built in functions it is also possible to script any of the Zeus

keyboard functions. "

For Zeus to be super useful to the user ....he Must understand how to script Zeus using his favorite script language. It is not enough for the user to know his favorite language, he needs to see a variety of

code block examples that paint the picture.

I learn from looking at examples (small and specific) that work if I execute them.

I would be glad to submit examples in vbs, if I could get smart enough to write test code and prove the snippets work!

If I could understand the methods of the Zeus object better, so that I could easily script all functions that are scriptable I could find better workarounds.

Thanks for your Help - Ed
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,
Arguments: zeus "C:\Documents and Settings\ED\Desktop\TEXT NOTES TEMP\x.vbs"
I can see how that will work ;)
e.g. Knowing vbscript fairly well, I still can't even figure out how to use the "fileopen function" that you say is scriptable in vbs.
Here is an example in vbs:

Code: Select all

Function key_macro()
   'set the starting directory
   directory = "d:\temp"

   'build a file filter string
   cpp_files = "C/C++ files (*.cpp;*.c;*.hpp;*.h)|*.cpp;*.c;*.hpp;*.h|"
   res_files = "RC files (*.rc;*.rh;*.dlg)|*.rc;*.rh;*.dlg|"
   txt_files = "Text Files (*.txt)|*.txt|"

   'the two argmument version of the file open dialog
   file_name = zeus.file_select_dialog( directory, cpp_files & res_files & txt_files )

   if Len(file_name) > 0  then
      zeus.file_open(file_name)
   end if
End Function

key_macro() 'run the macro
five that referred to Keyboard functions
When writing macros I always suggest letting Zeus do all the hard work ;)

For example, assuming you have configured VbScript to be the default scripting language, as a starting point all I would do is the following:
  1. Macros menu, Record Start/Stop
  2. File Menu, New
  3. Type in "This is a test macro...."
  4. Macros menu, Record Start/Stop
  5. Macros menu, View Source
What this does is create the following macro script:

Code: Select all

Function key_macro()
    call zeus.screen_update_disable
    call zeus.FileNew
    call zeus.write("This is a test macro....")
    call zeus.screen_update_enable
    call zeus.screen_update
End Function

key_macro() 'run the macro
In this example Zeus has written a macro with several calls to built-in functions (i.e screen_update, screen_update_enable, write etc) and the one call to the FileNew keyboard function.

Naturally, if you use a different set of menu and/or key strokes combinations Zeus will write you a differnet macro ;)
I would be glad to submit examples in vbs, if I could get smart enough to write test code and prove the snippets work!
The thing to remember is the built-in functions are all in lower case and are described in the built-in function section of the online help.

The camel case functions are the Zeus keyboard functions and these are listed in the Options, Editor Options menu, Keyboard Mapping panel, select a mapping to edit, hit the Edit button.

Where available, you can also view the help for a keyboard function by placing the cursor on the keyboard function text and using the Help, Quick Help Current Word menu.
If I could understand the methods of the Zeus object better
The Zeus scripting layer is different to other VbScript application interfaces in that it really does not have an object. There are just built-in functions and keyboard functions and that is it ;)

The zeus. qualifier is just needed by VbScript to let it know that you are calling one of the Zeus functions.

Cheers Jussi
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Thanks, that helped.

Post by Ed Grossheim »

6/29/2007 8:56:50 AM

I will be studying this, and trying stuff today (and tom !).

I've got the file open working, elegance may not be far away!

I see I can execute a script as a Tool or a Macro. Is there anything I could add to the script at the end to suppress the "Tool" tab window at the end?

I have a tool set to bring up (via .exe) a notepad file of "crib notes".
I bring it up, make notes, then exit. Then Zeus brings up the tool tab that I have to right click on and close.

Thanks for all the great points, and the patience.

-- your friend in Zeus, Ed
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,
Is there anything I could add to the script at the end to suppress the "Tool" tab window at the end?
If you turn off the capture standard output and standard error options in the tool this should remove the Tool window.

Cheers Jussi
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

It worked

Post by Ed Grossheim »

7/2/2007 12:25:30 PM

Thanks Jussi.
--Ed
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The latest Zeus patch provides a way to set the working directory:
bool set_default_directory(directory)

Set the default directory. The default directory is used by the file open dialog.

The latest Zeus 3.96i patch can be found here: http://www.zeusedit.com/forum/viewtopic.php?t=1231

Cheers Jussi
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Wow !!! I just can't believe the SERIOUS Support for Zeus

Post by Ed Grossheim »

8/7/2007 7:26:34 PM

Ok I have downloaded the patch, but I will give serious attention to this in the week ahead.

I was coping fine with macros like:

Code: Select all

Function key_macro() 
   directory = "C:\Program Files\Zeus\zScript" 
   file_name = zeus.file_select_dialog(directory) 

   'I have no idea why these three lines are important, but without it I have trouble opening this file! 
   if Len(file_name) > 0  then   
      zeus.file_open(file_name) 
   end if 
 
End Function

But I had about one dozen macros like this in my drop-down macro menu!!!

This will be a valuable addition to a terrific Script Editor.

I have been putting Zeus to some extreme use, and have been very happy with it. :D :mrgreen:

Applause and Cheers :) to Jussi - Ed
[/color]
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,

I'm glad to read Zeus is working for you :)

Code: Select all

   'I have no idea why these three lines are important, but without it I have trouble opening this file! 
   if Len(file_name) > 0  then   
      zeus.file_open(file_name) 
   end if 

Why you need these three lines is the file_select_dialog function only returns the name of the file as selected by the user.

But if the user hits the cancel button then a string of length zero is returned.

So these three lines basically read if the user did not hit cancel, open the file selected by the user ;)

Cheers Jussi
Post Reply