wxMenuBar * menubar = m_frame->GetMenuBar();
wxMenu * menu = menubar->GetMenu(1);
wxInt32 menuId = menu->FindItem(wxT("MENU"));
wxMenuItem * menuItem = menu->FindItem(menuId);
wxMenu * steps = menuItem->GetSubMenu();
steps->Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Class::OnMENU), NULL, this);
This is the code but when I click on the menu, OnMENU is not triggered. Is this right?
AFAIK command events, such as menu events, are sent to the parent window, which in this case is m_frame. You need to call Connect() on m_frame, not on the menu (item).
Related
I am working on a DM script that creates a technique which contains a few dialogs.
In this script I am trying to update the pulldown menu items in one dialog from inside another dialog.
I currently have a button inside the dialog with the pulldown menu called "update" which calls a function inside the dialog class that is called "updateDialog".
This function removes all pulldown menu items and then inserts all the items stored in a taglist.
It also changes the state of a few buttons in that dialog.
This update button works perfectly.
Now if I call this updateDialog function from inside the other dialog, the button states change as they should, but the pulldown menu does not update.
Does anyone know why this happens and/or if there is a way to make this work?
Thanks!
Example code:
taggroup menuitems = newtaglist()
object firstdialog, seconddialog
interface I_seconddialog{
void updatedropdowndialog(object self);
}
class firstdialog : uiframe{
void additemresponse (object self){
number items = menuitems.taggroupcounttags()+1
menuitems.taggroupinserttagasstring(infinity(), "Created item #"+items)
menuitems.taggroupopenbrowserwindow(0)
seconddialog.updatedropdowndialog()
}
taggroup createdialog (object self){
taggroup dialog, dialogitems, additembutton
dialog = DLGCreateDialog("first_dialog", dialogItems)
additembutton = DLGCreatePushButton("Add pulldown item", "additemresponse")
dialogitems.dlgaddelement(additembutton)
return dialog
}
object init (object self){
return self.super.init( self.createdialog() )
}
}
class seconddialog : uiframe{
number isbuttonenabled
void updatedropdowndialog (object self){
// Change the state of the state button to show that that does work
isbuttonenabled = abs(isbuttonenabled-1)
self.Setelementisenabled("statebutton",isbuttonenabled);
// Empty the dropdown as the menuitems list might be completely different
taggroup dropdown = self.lookupelement("dropdown")
taggroup dropdown_items
dropdown.taggroupgettagastaggroup("Items",dropdown_items)
dropdown_items.taggroupdeletealltags()
// Add the current tags in menuitems to the dropdown
for(number i=0;i<menuitems.taggroupcounttags();i++){
string item_name
menuitems.taggroupgetindexedtagasstring(i,item_name)
dropdown.dlgaddchoiceitementry(item_name)
}
}
taggroup createdialog (object self){
taggroup dialog, dialogitems, dropdown, updatebutton, statebutton
dialog = DLGCreateDialog("second_dialog", dialogItems)
taggroup initial_items
dropdown = DLGCreateChoice(initial_items,0,"dropdownchange").dlgidentifier("dropdown")
dropdown.dlgaddchoiceitementry("Initial item")
updatebutton = DLGCreatePushButton("Update dropdown", "updatedropdowndialog")
statebutton = DLGCreatePushButton("state changes", "stateresponse").dlgidentifier("statebutton")
dialogitems.dlgaddelement(dropdown)
dialogitems.dlgaddelement(updatebutton)
dialogitems.dlgaddelement(statebutton)
return dialog
}
object init (object self){
isbuttonenabled = 1
return self.super.init( self.createdialog() )
}
}
void main(){
String techniqueName = "Example"
Image techniqueIcon := RGBImage( "Test icon", 4, 75, 75 )
techniqueIcon = RGB( icol, irow, iradius )
object technique = CreateTechnique( techniqueName, techniqueIcon )
firstdialog = Alloc( firstdialog ).Init()
String taskName = "First dialog"
Number taskID = RegisterWorkflowTask( firstdialog, taskName )
Number bOpenByDefault = 1
Number bEssential = 0
AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )
seconddialog = Alloc( seconddialog ).Init()
taskName = "Second dialog"
taskID = RegisterWorkflowTask( seconddialog, taskName )
bOpenByDefault = 1
bEssential = 0
AddWorkflowTask( technique, taskID, bEssential, bOpenByDefault )
AddCustomTechnique( technique )
}
main()
Not an answer (yet), but a longer clarification comment
I'm testing your script code on GMS 3.4.2 and this is the behavior I see, running the script (once) right after GMS start:
Custom technique is added:
It shows two dialogs initially as:
Pressing "Update dropdown" on the Second dialog toggles the "state
changes" button enabled/disabled:
Pressing the "Add pulldown item" button on the First dialog each
time adds to the drop-down and toggles the "state changes" button in
the Second dialog (and displays the tagList of entries):
Isn't that exactly the intended behavior ?
I have a program where I want the user to be able to register for an account. The main view controller has a register button that they can click. I want the window to be replaced, instead of sheet or modal segues. Then, when they click done, they will be redirected back to the main view controller.
You can use follow way to navigate to another window :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Click");
NSWindow newWindow = new NSWindow();
newWindow.Title = "Second Window";
newWindow.SetFrame(new CGRect(500, 500, 300, 200),true);
// set be key window and be front
newWindow.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
And when back to previous , also can use this way .
============================Update==================================
I will share an screenshot to explain that as follow :
You will see there are two WindowControllers and two ViewControllers .
First Window Controller (MainWindow) -> First View Controller (ViewController)
Second Window Controller (SecondWindow) -> Second View Controller (SecondViewController)
First View Controller :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Push");
var storyboard = NSStoryboard.FromName ("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier ("SecondWindow") as NSWindowController;
// display
controller.Window.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
Second View Controller :
ButtonClickEvent.Activated += (sender, e) => {
Console.WriteLine("Button Back");
var storyboard = NSStoryboard.FromName ("Main", null);
var controller = storyboard.InstantiateControllerWithIdentifier ("MainWindow") as NSWindowController;
// display
controller.Window.MakeKeyAndOrderFront(null);
// close current window
View.Window.OrderOut(Self);
};
The effect :
==================================Update===============================
Open Main.storyboard with Xcode Interface Builder :
Review whether Storyboard ID be setted in project :
I want to add a context menu to a dialogue. I want it in such a way that when clicked anywhere where it is empty a deafaul context menu appears. I have seen example of context menu added to table and tree but not a dialogue as a whole any snippets or examples will be greatly appreciated.
This is what I have tried.
import org.eclipse.jface.action.MenuManager;
#Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(4, false);
layout.marginRight = 5;
layout.marginLeft = 10;
container.setLayout(layout);
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.add(new Action("New Thing") {
/* (non-Javadoc)
* #see org.eclipse.jface.action.Action#run()
*/
#Override
public void run() {
System.out.println("came in options");
}
});
parent.setMenu(menuMgr.createContextMenu(parent));
productListTreeCheckBox(parent);
return super.createDialogArea(parent);
}
Try creating the menu in a similar way to the table/tree menu, but using to top level Composite for the dialog. Using a menu manager that might be something like:
Control topLevelComposite = ... get top level composite
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(... you menu listener....);
final Menu menu = menuMgr.createContextMenu(topLevelComposite);
topLevelComposite.setMenu(menu);
You will then have to call setMenu on every Composite and control in the dialog which you want to use this menu. You can just use:
control.setMenu(parent.getMenu());
for this (as long as you do it on everything starting from the children of topLevelComposite).
hi i have created a user control.
now i want to add this control to a page e.g. when the user clicks a button (important is, that i dont want to add it direcly in xaml, i want to add id in the c# code section)
how to so this?
In your button's Click event, you could do something like:
MyControl control = new MyControl();
// Set whatever properties you need in your control here
LayoutRoot.Children.Add(control);
if (listBox1.Items.Count == 0)
{
Popup popup = new Popup();
WPCpopup po = new WPCpopup(popup);
popup.Width = System.Windows.Application.Current.Host.Content.ActualWidth;
popup.Child = po;
popup.VerticalOffset = 300;
popup.IsOpen = true;
}
WPCpopup is usercontrol
I'm trying to get the parent name of a context menu item.
So I tried something like this on menuItem_click :
Button clikance = (Button)sender;
string ladyGaga = Convert.ToString(clikance.Content);
But it didn't work (invalid cast exception). thx for any help
i have use a different approach for getting the sender button of my context menu. i have made an event on the "hold_click"
where i have get back the content of the button in a public string
private void GestureListener_DoubleTap(object sender, GestureEventArgs e)
{
Button clikance = (Button)sender;
ButtonEnvoyeur = Convert.ToString(clikance.Content);
}
If you look in the debugger at the point where the exception is raised, you'll see that sender isn't a Button, so trying to do an explicit cast to Button will obviously throw an InvalidCastException.
You can use the VisualTreeHelper to walk up the tree from your actual sender to the Button element:
VisualTreeHelper.GetParent((sender as DependencyObject));
UPDATE: In your instance sender is the MenuItem in the ContextMenu. You can get to the parent ContextMenu from the MenuItem by using the VisualTreeHelper, but unfortunately, ContextMenu does not expose any public members that enable you to access the owner; the Owner property is internal. You could get the source code for the Toolkit and expose the Owner property as publi instead, or use a completely different approach.
Have you thought of using an MVVM framework (such as MVVM Light) to wire up commands to these context menu items? Your current approach is very fragile and will break as soon as you change the visual tree. If you used commands, you could pass any additional information that you need for processing via the command parameter.
Use the Tag property of the MenuItem to retrieve your Button :
// Object creation
Button myButtonWithContextMenu = new Button();
ContextMenu contextMenu = new ContextMenu();
MenuItem aMenuItem = new MenuItem
{
Header = "some action",
Tag = myButtonWithContextMenu, // tag contains the button
};
// Events handler
aMenuItem.Click += new RoutedEventHandler(itemClick);
private void itemClick(object sender, RoutedEventArgs e)
{
// Sender is the MenuItem
MenuItem menuItem = sender as MenuItem;
// Retrieve button from tag
Button myButtonWithContextMenu = menuItem.Tag as Button;
(...)
}
Alex.