I've put together a very basic sample that tries to use accelerators.
Clicking on the menu item's call the methods appropriately, but the
accelerators don't work. I used AccelMap.AddEntry() to map the
accelerators to paths, then told the menu items what their accelerator
paths were. Is more needed? I still can't figure out how to use
AccelGroup, as I don't know how to make an IntPtr closure (notice the
??? in the accelGroup.Connect() calls). The documentation for
AccelGroup says to use ItemFactory, but the documentation for
ItemFactory has "Obselete" and "Do not use" in it.
The sample code is attached. Help on this would be great, it doesn't
seem like it should be this complicated.
On Tue, Aug 26, 2008 at 12:03 AM, True Friend <[EMAIL PROTECTED]> wrote:
> I tried to use this shortcut but couldn't. I had created an Accelerator for
> Gtk.Toolbar.Action button in MD sidebar with Ctrl + o but it doesn't
> activate the button while on click activates it.
> Something more to do after adding key combination in md designer's sidebar?
> Regards
>
> --
> Muhammad Shakir Aziz محمد شاکر عزیز
>
>
using System;
using Gtk;
namespace MenuAccels
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
}
class MainWindow : Gtk.Window
{
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Title = "Menu Accels Demo";
SetSizeRequest(600, 600);
DeleteEvent += OnDelete;
// add the accelerators to the accelmap
Gtk.AccelMap.AddEntry("<Demo>/File/New", Gdk.Keyval.FromName("n"), Gdk.ModifierType.ControlMask);
Gtk.AccelMap.AddEntry("<Demo>/File/Open", Gdk.Keyval.FromName("o"), Gdk.ModifierType.ControlMask);
// create the accel group
// Gtk.AccelGroup accelGroup = new Gtk.AccelGroup();
// AddAccelGroup(accelGroup);
// accelGroup.Connect(Gdk.Keyval.FromName("n"), Gdk.ModifierType.ControlMask, Gtk.AccelFlags.Visible, ???);
// accelGroup.ConnectByPath("<Demo>/File/New", ???);
// create the menu and add it to the window
Gtk.VBox vbox = new Gtk.VBox();
Add(vbox);
Gtk.MenuBar menuBar = new Gtk.MenuBar();
vbox.PackStart(menuBar, false, true, 0);
// add the file menu
Gtk.MenuItem fileItem = new Gtk.MenuItem("File");
menuBar.Append(fileItem);
Gtk.Menu fileMenu = new Gtk.Menu();
fileItem.Submenu = fileMenu;
Gtk.MenuItem newItem = new Gtk.MenuItem("New");
newItem.Activated += OnNewFile;
newItem.AccelPath = "<Demo>/File/New";
fileMenu.Append(newItem);
Gtk.MenuItem openItem = new Gtk.MenuItem("Open");
fileMenu.Append(openItem);
openItem.Activated += OnOpenFile;
openItem.AccelPath = "<Demo>/File/Open";
ShowAll();
}
protected void OnDelete(object sender, Gtk.DeleteEventArgs args)
{
args.RetVal = true;
Gtk.Application.Quit();
}
protected void OnNewFile(object sender, EventArgs args)
{
Console.WriteLine("new file");
}
protected void OnOpenFile(object sender, EventArgs args)
{
Console.WriteLine("open file");
}
}
}
_______________________________________________
Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list