Ejemplo n.º 1
0
func (e *TabbedEditor) Open(hiddenPrefix, path, headerText string, environ []string) *CodeEditor {
	name := relPath(hiddenPrefix, path)
	if editor, ok := e.editors[name]; ok {
		e.Select(e.PanelIndex(editor))
		e.Focus()
		return editor
	}
	editor := &CodeEditor{}
	// We want the OnRename trigger set up before the editor opens the file
	// in its Init method.
	editor.OnRename(func(newPath string) {
		e.driver.Call(func() {
			delete(e.editors, name)
			newName := relPath(hiddenPrefix, newPath)
			focused := e.SelectedPanel()
			e.editors[newName] = editor
			idx := e.PanelIndex(editor)
			if idx == -1 {
				return
			}
			e.RemovePanel(editor)
			e.AddPanelAt(editor, newName, idx)
			e.Select(e.PanelIndex(focused))
			e.Focus()
		})
	})
	editor.Init(e.driver, e.theme, e.font, path, headerText)
	editor.SetTabWidth(4)
	suggester := suggestions.NewGoCodeProvider(editor, environ)
	editor.SetSuggestionProvider(suggester)
	e.Add(name, editor)
	return editor
}
Ejemplo n.º 2
0
func (e *Editor) Open(file string) {
	if editor, ok := e.editors[file]; ok {
		e.Select(e.PanelIndex(editor))
		e.Focus()
		return
	}
	editor := new(editor)
	editor.Init(e.driver, e.theme, e.font, file)
	editor.SetTabWidth(8)
	suggester := suggestions.NewGoCodeProvider(editor).(*suggestions.GoCodeProvider)
	editor.SetSuggestionProvider(suggester)

	e.editors[file] = editor
	e.AddPanel(editor, file)
	e.Select(e.PanelIndex(editor))
	e.Focus()
}