@@ -22,7 +22,6 @@ import (
2222
2323 "github.com/anacrolix/torrent"
2424 "github.com/jwijenbergh/puregotk/v4/adw"
25- "github.com/jwijenbergh/puregotk/v4/gdk"
2625 "github.com/jwijenbergh/puregotk/v4/gio"
2726 "github.com/jwijenbergh/puregotk/v4/glib"
2827 "github.com/jwijenbergh/puregotk/v4/gobject"
@@ -111,13 +110,10 @@ type MainWindow struct {
111110 adapterCtx context.Context
112111 cancelAdapterCtx func ()
113112
114- descriptionWindow * adw.Window
115- descriptionText * gtk.TextView
116- descriptionHeaderbarTitle * gtk.Label
117- descriptionHeaderbarSubtitle * gtk.Label
118- warningDialog * adw.AlertDialog
119- preferencesDialog * adw.PreferencesWindow
120- mpvCommandInput * adw.EntryRow
113+ descriptionWindow DescriptionWindow
114+ warningDialog WarningDialog
115+ preferencesDialog * adw.PreferencesWindow
116+ mpvCommandInput * adw.EntryRow
121117}
122118
123119func NewMainWindow (
@@ -148,9 +144,9 @@ func NewMainWindow(
148144 v .cancel = cancel
149145 v .tmpDir = tmpDir
150146
151- // TODO: Make these their own subclasses
152- v .initializeDescriptionWindow ()
153- v .initializeWarningDialog ( )
147+ v . descriptionWindow = NewDescriptionWindow ( & v . ApplicationWindow )
148+ v .warningDialog = NewWarningDialog ()
149+ v .warningDialog . SetResponseCallback ( v . onWarningDialogResponse )
154150
155151 v .preferencesDialog , v .mpvCommandInput = AddMainMenu (
156152 ctx ,
@@ -219,60 +215,6 @@ func (w *MainWindow) setupSignalHandlers() {
219215 w .ApplicationWindow .ConnectShow (& onShow )
220216}
221217
222- func (w * MainWindow ) initializeDescriptionWindow () {
223- descriptionBuilder := gtk .NewBuilderFromResource (resources .ResourceDescriptionPath )
224- defer descriptionBuilder .Unref ()
225-
226- var (
227- descriptionWindow adw.Window
228- descriptionText gtk.TextView
229- descriptionHeaderbarTitle gtk.Label
230- descriptionHeaderbarSubtitle gtk.Label
231- )
232- descriptionBuilder .GetObject ("description-window" ).Cast (& descriptionWindow )
233- descriptionBuilder .GetObject ("description-text" ).Cast (& descriptionText )
234- descriptionBuilder .GetObject ("headerbar-title" ).Cast (& descriptionHeaderbarTitle )
235- descriptionBuilder .GetObject ("headerbar-subtitle" ).Cast (& descriptionHeaderbarSubtitle )
236-
237- w .descriptionWindow = & descriptionWindow
238- w .descriptionText = & descriptionText
239- w .descriptionHeaderbarTitle = & descriptionHeaderbarTitle
240- w .descriptionHeaderbarSubtitle = & descriptionHeaderbarSubtitle
241-
242- ctrl := gtk .NewEventControllerKey ()
243- descriptionWindow .AddController (& ctrl .EventController )
244- descriptionWindow .SetTransientFor (& w .ApplicationWindow .Window )
245-
246- closeRequestCallback := func (gtk.Window ) bool {
247- descriptionWindow .Close ()
248- descriptionWindow .SetVisible (false )
249- return true
250- }
251- descriptionWindow .ConnectCloseRequest (& closeRequestCallback )
252-
253- keyReleasedCallback := func (ctrl gtk.EventControllerKey , keyval , keycode uint , state gdk.ModifierType ) {
254- if keycode == keycodeEscape {
255- descriptionWindow .Close ()
256- descriptionWindow .SetVisible (false )
257- }
258- }
259- ctrl .ConnectKeyReleased (& keyReleasedCallback )
260- }
261-
262- func (w * MainWindow ) initializeWarningDialog () {
263- warningBuilder := gtk .NewBuilderFromResource (resources .ResourceWarningPath )
264- defer warningBuilder .Unref ()
265-
266- var warningDialog adw.AlertDialog
267- warningBuilder .GetObject ("warning-dialog" ).Cast (& warningDialog )
268-
269- w .warningDialog = & warningDialog
270-
271- responseCallback := func (dialog adw.AlertDialog , response string ) {
272- w .onWarningDialogResponse (response )
273- }
274- warningDialog .ConnectResponse (& responseCallback )
275- }
276218
277219func (w * MainWindow ) onNext () {
278220 switch w .stack .GetVisibleChildName () {
@@ -413,16 +355,16 @@ func (w *MainWindow) onNext() {
413355 w .previousButton .SetVisible (true )
414356
415357 w .buttonHeaderbarTitle .SetLabel (w .torrentTitle )
416- w .descriptionHeaderbarTitle .SetLabel (w .torrentTitle )
358+ w .descriptionWindow . HeaderbarTitle () .SetLabel (w .torrentTitle )
417359
418360 w .mediaInfoDisplay .SetVisible (false )
419361 w .mediaInfoButton .SetVisible (true )
420362
421- w .descriptionText .SetWrapMode (gtk .WrapWordValue )
363+ w .descriptionWindow . Text () .SetWrapMode (gtk .WrapWordValue )
422364 if ! utf8 .Valid ([]byte (w .torrentReadme )) || strings .TrimSpace (w .torrentReadme ) == "" {
423- w .descriptionText .GetBuffer ().SetText (L (readmePlaceholder ), - 1 )
365+ w .descriptionWindow . Text () .GetBuffer ().SetText (L (readmePlaceholder ), - 1 )
424366 } else {
425- w .descriptionText .GetBuffer ().SetText (w .torrentReadme , - 1 )
367+ w .descriptionWindow . Text () .GetBuffer ().SetText (w .torrentReadme , - 1 )
426368 }
427369
428370 w .stack .SetVisibleChildName (mediaPageName )
@@ -592,24 +534,24 @@ func (w *MainWindow) onNext() {
592534 w .previousButton .SetVisible (true )
593535
594536 w .buttonHeaderbarTitle .SetLabel (w .torrentTitle )
595- w .descriptionHeaderbarTitle .SetLabel (w .torrentTitle )
537+ w .descriptionWindow . HeaderbarTitle () .SetLabel (w .torrentTitle )
596538
597539 w .mediaInfoDisplay .SetVisible (false )
598540 w .mediaInfoButton .SetVisible (true )
599541
600- w .descriptionText .SetWrapMode (gtk .WrapWordValue )
542+ w .descriptionWindow . Text () .SetWrapMode (gtk .WrapWordValue )
601543 if ! utf8 .Valid ([]byte (w .torrentReadme )) || strings .TrimSpace (w .torrentReadme ) == "" {
602- w .descriptionText .GetBuffer ().SetText (L ("No README found." ), - 1 )
544+ w .descriptionWindow . Text () .GetBuffer ().SetText (L ("No README found." ), - 1 )
603545 } else {
604- w .descriptionText .GetBuffer ().SetText (w .torrentReadme , - 1 )
546+ w .descriptionWindow . Text () .GetBuffer ().SetText (w .torrentReadme , - 1 )
605547 }
606548
607549 w .nextButton .SetVisible (false )
608550
609551 w .buttonHeaderbarSubtitle .SetVisible (true )
610- w .descriptionHeaderbarSubtitle .SetVisible (true )
552+ w .descriptionWindow . HeaderbarSubtitle () .SetVisible (true )
611553 w .buttonHeaderbarSubtitle .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
612- w .descriptionHeaderbarSubtitle .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
554+ w .descriptionWindow . HeaderbarSubtitle () .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
613555
614556 w .stack .SetVisibleChildName (readyPageName )
615557 }()
@@ -618,9 +560,9 @@ func (w *MainWindow) onNext() {
618560 w .nextButton .SetVisible (false )
619561
620562 w .buttonHeaderbarSubtitle .SetVisible (true )
621- w .descriptionHeaderbarSubtitle .SetVisible (true )
563+ w .descriptionWindow . HeaderbarSubtitle () .SetVisible (true )
622564 w .buttonHeaderbarSubtitle .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
623- w .descriptionHeaderbarSubtitle .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
565+ w .descriptionWindow . HeaderbarSubtitle () .SetLabel (getDisplayPathWithoutRoot (w .selectedTorrentMedia ))
624566
625567 w .stack .SetVisibleChildName (readyPageName )
626568 }
@@ -640,7 +582,7 @@ func (w *MainWindow) onPrevious(gtk.Button) {
640582 w .nextButton .SetVisible (true )
641583
642584 w .buttonHeaderbarSubtitle .SetVisible (false )
643- w .descriptionHeaderbarSubtitle .SetVisible (false )
585+ w .descriptionWindow . HeaderbarSubtitle () .SetVisible (false )
644586
645587 if ! w .isNewSession {
646588 if w .adapter != nil {
0 commit comments