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: toolbar action key  (Read 8587 times)
Alessandro (Efisio) R.
Posts: 42


« on: April 22, 2014, 05:57:55 pm »

Hi,
I'm working with the Genero 2.50 + GDC and I'm having some troubles with the toolbars.
The form-initializer-function in my project defines 'dynamically' (NOT loading an xml file) a toolbar which has the ok, cancel, back buttons... and the f1, f2, f3... buttons that map the keyboard function keys for backward compatibility. Example: ok-button name is 'accept' and f1-button name is 'f1'. So when I define in an input section the ON KEY (F1) block the f1 toolbar button is enabled since the input statement starts until it finishes. In the on key block I put a infield instruction to apply this event only on one/some field. I would like to have the button enabled only when the focus is on the field which can trigger the event, and when is out, the toolbar button comes back grey. I tried with the "ON ACTION f1 INFIELD (myfield)" but it works only with the toolbarbutton click and when i press the keyboard F1 doesn't happen anything. Help me to find a way to solve this problem and forgive me for my bad english please.

Bye,
Alessandro
Reuben B.
Four Js
Posts: 949


« Reply #1 on: April 22, 2014, 11:20:13 pm »

When you use the ON ACTION f1 statement, it is creating an action with the following attributes...
name=f1
accelerator=
text=
comment=
image=
... and the expectation that you will define in a .4ad (or action defaults section of a .per) the various attributes.

When you use ON KEY (F1), it is creating an action that has the following attributes...
name=f1
accelerator=f1
text=
comment=
image=
... (note the accelerator attribute is defined)so it will work as before in character without requiring you to define any more in a .4ad (or action defaults section of a .per).

So to get what you want,  in your .4ad (or perhaps create dynamically like you did for the toolbar), add the following actiondefault entry for each functionkey ...

<ActionDefault name="f1" acceleratorName="f1" />

For most migrations I'd recommend replacing ON KEY(*) with ON ACTION action-name.  Not only does it make the code more readable but gives you flexibility to easily change function keys assignments.  Some people when moving to Genero make the decision to use F1 for help, if accelerator defined in a .4ad then this is an easy coding change.

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Leo S.
Four Js
Posts: 119


« Reply #2 on: April 23, 2014, 01:21:26 pm »

Hi Allesandro, small sample which hopefully does what you want:
.4gl
MAIN
  DEFINE a,b INT
  OPEN FORM f FROM "simpleinput"
  DISPLAY FORM f
  INPUT BY NAME a,b
     ON ACTION test INFIELD a
       MESSAGE "test"
  END INPUT
END MAIN
.per
ACTION DEFAULTS
  ACTION test(TEXT="Test",IMAGE="smiley",ACCELERATOR=F1)
END
TOOLBAR
  ITEM accept
  ITEM test
END
LAYOUT(TEXT="Title")
GRID
{
a[a           ]
b[b           ]
}
END
ATTRIBUTES
a=FORMONLY.a;
b=FORMONLY.b;
Alessandro (Efisio) R.
Posts: 42


« Reply #3 on: April 23, 2014, 03:05:15 pm »

Thanks Leo for the sample but I followed the advice of Reuben because most of programs in the project have the toolbar with same actions mapping function keys, so I added to the .4ad file all the actions needed and I replaced the "ON KEY(F1)" block with the "ON ACTION f1 INFIELD myfield" block and it works like a charm! If I set the action attribute to f1 in myfield that is a buttonedit , I'll notice that when the focus is in myfield, buttonedit's image is highlighted and, at its blur, it'll return gray... Is there a way to keep it always highlighted without losing my recent changes to action-defaults?

Another question:
The form-initializer-function defines 2 rows of toolbar, so I've 2 "<ToolBar>...</ToolBar>" tag which I can show/hide simply by setting a control-global-variable and by checking it and by not creating the toolbar/s that I don't want appears. Since these 2 toolbars are always the same, if I write them in XML into 2 .4tb files, how can I manage their creation considering that ui.Form.loadToolBar(xmlFile) function replaces any toolbar present in the form everytime it's called?
Reuben B.
Four Js
Posts: 949


