EditorGadGet

Just starting out? Need help? Post your questions and find answers here.
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

EditorGadGet

Post by spacebuddy »

is there any way programmatically to select all the text in an EditorGadget?
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: EditorGadGet

Post by skywalk »

Windows only...
SendMessage_(GadgetID(gadgetnum), #EM_SETSEL, 0, -1) ; Select ALL
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: EditorGadGet

Post by Danilo »

Mac OS X only:

Code: Select all

CocoaMessage(0,GadgetID(editorGadget),"selectAll:",0)
And before you ask:

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:
Inherits from NSText : NSView : NSResponder : NSObject
All methods of those classes are inherited and available for NSTextView/EditorGadget as well.
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.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: EditorGadGet

Post by Shardik »

spacebuddy wrote:is there any way programmatically to select all the text in an EditorGadget?
This is a cross-platform example for selecting and deselecting all the text in an EditorGadget which I tested successfully on
- 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
Post Reply