This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
107 lines (88 loc) · 2.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"log"
"path/filepath"
"github.com/DK-92/harviewer/screens/model"
"github.com/DK-92/harviewer/screens/logic"
_ "github.com/andlabs/ui/winmanifest"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
type ApplicationWindow struct {
*walk.MainWindow
tabWidget *walk.TabWidget
prevFilePath string
}
func main() {
mw := new(ApplicationWindow)
var openAction *walk.Action
if _, err := (MainWindow{
AssignTo: &mw.MainWindow,
Title: "Haralyzer",
MenuItems: []MenuItem{
Menu{
Text: "&File",
Items: []MenuItem{
Action{
AssignTo: &openAction,
Text: "&Open",
OnTriggered: mw.openAction_Triggered,
},
Separator{},
Action{
Text: "Exit",
OnTriggered: func() { mw.Close() },
},
},
},
Menu{
Text: "&Help",
Items: []MenuItem{
Action{
Text: "About",
OnTriggered: mw.aboutAction_Triggered,
},
},
},
},
MinSize: Size{320, 240},
Size: Size{800, 600},
Layout: VBox{MarginsZero: true},
Children: []Widget{
TabWidget{
AssignTo: &mw.tabWidget,
},
},
}.Run()); err != nil {
log.Fatal(err)
}
}
func (mw *ApplicationWindow) openAction_Triggered() {
if err := mw.openFile(); err != nil {
log.Print(err)
}
}
func (mw *ApplicationWindow) openFile() error {
fileDialog := new(walk.FileDialog)
fileDialog.FilePath = mw.prevFilePath
fileDialog.Filter = "Image Files (*.har)|*.har"
fileDialog.Title = "Select a file"
if ok, err := fileDialog.ShowOpen(mw); err != nil {
return err
} else if !ok {
return nil
}
mw.prevFilePath = fileDialog.FilePath
position := logic.LoadHarFile(mw.MainWindow, fileDialog.FilePath)
if position != -1 {
page, _ := walk.NewTabPage()
page.SetTitle(filepath.Base(fileDialog.FilePath))
mw.tabWidget.Pages().Add(page)
mw.tabWidget.SetCurrentIndex(mw.tabWidget.Pages().Len() - 1)
model.MakeFileContentTab(page, position, filepath.Base(fileDialog.FilePath))
}
return nil
}
func (mw *ApplicationWindow) aboutAction_Triggered() {
walk.MsgBox(mw, "About", "Standalone HAR viewer for Windows.\n\nVersion 1.0 released on 20-06-2019.", walk.MsgBoxIconInformation)
}