Radio items in GNOME panel applet's context menu - applet

Is there a way to put radio menu items in a GNOME panel applet's context menu, and then control which of the items is marked as active? The official documentation is less than helpful, and all of the applets installed on my computer use normal menu items, so I can't look at their source code for any guidance.

In the XML file defining the context menu, for each radio <menuitem> set type="radio" and the group property to the name of the radio item group, like this:
<Root>
<popups>
<popup name="button3">
<menuitem name="Foo" verb="DoFoo" label="Foo is awesome" type="radio" group="mygroup"/>
<menuitem name="Bar" verb="DoBar" label="Bar is cool" type="radio" group="mygroup"/>
<menuitem name="Baz" verb="DoBaz" label="Baz rocks" type="radio" group="mygroup"/>
</popup>
</popups>
</Root>
You don't set up handlers to respond to the items being selected the same way you would for normal menu items. Instead, you listen for the "ui-event" signal on the BonoboUIComponent for the menu:
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
g_signal_connect (component, "ui-event", G_CALLBACK (popup_component_ui_event_cb), NULL);
/* ... */
static void
popup_component_ui_event_cb (BonoboUIComponent *component,
const gchar *path,
Bonobo_UIComponent_EventType type,
const gchar *state_string,
gpointer data)
{
}
path will be the full path (see below) of the item that was clicked. state_string will be the new state value of the item (see below). There will be two events for each click of a radio item: one to deselect the old item, and one to select the new one.
To manipulate the checked state of the buttons, use bonobo_ui_component_set_prop to set the "state" property to "0" (unchecked) or "1" (checked). To be safe, explicitly uncheck the old value; there are some corner cases where you could otherwise wind up with multiple radio items in the same group checked (particularly if the context menu hasn't yet actually been drawn).
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
bonobo_ui_component_set_prop (component, "/commands/Foo", "state", "1", NULL);
bonobo_ui_component_set_prop (component, "/commands/Bar", "state", "0", NULL);
bonobo_ui_component_set_prop (component, "/commands/Baz", "state", "0", NULL);
Note that you identify the radio item by "/commands/name", where name is the name you gave the item in the XML file.
You could likewise use bonobo_ui_component_get_prop to look for which radio item is checked, but you're better off using the event handlers to detect when the user clicks on one.
In general, the documentation for BonoboUIComponent in libbonoboui should provide more information about ways to manipulate items in the menu.

Related

How to disable a Dynamic Menu Contribution parent in Eclipse 4 RCP Application

This question stems from
How to disable or enable a MMenu (not MMenuItem) in an Eclipse E4 application
I have been attempting to grey-out/disable an entire Dynamic Menu Contribution in Eclipse 4 when a condition is met in the application. The Dynamic Menu Contribution is itself in the File Menu Model Element. My workaround has been to remove all options so the menu does not show anything, but is still active (not-grey) when the condition is met with the code below for clearing the menu.
items.clear();
if (checkMenuEnabled()) {
Fillthemenu();
}
This code below doesn't seem to disable the dynamic menu contribution like I want it to.
MenuImpl menu = (MenuImpl) modelService.find("menuID", application.getChildren().get(0).getMainMenu());
menu.setEnabled(checkMenuEnabled());
Here is an image of the model xmi UI items. The File->Submenu is what I am trying to grey out. Not the individual Dynamic Menu Contribution Items.
Model XMI
Thanks
So in your e4xmi file, you have a "Menu" with a "Dynamic Menu Contribution" and you want to gray out some items in the menu on some application condition, right?
The "Dynamic Menu Contribution" is attached to some "class", right?
In this class, when you generate a disabled "menu":
public class <the class referenced in e4xml> {
#Inject private EModelService modelService;
#AboutToShow
public void aboutToShow(List<MMenuElement> items, {...}) {
MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
dynamicItem.setLabel(<some label>);
dynamicItem.setIconURI(<some icon URI>);
dynamicItem.setContributorURI("platform:/plugin/platform:/plugin/<nom plugin>");
dynamicItem.setContributionURI(<menu item handler> "bundleclass://<plugin name>/<menu item handler class>");
--> dynamicItem.setEnabled(true/false); to enable/grey out the menu
--> dynamicItem.setvisible(true/false); to show/hide the menu
// add one or many MDirectMenuItems ...
items.add(dynamicItem);
}
}
In the menu item handler ("setContributionURI" class) where you implement the logic of the menu item, you can also show/hide/enable/disable the menu item:
public class <menu item handler class> {
#Execute
public void execute({...}) {
<code linked to the menu item selection here>
}
#CanExecute
public boolean canExecute(#Optional MMenuItem menuItem, {...}) {
// implement the logic to show/hide, enable/disable the menu item
menuItem.setVisible(true/false); // show/hide the menu item
return true/false; // enable/grey out the menu item
}
}

How to show hide elements based on select inside a multifield in Touch UI AEM 6?

I have a dropdown that has two options "image" and "icon".
When the user selects "image" I want to show the pathbrowser and when he selects "icon" I will show a text field.
This is famous problem, now I want to do this when these above mentioned fields are inside a multifield in Touch UI.
So say I have two items under this multifield, when I select "image", in the select present in the first item(of the multfield) the OOTB showhide hides my "icon" textfield of the first and the second item entry in the multifield as well.
How do I resolve this ?
Long story short See Blog. I want to do this. Just that my fields are inside a multifield.
Note:
I was able to implement the Classic UI code using ExtJs field.nextSibling() so I don't affect the entries in the other multifield item entries.
Find the code below and for more details check this gitlink here
.content.xml
<enable
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
text="Enable"
id="enable"
value="true"
name="./enable"
class="cq-dialog-checkbox-showhide"
cq-dialog-checkbox-showhide-target=".button-option-enable-showhide-target"/>
<deleteEnable
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/hidden"
name="./enable#Delete"
value="true"/>
<showHideContainer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container"
class="hidden button-option-enable-showhide-target"
showhidetargetvalue="true">
<items jcr:primaryType="nt:unstructured">
<!-- some components to show/hide -->
</items>
</showHideContainer>
checkboxshowhide.js
(function(document, $) {
"use strict";
// when dialog gets injected
$(document).on("foundation-contentloaded", function(e) {
// if there is already an inital value make sure the according target element becomes visible
$(".cq-dialog-checkbox-showhide").each( function() {
showHide($(this));
});
});
$(document).on("change", ".cq-dialog-checkbox-showhide", function(e) {
showHide($(this));
});
function showHide(el){
// get the selector to find the target elements. its stored as data-.. attribute
var target = el.data("cqDialogCheckboxShowhideTarget");
// is checkbox checked?
var checked = el.prop('checked');
// get the selected value
// if checkbox is not checked, we set the value to empty string
var value = checked ? el.val() : '';
// make sure all unselected target elements are hidden.
$(target).not(".hide").addClass("hide");
// unhide the target element that contains the selected value as data-showhidetargetvalue attribute
$(target).filter("[data-showhidetargetvalue='" + value + "']").removeClass("hide");
}
})(document,Granite.$);

I want to use the onSelect event of a ZK tree which is rendered through MVVM

Here is the zul file for reference
<?page title="MVVM Tree POC"?>
<zk>
<borderlayout height="800px">
<west size="25%"></west>
<center>
<window apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('com.nagarro.viewmodel.TreeViewModel')"
title="Dynamic Tree" border="normal">
<tree checkmark="true" model="#bind(vm.treeModel)"
onSelect="#command('select')" >
<template name="model" var="node" status="s">
<treeitem checkable="#load(node.checkable)"
open="true">
<treerow style="text-align:center;">
<treecell
label="#bind(node.data.firstName)" style="text-align:left;">
</treecell>
</treerow>
</treeitem>
</template>
</tree>
</window>
</center>
</borderlayout>
</zk>
There is a "onSelect" event in the tree tag and there are checkboxes for some treeItems only. Now, I want to create certain components like a combobox for the corresponding tree row when its checkbox is selected. I am trying to do it with the onSelect event of the tree but the problem is I need to pass the reference of the selected checkbox which I am unable to pass as the onSelect event is kept outside the scope of the template through which treeItems are getting rendered.
Is there any other way out to do what I want
This is the page which I get through the above zul file.
I want to know which checkbox is selected ?
You can pass any parameter on every event like that (from ZK docs):
<button label="Delete" onClick="#command('delete', item=item)"/>
and use this parameter in your java code:
#Command
public void delete(#BindingParam("item") Item item ) {
//do some stuff based on what item you've picked
}
In your case I would move onSelect-Event from Tree-Component to Treeitem, like this:
<tree checkmark="true" model="#bind(vm.treeModel)">
<template name="model" var="node" status="s">
<treeitem checkable="#load(node.checkable)"
open="true" onSelect="#command('select', nameParameter=node.data.firstName">
<treerow style="text-align:center;">
<treecell
label="#bind(node.data.firstName)" style="text-align:left;">
</treecell>
</treerow>
</treeitem>
</template>
</tree>
and use parameter in your #Command-method:
#Command
public void select(#BindingParam("nameParameter") String nameParameter ) {
System.out.println(nameParameter + " selected");
}
See ZK MVVM > Advance > Parameter Docs for more information
This is an issue I often run into. My solution has always been to attach data to the component itself; keep a database entity's id or an object itself on the checkbox for retrieval during the event.
checkbox.setAttribute("myAttributeName", myAttributeValue);
This requires a cast to retrieve, which is unfortunate, but with some best practices you can do so confidently.

Checkbox and radio buttons

Do checkboxes have the permission to behave like radio buttons.I am developing a quiz application where in the options have the behaviour of radio buttons and the icon of the options are to be like the checkbox and is it possible for me to group the checkbox as we group radio buttons?
If you want Radio Buttons which look like Check boxes. Set Style of RadioButton as #android:style/Widget.CompoundButton.CheckBox
e.g:
<RadioButton style="#android:style/Widget.CompoundButton.CheckBox" />
I don't know if this is the best solution but you can create a "manager" for your checkboxes, and run it whenever any of them gets clicked.
For simplicity I've added the manager in the xml code, but feel free to use setOnClickListener, or setOnCheckedChangeListener as well.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox1"
android:onClick="cbgroupmanager"
/>
...
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox5"
android:onClick="cbgroupmanager"/>
</LinearLayout>
You need an ArrayList to iterate through, so you can settle the status of each checkbox, whenever any of them gets clicked on.
public class Q6910875 extends Activity
ArrayList<CheckBox> cb = new ArrayList<CheckBox>();
int CheckBoxNum = 5; //number of checkboxes
Iterator<CheckBox> itr ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb.add((CheckBox) findViewById(R.id.checkBox1));
cb.add((CheckBox) findViewById(R.id.checkBox2));
cb.add((CheckBox) findViewById(R.id.checkBox3));
cb.add((CheckBox) findViewById(R.id.checkBox4));
cb.add((CheckBox) findViewById(R.id.checkBox5));
itr = cb.iterator();
}
And here we have our manager, one iterator to pass trough the whole list, unchecking everything, when it reaches the clicked one, checks!
public void cbgroupmanager(View v) {
CheckBox cbaux;
while(itr.hasNext()) {
cbaux = (CheckBox) itr.next(); // we need this because it returns a Object, and we need the setChecked, which is a CheckBox method.
Log.d("soa", "click");
if (cbaux.equals(v)) //if its the one clicked, mark it as checked!
cbaux.setChecked(true);
else
cbaux.setChecked(false);
}
I also could find this other solution linked below, you can change the theme of your checkbox, but I dont have any experience on themes, so I can't help you any further on this approach.
Is it possible to change the radio button icon in an android radio button group
In radiabutton we can have the only one decision.But
checkbox we can have mulitiple options.
based on the usage we choose these controls.
for example,
RadioButton
Gender - o Male o Female
here we can select only one option
for example,
CheckBox
your Interested Games?
o cricket o football o valleyball o hockey

OpenXML - Limiting the number of buttons showed in the group in custom MS-Word ribbon

I want to limit the number of buttons in the group of a ribbon in Word 2007 as the buttons are getting generated on the basis of data in the database. See the pic below. . I wanted to have limited number, say 6 or so in the ribbon with a dialogboxlauncher which when clicked will open a pane showing all the buttons. Is there any way of doing the same. Can somebody also tell me how to create that pane when somebody clicks on the dialogbox launcher?
The way I did it is to load some (say 6) of the items in the ribbon as buttons and add all the items as the CustomXMlPart in the document. In the document, I added a user control which contained a listbox. On the ribbon load, I get all the items from the CustomXmlPart and put them in the listbox. On the dialogbox launcher button click, I show/hide the user control to show all the items in the list.
Following are the steps in detail :-
a) Get all the items from the database and keep that in collection.
b) Generate the ribbon XML like the following withe the 6 buttons from the above collection :-
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonLoad">
<ribbon>
<tabs>
<tab id="tabMyTab" label="MyTab">
<group id="grpItems" label="My items">
<button id="test1" label="test1"/>
<button id="test2" label="test2"/>
<button id="test3" label="test3"/>
<button id="test4" label="test4"/>
<button id="test5" label="test5"/>
<button id="test6" label="test6"/>
<dialogBoxLauncher>
<button id="btnShowAllItems" label="Show all custom tags" onAction="ShowAllItems" />
</dialogBoxLauncher>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
c) Add the collection as the CustomXMLPart to the document :-
static void AddCustomTableXmlPart(WordprocessingDocument document)
{
MainDocumentPart mainDocumentPart = document.MainDocumentPart;
XDocument customTagsXml = GetAllItemsAsCustomXML();
if (mainDocumentPart.GetPartsCountOfType<CustomXmlPart>() > 0)
mainDocumentPart.DeleteParts<CustomXmlPart>(mainDocumentPart.CustomXmlParts);
//Add a new customXML part and then add content
var customXmlPart = mainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
//copy the XML into the new part...
using (var ts = new StreamWriter(customXmlPart.GetStream()))
{
ts.Write(customTagsXml.ToString());
ts.Flush();
}
}
d) Go to the developer tab of your docm file, add a UserForm to the project and add a listbox to it. Write a subroutine which would load the items from the CustomXMlPart added already to the document and add those items to the listbox in the userform. Something like below :-
Sub LoadItems()
Dim totalItemsCount As Integer
totalItemsCount = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes.Count
Dim item As String
For i = 1 To totalItemsCount
item = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes(i).text
' I had to remove the spaced before adding it as It was throwing errors
item = Replace(item, " ", Empty)
If Len(item) > 1 Then
ItemUserControl.lstItems.AddItem pvargItem:item
End If
Next i
End Sub
e) Define the sub named RibbonLoad which is called from the onLoad event of the ribbon (check the RibbonXML). Call the LoadItems sub from this RibbonLoad sub.
Sub RibbonLoad(ribbon As IRibbonUI)
LoadItems
End Sub
f) Define the following sub which will show/hide the user control. This is called on the onAction of the dialogBoxLauncher button. (see the RibbonXML)
Sub ShowAllItemss(control As IRibbonControl)
If ItemsUserControl.Visible = False Then
If ItemsUserControl.lstItems.ListCount = 0 Then
LoadCustomTags
End If
ItemsUserControl.Show
Else
ItemsUserControl.Hide
End If
End Sub