コード例 #1
0
ファイル: main.go プロジェクト: kch42/biomed
func (g *GUI) Init() {
	g.biomes = ReadDefaultBiomes()

	g.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	g.window.SetTitle("biomed")

	g.accel = gtk.NewAccelGroup()
	g.window.AddAccelGroup(g.accel)

	menubar := g.mkMenuBar()
	vbox := gtk.NewVBox(false, 0)
	vbox.PackStart(menubar, false, false, 0)

	hbox := gtk.NewHBox(false, 0)

	g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy}, MkBiomeLookup(g.biomes))
	hbox.PackStart(g.mapw.DArea(), true, true, 3)

	sidebar := g.mkSidebar()
	hbox.PackEnd(sidebar, false, false, 3)

	vbox.PackStart(hbox, true, true, 0)

	g.statusbar = gtk.NewStatusbar()
	g.statusContext = g.statusbar.GetContextId("mapinfo")
	vbox.PackEnd(g.statusbar, false, false, 0)

	g.window.Add(vbox)
	g.window.SetDefaultSize(800, 600)

	g.window.Connect("destroy", g.exitApp)

	g.setTool(NewFillTool())
}
コード例 #2
0
ファイル: inotify_unix.go プロジェクト: udhos/tabby
// Returns true in case of reloading files, and false in case of keeping as is.
func inotify_dialog(s map[string]int) bool {
	if nil == accel_group {
		accel_group = gtk.NewAccelGroup()
	}
	inotify_dlg := gtk.NewDialog()
	defer inotify_dlg.Destroy()
	inotify_dlg.SetTitle("Some files have beed modified outside of tabby")
	inotify_dlg.AddButton("_Reload all", gtk.RESPONSE_ACCEPT)
	inotify_dlg.AddButton("_Keep all as is", gtk.RESPONSE_CANCEL)
	w := inotify_dlg.GetWidgetForResponse(int(gtk.RESPONSE_ACCEPT))
	inotify_dlg.AddAccelGroup(accel_group)
	w.AddAccelerator("clicked", accel_group, gdk.KEY_Return,
		0, gtk.ACCEL_VISIBLE)
	inotify_dlg.SetSizeRequest(800, 350)
	inotify_store := gtk.NewTreeStore(gtk.TYPE_STRING)
	inotify_view := gtk.NewTreeView()
	inotify_view.AppendColumn(
		gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 0))
	inotify_view.ModifyFontEasy("Regular 8")
	inotify_model := inotify_store.ToTreeModel()
	inotify_view.SetModel(inotify_model)
	inotify_view.SetHeadersVisible(false)
	var iter gtk.TreeIter
	for name, _ := range s {
		inotify_store.Append(&iter, nil)
		inotify_store.Set(&iter, name)
	}
	inotify_view.SetVisible(true)
	view_window := gtk.NewScrolledWindow(nil, nil)
	view_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	view_window.SetVisible(true)
	view_window.Add(inotify_view)
	vbox := inotify_dlg.GetVBox()
	vbox.Add(view_window)
	if gtk.RESPONSE_ACCEPT == inotify_dlg.Run() {
		return true
	}
	return false
}
コード例 #3
0
ファイル: navigation.go プロジェクト: udhos/tabby
func init_navigation() {
	accel_group = gtk.NewAccelGroup()
}
コード例 #4
0
ファイル: main.go プロジェクト: JessonChan/tabby
func init_tabby() {
	init_navigation()
	init_inotify()

	search_view.Init()

	source_buf = gtksourceview.NewSourceBuffer()
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("modified-changed", buf_changed_cb, nil)

	init_lang()

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

	tree_store = gtk.NewTreeStore(glib.G_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)

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

	source_view = gtksourceview.NewSourceViewWithBuffer(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.SetTabWidth(2)
	source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
	source_view.SetDrawSpaces(gtksourceview.SOURCE_DRAW_SPACES_TAB)
	source_view.SetSmartHomeEnd(gtksourceview.SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.WRAP_WORD)

	vbox := gtk.NewVBox(false, 0)
	inner_hpaned := gtk.NewHPaned()
	view_vpaned := gtk.NewVPaned()
	outer_hpaned := gtk.NewHPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

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

	file_item := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.NewMenu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.NewAccelGroup()

	new_item := gtk.NewMenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.KEY_n, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	open_item := gtk.NewMenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.KEY_o, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

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

	save_item := gtk.NewMenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.KEY_s, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

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

	close_item := gtk.NewMenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.KEY_w, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

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

	navigation_item := gtk.NewMenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.NewMenu()
	navigation_item.SetSubmenu(navigation_submenu)

	prev_instance_item := gtk.NewMenuItemWithMnemonic("_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.KEY_F2,
		0, gtk.ACCEL_VISIBLE)

	next_instance_item := gtk.NewMenuItemWithMnemonic("_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.KEY_F3,
		0, gtk.ACCEL_VISIBLE)

	prev_result_item := gtk.NewMenuItemWithMnemonic("Prev search result")
	navigation_submenu.Append(prev_result_item)
	prev_result_item.Connect("activate", func() { search_view.PrevResult() }, nil)
	prev_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F4,
		0, gtk.ACCEL_VISIBLE)

	next_result_item := gtk.NewMenuItemWithMnemonic("Next search result")
	navigation_submenu.Append(next_result_item)
	next_result_item.Connect("activate", func() { search_view.NextResult() }, nil)
	next_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F5,
		0, gtk.ACCEL_VISIBLE)

	find_item := gtk.NewMenuItemWithMnemonic("_Find")
	navigation_submenu.Append(find_item)
	find_item.Connect("activate", find_cb, nil)
	find_item.AddAccelerator("activate", accel_group, gdk.KEY_f, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	find_file_item := gtk.NewMenuItemWithMnemonic("_Find file")
	navigation_submenu.Append(find_file_item)
	find_file_item.Connect("activate", find_file_cb, nil)
	find_file_item.AddAccelerator("activate", accel_group, gdk.KEY_d, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	fnr_item := gtk.NewMenuItemWithMnemonic("Find and Replace")
	navigation_submenu.Append(fnr_item)
	fnr_item.Connect("activate", fnr_cb, nil)
	fnr_item.AddAccelerator("activate", accel_group, gdk.KEY_r, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	prev_file_item := gtk.NewMenuItemWithMnemonic("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.KEY_F7,
		0, gtk.ACCEL_VISIBLE)

	next_file_item := gtk.NewMenuItemWithMnemonic("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.KEY_F8,
		0, gtk.ACCEL_VISIBLE)

	tools_item := gtk.NewMenuItemWithMnemonic("_Tools")
	menubar.Append(tools_item)
	tools_submenu := gtk.NewMenu()
	tools_item.SetSubmenu(tools_submenu)

	gofmt_item := gtk.NewMenuItemWithMnemonic("_Gofmt")
	tools_submenu.Append(gofmt_item)
	gofmt_item.Connect("activate", gofmt_cb, nil)
	gofmt_item.AddAccelerator("activate", accel_group, gdk.KEY_F9,
		0, gtk.ACCEL_VISIBLE)

	gofmtAll_item := gtk.NewMenuItemWithMnemonic("Gofmt _All")
	tools_submenu.Append(gofmtAll_item)
	gofmtAll_item.Connect("activate", gofmt_all, nil)
	gofmtAll_item.AddAccelerator("activate", accel_group, gdk.KEY_F9, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	options_item := gtk.NewMenuItemWithMnemonic("_Options")
	menubar.Append(options_item)
	options_submenu := gtk.NewMenu()
	options_item.SetSubmenu(options_submenu)

	search_chkitem := gtk.NewCheckMenuItemWithMnemonic("Show _Searchview")
	options_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.NewCheckMenuItemWithMnemonic("Show _Errorview")
	options_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.NewCheckMenuItemWithMnemonic("Spaces for _Tabs")
	options_submenu.Append(notab_chkitem)
	notab_chkitem.SetActive(opt.space_not_tab)
	notab_chkitem.Connect("toggled", func() { notab_chk_cb(notab_chkitem.GetActive()) }, nil)

	font_item := gtk.NewMenuItemWithMnemonic("_Font")
	options_submenu.Append(font_item)
	font_item.Connect("activate", font_cb, nil)

	tabsize_item := gtk.NewMenuItemWithMnemonic("_Tab size")
	options_submenu.Append(tabsize_item)
	tabsize_submenu := gtk.NewMenu()
	tabsize_item.SetSubmenu(tabsize_submenu)
	const tabsize_cnt = 8
	tabsize_chk := make([]*gtk.CheckMenuItem, tabsize_cnt)
	for y := 0; y < tabsize_cnt; y++ {
		tabsize_chk[y] = gtk.NewCheckMenuItemWithMnemonic(strconv.Itoa(y + 1))
		tabsize_submenu.Append(tabsize_chk[y])
		cur_ind := y
		tabsize_chk[y].Connect("activate", func() {
			if false == tabsize_chk[cur_ind].GetActive() {
				active_cnt := 0
				for j := 0; j < tabsize_cnt; j++ {
					if tabsize_chk[j].GetActive() {
						active_cnt++
					}
				}
				if 0 == active_cnt {
					tabsize_chk[cur_ind].SetActive(true)
				}
				return
			}
			for j := 0; j < tabsize_cnt; j++ {
				if j != cur_ind {
					tabsize_chk[j].SetActive(false)
				}
			}
			options_set_tabsize(cur_ind + 1)
		},
			nil)
	}

	tree_window := gtk.NewScrolledWindow(nil, nil)
	tree_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	inner_hpaned.Add1(tree_window)
	tree_window.Add(tree_view)

	outer_hpaned.Add2(search_view.window)

	text_window := gtk.NewScrolledWindow(nil, nil)
	text_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
	view_vpaned.Add1(text_window)
	text_window.Add(source_view)

	error_window = gtk.NewScrolledWindow(nil, nil)
	error_window.SetPolicy(gtk.POLICY_AUTOMATIC, 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.NewWindow(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 when is called after ShowAll.
	init_vars()
	main_window.ShowAll()
	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()
}