« Reply #4 on: April 24, 2014, 03:31:07 am »

Quote
If I set the action attribute to f1 in myfield that is a buttonedit , I'll notice that when the focus is in myfield, buttonedit's image is highlighted and, at its blur, it'll return gray... Is there a way to keep it always highlighted without losing my recent changes to action-defaults?

Might be something lost in translation but if I understand you correctly, the behaviour you see is because of the INFIELD clause.  The action is only active when you are in the field, so the button is only active when you are in the field

Quote
The form-initializer-function defines 2 rows of toolbar, so I've 2 "<ToolBar>...</ToolBar>" tag which I can show/hide simply by setting a control-global-variable and by checking it and by not creating the toolbar/s that I don't want appears. Since these 2 toolbars are always the same, if I write them in XML into 2 .4tb files, how can I manage their creation considering that ui.Form.loadToolBar(xmlFile) function replaces any toolbar present in the form everytime it's called?

I think I'm familiar with the issue.  I had a simliar issue when migrating my first Genero app over 10 years ago.  We had it with both Toolbar and Topmenu, but it is easier to visualise with TopMenu.  All our TopMenu's we wanted to have the same entries underneath File,Edit on the left hand side, and Help on the right hand side, what varied between style of program was the entries in the middle.  Being good programmers we didn't want to repeat code so we had a left.4tm with File, Edit entries, and a right.4tm with Help entries, and each style of program having their own .4tm for the middle entries.  So at runtime we had 3 .4tm files to deal with.  The solution in our first version would take the 3 .4tm files, and combine them into 1 .4tm that was then loaded by the loadTopMenu method.  The solution in a later version of the app was to do this merging and loading in memory using DOM tree manipulation rather than outputting an intermediate file.


Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Alessandro (Efisio) R.
Posts: 42


« Reply #5 on: April 24, 2014, 11:05:29 am »

I think I'm familiar with the issue.  I had a simliar issue when migrating my first Genero app over 10 years ago.  We had it with both Toolbar and Topmenu, but it is easier to visualise with TopMenu.  All our TopMenu's we wanted to have the same entries underneath File,Edit on the left hand side, and Help on the right hand side, what varied between style of program was the entries in the middle.  Being good programmers we didn't want to repeat code so we had a left.4tm with File, Edit entries, and a right.4tm with Help entries, and each style of program having their own .4tm for the middle entries.  So at runtime we had 3 .4tm files to deal with.  The solution in our first version would take the 3 .4tm files, and combine them into 1 .4tm that was then loaded by the loadTopMenu method.  The solution in a later version of the app was to do this merging and loading in memory using DOM tree manipulation rather than outputting an intermediate file.
I am not able to merge the two files 4tb due to the limitations of the libraries manipulation of XML files.

FUNCTION join_xml()
DEFINE domDoc1, domDoc2 om.DomDocument
DEFINE node1, node2 om.DomNode
    LET domDoc1 = om.DomDocument.createFromXmlFile("./toolbar1.4tb")
    LET domDoc2 = om.DomDocument.createFromXmlFile("./toolbar2.4tb")
    LET node1 = domDoc1.getDocumentElement()
    LET node2 = domDoc2.getDocumentElement()
    ...
END FUNCTION

I'm stuck at this point because in each of these 4tb files the root node is <ToolBar> and the file that I should produce, should contain two main nodes <ToolBar> but with the DOMDocument class I can't save the whole document as I can only do this with the class DomNode, which saves only ONE node <ToolBar>. I can't come out by processing the file with genero xml classes following your advice, so for the moment I chose to manually create and load a third file that brings together both the toolbar but I know that it is not the best practice, perhaps the worst I'd say.
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines