Page 1 of 1

[Implemented] Advanced InputRequester()

Posted: Wed Mar 01, 2006 3:38 pm
by va!n
The InputRequester is nice to let the user enter any text and press on OK! But what, if the user dont want enter enythink and want cancel? (as i have read in a turotial "how to create a good GUI", every action should have a cancel option too!

So what about having an advanced InputRequester, like:

Code: Select all

Text$ = InputRequester(Title$, Message$, DefaultText$,#Flags)

Possible Flags:
  #PB_InputRequester_OK             : to have the 'ok' only button
  #PB_InputRequester_OKCancel   : to have 'ok' and 'cancel' buttons

Possible return values are following constants: 
  #PB_InputRequester_OK         : the 'OK' button was pressed
  #PB_InputRequester_Cancel    : the 'Cancel' button was pressed
maybe a flag for PASSWORD, also showing only **** when typing anythink would make sence!?

Posted: Wed Mar 01, 2006 7:16 pm
by USCode
I agree va!n, those things would be nice but it sounds like someone should develop an "Advanced InputRequester" library.

At a minimum the InputRequester and MessageRequester should be enhanced to allow the specification of which Icon to display. Windows, Mac and Linux have some of the same types of icons (question, warning, exclamation) I believe, so it could be cross-platform.

In the meantime, you can create your own simple modal dialog using the new StickyWindow and DisableWindow commands with a StringGadget. The StringGadget #PB_String_Password option would give you the password effect you're looking for.

Re: Advanced InputRequester()

Posted: Wed Mar 01, 2006 8:06 pm
by PB
Been there, asked that:
viewtopic.php?t=16666
:)

Also, see my tip here, which may suffice until Fred can do this natively:
viewtopic.php?p=129817

Posted: Wed Mar 07, 2007 4:57 am
by Joakim Christiansen
Yeah, we need the cancel option!

I made a very simple one:

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$)
  Protected Result$, Window, String, OK, Cancel
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered) 
  If Window And CreateGadgetList(WindowID(Window))
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    Repeat
      If WaitWindowEvent() = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If GetKeyState_(#VK_RETURN) > 1
        Result$ = GetGadgetText(String)
        Break
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure

Input$ = InputRequesterOkCancel("Hello","Enter a string:","")
If Input$
  Debug Input$
EndIf

Posted: Wed Mar 07, 2007 2:57 pm
by AND51
Another thing regarding PB's InputRequester:

Please, write "OK", not "Ok". OK? :wink:
(To make the OK-Button matching the Windows-Requester-OK-Buttons)

Re: Advanced InputRequester()

Posted: Fri Jul 22, 2011 1:33 pm
by djes
Thank you! Added close button to your "InputRequesterEx()" (psychological effect)

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$)
  Protected Result$, Window, String, OK, Cancel, Event
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered| #PB_Window_SystemMenu ) 
  If Window
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    Repeat
      Event = WaitWindowEvent() 
      If Event = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If Event = #PB_Event_CloseWindow
        Break
      EndIf
      If GetKeyState_(#VK_RETURN) > 1
        Result$ = GetGadgetText(String)
        Break
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure

Re: Advanced InputRequester()

Posted: Fri Sep 23, 2011 9:40 am
by djes
Multiplatform

Code: Select all

Procedure.s InputRequesterOkCancel(Title$,Message$,DefaultString$="")
  Protected Result$, Window, String, OK, Cancel, Event
  Window = OpenWindow(#PB_Any,0,0,300,95,Title$,#PB_Window_ScreenCentered| #PB_Window_SystemMenu ) 
  If Window
    TextGadget(#PB_Any,10,10,280,20,Message$)
    String = StringGadget(#PB_Any,10,30,280,20,DefaultString$): SetActiveGadget(String)
    OK     = ButtonGadget(#PB_Any,60,60,80,25,"OK",#PB_Button_Default)
    Cancel = ButtonGadget(#PB_Any,150,60,80,25,"Cancel")
    AddKeyboardShortcut(Window, #PB_Shortcut_Return, 1000)
    Repeat
      Event = WaitWindowEvent() 
      If Event = #PB_Event_Gadget
        If EventGadget() = OK
          Result$ = GetGadgetText(String)
          Break
        ElseIf EventGadget() = Cancel
          Result$ = ""
          Break
        EndIf
      EndIf
      If Event = #PB_Event_CloseWindow
        Break
      EndIf
      If Event = #PB_Event_Menu
        If EventMenu() = 1000
          Result$ = GetGadgetText(String)
          Break
        EndIf  
      EndIf
    ForEver
  EndIf
  CloseWindow(Window)
  ProcedureReturn Result$
EndProcedure

Re: Advanced InputRequester()

Posted: Fri Sep 23, 2011 10:22 am
by c4s
+1 for the original request!

Especially window width fitting the text width (as MessageRequester()), multiple text lines (as MessageRequester()) and a simple cancel button (as MessageRequester()): http://www.purebasic.fr/english/viewtop ... =3&t=42058