예제 #1
0
파일: navigation.go 프로젝트: udhos/tabby
func find_prev_instance(start, be, en *gtk.TextIter, pattern string) bool {
	if start.BackwardSearch(pattern, 0, be, en, nil) {
		return true
	}
	source_buf.GetEndIter(be)
	return be.BackwardSearch(pattern, 0, be, en, nil)
}
예제 #2
0
파일: navigation.go 프로젝트: udhos/tabby
func find_next_instance(start, be, en *gtk.TextIter, pattern string) bool {
	if start.ForwardSearch(pattern, 0, be, en, nil) {
		return true
	}
	source_buf.GetStartIter(be)
	return be.ForwardSearch(pattern, 0, be, en, nil)
}
예제 #3
0
파일: navigation.go 프로젝트: udhos/tabby
func mark_set_cb() {
	var cur gtk.TextIter
	var be, en gtk.TextIter

	source_buf.GetSelectionBounds(&be, &en)
	selection := source_buf.GetSlice(&be, &en, false)
	if prev_selection == selection {
		return
	}
	prev_selection = selection

	if selection_flag {
		source_buf.GetStartIter(&be)
		source_buf.GetEndIter(&en)
		source_buf.RemoveTagByName("instance", &be, &en)
		selection_flag = false
	}

	sel_len := len(selection)
	if (sel_len <= 1) || (sel_len >= MAX_SEL_LEN) {
		return
	} else {
		selection_flag = true
	}

	source_buf.GetStartIter(&cur)
	for cur.ForwardSearch(selection, 0, &be, &cur, nil) {
		source_buf.ApplyTagByName("instance", &be, &cur)
	}
}
예제 #4
0
파일: textview.go 프로젝트: hauke96/go-gtk
func main() {
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.SetIconName("textview")
	window.Connect("destroy", gtk.MainQuit)

	textview := gtk.NewTextView()
	textview.SetEditable(true)
	textview.SetCursorVisible(true)
	var iter gtk.TextIter
	buffer := textview.GetBuffer()

	buffer.GetStartIter(&iter)
	buffer.Insert(&iter, "Hello ")

	tag := buffer.CreateTag("bold", map[string]string{"background": "#FF0000", "weight": "700"})
	buffer.InsertWithTag(&iter, "Google!", tag)

	u := "http://www.google.com"
	tag.SetData("tag-name", unsafe.Pointer(&u))
	textview.Connect("event-after", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		if ev := *(**gdk.EventAny)(unsafe.Pointer(&arg)); ev.Type != gdk.BUTTON_RELEASE {
			return
		}
		ev := *(**gdk.EventButton)(unsafe.Pointer(&arg))
		var iter gtk.TextIter
		textview.GetIterAtLocation(&iter, int(ev.X), int(ev.Y))
		tags := iter.GetTags()
		for n := uint(0); n < tags.Length(); n++ {
			vv := tags.NthData(n)
			tag := gtk.NewTextTagFromPointer(vv)
			u := *(*string)(tag.GetData("tag-name"))
			fmt.Println(u)
		}
	})

	window.Add(textview)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
예제 #5
0
파일: tools.go 프로젝트: udhos/tabby
func gofmt(file string) {
	rec, _ := file_map[file]
	var buf []byte
	if file == cur_file {
		buf = []byte(get_source())
	} else {
		buf = rec.buf
	}
	bin := os.Getenv("GOBIN")
	if bin != "" {
		bin = filepath.Join(bin, "gofmt")
	} else {
		bin, _ = exec.LookPath("gofmt")
	}
	std, error, e := get_output([]string{bin}, buf)
	if e != nil {
		tabby_log(e.Error())
		return
	}
	if file == cur_file {
		error_buf.SetText(string(error))
	} else {
		rec.error = error
	}
	if 0 != len(error) {
		return
	}
	if file == cur_file {
		if string(buf) != string(std) {
			var be, en gtk.TextIter
			source_buf.GetSelectionBounds(&be, &en)
			sel_be := be.GetOffset()
			source_buf.SetText(string(std))
			source_buf.GetIterAtOffset(&be, sel_be)
			move_focus_and_selection(&be, &be)
		}
	} else if string(rec.buf) != string(std) {
		rec.buf = std
		rec.modified = true
	}
}
예제 #6
0
func fnr_find_next(pattern string, global bool, map_filled *bool, m *map[string]int) bool {
	var be, en, scope_en gtk.TextIter
	get_iter_at_mark_by_name("fnr_en", &scope_en)
	get_iter_at_mark_by_name("selection_bound", &en)
	if en.ForwardSearch(pattern, 0, &be, &en, &scope_en) {
		move_focus_and_selection(&be, &en)
		return true
	}
	// Have to switch to next file or to beginning of current depending on <global>.
	if global {
		// Switch to next file.
		fnr_find_next_fill_global_map(pattern, m, map_filled)
		next_file := pop_string_from_map(m)
		if "" == next_file {
			return false
		}
		file_save_current()
		file_switch_to(next_file)
		fnr_refresh_scope(true)
		source_buf.GetStartIter(&be)
		source_buf.MoveMarkByName("insert", &be)
		source_buf.MoveMarkByName("selection_bound", &be)
		return fnr_find_next(pattern, global, map_filled, m)
	} else {
		// Temporary fix. Is there necessity to search the document all over again?
		return false
		// Start search from beginning of scope.
		// get_iter_at_mark_by_name("fnr_be", &be)
		// if be.ForwardSearch(pattern, 0, &be, &en, &scope_en) {
		//	move_focus_and_selection(&be, &en)
		//	return true
		//} else {
		//	return false
		//}
	}
	return false
}
예제 #7
0
파일: navigation.go 프로젝트: udhos/tabby
func file_save_current() {
	var be, en gtk.TextIter
	rec, found := file_map[cur_file]
	if false == found {
		rec = new(FileRecord)
	}
	rec.buf = ([]byte)(get_source())
	rec.modified = source_buf.GetModified()
	source_buf.GetSelectionBounds(&be, &en)
	rec.sel_be = be.GetOffset()
	rec.sel_en = en.GetOffset()
	file_stack_push(cur_file)
	if found {
		runtime.GC()
	}
}