EDALLBTN

Synopsis
EDALLBTN
Description

Opens all definitions in the workspace in the editor, just like EDALL.

EDALLBTN is a library procedure that exists to enable you to change what happens when you press the Commander's Edall Button. By redefining it, you can make the Edall Button open the workspace in an external editor, change it to open a specific file, or replace the workspace editor with your own user interface created with WINDOWCREATE.

Example

The following example shows how to change the Edall button to open a specific file instead of the entire workspace.

TO EDITFILE
  ; EDITFILE is a simple procedure for editing (and re-editing)
  ; an external file using FMSLogo's editor.

  ; See if the file to edit already been designated.
  IF NOT NAMEP "editfile.filetoedit [
    ; The file to edit has not been designated.
    ; As the user to select one.
    ;
    ; Note that we use a "save" variant of the file picker
    ; to be able to select a file that doesn't exist.
    MAKE "editfile.filetoedit DIALOGFILESAVE "*.lgo
    IF EQUALP [] :editfile.filetoedit [
      ; The user cancelled the selection.
      ERASE NAMELIST "editfile.filetoedit
      STOP
    ]

    ; Bury the filename so that it doesn't pollute the workspace.
    BURY NAMELIST "editfile.filetoedit
  ]

  ; If an editor is already open for this file, then
  ; activate it and give it focus.
  WINDOWSET :editfile.filetoedit 9
  SETFOCUS  :editfile.filetoedit

  IF NOTEQUALP GETFOCUS :editfile.filetoedit [
    ; No editor session for this file was found.
    ; Open the file in the FMSLogo editor.

    ; When the file is saved, LOAD it into the workspace.
    ;
    ; If we used [ LOAD :editfile.filetoedit ], the file might
    ; fail to load if :editfile.filetoedit were erased
    ; or modified while the editor was open.  Therefore, we
    ; create an instruction list that has the value of
    ; :editfile.filetoedit as a word literal, instead of the
    ; relying on the variable's name.
    ;
    ; Unfortunately, file names may contain special characters
    ; which must be backslashed to be preserved.  The MAP adds a
    ; backslash to any character which needs it, as described in
    ; the documentation of BACKSLAHEDP.  QUOTED creates the word
    ; literal.
    ;
    WINDOWFILEEDIT :editfile.filetoedit (LIST
      "LOAD
      QUOTED MAP [
         IFELSE MEMBERP ? "|	 \n()[]{}\|+-*/=<>":;\\~?| [
           WORD "\\ ?
         ][
           ?
         ]
      ] :editfile.filetoedit)
  ]
END

TO EDITNEWFILE
  ; EDITNEWFILE is like EDITFILE, except that it always prompts
  ; for the file to edit.  EDITFILE will subsequently open the
  ; newly selected file each time it's run without prompting.
  ;
  ; EDITDIFFERENTFILE would be a better name, since the file isn't
  ; created, but that's harder to type.

  ERASE NAMELIST "editfile.filetoedit
  EDITFILE
END


TO EDALLBTN
  ; When using EDITFILE to open a file, EDALL has confusing behavior
  ; because it doesn't save the changes back to the file and includes things
  ; in the workspace which don't come from the file.  To avoid accidentally
  ; editing the workspace, redefine the Edall button to use EDITFILE.
  EDITFILE
END

The next example shows how to change the Edall button to show a simple procedure picker.

TO EDALLBTN
  ; Override the "Edall" button with a procedure picker.

  WINDOWCREATE   "main "procedurepicker [Select a procedure] 200 200 230 255 []
  COMBOBOXCREATE "procedurepicker "procedurepicker.proclist 2 2 180 240

  BUTTONCREATE   "procedurepicker "procedurepicker.edit    [Edit]      184   2 40 18 [
    IF NOT EMPTYP COMBOBOXGETTEXT "procedurepicker.proclist [
      EDIT COMBOBOXGETTEXT "procedurepicker.proclist WINDOWDELETE "procedurepicker
    ]
  ]

  BUTTONCREATE   "procedurepicker "procedurepicker.editall [Edit All]  184  22 40 18 [
    EDIT PROCEDURES WINDOWDELETE "procedurepicker
  ]

  BUTTONCREATE   "procedurepicker "procedurepicker.cancel  [Cancel]    184 220 40 18 [
    WINDOWDELETE "procedurepicker
  ]

  ; Populate the listbox with the name of all procedures.
  FOREACH PROCEDURES [ COMBOBOXADDSTRING "procedurepicker.proclist ? ]
  COMBOBOXSETTEXT "procedurepicker.proclist [] ; clear selection
END
BURY "EDALLBTN

The last example shows how to change the Edall button to open the workspace in an external editor. In this case it uses Microsoft Wordpad, which is among the worst possible choices for editing Logo programs.

TO GETTEMPPATH
  ; Calls the win32 function GetTempPathW.
  ; Outputs the temporary path as a word.
  ; Outputs [] on error.

  LOCAL [rval temppath size buffer codepoint]

  DLLLOAD "kernel32.dll

  MAKE "rval (DLLCALL [L GetTempPathW B 261 L 261] "kernel32.dll)
  IFELSE EQUALP 0 ITEM 1 :rval [
    MAKE "temppath [] ; error
  ][
    ; Convert from WCHAR* to a Logo word.
    MAKE "size   ITEM 1 :rval
    MAKE "buffer ITEM 2 :rval

    MAKE "temppath "||
    REPEAT :size [
      ; Determine the code point of the REPCOUNTth character.
      MAKE "codepoint (SUM
        ASCII ITEM (2*REPCOUNT-1) :buffer         ; low byte comes first
        LSHIFT ASCII ITEM (2*REPCOUNT) :buffer 8) ; high byte comes second

      ; Append the REPCOUNTth character to the value.
      MAKE "temppath WORD :temppath CHAR :codepoint
    ]
  ]

  (DLLFREE "kernel32.dll)
  OUTPUT :temppath
END
BURY "GETTEMPPATH

TO EDALLBTN
  LOCALMAKE "editor "|C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe|
  LOCALMAKE "file   WORD GETTEMPPATH "\\tmp.lgo

  BURY [[] [editor file]] ; hide local variables from SAVE
  SAVE :file

  FOREVER [
    IF NOT (SHELL (LIST (WORD "" :editor "") (WORD "" :file "") ) "TRUE) [
      ; The program returned an error code.
      ERASEFILE :file
      STOP
    ]

    ; Try to load the new file.
    CATCH "ERROR [ LOAD :file ]
    LOCALMAKE "error ERROR
    IF EQUALP :error [] [
      ; Successfully loaded the new file.
      ERASEFILE :file
      STOP
    ]

    PRINT [There was an error in the file:]
    PRINT ITEM 2 :error
    PRINT (SENTENCE [On the line:] ITEM 4 :error)
  ]
END
BURY "EDALLBTN


SourceForge.net Logo