It is currently Thu Oct 24, 2019 5:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 8:30 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4368
Location: Germany
Hi,

I used the InputRequester() for a search function in an EditorGadget().
I used the last search string as default value.
But when someone simply start to enter a new search text, it was appended to the old text.
To avoid this I needed that the default text is 'selected'. Then the behaviour is more 'normal'.

Code:
CompilerIf Not Defined(PB_InputRequester_SelectText, #PB_Constant)
  #PB_InputRequester_SelectText = 2
CompilerEndIf

; if you need crossplatform selection look here:
; https://www.purebasic.fr/english/viewtopic.php?f=13&t=51950&start=3

Procedure.s OwnInputRequester(Titel$, Message$, DefaultString$, Flags.i=0)
 
  Protected Win.i, StringG.i, StringGFlags.i, ButtonG.i, Text$, Exit.i, Event.i, ActiveWindow.i
 
  ActiveWindow = GetActiveWindow()
  If IsWindow(ActiveWindow)
    Win = OpenWindow(#PB_Any, 0, 0, 300, 110, Titel$, #PB_Window_SystemMenu|#PB_Window_WindowCentered, WindowID(ActiveWindow))
  Else
    Win = OpenWindow(#PB_Any, 0, 0, 300, 110, Titel$, #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  EndIf
  If Win
   
    If Flags & #PB_InputRequester_Password
      StringGFlags = #PB_String_Password
    EndIf
   
    TextGadget(#PB_Any, 10, 10, 280, 20, Message$)
   
    StringG = StringGadget(#PB_Any, 10, 35, 280, 20, DefaultString$)
    If Flags & #PB_InputRequester_SelectText
      SendMessage_(GadgetID(StringG), #EM_SETSEL, 0, -1)
    EndIf
   
    ButtonG = ButtonGadget(#PB_Any, 110, 70, 80, 25, "Ok")
   
    SetActiveGadget(StringG)
   
    AddKeyboardShortcut(Win, #PB_Shortcut_Return, 1)
    AddKeyboardShortcut(Win, #PB_Shortcut_Escape, 2)
   
    Repeat
      Event = WaitWindowEvent()
     
      If EventWindow() = Win
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case 1 : PostEvent(#PB_Event_Gadget, Win, ButtonG)
              Case 2 : Exit = #True
            EndSelect
           
          Case #PB_Event_Gadget
            Select EventGadget()
              Case ButtonG
                Text$ = GetGadgetText(StringG)
                Exit = #True
            EndSelect
           
          Case #PB_Event_CloseWindow
            Exit = #True

        EndSelect
      EndIf
     
    Until Exit
   
    CloseWindow(Win)
   
  EndIf
 
  ProcedureReturn Text$
 
EndProcedure



Search$ = OwnInputRequester("Search", "Enter your search string:", Search$, #PB_InputRequester_SelectText)

MessageRequester("Info", "Now the second search")

Search$ = OwnInputRequester("Search", "Enter your search string:", Search$, #PB_InputRequester_SelectText)


Last edited by infratec on Mon May 27, 2019 10:25 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 3:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 264
Location: France
I'm no sure to understand what you need. Maybe something like that ?

Code:
CompilerIf Not Defined(PB_InputRequester_SelectText, #PB_Constant)
  #PB_InputRequester_SelectText = 2
CompilerEndIf

; if you need crossplatform selection look here:
; https://www.purebasic.fr/english/viewtopic.php?f=13&t=51950&start=3

Procedure.s OwnInputRequester(Titel$, Message$, DefaultString$, Flags.i=0)
 
  Protected Win.i, StringG.i, StringGFlags.i, ButtonG.i, Text$, Exit.i, Event.i, ActiveWindow.i
 
  ActiveWindow = GetActiveWindow()
  If IsWindow(ActiveWindow)
    Win = OpenWindow(#PB_Any, 0, 0, 300, 120, Titel$, #PB_Window_SystemMenu|#PB_Window_WindowCentered, WindowID(ActiveWindow))
  Else
    Win = OpenWindow(#PB_Any, 0, 0, 300, 120, Titel$, #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  EndIf
  If Win
   
    If Flags & #PB_InputRequester_Password
      StringGFlags = #PB_String_Password
    EndIf
   
    TextGadget(#PB_Any, 10, 10, 280, 20, Message$)
   
    StringG = StringGadget(#PB_Any, 10, 40, 280, 20, DefaultString$)
   
   
;     
;     If Flags & #PB_InputRequester_SelectText
;       SendMessage_(GadgetID(StringG), #EM_SETSEL, 0, -1)
;     EndIf
   
    ButtonG = ButtonGadget(#PB_Any, 25, 80, 240, 30, "Write txt then Push me (" +Str(3-Count) + " try To test)")
   
    SetActiveGadget(StringG)
    SetActiveGadget(ButtonG)
   
    Repeat
      Event = WaitWindowEvent()
     
      If EventWindow() = Win
        Select Event
          Case #PB_Event_Gadget
            Select EventGadget()
              Case StringG
                Select EventType()
                  Case #PB_EventType_Focus
                    If GetGadgetText(StringG) = OldM.s
                      SetGadgetText(StringG,"")
                    EndIf
                  Case #PB_EventType_LostFocus
                    OldM.s = GetGadgetText(StringG)
                EndSelect
               
               
               
               
              Case ButtonG
                OldM.s = GetGadgetText(StringG)
                Count + 1
               
                SetGadgetText( ButtonG, "Write txt then Push me (" +Str(3-Count) + " try To test)")
                If COunt = 3
                  Exit = #True
                EndIf
             
            EndSelect
           
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
      EndIf
     
    Until Exit
   
    CloseWindow(Win)
   
  EndIf
 
  ProcedureReturn Text$
 
EndProcedure

Debug OwnInputRequester("Search", "Enter your search string:", "test", #PB_InputRequester_SelectText)

_________________
~Ar-S~

ResizerGold : The easiest way to resize your pictures and more
My webSite (french) : LDVMULTIMEDIA
PB - 5.4x LTS / 5.6x - W10 x64 - GTX1080 - i5 6600k
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 3:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Sep 10, 2012 10:41 am
Posts: 123
Location: Savoie
I don't think he needs anything...
He's just proposing a solution for an inputrequester that behaves like he wants to : an option for the text in the requester to be already selected

_________________
MacBook Pro 13" Retina - 16 Gb - OSX 10.14 - Iphone X - iPad at home
...and unfortunately... Windows at work...


Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 4:05 pm 
Online
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3089
Location: Boston, MA
Optionally this is fine, but definitely an example of "you cannot please all the people all the time".
I hate any dialog box that is preselected. :evil:
Many of my additional searches require 1 or 2 characters to change.
So, each attempt to do a 2nd or 3rd search requires I mouse click to unselect, then navigate to the character position that needs to change. Very annoying when you have a very long string to navigate.

stepping off soapbox...

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 8:07 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4368
Location: Germany
Hey, we are here in Tricks 'n' Tips not in Coding Questions :wink:

I wrote this InputRequester() with an optional flag for selecting the text.

So I can now use the InputRequester() for searching in a text.
It has now the same behaviour like ctrl+f in FireFox (and in other editors).
The first input is stored an if you open the dialog the second time, the old search text is selected.
If you want you can start with a new search text, or press end and modify the text.

I made also a feature request for this flag.


Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Fri May 24, 2019 8:21 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4368
Location: Germany
I added above a keyboard shortcut for return (like in the original InputRequester)
And I modified the example, so that you have more an impression why I did this.

Btw. you should enter a few letters in the first requester :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: InputRequester with Flag for selecting the default text
PostPosted: Mon May 27, 2019 10:26 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4368
Location: Germany
Added shortcut for escape key.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye