Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: frontcall cbpaste question  (Read 8698 times)
.
Posts: 64


« on: October 30, 2008, 02:51:12 pm »

I am trying to use frontcall with cbpaste to insert a value into text in a textedit, without luck. Can anyone help find a way around it please?

I want the users to select the text to insert from a function that produces a popup menu and I think it is this going off to another function that effectively loses focus from the field I'm in, even once I've returned back to the action block.

THIS WORKS (never leaving the on action block):

ON ACTION myaction
  IF ( INFIELD(myfield) )
  THEN
    CALL ui.Interface.frontCall("standard","cbset",["My Text"],[lv_result])
    CALL ui.Interface.frontCall("standard","cbpaste",[],[lv_result])
  END IF


THIS DOES NOT WORK:


ON ACTION myaction
  IF ( INFIELD(myfield) )
  THEN
    CALL my_menu() RETURNING lv_string
    CALL ui.Interface.frontCall("standard","cbset",[lv_string],[lv_result])
    CALL ui.Interface.frontCall("standard","cbpaste",[],[lv_result])
  END IF

Although, then right clicking and selected Paste will then insert the text as I want it to.

I've also tried (and this doesn't work either, though not that useful anyway):

ON ACTION myaction
  IF ( INFIELD(myfield) )
  THEN
    CALL my_menu() RETURNING lv_string
    NEXT FIELD CURRENT
  END IF

BEFORE FIELD myfield
    IF ( lv_string IS NOT NULL )
    THEN
       CALL ui.Interface.frontCall("standard","cbset",[lv_string],[lv_result])
       CALL ui.Interface.frontCall("standard","cbpaste",[],[lv_result])
       LET lv_string = NULL
    END IF
.
Four Js
Posts: 115


« Reply #1 on: October 30, 2008, 04:12:19 pm »

Jeff,

From a "GDC point of view", this is unfortunately expected: cbPaste pastes the clipboard in the current field (i.e. the widget associated to the Node pointed by UserInterface.focus) if the field is "pastable" (a Menuaction can get the focus but can't be "pasted").

Code
  1. ON ACTION myaction
  2.  IF ( INFIELD(myfield) )
  3.  THEN
  4.    CALL my_menu() RETURNING lv_string
  5.    CALL ui.Interface.frontCall("standard","cbset",[lv_string],[lv_result])
  6.    CALL ui.Interface.frontCall("standard","cbpaste",[],[lv_result])
  7.  END IF
  8.  


my_menu() creates a menu which changes the focused node (the focus goes to one of the menu items). Then, when my_menu is closed and you call the frontCall, the focused node does not exists anymore ; then the runtime system set the focus to the fallback node, i.e. the UserInterface:

Code
  1. om 14  { {rn 106} {an 0 FunctionCall 111 { {isSystem "0"} {moduleName "standard"} {name "cbset"}
  2. {paramCount "1"} {returnCount "1"}} { {FunctionCallParameter 112 { {dataType "STRING"} {isNull "0"} {value "bar"}}
  3. {}}}} [b]{un 0 { {focus "0"}}}[/b]}

cbPaste will then do nothing because the focused node is a not a "pastable" field ; the same in the BEFORE FIELD: you're not in the field, you are BEFORE the field. Out of my head I see no clean and quick solution, I just wanted to explain you the behavior.

Regards,
.
Posts: 64


« Reply #2 on: October 30, 2008, 05:09:13 pm »

Hi Pierre-Nicolas,

Thanks for the response.

Is there a way of forcing focus back to the field I am in? I never leave my field as such (although GDC sees that I did) and I am still positioned within the text edit where I was before the menu was called (menu style=popup). I have returned back from the menu into the ON ACTION block at the point where I do the cbset and cbpaste.

I did try to get the cursor position to manually insert rather than using clipboard from the text edit but unfortunately the attributes cursor and cursor2 only seem to get updated when you exit the field (unfortunately, here GDC doesn't see that I did as they don't get updated). I want to know where the cursor is in the text at the point the action is triggered!

If I outline what I am trying to do, maybe someone will have a solution:

The user is typing into a text edit and at some point in the text (not always at the end) they want to insert a common phrase by pressing a key and selecting from a popup menu. I then want to insert that phrase at the point the cursor is at

I would really appreciate if anyone has an answer.

Cheers

Jeff
Reuben B.
Four Js
Posts: 1047


« Reply #3 on: October 30, 2008, 10:11:31 pm »

Jeff,

Does this meet your needs.  Only downside I can see is if you either a) want to replace any selected text rather than just insert at the current point and b) you are using UNBUFFERED

Code
  1. DEFINE c INTEGER
  2. DEFINE s1,s2, p STRING
  3.  
  4. ...
  5.      ON ACTION myaction
  6.         LET s1 = FGL_DIALOG_GETBUFFER()
  7.         LET c = FGL_DIALOG_GETCURSOR()
  8.         LET p = mymenu()
  9.         IF p.getLength() > 0 THEN
  10.            LET s2 = SFMT("%1%2%3",s1.subString(1,c-1),p,s1.subString(c,s1.getLength()))
  11.            CALL FGL_DIALOG_SETBUFFER(s2)
  12.            CALL FGL_DIALOG_SETCURSOR(c+p.getLength())
  13.         END IF

Pierre-Nicolas,

Maybe ui.Interface.Refresh() should update the value of the node with focus?  I ran into the same issue once when attempting to use Windows SendKeys.  I couldn't have an 'Are you sure you want to do this?' Menu dialog because the current field focus was lost.

Is there an equivalent FGL_ function call to to get the cursor2 value?

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines