Select-Case section maker tool
Posted: Fri Dec 27, 2013 3:00 am
Hi To All & Merry Xmas + New Year
Here is a small tool that produces a Select case EndSelect section that may be useful to some
Basically a small GUI tool that takes a list of words / constants / numbers etc a cvs list if you like, delimeter can be whatever and can be specified in the string gadget.
Features a checkboxgadget for quoted strings ie ( Case "foobar" ), so you could pass 100 constants to the clipboard via copy from a browser/text editor/source code etc press the make button and you have a Select case EndSelect section complete in a jiffy.
after initial processing you can alter the delimiter - reprocess with the original clipboard data. On Exit the processed data is copied to the clipboard ready for pasting into the ide. just saved me hours this afternoon
Should be cross platform
code updated 03:00 codeline -- --- caused initial error no clipboard data on first run should be ----
Update: Added --- Default section
Zebuddi.

Here is a small tool that produces a Select case EndSelect section that may be useful to some

Features a checkboxgadget for quoted strings ie ( Case "foobar" ), so you could pass 100 constants to the clipboard via copy from a browser/text editor/source code etc press the make button and you have a Select case EndSelect section complete in a jiffy.
after initial processing you can alter the delimiter - reprocess with the original clipboard data. On Exit the processed data is copied to the clipboard ready for pasting into the ide. just saved me hours this afternoon


Should be cross platform

code updated 03:00 codeline --
Code: Select all
clipboard_text.s=old_clipboard.text.s
Code: Select all
old_clipboard_text.s=clipboard_text.s
Update: Added --- Default section
Zebuddi.

