Skip to content

Commit 7e85ebe

Browse files
committed
hsapp: remove hsinput; use giu implementation of imput handler
1 parent 270fa82 commit 7e85ebe

File tree

22 files changed

+82
-352
lines changed

22 files changed

+82
-352
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ linters:
4747
- goconst
4848
- gocritic
4949
- gocyclo
50-
- godox
5150
- gofmt
5251
- goimports
5352
- gomnd

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/go-resty/resty/v2 v2.6.0 // indirect
1313
github.com/gravestench/osinfo v0.0.0-20210525170338-34eb1ac010f7
1414
github.com/hajimehoshi/oto v0.7.1 // indirect
15-
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69
15+
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649
1616
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6
1717
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
1818
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
@@ -25,6 +25,6 @@ require (
2525
golang.org/x/exp v0.0.0-20210526181343-b47a03e3048a // indirect
2626
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e // indirect
2727
golang.org/x/mobile v0.0.0-20210527171505-7e972142eb43 // indirect
28-
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
28+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
2929
golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b // indirect
3030
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk
6060
github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
6161
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69 h1:8/TnUIv7dy6smaOQiWsOB9MMHbiOgHrllYXRimQPx+Y=
6262
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69/go.mod h1:twqK/c83RuUbBV8sWkV9TMpcdaBs3Pec2FBN5gC+hEA=
63+
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649 h1:V+knrBNqCF2mrLnQRSiS27DwlSlOqzQxwE7Nx0dQCfA=
64+
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649/go.mod h1:twqK/c83RuUbBV8sWkV9TMpcdaBs3Pec2FBN5gC+hEA=
6365
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6 h1:cYyhJBJpHS3ccwS/Hn9SI4T3SUzORnfiBvB+/1mopLs=
6466
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6/go.mod h1:XJ3IHn74S/5gKA6R5tYya4x7bsucY4tHgfnGO94FmEc=
6567
github.com/jakecoffman/cp v1.0.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
@@ -162,6 +164,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
162164
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
163165
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo=
164166
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
167+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
168+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
165169
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
166170
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
167171
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

hsapp/app.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/OpenDiablo2/HellSpawner/hscommon/hsfiletypes"
2020
"github.com/OpenDiablo2/HellSpawner/hscommon/hsproject"
2121
"github.com/OpenDiablo2/HellSpawner/hsconfig"
22-
"github.com/OpenDiablo2/HellSpawner/hsinput"
2322
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hsaboutdialog"
2423
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hspreferencesdialog"
2524
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hsprojectpropertiesdialog"
@@ -95,7 +94,6 @@ type App struct {
9594
diabloBoldFont imgui.Font
9695
diabloRegularFont imgui.Font
9796

98-
InputManager *hsinput.InputManager
9997
TextureLoader hscommon.TextureLoader
10098

10199
showUsage bool
@@ -108,7 +106,6 @@ func Create() (*App, error) {
108106
editors: make([]hscommon.EditorWindow, 0),
109107
editorConstructors: make(map[hsfiletypes.FileType]editorConstructor),
110108
TextureLoader: hscommon.NewTextureLoader(),
111-
InputManager: hsinput.NewInputManager(),
112109
abyssWrapper: abysswrapper.Create(),
113110
}
114111

@@ -128,7 +125,7 @@ func (a *App) Run() (err error) {
128125
// setting up the logging here, as opposed to inside of app.setup(),
129126
// because of the deferred call to logfile.Close()
130127
if a.config.LoggingToFile || *a.Flags.logFile != "" {
131-
var path = a.config.LogFilePath
128+
path := a.config.LogFilePath
132129
if *a.Flags.logFile != "" {
133130
path = *a.Flags.logFile
134131
}
@@ -157,7 +154,6 @@ func (a *App) Run() (err error) {
157154
}
158155
}
159156

160-
a.masterWindow.SetInputCallback(a.InputManager.HandleInput)
161157
a.masterWindow.Run(a.render)
162158

163159
return nil

hsapp/menubar.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,26 +333,31 @@ func (a *App) renderEditors() {
333333
if !editor.IsVisible() {
334334
editor.Cleanup()
335335

336-
if editor.HasFocus() {
337-
a.focusedEditor = nil
338-
}
339-
340336
a.editors = append(a.editors[:idx], a.editors[idx+1:]...)
341337

342338
continue
343339
}
344340

345341
hadFocus := editor.HasFocus()
346342

343+
// common shortcut
344+
editor.RegisterKeyboardShortcuts(
345+
g.WindowShortcut{
346+
Key: g.KeyS,
347+
Modifier: g.ModControl,
348+
Callback: func() {
349+
editor.Save()
350+
},
351+
},
352+
)
353+
354+
editor.RegisterKeyboardShortcuts(
355+
editor.KeyboardShortcuts()...,
356+
)
357+
347358
editor.Build()
348359

349-
// if this window didn't have focus before, but it does now,
350-
// unregister any other window's shortcuts, and register this window's keyboard shortcuts instead
351360
if !hadFocus && editor.HasFocus() {
352-
a.InputManager.UnregisterWindowShortcuts()
353-
354-
editor.RegisterKeyboardShortcuts(a.InputManager)
355-
356361
a.focusedEditor = editor
357362
}
358363

hsapp/setup.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ func (a *App) setupMainMpqExplorer() error {
152152

153153
func (a *App) setupProjectExplorer() error {
154154
x, y := float32(projectExplorerDefaultX), float32(projectExplorerDefaultY)
155+
155156
window, err := hsprojectexplorer.Create(a.TextureLoader,
156157
a.openEditor, x, y)
157-
158158
if err != nil {
159159
return fmt.Errorf("error creating a project explorer: %w", err)
160160
}
@@ -248,17 +248,19 @@ func (a *App) setupFonts() {
248248
}
249249

250250
func (a *App) registerGlobalKeyboardShortcuts() {
251-
a.InputManager.RegisterShortcut(a.onNewProjectClicked, g.KeyN, g.ModControl+g.ModShift, true)
252-
a.InputManager.RegisterShortcut(a.onOpenProjectClicked, g.KeyO, g.ModControl, true)
253-
a.InputManager.RegisterShortcut(a.Save, g.KeyS, g.ModControl, true)
254-
a.InputManager.RegisterShortcut(a.onFilePreferencesClicked, g.KeyP, g.ModAlt, true)
255-
a.InputManager.RegisterShortcut(a.Quit, g.KeyQ, g.ModAlt, true)
256-
a.InputManager.RegisterShortcut(a.onHelpAboutClicked, g.KeyF1, g.ModNone, true)
257-
258-
a.InputManager.RegisterShortcut(a.closeActiveEditor, g.KeyW, g.ModControl, true)
259-
a.InputManager.RegisterShortcut(func() { a.closePopups(); a.closeActiveEditor() }, g.KeyEscape, g.ModNone, true)
260-
261-
a.InputManager.RegisterShortcut(a.toggleMPQExplorer, g.KeyM, g.ModControl+g.ModShift, true)
262-
a.InputManager.RegisterShortcut(a.toggleProjectExplorer, g.KeyP, g.ModControl+g.ModShift, true)
263-
a.InputManager.RegisterShortcut(a.toggleConsole, g.KeyC, g.ModControl+g.ModShift, true)
251+
a.masterWindow.RegisterKeyboardShortcuts(
252+
g.WindowShortcut{Key: g.KeyN, Modifier: g.ModControl + g.ModShift, Callback: a.onNewProjectClicked},
253+
g.WindowShortcut{Key: g.KeyO, Modifier: g.ModControl, Callback: a.onOpenProjectClicked},
254+
g.WindowShortcut{Key: g.KeyS, Modifier: g.ModControl, Callback: a.Save},
255+
g.WindowShortcut{Key: g.KeyP, Modifier: g.ModAlt, Callback: a.onFilePreferencesClicked},
256+
g.WindowShortcut{Key: g.KeyQ, Modifier: g.ModAlt, Callback: a.Quit},
257+
g.WindowShortcut{Key: g.KeyF1, Modifier: g.ModNone, Callback: a.onHelpAboutClicked},
258+
259+
g.WindowShortcut{Key: g.KeyW, Modifier: g.ModControl, Callback: a.closeActiveEditor},
260+
g.WindowShortcut{Key: g.KeyEscape, Modifier: g.ModNone, Callback: func() { a.closePopups(); a.closeActiveEditor() }},
261+
262+
g.WindowShortcut{Key: g.KeyM, Modifier: g.ModControl + g.ModShift, Callback: a.toggleMPQExplorer},
263+
g.WindowShortcut{Key: g.KeyP, Modifier: g.ModControl + g.ModShift, Callback: a.toggleProjectExplorer},
264+
g.WindowShortcut{Key: g.KeyC, Modifier: g.ModControl + g.ModShift, Callback: a.toggleConsole},
265+
)
264266
}

hscommon/renderable.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package hscommon
22

3-
import (
4-
"github.com/OpenDiablo2/HellSpawner/hsinput"
5-
)
3+
import "github.com/ianling/giu"
64

75
// Renderable represents renderable objects
86
type Renderable interface {
97
Build()
108
Cleanup()
11-
RegisterKeyboardShortcuts(inputManager *hsinput.InputManager)
9+
// KeyboardShortcuts returns a list of keyboard shortcuts
10+
KeyboardShortcuts() []giu.WindowShortcut
1211
IsVisible() bool
12+
// RegisterKeyboardShortcuts wraps giu.RegisterKeyboardShortcuts
13+
RegisterKeyboardShortcuts(...giu.WindowShortcut)
1314
}

hsinput/input_handler.go

Lines changed: 0 additions & 97 deletions
This file was deleted.

hsinput/input_handler_test.go

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)