Ejemplo n.º 1
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Stock Icons")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	}, nil)

	swin := gtk.ScrolledWindow(nil, nil)

	store := gtk.ListStore(gtk.TYPE_STRING, gtk.TYPE_BOOL, gdkpixbuf.GetGdkPixbufType())
	treeview := gtk.TreeView()
	swin.Add(treeview)

	treeview.SetModel(store.ToTreeModel())
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("name", gtk.CellRendererText(), "text", 0))
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("check", gtk.CellRendererToggle(), "active", 1))
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("icon", gtk.CellRendererPixbuf(), "pixbuf", 2))
	n := 0
	gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) {
		id := glib.GPtrToString(d)
		var iter gtk.GtkTreeIter
		store.Append(&iter)
		store.Set(&iter, id, (n == 1), gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf)
		n = 1 - n
	}, 0)

	window.Add(swin)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
Ejemplo n.º 2
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Folder View")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	},
		nil)

	swin := gtk.ScrolledWindow(nil, nil)

	store := gtk.TreeStore(gdkpixbuf.GetGdkPixbufType(), gtk.TYPE_STRING)
	treeview := gtk.TreeView()
	swin.Add(treeview)

	treeview.SetModel(store.ToTreeModel())
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("pixbuf", gtk.CellRendererPixbuf(), "pixbuf", 0))
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 1))

	for n := 1; n <= 10; n++ {
		var iter1, iter2, iter3 gtk.GtkTreeIter
		store.Append(&iter1, nil)
		store.Set(&iter1, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "Folder"+strconv.Itoa(n))
		store.Append(&iter2, &iter1)
		store.Set(&iter2, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n))
		store.Append(&iter3, &iter2)
		store.Set(&iter3, gtk.Image().RenderIcon(gtk.GTK_STOCK_FILE, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "File"+strconv.Itoa(n))
	}

	treeview.Connect("row_activated", func() {
		var path *gtk.GtkTreePath
		var column *gtk.GtkTreeViewColumn
		treeview.GetCursor(&path, &column)
		mes := "TreePath is: " + path.String()
		dialog := gtk.MessageDialog(
			treeview.GetTopLevelAsWindow(),
			gtk.GTK_DIALOG_MODAL,
			gtk.GTK_MESSAGE_INFO,
			gtk.GTK_BUTTONS_OK,
			mes)
		dialog.SetTitle("TreePath")
		dialog.Response(func() {
			dialog.Destroy()
		},
			nil)
		dialog.Run()
	},
		nil)

	window.Add(swin)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
