コード例 #1
0
ファイル: commander.go プロジェクト: gitter-badger/vidar
// Init resets c's state.
func (c *Commander) Init(driver gxui.Driver, theme *basic.Theme, font gxui.Font) {
	c.LinearLayout.Init(c, theme)
	c.bindings = make(map[gxui.KeyboardEvent]commands.Command)
	c.driver = driver
	c.theme = theme
	c.font = font
	c.SetDirection(gxui.BottomToTop)
	c.SetSize(math.MaxSize)

	c.controller = controller.New(c.driver, c.theme, c.font)
	c.box = NewCommandBox(c.theme, c.controller)

	c.AddChild(c.box)
	c.AddChild(c.controller)

	// TODO: Store these in a config file or something
	openFile := commands.NewFileOpener(c.driver, c.theme)
	c.commands = append(c.commands, openFile)
	ctrlO := gxui.KeyboardEvent{
		Key:      gxui.KeyO,
		Modifier: gxui.ModControl,
	}
	supO := gxui.KeyboardEvent{
		Key:      gxui.KeyO,
		Modifier: gxui.ModSuper,
	}
	c.bindings[ctrlO] = openFile
	c.bindings[supO] = openFile

	addProject := commands.NewProjectAdder(c.driver, c.theme)
	c.commands = append(c.commands, addProject)
	ctrlShiftN := gxui.KeyboardEvent{
		Key:      gxui.KeyN,
		Modifier: gxui.ModControl | gxui.ModShift,
	}
	supShiftN := gxui.KeyboardEvent{
		Key:      gxui.KeyN,
		Modifier: gxui.ModSuper | gxui.ModShift,
	}
	c.bindings[ctrlShiftN] = addProject
	c.bindings[supShiftN] = addProject
}
コード例 #2
0
ファイル: main.go プロジェクト: nelsam/vidar
func uiMain(driver gxui.Driver) {
	theme := dark.CreateTheme(driver).(*basic.Theme)
	font := font(driver)
	if font == nil {
		font = theme.DefaultMonospaceFont()
	}
	theme.SetDefaultMonospaceFont(font)
	theme.SetDefaultFont(font)
	theme.WindowBackground = background

	// TODO: figure out a better way to get this resolution
	window := theme.CreateWindow(1600, 800, "Vidar - GXUI Go Editor")
	controller := controller.New(driver, theme)

	nav := navigator.New(driver, theme, controller)
	controller.SetNavigator(nav)

	editor := editor.New(driver, window, theme, theme.DefaultMonospaceFont())
	controller.SetEditor(editor)

	projTree := navigator.NewProjectTree(driver, window, theme)
	projects := navigator.NewProjectsPane(driver, theme, projTree.Frame())

	nav.Add(projects)
	nav.Add(projTree)

	nav.Resize(window.Size().H)
	window.OnResize(func() {
		nav.Resize(window.Size().H)
	})

	commander := commander.New(driver, theme, controller)

	// TODO: Check the system's DPI settings for this value
	window.SetScale(1)

	window.AddChild(commander)

	for _, command := range commands.Commands(driver, theme, projTree.Frame()) {
		commander.Map(command, settings.Bindings(command.Name())...)
	}

	window.OnKeyDown(func(event gxui.KeyboardEvent) {
		if (event.Modifier.Control() || event.Modifier.Super()) && event.Key == gxui.KeyQ {
			os.Exit(0)
		}
		if event.Modifier == 0 && event.Key == gxui.KeyF11 {
			window.SetFullscreen(!window.Fullscreen())
		}
		if window.Focus() == nil {
			commander.KeyDown(event)
		}
	})
	window.OnKeyUp(func(event gxui.KeyboardEvent) {
		if window.Focus() == nil {
			commander.KeyPress(event)
		}
	})

	for _, file := range files {
		filepath, err := filepath.Abs(file)
		if err != nil {
			log.Printf("Failed to get path: %s", err)
		}
		commander.Controller().Editor().Open(filepath, token.Position{})
	}

	window.OnClose(driver.Terminate)
	window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10})
}