-
Notifications
You must be signed in to change notification settings - Fork 1
/
goto.go
103 lines (84 loc) · 2.96 KB
/
goto.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
/*
* Copyright (c) 2013-2021 Utkan Güngördü <[email protected]>
* Copyright (c) 2021-2024 Piotr Grabowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gomicsv
import (
"log"
"github.com/fauu/gomicsv/util"
"github.com/gotk3/gotk3/gtk"
)
func (app *App) goToDialogInit() {
_, err := app.W.GoToDialog.AddButton("_Cancel", gtk.RESPONSE_CANCEL)
checkDialogAddButtonErr(err)
goButton, err := app.W.GoToDialog.AddButton("_Go", gtk.RESPONSE_ACCEPT)
checkDialogAddButtonErr(err)
app.W.GoToDialog.SetDefault(goButton)
app.W.GoToSpinButton.Connect("value-changed", func() {
app.W.GoToScrollbar.SetValue(app.W.GoToSpinButton.GetValue())
app.goToDialogUpdateThumbnail()
})
app.W.GoToScrollbar.Connect("value-changed", func() {
app.W.GoToSpinButton.SetValue(app.W.GoToScrollbar.GetValue())
})
}
func (app *App) goToDialogUpdateThumbnail() {
n := int(app.W.GoToSpinButton.GetValue() - 1)
pixbuf, err := app.S.Archive.Load(n, app.Config.EmbeddedOrientation, 0)
if err != nil {
log.Printf("Error getting thumbnail: %v", err)
return
}
w, h := util.Fit(pixbuf.GetWidth(), pixbuf.GetHeight(), 128, 128)
scaled, err := pixbuf.ScaleSimple(w, h, interpolations[app.Config.Interpolation])
if err != nil {
log.Printf("Error scaling thumbnail: %v", err)
return
}
app.S.GoToThumbPixbuf = scaled
app.W.GoToThumbnailImage.SetFromPixbuf(scaled)
util.GC()
}
func (app *App) goToDialogRun() {
if !app.archiveIsLoaded() {
return
}
if app.S.Archive.Len() == nil {
app.goToDialogUpdateSpinButton(9999)
app.W.GoToScrollbar.Hide()
} else {
app.goToDialogUpdateSpinButton(*app.S.Archive.Len())
app.W.GoToScrollbar.SetRange(1, float64(*app.S.Archive.Len()))
app.W.GoToScrollbar.SetValue(float64(app.S.ArchivePos) + 1)
app.W.GoToScrollbar.SetIncrements(1, float64(*app.S.Archive.Len()))
app.W.GoToScrollbar.Show()
}
app.W.GoToSpinButton.GrabFocus()
app.goToDialogUpdateThumbnail()
res := gtk.ResponseType(app.W.GoToDialog.Run())
app.W.GoToDialog.Hide()
if res == gtk.RESPONSE_ACCEPT {
app.setPage(int(app.W.GoToSpinButton.GetValue()) - 1)
app.W.GoToThumbnailImage.Clear()
app.S.GoToThumbPixbuf = nil
util.GC()
}
}
func (app *App) goToDialogUpdateSpinButton(archiveLen int) {
app.W.GoToSpinButton.SetRange(1, float64(archiveLen))
app.W.GoToSpinButton.SetValue(float64(app.S.ArchivePos) + 1)
app.W.GoToSpinButton.SetIncrements(1, float64(app.Config.NSkip))
}