Code: Select all
EnableExplicit
Global Window_0
Global Window_0_Button_MakeCase
Global Window_0_String_Delimeter
Global Window_0_Editor_1
Global Window_0_Text_Delimeter
Global Window_0_Option_String
Global Window_0_Option_Constant
Global Window_0_Option_Numb
Global StatusBar_Window_0
Global clipboard_text.s , delimeter.s , Finished_data.s , collacted_string.s , regex_spaces.i , delimeter_position.i , numb.i , i.i , extracted_word.s , ls.i , delimeter_length.i , counter.i
Global old_clipboard_text.s , old_delimeter.s ,c.i
Define.l Event
Global NewList cbdata.s()
Procedure OpenWindow_Window_0()
Window_0 = OpenWindow(#PB_Any , 482 , 41 , 400 , 430, "Select-Case section maker" , #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If Window_0
StatusBar_Window_0 = CreateStatusBar(#PB_Any, WindowID(Window_0))
If StatusBar_Window_0
AddStatusBarField(#PB_Ignore)
StatusBarText(StatusBar_Window_0, 0, "Entries : ")
EndIf
Window_0_Button_MakeCase = ButtonGadget(#PB_Any , 10 , 10 , 70 , 20 , "Make")
Window_0_Text_Delimeter = TextGadget(#PB_Any , 85, 13, 60, 16 , "Delimeter=")
Window_0_String_Delimeter = StringGadget(#PB_Any , 145 , 10 , 170 , 19 , "")
Window_0_Option_String = CheckBoxGadget(#PB_Any, 320, 10, 60, 20, "Quoted")
Window_0_Editor_1 = EditorGadget(#PB_Any , 10 , 35 , 380 , 355)
EndIf
EndProcedure
Procedure reset()
clipboard_text.s = "" : delimeter.s = "" : Finished_data.s = "" : collacted_string.s = "" : extracted_word.s = ""
delimeter_position.i = 0 : numb.i = 0 : i.i = 0 : ls.i = 0: delimeter_length.i = 0 : counter.i = 0
ClearGadgetItems(Window_0_String_Delimeter)
EndProcedure
regex_spaces.i=CreateRegularExpression(#PB_Any , "\s+") ; reduces multipule consecutive white spaces to one single one
OpenWindow_Window_0()
ClearClipboard()
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case Window_0_Button_MakeCase
reset()
ClearList(cbdata())
delimeter.s=GetGadgetText(Window_0_String_Delimeter) :
clipboard_text.s=GetClipboardText()
CallDebugger
c+1
Debug "run "+Str(c)+" "+ clipboard_text.s
If old_delimeter.s<>delimeter Or delimeter.s>"" ; check to see if delimeter has changed and data already processed if true revert to original clipboard text
old_clipboard_text.s=clipboard_text.s ; for reprocessing
old_delimeter.s=delimeter.s
EndIf
;{ -- error checking
If delimeter.s = "" Or clipboard_text.s = "" Or CountString(clipboard_text,delimeter.s)=0
If delimeter.s = ""
MessageRequester("Delimeter Error" , "Delimeter String Can Not Be Blank")
ElseIf clipboard_text.s = ""
MessageRequester("Data Error" , "ClipBoard Cleared @ Program Start ..... No Data on The Clipboard")
ElseIf CountString(clipboard_text,delimeter.s)=0
MessageRequester("Delimeter Error" , "No " + Chr(34) + delimeter.s + Chr(34) + " Match`s in the ClipBoard Data")
EndIf
;}
Else
;{ -- Main Processing
clipboard_text.s = ReplaceString(clipboard_text.s , Chr(13) , "" , #PB_String_NoCase , 1) ; remove CR`s
clipboard_text.s = ReplaceString(clipboard_text.s , Chr(10) , "" , #PB_String_NoCase , 1) ; remove LF`s
clipboard_text.s = ReplaceString(clipboard_text.s , Chr(9) , "" , #PB_String_NoCase , 1) ; remove Tab`s
clipboard_text.s = Trim(clipboard_text.s)
clipboard_text.s = ReplaceRegularExpression(regex_spaces , clipboard_text.s , " ") ; reduce white space`s to single white space
clipboard_text.s = ReplaceString(clipboard_text.s , " , " , ",") ; replace white spaced comma`s to just a comma seperator
delimeter_position.i = 0
delimeter.s = GetGadgetText(Window_0_String_Delimeter)
;{ -- check for multipul white space as the delimeter and show in window tiltle as wont show clearly in string gadget
delimeter_length.i =Len(delimeter.s)
For i = 1 To delimeter_length.i
If Mid(delimeter.s , i , 1) = " "
counter.i+1
EndIf
Next
If counter.i = delimeter_length.i
SetWindowTitle(Window_0 , " USING --- " + Str(delimeter_length.i) +Chr(34)+" "+Chr(34) + " white space" )
EndIf
;}
numb = CountString(clipboard_text.s , delimeter.s)
For i.i = 0 To numb.i
delimeter_position.i = FindString(clipboard_text.s , delimeter.s, 1)
extracted_word.s = Mid(clipboard_text.s , 0 , delimeter_position.i-1)
AddElement(cbdata()) : cbdata()=extracted_word.s
;{ -- check to see if we need data items quoted
If GetGadgetState(Window_0_Option_String)=1
cbdata() ="Case " + Chr(34) + cbdata() + Chr(34) + Chr(13)+Chr(13)
Else
cbdata()="Case " + cbdata() + Chr(13) + Chr(13)
cbdata()=ReplaceString(cbdata() , Chr(34) , "")
EndIf
;}
clipboard_text.s = ReplaceString(clipboard_text.s , extracted_word.s+delimeter.s , "" , #PB_String_NoCase , 1 , 1) ;remove the last data item and delimeter from the clipboard text$
clipboard_text.s = Trim(clipboard_text.s)+delimeter.s ; add a delimeter to end of clipboard text$ so we dont miss the last data item out
collacted_string.s+Chr(9)+cbdata() ; collate the data item`s and Tab them
Next
collacted_string.s = Left(collacted_string , Len(collacted_string.s)-( Len(Chr(13)) )) ; remove the last CRLF else "EndSelect" jumps down two places
Finished_data.s = "Select " + Chr(13) + collacted_string.s + Chr(13) +Chr(9)+"Default "+Chr(13)+Chr(13)+ "EndSelect" ; prepared data
ClearGadgetItems(Window_0_Editor_1)
SetGadgetText(Window_0_Editor_1 , Finished_data.s)
ls.i=ListSize(cbdata())
StatusBarText(StatusBar_Window_0 , 0 , "Entries: "+Str(ls.i))
EndIf
EndSelect
Case #PB_Event_CloseWindow
Select EventWindow()
Case Window_0
ClearClipboard()
SetClipboardText(Finished_data.s)
CloseWindow(Window_0)
Window_0 = 0
FreeList(cbdata())
Break
EndSelect
EndSelect
ForEver