Actually, if one can live with the restriction of selecting text on a
single line, as opposed to a rectangle, this is not too hard.  At the end
of this message, I will paste some script code that is a good start on
this.

If you need to define a rectangle, things get a bit more complicated
because you have to decide what happens to words that cross the right and
left boundaries.

The CopyToClipboard function, according to the description in the script
manager, only grabs text which is selected.

The following fragment of script code makes use of the GetTextBetween and
TypeString functions in manipulating a global string called clipboard.
Maybe some of you scripters can help improve this code and we can get
Joe, Sean and company to include it in future versions of the default
scripts.

Those of you who are not comfortable with scripting should probably leave
this alone for now.  Wiring it in to your default scripts involves
several steps and, at the moment, might cause you more frustration than
you would like.  If you do choose to boldly go forth, however, please
remember to save your default files, all of them including jss jsd jkm
etc before you start editing them.

If you are not interested in scripting, you will want to ignore the rest
of this message.


The following code uses a menu.  You need to attach a key to the
ClipboardManager function to start the process.  You would probably also
want to attach hot keys to the second level functions so you don't have
to go through the menu.  Besides, I think there is a problem in
activating the jaws dialog when you are in the menu of your application
and hot keys may help there.

This code will only work for text which is all on a single line on the
screen.  Yes, I know it does not use message constants and is only in
english.  But, that can be adapted later if this catches fire.


The following operations are supported:
  - set left marker
  - set right marker
  - route cursor to left marker (incase you forgot where it was and
wanted to change it)
  - route cursor to right marker (change it by just setting it again)
  - copy selection to clipboard (clears previous text)
   - append selection to clipboard (add to existing text)
  - paste from clipboard
  - speak clipboard.

There is also code here to specify a delimiter, but it does not currently
work because the dialog for doing so does not activate.  This is probably
due to the famous jfw bug regarding the DLGSelectItemInList function.
Maybe there is another way of doing this.

Have great fun and remember to post your improvements.

Happy Scripting,

Jim Snowbarger


*********



include "hjconst.jsh"
include "hjglobal.jsh"

globals
  int LeftX,     ; these are cursor locations of the markers
  int LeftY,
  int RightX,
  int RightY,
  string delimiter,      ; between appends
  string clipboard     ; the big collecter

; The main menu top level script
Script ClipboardManager ()
var
  string p,
  string BoxTitle,
  int selection

if (GetVerbosity () == BEGINNER) THEN
SayString ("clipboard manager")
SayString ("use up and down arrow to select from the following hot keys")
SayString ("then press enter to select or escape to cancel")
Let BoxTitle = " "      ; blank title
else
Let BoxTitle = "Clipboard"
endif

; Build the menu
Let p = "a = add to clipboard|"
Let p=p+"c = copy to clipboard|"
Let p=p+"d = choose delimiter|"
Let p=p+"g = go to left end of selection|"
Let p=p+"h = go to right end of selection|"
Let p=p+"l = set left end marker|"
Let p=p+"r = set right end marker|"
Let p=p+"s = speak clipboard|"
Let p=p+"p = paste from clipboard"

; get a selection from the user
Let selection =DlgSelectItemInList (p, BoxTitle, FALSE)
pause ()  ; let the dialog box disappear

; decode the selection
if (selection == 1) then
  append ()
elif (selection == 2) then
  CopyTo ()
elif (selection == 3) then
  ChooseDelimiter ()
elif (selection == 4) then
  GoToLeft ()
elif (selection == 5) then
  GoToRight ()
elif (selection == 6) then
  SetLeft ()
elif (selection == 7) then
  SetRight ()
elif (selection == 8) then
  SpeakClipboard ()
elif (selection == 9) then
  PasteFrom ()
endif
EndScript


Int Function SelectionIsValid ()
if (( LeftX != 0) && (RightX != 0) && (RightX > LeftX)) then
  return (1)  ; it is valid
endif
return (0)
EndFunction

Void Function GoToLeft ()
if (LeftX != 0) then  ; marker set
  MoveTo (LeftX, LeftY)
  return
endif
SayString ("the left end is not marked")
EndFunction

Void Function GoToRight ()
if (RightX != 0) then
  MoveTo  (RightX, RightY)
  return
endif
SayString ("the right end is not marked")
EndFunction


Function clear ()
Let clipboard = ""    ; blank
Let LeftX = 0
Let RightX = 0
EndFunction

Function SetLeft ()
Let LeftX = GetCursorCol ()
Let LeftY = GetCursorRow ()
EndFunction

Function SetRight ()
Let RightX = GetCursorCol ()
Let RightY = GetCursorRow ()
EndFunction

Function CopyTo ()
If (SelectionIsValid ()) then
  Let clipboard = GetTextBetween (LeftX, RightX)
  Let LeftX = 0   ; clear the clipboard markers
  Let RightX = 0
  return
endif
SayString ("nothing selected")
EndFunction


Void Function append ()
If (SelectionIsValid ()) then
  Let clipboard = clipboard + delimiter
  Let clipboard = clipboard + GetTextBetween (LeftX, RightX)
  Let LeftX = 0   ;clear the marks
  Let RightX = 0
  return
endif
SayString ("nothing selected")
EndFunction

Void Function PasteFrom ()
TypeString (clipboard)
EndFunction


Void Function SpeakClipboard ()
SayString (clipboard)
EndFunction

Void Function ChooseDelimiter ()
var
  string p,
  string BoxTitle,
  int selection
;  this function does not currently work because the dialog is not presented
Let BoxTitle = "choose the delimiter"

Let p= "space|comma|enter"
pause ()
Let selection =DlgSelectItemInList (p, BoxTitle, FALSE)

if (selection == 1) then
  Let delimiter = " "
elif (selection == 2) then
  Let delimiter = ","
elif (selection == 3) then
  Let delimiter = "\10"     ;a line feed
endif
EndFunction

*** end of file
-
Visit the jfw ml web page: http://yoyo.cc.monash.edu.au/~nallan/jfw

Reply via email to