mirror of
https://github.com/bloeys/gopad.git
synced 2025-12-29 15:08:21 +00:00
Native windows open file dialog
This commit is contained in:
36
main.go
36
main.go
@ -16,7 +16,9 @@ import (
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
//TODO: Cache os.ReadDir so we don't have to use lots of disk
|
||||
// @TODO:
|
||||
// - Cache os.ReadDir so we don't have to use lots of disk
|
||||
// - Seems undo is broken
|
||||
|
||||
type Gopad struct {
|
||||
Win *engine.Window
|
||||
@ -85,7 +87,7 @@ func main() {
|
||||
// so we do it here
|
||||
g.LoadFonts()
|
||||
|
||||
// engine.SetVSync(true)
|
||||
engine.SetVSync(true)
|
||||
engine.Run(&g, g.Win, g.ImGUIInfo)
|
||||
}
|
||||
|
||||
@ -171,6 +173,18 @@ func (g *Gopad) Update() {
|
||||
g.showErrorPopup()
|
||||
}
|
||||
|
||||
if input.KeyDownCaptured(sdl.K_LCTRL) && input.KeyClickedCaptured(sdl.K_o) {
|
||||
|
||||
filepath, err := OpenFileDialog("Open")
|
||||
if err != nil && err != Err_No_File_Chosen {
|
||||
g.triggerError(err.Error())
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
g.loadFileFromPath(filepath)
|
||||
}
|
||||
}
|
||||
|
||||
if input.MouseClickedCaptued(sdl.BUTTON_LEFT) {
|
||||
x, y := input.GetMousePos()
|
||||
g.getActiveEditor().SetCursorPos(int(x), int(y))
|
||||
@ -189,15 +203,11 @@ func (g *Gopad) Update() {
|
||||
e := g.getActiveEditor()
|
||||
|
||||
//Save if needed
|
||||
if !e.IsModified {
|
||||
return
|
||||
if e.IsModified {
|
||||
if input.KeyDownCaptured(sdl.K_LCTRL) && input.KeyClickedCaptured(sdl.K_s) {
|
||||
g.saveEditor(e)
|
||||
}
|
||||
}
|
||||
|
||||
if !input.KeyDownCaptured(sdl.K_LCTRL) || !input.KeyClickedCaptured(sdl.K_s) {
|
||||
return
|
||||
}
|
||||
|
||||
g.saveEditor(e)
|
||||
}
|
||||
|
||||
func (g *Gopad) saveEditor(e *Editor) {
|
||||
@ -406,11 +416,11 @@ func (g *Gopad) drawDir(dir fs.DirEntry, path string) {
|
||||
func (g *Gopad) drawFile(f fs.DirEntry, path string) {
|
||||
|
||||
if imgui.Button(f.Name()) {
|
||||
g.handleFileClick(path)
|
||||
g.loadFileFromPath(path)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Gopad) handleFileClick(fPath string) {
|
||||
func (g *Gopad) loadFileFromPath(fPath string) {
|
||||
|
||||
//Check if we already have the file open
|
||||
editorIndex := -1
|
||||
@ -432,11 +442,13 @@ func (g *Gopad) handleFileClick(fPath string) {
|
||||
//Read new file and switch to it
|
||||
e := NewEditor(fPath)
|
||||
e.RefreshFontSettings()
|
||||
|
||||
g.editors = append(g.editors, e)
|
||||
g.activeEditor = len(g.editors) - 1
|
||||
}
|
||||
|
||||
func (g *Gopad) FrameEnd() {
|
||||
|
||||
g.newRunes = []rune{}
|
||||
|
||||
// Close editors if needed
|
||||
|
||||
Reference in New Issue
Block a user