Index of Functions ------------------ 1: ScriptEditRestore Function Name ( 1): ScriptEditRestore -------------------------------------------------------------------------------- 'Date Created: 14-Apr-2006 10:49:54 AM 'Last Updated: 02-Jun-2006 07:56:30 PM 'Created By : Ira J. Perlow 'Updated By : Ira J. Perlow FUNCTION ScriptEditRestore AS C (Flag=" " as C) 'DESCRIPTION: Restores the script editor after a restart of the database '====================================================================== ' Created by Computer Systems Design & Associates, Ira J. Perlow ' Copyright 2006 Computer Systems Design & Associates, All Rights Reserved ' You may use this code at your own risk in whole or as a part. ' Use in full or part is permitted with proper attributions to the ' source, except it may not be sold as part of any software package. '====================================================================== ' Version History: ' 06/02/2006 Changed code to save current scripts on can exit ' Stopped redundant event creation, ' Fixed bug with no scripts opened ' 05/30/2006 Fixed timing of database exit event to save current scripts ' 05/21/2006 Improved timing a bit for restart and close of A5 ' 05/18/2006 Code Editor tab being edited is now the last script restored ' (i.e. the selected code editor tab) and cursor is placed ' in the same location before restart ' 05/12/2006 Add Controlpanel show in case it's not showing ' 05/11/2006 Added auto-creation of "___" script, eliminated need for ' autoexec script modification ' 04/16/2006 Initial version '====================================================================== ' Installation: ' To import the script import format and install it properly ' 1. Go to the A5 Control Panel ' 2. Select the Code tab ' 3. Right-click in a blank area of the panel and select import ' 4. Select the script import file "CSDA_A5_ScriptEditRestore.txt" ' 5. To install the "___" script for the 1st time, go to the Interactive window and type ' ScriptEditRestore() followed by enter ' The "___" will automatically be created IF it does not exist ' (Warning!!! Any script of the same name will be overwritten, so change it 1st if this is a concern) ' This newest version requires no changes to the AUTOEXEC global script. ' Remove any previous code in AUTOEXEC that calls ScriptEditRestore(). It will not cause any problem if not deleted, though. '====================================================================== ' Using the scripts: ' To use the code ' 1. Double-click on "___" script. This will save scripts being edited, close A5 and reopen A5, and reopen scripts for editing ' 2. Close A5 (scripts will be remembered if this code has been executed). You can activate A5 with a Windows shortcut that has a target line similar to: ' "C:\Program Files\A5V7\alpha5.exe" "C:\Program Files\A5V7\databasename.adb" -COMMAND="scripteditrestore()" ' 3. To remember scripts and just close A5, you can execute ScriptEditRestore("2"). If the scripts have been previously remembered (by a previous "___" script execution), then just close A5. '====================================================================== ' Purpose: Saves a list of all scripts currently be edited, Closes A5, ' then restarts with the same scripts open for edit ' This saves a lot of time when you have to close A5 ' and restart to eliminate a problem. This happens with open ' files, DECLARESTRUCT, certain errors, crashes, etc. ' Input: Flag = If not null, then saves all scripts being edited in ' file databasename.aed in database path ' If null, then restores all database files ' Default is blank and leaves AED file ' Output: List of Script or UDF's being edited, ' and file "databasename.aed" with the same text ' Errors: ' Typical Usage: ' Example: ' ScriptEditRestore() ' Restores all scripts, leaves ".aed" file ' ScriptEditRestore("") ' Restores all scripts, deletes ".aed" file ' ScriptEditRestore(" ") ' Restores all scripts, leaves ".aed" file ' ScriptEditRestore("1") ' Remember all scripts being edited, ' close A5, restart and restore scripts ' being edited ' ScriptEditRestore("2") ' Remember all scripts being edited ' and close A5 (don't restart) ' ScriptEditRestore("3") ' Remember all scripts being edited ' Notes: ' databasename.AED file contains list of current scripts being edited. ' This script creates a script that can be just double clicked in the ' code window that will execute to save scripts being edited and reload ' A5 process. It will be named "___" to make it appear at the top ' of the code list when in alphabetical order. It will have 1 line ' of active code in it that looks like this ' ScriptEditRestore("1") ' Save script names being edited & reloads A5 ' To start A5 with a shortcut to the database (adb file) and restore ' the previously saved script names, create a shortcut with a "Target:" ' line similar to: ' "C:\Program Files\A5V7\alpha5.exe" "C:\Program Files\A5V7\databasename.adb" -COMMAND="scripteditrestore()" ' Also, if scripts are not saved, the A5 window will not close as the ' new one starts to open, which will error out. ' Just close the 2nd window, and then save the scripts in the 1st one. ' If any of the scripts require a password, it will prompt you ' without telling you which script the password is needed for. ' Look at the bottom status bar for the name '====================================================================== ' This is the EXE that starts Alpha 5 (without a path which is ' determined automatically). If different, you must change this A5exe="Alpha5.exe" ' Get name of file containing script list aednam=file.filename_parse(IF(a5.Get_Master_Name()=="",A5.Get_Name(),a5.Get_Master_Name()),"DPN")+".aed" ' If flag is blank or null IF UT(flag)=="" ' Restore scripts being edited scpedit="" ' See if file with list of scripts being edited exists IF file.exists(aednam) ' Get list of scripts previously being edited scpedit=Alltrim(get_from_file(aednam)) ' If flag is null, then delete, otherwise, leave last scripts edited file IF len(Flag)=0 file.remove(aednam) END IF ' Restore if list is not empty IF .not.(scpedit=="") for i=3 to line_count(scpedit) scpnam=alltrim(word(word(scpedit,i,crlf()),1,"|")) IF RIGHT(scpnam,2)=="()" scpnam=LEFT(scpnam,LEN(scpnam)-2) statusbar.set_text("Opening UDF: "+scpnam) udf_design(scpnam) ELSE statusbar.set_text("Opening Script: "+scpnam) script_design(scpnam) END IF next i scpnam=alltrim(word(word(scpedit,2,crlf()),1,"|")) IF RIGHT(scpnam,2)=="()" scpnam=LEFT(scpnam,LEN(scpnam)-2) statusbar.set_text("Opening UDF: "+scpnam) udf_design(scpnam) ELSE statusbar.set_text("Opening Script: "+scpnam) script_design(scpnam) END IF ' Restore cursor to last script opened. If Interactive Window, ' then cursor will be left at 0 ptr=obj("CODEEDITOR") p=a5_get_ptr_to_code_ed(ptr) ' Restore cursor curpos=Val(alltrim(word(word(scpedit,1,crlf()),1,"|"))) if curpos>0 p.Set_Cursor() END IF end if ' Show Control Panel in case autoexec hid it. If form hid it ' we are out of luck ControlPanel.show() END IF statusbar.set_text("") ' Return list of scripts being saved ScriptEditRestore=scpedit DIM aiv as P aiv=addin.variables() DIM aiv.ScriptEditEvent as C ' If not set up, then install event IF aiv.ScriptEditEvent=="" ' Setup to restore scripts as we go from 1 database to another y=on_database_init("y=ScriptEditRestore()") aiv.ScriptEditEvent="1" END IF ' Always set this event up as it is cleared after executing ' Setup to save current scripts when we leave a database ' Assigning ScriptEditRestore to a variable makes sure it complete y=can_database_exit("y=ScriptEditRestore(\"3\")") ' Get list of scripts scplist=CRLF()+:A5.SCRIPT_ENUM(2)+CRLF() ' IF "___" is not a script, then create it IF .not.((crlf()+"___"+crlf()) $ scplist) scpcod=<<%code% ' This is a script that can be just double clicked in the code window ' that will execute the save scripts being edited and reload A5 process. ' It is named "___" to make it appear at the top of the code list when ' in alphabetical order ScriptEditRestore("1") %code% ' save script for later use script_save("___",scpcod) ' Refresh control panel so new script shows up ControlPanel.Refresh() END IF ELSE IF VAL(UT(flag))>=1 ' Get list of scripts being edited scpedit=a5_what_being_edited() ' Check flag to see if we already set event DIM aiv as P aiv=addin.variables() DIM aiv.ScriptEditEvent as C IF aiv.ScriptEditEvent=="" ' Setup to restore scripts as we go from 1 database to another y=on_database_init("y=ScriptEditRestore()") ' Setup to save current scripts when we leave a database ' Assigning ScriptEditRestore to a variable makes sure it completes y=can_database_exit("y=ScriptEditRestore(\"3\")") aiv.ScriptEditEvent="1" END IF ' If there are scripts to save, otherwise leave last one IF .not.(trim(scpedit)=="") ' Get cursor of current window and put at beginning of file ptr=obj("CODEEDITOR") p=a5_get_ptr_to_code_ed(ptr) error_flag=0 on error goto error_handler curpos=p.get_cursor() on error goto 0 IF error_flag=1 curpos=0 END IF scpedit=LTRIM(STR(curpos))+CRLF()+scpedit dim global ScriptEditLast as C IF .not.(ScriptEditLast==scpedit) ' Save to file in current database directory if list has changed yl=save_to_file(scpedit,aednam) ScriptEditLast=scpedit END IF END IF END IF IF VAL(UT(flag))=1 ScriptEditRestore="" ' Compute command line to restart A5 cmdline=chr(34)+:A5.GET_EXE_PATH()+chr(92)+A5exe+chr(34)+" "\ +chr(34)+IF(a5.Get_Master_Name()=="",A5.Get_Name(),a5.Get_Master_Name())+chr(34)\ +" -COMMAND=\"scripteditrestore()\"" ' Start command line shell. ' This may be timing sensitive and may start before the A5.close() ' causing Alpha to think that 2 copies are running of same database SYS_SHELL(cmdline) ' Close A5 a5.close() EXIT FUNCTION ELSE IF VAL(UT(flag))=2 ' Close A5 a5.close() EXIT FUNCTION END IF END IF EXIT FUNCTION '============================ error_handler: error_flag=1 resume NEXT EXIT FUNCTION END FUNCTION End Function ( 1)---------------------------------------------------------------