EditorGadGet
-
- Enthusiast
- Posts: 356
- Joined: Thu Jul 02, 2009 5:42 am
EditorGadGet
is there any way programmatically to select all the text in an EditorGadget?
Re: EditorGadGet
Windows only...
SendMessage_(GadgetID(gadgetnum), #EM_SETSEL, 0, -1) ; Select ALL
SendMessage_(GadgetID(gadgetnum), #EM_SETSEL, 0, -1) ; Select ALL
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: EditorGadGet
Mac OS X only:
And before you ask:

Documentation:
- NSTextView Class Reference
At the top of the reference you see:
Same for all listed protocols/interfaces (entry: Conforms to).
Now look at NSText reference:
- NSText Class Reference
and find "selectAll:", "cut:", "copy:", and "paste:"
For offline browsing I recommend Dash 2 (Docs & Snippets) with PB IDE Tool: Dash Mac OS X API help starter
Press ALT+F1 on keywords like "NSTextView" and "NSText" within the PB IDE, and it opens Dash 2 with the class reference for the class.
Code: Select all
CocoaMessage(0,GadgetID(editorGadget),"selectAll:",0)
Code: Select all
CocoaMessage(0,GadgetID(editorGadget),"cut:",0)
CocoaMessage(0,GadgetID(editorGadget),"copy:",0)
CocoaMessage(0,GadgetID(editorGadget),"paste:",0)

Documentation:
- NSTextView Class Reference
At the top of the reference you see:
All methods of those classes are inherited and available for NSTextView/EditorGadget as well.Inherits from NSText : NSView : NSResponder : NSObject
Same for all listed protocols/interfaces (entry: Conforms to).
Now look at NSText reference:
- NSText Class Reference
and find "selectAll:", "cut:", "copy:", and "paste:"
For offline browsing I recommend Dash 2 (Docs & Snippets) with PB IDE Tool: Dash Mac OS X API help starter
Press ALT+F1 on keywords like "NSTextView" and "NSText" within the PB IDE, and it opens Dash 2 with the class reference for the class.
Re: EditorGadGet
This is a cross-platform example for selecting and deselecting all the text in an EditorGadget which I tested successfully onspacebuddy wrote:is there any way programmatically to select all the text in an EditorGadget?
- MacOS 10.6.8 x86
- Ubuntu 12.04 x64 with KDE and Unity
- Windows 7 x64 SP1
Code: Select all
EnableExplicit
Procedure SelectAll(EditorGadgetID.I, SelectAll.I)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected TextBuffer.I
Protected StartIter.GtkTextIter
Protected EndIter.GtkTextIter
TextBuffer = gtk_text_view_get_buffer_(GadgetID(EditorGadgetID))
gtk_text_buffer_get_start_iter_(TextBuffer, @StartIter)
gtk_text_buffer_get_end_iter_(TextBuffer, @EndIter)
If SelectAll
gtk_text_buffer_select_range_(TextBuffer, @StartIter, @EndIter)
Else
gtk_text_buffer_select_range_(TextBuffer, @StartIter, @StartIter)
EndIf
CompilerCase #PB_OS_MacOS
Protected Range.NSRange
If SelectAll
CocoaMessage(0, GadgetID(EditorGadgetID), "selectAll:", 0)
Else
Range\length = 0
CocoaMessage(0, GadgetID(EditorGadgetID), "setSelectedRange:@", @Range)
EndIf
CompilerCase #PB_OS_Windows
If SelectAll
SendMessage_(GadgetID(EditorGadgetID), #EM_SETSEL, 0, -1)
Else
SendMessage_(GadgetID(EditorGadgetID), #EM_SETSEL, 0, 0)
EndIf
CompilerEndSelect
EndProcedure
OpenWindow(0, 270, 100, 200, 130, "EditorGadget")
EditorGadget(0, 10, 10, 180, 80, #PB_Editor_WordWrap)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog.")
ButtonGadget(1, 5, 100, 95, 25, "Select all")
ButtonGadget(2, 100, 100, 95, 25, "Deselect all")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SelectAll(0, #True)
Case 2
SelectAll(0, #False)
EndSelect
EndSelect
ForEver