当前位置: 首页>>代码示例>>C#>>正文


C# ImageMenuItem.Add方法代码示例

本文整理汇总了C#中Gtk.ImageMenuItem.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ImageMenuItem.Add方法的具体用法?C# ImageMenuItem.Add怎么用?C# ImageMenuItem.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gtk.ImageMenuItem的用法示例。


在下文中一共展示了ImageMenuItem.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnButtonPressEvent

        public static void OnButtonPressEvent(Gdk.EventButton evnt, Item item)
        {
            if (evnt.Button == 1)
            {
                item.open();
            }
            else if (evnt.Button == 3)
            {
             	Menu popup_menu = new Menu();

                MenuItem open_item = new MenuItem(Mono.Unix.Catalog.GetString("Open"));
                open_item.Activated += delegate { item.open(); };
                popup_menu.Add(open_item);

                MenuItem open_with_item = new MenuItem(Mono.Unix.Catalog.GetString("Open with"));

                Gnome.Vfs.MimeApplication[] application_handlers = Gnome.Vfs.Mime.GetAllApplications(item.mime_type);

                if (application_handlers.Length > 0) {
                    Menu handlers_menu = new Menu();

                    foreach (Gnome.Vfs.MimeApplication m in application_handlers)
                    {
                        MenuItem handlers_menu_item = new MenuItem(m.Name);
                        GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name
                        tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(item.path));
                        Gnome.Vfs.MimeApplication tmp_m = m; // go lambda bug, go
                        handlers_menu_item.Activated += delegate { tmp_m.Launch(tmp); };
                        handlers_menu.Add(handlers_menu_item);
                    }

                    open_with_item.Submenu = handlers_menu;
                }

                popup_menu.Add(open_with_item);

                MenuItem open_folder = new MenuItem(Mono.Unix.Catalog.GetString("Open dir containing file"));
                open_folder.Activated += delegate {
                    string path = item.path;
                    int index = -1;
                    if ((index = path.LastIndexOf('/')) != -1) {
                        Gnome.Vfs.MimeApplication[] folder_handlers = Gnome.Vfs.Mime.GetAllApplications("inode/directory");
                        GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name
                        tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(path.Substring(0, index+1)));
                        folder_handlers[0].Launch(tmp);
                    }
                };
                popup_menu.Add(open_folder);

                MenuItem clipboard_item = new MenuItem(Mono.Unix.Catalog.GetString("Copy path to clipboard"));
                clipboard_item.Activated += delegate {
                    Gtk.Clipboard clipboard_x = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true));
                    clipboard_x.Text = item.path;
                    Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));
                    clipboard.Text = item.path;
                };
                popup_menu.Add(clipboard_item);

                MenuItem labels_item = new MenuItem(Mono.Unix.Catalog.GetString("Labels"));
                Menu categories_menu = new Menu();

                bool first_category = true;

                foreach (Category cat in Singleton<Categories>.Instance.categories) {

                    if (cat.labels.Count > 0 || Singleton<Categories>.Instance.categories.Count == 1) {

                        if (first_category)
                            first_category = false;
                        else
                            categories_menu.Add(new Gtk.SeparatorMenuItem());

                        MenuItem cat_item = new MenuItem(cat.metalabel.label);
                        categories_menu.Add(cat_item);

                        foreach (UserLabel tmp_label in cat.labels) {
                            UserLabel label = tmp_label; // go lambda bug, go

                            if (!item.contains_label(label))
                            {
                                ImageMenuItem label_item = new ImageMenuItem();

                                Gtk.Label l = new Gtk.Label(label.metalabel.label);
                                l.SetAlignment(0f, 0.5f);
                                GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b));
                                label_item.Add(l);

                                label_item.Image = CairoDrawing.create_dot_image(0, 0, 0, 0, 14, 14);

                                label_item.Activated += delegate { item.make_label(label); };
                                categories_menu.Add(label_item);
                            }
                            else
                            {
                                ImageMenuItem label_item = new ImageMenuItem();

                                Gtk.Label l = new Gtk.Label(label.metalabel.label);
                                l.SetAlignment(0f, 0.5f);
                                GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b));
                                label_item.Add(l);
//.........这里部分代码省略.........
开发者ID:GNOME,项目名称:nemo,代码行数:101,代码来源:Common.cs

示例2: LabelItem

		static MenuItem LabelItem (Gtk.Widget widget)
		{
			ImageMenuItem item;
			Label label;
			
			label = new Label (widget is Placeholder ? Catalog.GetString ("Placeholder") : widget.Name);
			label.UseUnderline = false;
			label.SetAlignment (0.0f, 0.5f);
			item = new ImageMenuItem ();
			item.Add (label);

			Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (widget);
			
			if (wrapper != null) {
				ClassDescriptor klass = wrapper.ClassDescriptor;
				if (klass != null) {
					Gdk.Pixbuf pixbuf = klass.Icon;
					int width, height;
					Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out width, out height);
					item.Image = new Gtk.Image (pixbuf.ScaleSimple (width, height, Gdk.InterpType.Bilinear));
				}
			}
			
			return item;
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:25,代码来源:ContextMenu.cs


注:本文中的Gtk.ImageMenuItem.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。