Beispiel #1
0
func createMenu(depth int, tearoff bool) gtk3.WidgetLike {
	if depth < 1 {
		return nil
	}

	var group *glib.GSList
	menu := gtk3.NewMenu()

	if tearoff {
		mt := gtk3.NewTearoffMenuItem()
		menu.Append(mt)
		mt.Show()
	}

	for i, j := 0, 1; i < 5; i, j = i+1, j+1 {
		mi := gtk3.NewRadioMenuItemWithLabel(group, fmt.Sprintf("item %2d - %d", depth, j))
		group = mi.GetGroup()

		menu.Append(mi)
		mi.Show()

		if i == 3 {
			mi.SetSensitive(false)
		}
		mi.SetSubmenu(createMenu(depth-1, true))
	}

	return menu
}
Beispiel #2
0
func createSearchMenu(entry *gtk3.Entry) *gtk3.Menu {
	menu := gtk3.NewMenu()

	item := gtk3.NewImageMenuItemWithMnemonic("Search by _name")
	image := gtk3.NewImageFromStock(gtk3.GtkStock.FIND, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.FIND)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by name\nClick here to change the search type")
		entry.SetPlaceholderText("name")
	})
	menu.Append(item)

	item = gtk3.NewImageMenuItemWithMnemonic("Search by _description")
	image = gtk3.NewImageFromStock(gtk3.GtkStock.EDIT, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.EDIT)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by description\nClick here to change the search type")
		entry.SetPlaceholderText("description")
	})
	menu.Append(item)

	item = gtk3.NewImageMenuItemWithMnemonic("Search by _file name")
	image = gtk3.NewImageFromStock(gtk3.GtkStock.OPEN, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.OPEN)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by file name\nClick here to change the search type")
		entry.SetPlaceholderText("file name")
	})
	menu.Append(item)

	menu.ShowAll()

	return menu
}