REVO7000 pbh_Script_Buddy3 P local sUndoArray,sUndoIndex,sIndex function getIndex # The index Marker for the Undo System return sIndex end getIndex command setIndex pPoint if pPoint is empty then put 1 into pPoint add pPoint to sIndex end setIndex d ^ PBH Script Buddy W (Message) W (Message),unicode U (Text) U (Text),unicode cLastAmend ]Add support for Undo/Redo Add prefs and info cards. Add Search and Replace. Add Script Vault. cDefaultFolder /Users/paulhibbert/Desktop cInfo Script Buddy v1.0.6 by Paul Hibbert Last Update: 15 June 2020 Script Buddy was written following an idea based on a request posted on the LC User List. The idea is to have a second window open to edit the LC script, well this isn't the perfect answer, but it could prove useful to some. I've added a few extra ideas like being able to save and print the Script Buddy text. Toolbar Icons from left to right: Cut - Cuts the selected text, if no selection it cuts the whole field. Copy - Copies the selected text, if no selection it copies the whole field. Paste - Simply pastes the clipboard text. Clear - Clears the selected text, if no selection it clears the whole field. Import - Imports the script text from the currently active tab in the LC IDE Script Editor. Export - Imports the Script Buddy text back to the currently active tab in the LC IDE Script Editor. Note: The export doesn't update the IDE SE field, so you will need to manually update the field by typing a space or pressing the tab bar then click the 'Apply' button. Save - Allows you to save the Script Buddy text to a text file, an RTF text file or a HTML file for future reference. Print - Allows you to easily print the Script Buddy text (or save to PDF on a Mac). Info - Just a little info about Script Buddy. Settings - Currently this just toggles the stack between 'Palette' and 'TopStack'. What it will do: 1. Give you a second window to work on your script. 2. Allow you to cut, copy, paste and clear text. 3. Colour your text just like LC. 4. Swap your script text back and forth between the IDE Script Editor and Script Buddy. 5. Save your script to plain text, rtf text or HTML file. 6. Print your script. What it won't do: 1. Format your script with indents just like the IDE SE. 2. Compile your scripts, you will need to do that manually. 3. Automatically update the IDE SE - I don't see the point in that, but it could be done. 4. Run or debug your scripts. 5. It doesn't use the strict compilation mode, variable checking or any of the other niceties of the IDE SE. 6. Make the coffee! Can Script Buddy be extended? Hell yes! I have quite a few more ideas to work on, this was just one day's work, most of that was testing! Contact paul@livecode.org with any requests or ideas (Please add Script Buddy to the subject). Script Buddy ©2020 P. B. Hibbert. Portions ©2000-2020 LiveCode Ltd. All rights reserved worldwide. cColorize true cWarnings true cUndoA cVersion 1.0.6.0 cRedoA cCopyright '(C)2020 P. B. Hibbert paul@livecode.org cComment true cRevOnline id 793 cRevStandaloneSettings ) cursors false Windows,productversion1 1 askDialog true OSX,copyright 4(C)2015 P. B. Hibbert. All rights reserved worldwide MacOS,longVersion Script Buddy 1.0.0.0 Windows,ProductName Script Buddy Windows,productversion3 0 scriptLibraries Internet Geometry Printing UNIX,fileSelector true OSX,identifier com.pbh.scriptbuddy Windows,fileversion4 0 inclusions search Windows,documenticonFile m/Applications/LiveCode Indy 7.1.app/Contents/Tools/Runtime/Windows/x86-32/Support/Sample Icons/genericdoc.ico OSX,shortVersion 1.0.2.1 OSX,documentExtension name Script Buddy MacOS,documentType OSX,name Script Buddy MacOSX x86-32 true Windows,fileversion2 0 Windows true Linux true Windows,FileDescription Script Buddy 1.0.0.0 for Windows Windows,productversion2 0 UNIX,pageSetup true MacOS,creator ???? OSX,signature ???? OSX,info Script Buddy Version 1.0.2.1 Windows,productversion4 0 Windows,companyname Windows,fileversion1 1 OSX,documentType Windows,fileversion3 0 UNIX,colorChooser true UNIX,printerChooser true answerDialog true Windows,copyright #2015 All rights reserved worldwide Windows,iconFile m/Applications/LiveCode Indy 7.1.app/Contents/Tools/Runtime/Windows/x86-32/Support/Sample Icons/genericapp.ico MacOS,shortVersion 1.0.2.1 Windows,LegalCopyright #2015 All rights reserved worldwide OSX,longVersion Script Buddy 1.0.2.1 cREVLoadInfo revPreOpenStack false revPreOpenCard false cREVGeneral breakpoints breakpointstates debugEntryHandler M,updateLineCount scripteditorselection 230 breakpointconditions scripteditorvscroll debugParameters stackfileversion 7.0 scalefactor ? cREVGeometryCache stackID Script Buddy card 1 Pon openStack palette this stack end openStack on resizeStack updateLineCount set the vScroll of fld "lineNumbers_F" to the vScroll of fld "script_F" pass resizeStack end resizeStack command updateLineCount lock screen set the textSize of fld "lineNumbers_F" to the textSize of fld "script_F" set the textHeight of fld "lineNumbers_F" to the textHeight of fld "script_F" put max(round(the formattedHeight of fld "script_F"/the textHeight of fld "script_F"),(the number of lines in fld "script_F")) into tLineCount repeat with x = 1 to tLineCount put x & cr after tLineNumbers end repeat put line 1 to -1 of tLineNumbers into fld "lineNumbers_F" set the vScroll of fld "lineNumbers_F" to the vScroll of fld "script_F" unlock screen end updateLineCount global gUndoA,gUndoIndex,gIndex on doAction pAction --~~~~~~~~~~~~~~~ PART 1 - Check the index - Remove any unwanted Undo steps ~~~~~~~~~~~~~~~~~-- if gIndex is empty or gIndex < 1 then put 1 into gIndex if gUndoIndex is empty or gUndoIndex < 1 then put 1 into gUndoIndex put keys(gUndoA) into tKeys -- Find the highest available key of the array by recalling the keys then… replace return with comma in tKeys -- ...turn the keys into a list if max(tKeys) > gIndex then -- Check if there are any Keys higher than the current Index put max(tKeys) into tToDelete -- The highest available Key repeat with x = tToDelete down to (gIndex +1) -- Delete unwanted global entries delete global gUndoA[x] ##set the backgroundColor of grc x to empty -- FEEDBACK ONLY! - Just to show it's removed from the queue end repeat end if --Recort this point put the properties of fld "script_F" into gUndoA[gIndex]["script_F"] -- Adds this point to the Undo Array before the new action put fld "tab_L" into gUndoA[gIndex]["tab_L"] -- Adds this fld to the Undo Array before the new action --~~~~~~~~~~~ END PART 1 ~~~~~~~~~~~~~~~~~ switch pAction case "cut_B" send "processAction" to control pAction break default send "processAction" to control pAction end switch --~~~~~~~~~~~~~~~ PART 2 ~~~~~~~~~~~~~~~~~-- -- Then update the index put gIndex into gUndoIndex -- Record Prev Index add 1 to gIndex -- Update the UndoIndex put gIndex - fld "undoLimit_F" of stack "SB_Prefs" into tLower -- Delete any undo outside the range of the Undo Limit if min(tKeys) < tLower then -- Check if there are any Keys below the (Index - Limit) put min(tKeys) into tToDelete -- The Lowest available Key repeat with x = tToDelete to (tLower -1) -- Delete unwanted global entries delete global gUndoA[x] end repeat end if --~~~~~~~~~~~ END PART 2 ~~~~~~~~~~~~~~~~~-- focus on nothing end doAction --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- -- UNDO UNDO UNDO on undoAction --Record this point if not already recorded put keys(gUndoA) into tKeys -- Find the highest available Index replace return with comma in tKeys -- Turn tKeys into a list put min(tKeys) into tLastUndo -- Find the Lowest value if gIndex = tLastUndo then -- We have reached the last undo available answer "No Undos left!" -- Feedback exit undoAction -- Leave the script end if --~~~ Store the properties at the current state because they are not already stored. i.e. This is the first Undo ~~~-- if max(tKeys) < gIndex then -- Compare Highest available Index with the Current Index put the properties of fld "script_F" into gUndoA[gIndex]["script_F"] -- If the Current Index is Higher than the Available Index, store props put fld "tab_L" into gUndoA[gIndex]["tab_L"] -- Adds this fld to the Undo Array before the new action end if --~~~ Store the properties at the current state because they are not already stored. i.e. This is the first Undo ~~~-- --Undo the last action put gUndoIndex into gIndex -- Reads the undo Index set the properties of fld "script_F" to gUndoA[gIndex]["script_F"] set the text of fld "tab_L" to gUndoA[gIndex]["tab_L"] --~~~~~~~~~~~~~~~ Update the index ~~~~~~~~~~~~~~~~~-- put max(1,gIndex) into gIndex -- Limited to lowest value of "1" so no zeros or negative numbers put max(1,(gIndex-1)) into gUndoIndex -- Limited to lowest value of "1" so no zeros or negative numbers focus on nothing end undoAction --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- # REDO REDO REDO on redoAction --~~~~~~~~~~~~~~~ Read the array to find the last action (=the highest Key of gUndoA) ~~~~~~~~~~~~~~~~~-- put keys(gUndoA) into tMax -- Read the Keys into a var replace return with comma in tMax -- Change the Keys in the var into a list put max(tMax) into tLast -- Put the highest Key value into a var --Redo the last action put gIndex + 1 into tRedo -- Moves forward in the Undo queue if tRedo <= tLast then -- tLast is the highest array key so we still have some Redos to go --~~~~~~~~~~~~~~~ Now we can recall the properties and update the state of the controls ~~~~~~~~~~~~~~~~~-- set the properties of fld "script_F" to gUndoA[tRedo]["script_F"] -- SIMULATION -- Feedback to the small square indicators set the text of fld "tab_L" to gUndoA[tRedo]["tab_L"] -- Sample edit //// set the backgroundColor of grc "displayGrc" to the backgroundColor of grc tRedo -- Feedback -- This is where we restore the state --~~~~~~~~~~~~~~~ Update the index ~~~~~~~~~~~~~~~~~-- put tRedo into gIndex -- Updates the index with the current position put tRedo - 1 into gUndoIndex -- Ensures the next Undo is 1 less than the Index else answer "No Redo's left!" -- Just for feedback end if focus on nothing end redoAction : cSelectedText cSelectedChunk char 48 to 47 of field 3 cREVGeometryCacheIDs % 1443382831359 1444261682370 1443478762011 1443379704018 1443379704021 1443379704017 1443317093220 1443478652542 1443383309706 1443322694499 1445999350847 1443383310225 1443379631229 1443383310157 1444068962043 1443379704019 1443382831303 1444270969398 1443382831323 1444069018151 1443833031941 1443383309209 1443379704020 1443382831341 1443476431306 1443478652489 1443383198049 1443323128111 1443382831375 1445999928485 1443382831228 1443382831391 1443382831235 1444099886592 1445999928490 1443382831297 1443379631230 cREVGeneral scripteditorvscroll scripteditorselection 83 cREVGeometrycache total % order *1443322694499 1443323128111 1443833031941 tab_L {{{{{{ r x cREVTable currentview
Tab
cREVGeneral revUniqueID 1443317093220 scripteditorvscroll 0 scripteditorselection 0 Tab ' scriptField_Gi# For undo: # Need to know the target - Only fld script_F # The target's current state - Probably just record each word, so trigger on space or return # The change to be applied - Keystrokes!!! Delete/Cut/Paste/Import # Any changes to the app view - The selectedChunk/selectedText on textChanged put word 2 of the selectedLine into tLine if the cColorize of stack "pbh_Script_Buddy" then scriptColorize "line",tLine updateLineCount end textChanged on tabKey if the cColorize of stack "pbh_Script_Buddy" then scriptColorize "script_F" updateLineCount end tabKey ## This command is taken directly from the LC IDE Script Editor ## Therefore, copyright of this portion belongs to LiveCode Ltd. command scriptColorize pOption, pValue if pOption is "line" and pValue is not empty then try _internal script colorize line pValue to pValue of field "Script_F" of me end try else if pOption is "script_F" then try _internal script colorize char 1 to (the number of chars of field "Script_F" of me) of field "Script_F" of me end try else exit scriptColorize end if end scriptColorize . ~ cREVGeometry Master,scalerightDistance ? Master,expectedRect 0,46,670,299 Master,scaleRightObjectSide Right Master,scaleBottomObjectRef card Master,scalebottomDistance Master,scaleRightObjectRef card Master,scaleBottomAbsolute Master,scaleBottomObjectSide Bottom Master,scaleBottom Master,scaleRight Master Master,cardRanking @ Master,scaleRightAbsolute cREVGeneral revUniqueID 1443322694499 scripteditorvscroll scripteditorselection 287 lineNumbers_FH . # P cREVGeometry Master,scalerightDistance Master,movevDistance false Master,expectedRect 0,42,35,362 Master,scaleleftDistance Master,scaletopDistance Master,movehDistance false Master,scaleBottomObjectRef card Master,scalebottomDistance ( Master,scaleBottomAbsolute true Master,scaleBottomObjectSide Bottom Master,scaleBottom true Master true Master,cardRanking 1 cREVGeneral revUniqueID 1443833031941 scripteditorvscroll 0 scripteditorselection 0 1 ' 2 ' script_F )X local tText local sSelectedChunk,sSelectedText on textChanged put word 4 to -1 of the selectedChunk into tUndoTypingA if the number of lines in me <> the number of lines in fld "lineNumbers_F" then updateLineCount end if pass textChanged -- To the group end textChanged on scrollbarDrag pScroll set the vScroll of fld "lineNumbers_F" to the vScroll of me end scrollbarDrag on mouseDown pBtn if pBtn = 3 then lock screen set the cSelectedChunk of card "Script Buddy card 1" to the selectedChunk set the cSelectedText of card "Script Buddy card 1" to the selectedText popup btn "Script_F PopUp Menu" unlock screen end if end mouseDown on selectionChanged set the cSelectedChunk of card "Script Buddy card 1" to the selectedChunk set the cSelectedText of card "Script Buddy card 1" to the selectedText end selectionChanged # .n > cREVGeneral revUniqueID 1443323128111 scripteditorvscroll scripteditorselection 916 cREVGeometry Master,movevDistance false Master,scalerightDistance ? Master,expectedRect 0,25,400,401 Master,scaleleftDistance Master,scaleRightObjectSide Right Master,scaletopDistance Master,movehDistance false Master,scaleBottomObjectRef card Master,scalebottomDistance Master,scaleRightObjectRef card Master,scaleRight true Master true Master,scaleBottom true Master,scaleBottomAbsolute true Master,scaleBottomObjectSide Bottom Master,cardRanking 2 Master,scaleRightAbsolute true ' ` . a # c buttons_Gh { cREVGeneral revUniqueID 1443379631229 copy_BbcW# For undo: # Need to know the target - The clipBoard # The target's current state - Whatever is on the clipBoard # The data to be applied to the clipBoard - The selectedText # Any changes to the app view - The selectedChunk on mouseUp local tClip if the selectedText is empty then set the clipBoardData["text"] to fld "script_F" else copy the selectedText end if put the clipBoardData["text"] into tClip if the altKey is down then lock the clipBoard set the rawClipBoardData to empty -- Clear ALL ClipboardData if the platform is "Linux" then set the rawClipboardData["text/plain;charset=utf-8"] \ to textEncode(tClip, "UTF-8" ) -- Linux if the platform is "Win32" then set the rawClipboardData["CF_UNICODETEXT"] \ to textEncode(tClip, "UTF-16" ) -- Windows if the platform is "MacOS" then set the rawClipboardData["public.utf8-plain-text"] \ to textEncode(tClip, "UTF-8" ) -- OSX unlock the clipboard end if end mouseUp {{{{{{ VCopy the selection or the Script Buddy text. Hold the Alt key down to copy plain text.; Copy cREVGeneral revUniqueID 1443379631230 scripteditorvscroll paste_BbcW # Pastes the clipboardData into the selection on mouseUp doAction (the short name of me) end mouseUp command processAction if the selectedChunk is not empty and the fullClipboardData["text"] is not empty then paste end if end processAction {{{{{{ Paste; Paste cREVGeneral revUniqueID 1443379704017 scripteditorvscroll scripteditorselection 177 update_BbcW # Export the contents of fld "script_F" to the current tab in the script editor if it is open on mouseUp # Check if the IDE SE is open if "revNewScriptEditor 1" is not among the lines of the openStacks then exit to top put the number of controls in grp "Script Tabs" of stack "revNewScriptEditor 1" into tNum repeat with tTab = 1 to tNum if the textStyle of grp tTab of stack "revNewScriptEditor 1" = "Bold" and \ the short name of grp tTab of stack "revNewScriptEditor 1" contains "Tab " then put the label of btn "Tab" of grp tTab of stack "revNewScriptEditor 1" into tTabEdit end if end repeat if tTabEdit = the text of fld "tab_L" then updateIDEScript else answer \ "The tab of the IDE Script Editor does not match the Script Buddy reference, there is no undo for this step, do you really wish to continue?" \ with "Continue" or "Cancel" as sheet if it is "Cancel" then exit to top updateIDEScript end if end mouseUp on updateIDEScript if the hilite of btn "warnings_Chk" of stack "SB_Prefs" = "false" then answer "This will overwrite the contents of the currently open tab in the IDE Script Editor, there is no undo for this step, do you wish to continue?" with "Overwrite" or "Cancel" as sheet end if if it is "Cancel" then exit to top lock screen put the vScroll of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" into tScroll send "getLastSelectedChunk" to fld "script" of grp "Editor" of stack "revNewScriptEditor 1" put the result into tChunk put the htmlText of fld "script_F" into tScript go stack "revNewScriptEditor 1" set the htmlText of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" to tScript focus on fld "script" of grp "Editor" of stack "revNewScriptEditor 1" select after fld "script" of grp "Editor" of stack "revNewScriptEditor 1" if the cComment of stack "pbh_Script_Buddy" = true then put cr & "# Edited by Script Buddy" into tType if line -1 of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" contains "Script Buddy" then type "." else type tType end if end if type tab set the vScroll of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" to tScroll select after char (item 1 of tChunk) of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" unlock screen end updateIDEScript {{{{{{ ! >Send the modified Script Buddy text to the current IDE SE tab.9 Export cREVGeneral revUniqueID 1443379704018 scripteditorvscroll scripteditorselection 329 sync_BbcW# Import the contents of the current tab in the script editor if it is open on mouseUp doAction (the short name of me) end mouseUp command processAction # Check if the IDE SE is open if "revNewScriptEditor 1" is not among the lines of the openStacks then exit to top put the number of controls in grp "Script Tabs" of stack "revNewScriptEditor 1" into tNum repeat with tTab = 1 to tNum if the textStyle of grp tTab of stack "revNewScriptEditor 1" = "Bold" and \ the short name of grp tTab of stack "revNewScriptEditor 1" contains "Tab " then set the text of fld "tab_L" to the label of btn "Tab" of grp tTab of stack "revNewScriptEditor 1" end if end repeat put the htmlText of fld "script" of grp "Editor" of stack "revNewScriptEditor 1" into tScript set the htmlText of fld "script_F" to tScript updateLineCount end processAction {{{{{{ .Import the script from the current IDE SE tab.9 Import cREVGeneral revUniqueID 1443379704019 scripteditorvscroll scripteditorselection 121 clear_BbcW7# Clears the selectedText or the filed "script_F" on mouseUp doAction (the short name of me) end mouseUp command processAction if the selectedText is empty then put empty into fld "script_F" put "Tab" into fld "tab_L" else put empty into the selectedText end if end processAction {{{{{{ - ,Clear the selection, or Script Buddy editor.? Clear cREVGeneral revUniqueID 1443379704020 scripteditorvscroll scripteditorselection 56 mode_BbcW N# No undo necessary on mouseUp open stack "SB_prefs" as sheet end mouseUp {{{{{{ n Open Script Buddy preferences.; Mode cREVGeneral revUniqueID 1443379704021 scripteditorvscroll scripteditorselection 0 cut_BbcW on mouseUp doAction (the short name of me) end mouseUp command processAction if the selectedText is empty then select text of fld "script_F" cut the selectedText else cut the selectedText end if end processAction {{{{{{ +Cut the selection or the Script Buddy text.\ Cut cREVGeneral revUniqueID 1443383198049 scripteditorvscroll scripteditorselection 218 save_BbcW # No Undo necessary on mouseUp if the cDefaultFolder of this stack is empty then set the cDefaultFolder of this stack to specialFolderPath("documents") else set the defaultFolder to the cDefaultFolder of this stack end if put fld "tab_L" into tTabName put the defaultFolder & slash & tTabName into tFile -- ask file "Save Script as..." with tFile with filter "Text file,*.txt" as sheet ask file "Save Script as..." with tFile with type "Text file|txt" or \ type "RTF file|rtf" or type "HTML file|html" as sheet put the result into tFileType put it into tFilePath if tFileType is "Cancel" then exit to top set the itemDel to slash set the cDefaultFolder of this stack to item 1 to -2 of tFilePath Switch tFileType set the itemDel to "." case "Text file" put fld "tab_L" & return & return into tScript put fld "script_F" after tScript -- Contains the text to save if the last item of tFilePath <> "txt" then put ".txt" after tFilePath break case "RTF file" lock screen put the HTMLtext of fld "script_F" into tTempScript put fld "tab_L" & return & return before fld "script_F" put the RTFtext of fld "script_F" into tScript -- Contains the text to save set the HTMLtext of fld "script_F" to tTempScript unlock screen if the last item of tFilePath <> "rtf" then put ".rtf" after tFilePath break case "HTML file" put the HTMLtext of fld "tab_L" & "