Ejemplo n.º 3
0
func init_tabby() {
	init_navigation()
	gdk.ThreadsInit()
	inotify_init()

	lang_man := gtk.SourceLanguageManagerGetDefault()
	lang := lang_man.GetLanguage("go")
	if nil == lang.SourceLanguage {
		println("tabby: warning: no language specification")
	}
	source_buf = gtk.SourceBuffer()
	source_buf.SetLanguage(lang)
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("changed", buf_changed_cb, nil)

	source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})

	tree_store = gtk.TreeStore(gtk.TYPE_STRING)
	tree_view = file_tree.NewFileTree()
	tree_view.ModifyFontEasy("Regular 8")
	tree_model = tree_store.ToTreeModel()
	tree_view.SetModel(tree_model)
	tree_view.SetHeadersVisible(false)
	tree_view.Connect("cursor-changed", tree_view_select_cb, nil)

	search_store = gtk.TreeStore(gtk.TYPE_STRING)
	search_view = file_tree.NewSearchTree()
	search_view.ModifyFontEasy("Regular 8")
	search_model = search_store.ToTreeModel()
	search_view.SetModel(search_model)
	search_view.AppendColumn(gtk.TreeViewColumnWithAttributes(
		"", gtk.CellRendererText(), "text", 0))
	search_view.SetHeadersVisible(false)
	search_view.Connect("cursor-changed", search_view_select_cb, nil)

	error_view = gtk.TextView()
	error_view.ModifyFontEasy("Monospace Regular 8")
	error_view.SetEditable(false)
	error_buf = error_view.GetBuffer()

	source_view = gtk.SourceViewWithBuffer(source_buf)
	source_view.ModifyFontEasy("Monospace Regular 10")
	source_view.SetAutoIndent(true)
	source_view.SetHighlightCurrentLine(true)
	source_view.SetShowLineNumbers(true)
	source_view.SetRightMarginPosition(80)
	source_view.SetShowRightMargin(true)
	source_view.SetIndentWidth(2)
	source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
	source_view.SetDrawSpaces(gtk.GTK_SOURCE_DRAW_SPACES_TAB)
	source_view.SetTabWidth(2)
	source_view.SetSmartHomeEnd(gtk.GTK_SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.GTK_WRAP_WORD)

	vbox := gtk.VBox(false, 0)
	inner_hpaned := gtk.HPaned()
	view_vpaned := gtk.VPaned()
	outer_hpaned := gtk.HPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

	menubar := gtk.MenuBar()
	vbox.PackStart(menubar, false, false, 0)
	vbox.PackStart(outer_hpaned, true, true, 0)

	file_item := gtk.MenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.Menu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.AccelGroup()

	new_item := gtk.MenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.GDK_n,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	open_item := gtk.MenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.GDK_o,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	open_rec_item := gtk.MenuItemWithMnemonic("Open _Recursively")
	file_submenu.Append(open_rec_item)
	open_rec_item.Connect("activate", open_rec_cb, nil)

	save_item := gtk.MenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.GDK_s,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	save_as_item := gtk.MenuItemWithMnemonic("Save _as")
	file_submenu.Append(save_as_item)
	save_as_item.Connect("activate", save_as_cb, nil)

	close_item := gtk.MenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.GDK_w,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	exit_item := gtk.MenuItemWithMnemonic("E_xit")
	file_submenu.Append(exit_item)
	exit_item.Connect("activate", exit_cb, nil)

	navigation_item := gtk.MenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.Menu()
	navigation_item.SetSubmenu(navigation_submenu)

	prev_instance_item := gtk.MenuItemWithMnemonic("_Previous Instance")
	navigation_submenu.Append(prev_instance_item)
	prev_instance_item.Connect("activate", prev_instance_cb, nil)
	prev_instance_item.AddAccelerator("activate", accel_group, gdk.GDK_F2,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_instance_item := gtk.MenuItemWithMnemonic("_Next Instance")
	navigation_submenu.Append(next_instance_item)
	next_instance_item.Connect("activate", next_instance_cb, nil)
	next_instance_item.AddAccelerator("activate", accel_group, gdk.GDK_F3,
		0, gtk.GTK_ACCEL_VISIBLE)

	find_item := gtk.MenuItemWithMnemonic("_Find")
	navigation_submenu.Append(find_item)
	find_item.Connect("activate", find_cb, nil)
	find_item.AddAccelerator("activate", accel_group, gdk.GDK_f,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	fnr_item := gtk.MenuItemWithMnemonic("Find and Replace")
	navigation_submenu.Append(fnr_item)
	fnr_item.Connect("activate", fnr_cb, nil)
	fnr_item.AddAccelerator("activate", accel_group, gdk.GDK_r,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	prev_file_item := gtk.MenuItemWithMnemonic("Prev File")
	navigation_submenu.Append(prev_file_item)
	prev_file_item.Connect("activate", prev_file_cb, nil)
	prev_file_item.AddAccelerator("activate", accel_group, gdk.GDK_F7,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_file_item := gtk.MenuItemWithMnemonic("Next File")
	navigation_submenu.Append(next_file_item)
	next_file_item.Connect("activate", next_file_cb, nil)
	next_file_item.AddAccelerator("activate", accel_group, gdk.GDK_F8,
		0, gtk.GTK_ACCEL_VISIBLE)

	tools_item := gtk.MenuItemWithMnemonic("_Tools")
	menubar.Append(tools_item)
	tools_submenu := gtk.Menu()
	tools_item.SetSubmenu(tools_submenu)

	gofmt_item := gtk.MenuItemWithMnemonic("_Gofmt")
	tools_submenu.Append(gofmt_item)
	gofmt_item.Connect("activate", gofmt_cb, nil)
	gofmt_item.AddAccelerator("activate", accel_group, gdk.GDK_F9,
		0, gtk.GTK_ACCEL_VISIBLE)

	gofmtAll_item := gtk.MenuItemWithMnemonic("Gofmt _All")
	tools_submenu.Append(gofmtAll_item)
	gofmtAll_item.Connect("activate", gofmt_all, nil)
	gofmtAll_item.AddAccelerator("activate", accel_group, gdk.GDK_F9,
		gdk.GDK_CONTROL_MASK, gtk.GTK_ACCEL_VISIBLE)

	view_item := gtk.MenuItemWithMnemonic("_View")
	menubar.Append(view_item)
	view_submenu := gtk.Menu()
	view_item.SetSubmenu(view_submenu)

	search_chkitem := gtk.CheckMenuItemWithMnemonic("Show _Searchview")
	view_submenu.Append(search_chkitem)
	search_chkitem.SetActive(opt.show_search)
	search_chkitem.Connect("toggled", func() { search_chk_cb(search_chkitem.GetActive()) }, nil)

	error_chkitem := gtk.CheckMenuItemWithMnemonic("Show _Errorview")
	view_submenu.Append(error_chkitem)
	error_chkitem.SetActive(opt.show_error)
	error_chkitem.Connect("toggled", func() { error_chk_cb(error_chkitem.GetActive()) }, nil)

	notab_chkitem := gtk.CheckMenuItemWithMnemonic("Spaces for _Tabs")
	view_submenu.Append(notab_chkitem)
	notab_chkitem.SetActive(opt.space_not_tab)
	notab_chkitem.Connect("toggled", func() { notab_chk_cb(notab_chkitem.GetActive()) }, nil)

	tree_window := gtk.ScrolledWindow(nil, nil)
	tree_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	inner_hpaned.Add1(tree_window)
	tree_window.Add(tree_view)

	search_window = gtk.ScrolledWindow(nil, nil)
	search_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	outer_hpaned.Add2(search_window)
	search_window.Add(search_view)

	text_window := gtk.ScrolledWindow(nil, nil)
	text_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_ALWAYS)
	view_vpaned.Add1(text_window)
	text_window.Add(source_view)

	error_window = gtk.ScrolledWindow(nil, nil)
	error_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_ALWAYS)
	view_vpaned.Add2(error_window)
	error_window.Add(error_view)

	inner_hpaned.Connect("size_request", func() { ohp_cb(outer_hpaned.GetPosition()) }, nil)
	view_vpaned.Connect("size_request", func() { ihp_cb(inner_hpaned.GetPosition()) }, nil)
	source_view.Connect("size_request", func() { vvp_cb(view_vpaned.GetPosition()) }, nil)
	outer_hpaned.SetPosition(opt.ohp_position)
	inner_hpaned.SetPosition(opt.ihp_position)
	view_vpaned.SetPosition(opt.vvp_position)

	main_window = gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	main_window.AddAccelGroup(accel_group)
	main_window.SetSizeRequest(400, 200) //minimum size
	main_window.Resize(opt.window_width, opt.window_height)
	main_window.Move(opt.window_x, opt.window_y)
	main_window.Connect("destroy", exit_cb, "")
	main_window.Connect("configure-event", window_event_cb, "")
	main_window.Add(vbox)
	// init_tabby blocks for some reason if called after ShowAll.
	init_vars()
	main_window.ShowAll()
	search_window.SetVisible(opt.show_search)
	error_window.SetVisible(opt.show_error)
	// Cannot be called before ShowAll. This is also not clear.
	file_switch_to(file_stack_pop())
	stack_prev(&file_stack_max)
	if "" == cur_file {
		new_cb()
	}
	source_view.GrabFocus()
}