Skip to content

Commit ee88c08

Browse files
committed
Open file specified as the first command line arg
Closes #7
1 parent 404f5e8 commit ee88c08

1 file changed

Lines changed: 44 additions & 35 deletions

File tree

main.go

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log"
1111
"os"
1212
"os/signal"
13+
"path/filepath"
1314
"strconv"
1415
"strings"
1516

@@ -127,6 +128,43 @@ func run() error {
127128
openingMsg := container.NewCenter(widget.NewLabel("Opening ..."))
128129
gridScroll := container.NewVScroll(widget.NewLabel(""))
129130

131+
open := func(path string) {
132+
var err error
133+
134+
win.SetContent(openingMsg)
135+
sess, err = session.New(path)
136+
win.SetContent(startContent)
137+
if err != nil {
138+
dialog.ShowError(err, win)
139+
return
140+
}
141+
var grid *PageGrid
142+
grid = NewPageGrid(sess.PageCount(), func(page int) {
143+
win.SetContent(editingMsg)
144+
defer win.SetContent(openedContent)
145+
146+
modified, err := sess.Annotate(page)
147+
if err != nil {
148+
dialog.ShowError(err, win)
149+
return
150+
}
151+
if modified {
152+
grid.SetThumbnail(page, nil)
153+
}
154+
grid.SetAnnotated(page, sess.IsAnnotated(page))
155+
}, func(page int) {
156+
sess.Clear(page)
157+
grid.SetAnnotated(page, false)
158+
})
159+
160+
gridScroll.Content = grid.Root()
161+
162+
_, name := filepath.Split(path)
163+
fileNameLabel.SetText("Annotating: " + name)
164+
filePathLabel.SetText(path)
165+
win.SetContent(openedContent)
166+
}
167+
130168
startContent = container.NewCenter(widget.NewButton("Open PDF File", func() {
131169
dialog.ShowFileOpen(func(r fyne.URIReadCloser, err error) {
132170

@@ -146,40 +184,7 @@ func run() error {
146184
return
147185
}
148186
path = strings.TrimPrefix(path, "file://")
149-
150-
// Create a new annotation session and page grid
151-
152-
win.SetContent(openingMsg)
153-
sess, err = session.New(path)
154-
win.SetContent(startContent)
155-
if err != nil {
156-
dialog.ShowError(err, win)
157-
return
158-
}
159-
var grid *PageGrid
160-
grid = NewPageGrid(sess.PageCount(), func(page int) {
161-
win.SetContent(editingMsg)
162-
defer win.SetContent(openedContent)
163-
164-
modified, err := sess.Annotate(page)
165-
if err != nil {
166-
dialog.ShowError(err, win)
167-
return
168-
}
169-
if modified {
170-
grid.SetThumbnail(page, nil)
171-
}
172-
grid.SetAnnotated(page, sess.IsAnnotated(page))
173-
}, func(page int) {
174-
sess.Clear(page)
175-
grid.SetAnnotated(page, false)
176-
})
177-
178-
gridScroll.Content = grid.Root()
179-
180-
fileNameLabel.SetText("Annotating: " + r.URI().Name())
181-
filePathLabel.SetText(path)
182-
win.SetContent(openedContent)
187+
open(path)
183188

184189
}, win)
185190
}))
@@ -241,7 +246,11 @@ func run() error {
241246

242247
win.Resize(fyne.NewSize(600, 500))
243248
win.SetContent(startContent)
244-
win.ShowAndRun()
249+
win.Show()
250+
if flag.Arg(0) != "" {
251+
open(flag.Arg(0))
252+
}
253+
ap.Run()
245254

246255
return nil
247256
}

0 commit comments

Comments
 (0)