package main import ( "os" "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" ) func GenerateBody(window *gtk.ApplicationWindow, app *gtk.Application) { body := CreateVerticalBox() notebook := CreateNotebook() body.Add(notebook) for _, config := range configs { label := CreateLabel(config.Name) scrolledWindow := CreateScolledWindow() textarea := CreateTextViewNew(config.Content) saveButton := CreateButton("Save") saveButton.SetMarginEnd(5) stopButton := CreateButton("Stop") stopButton.SetMarginEnd(5) startButton := CreateButton("Start") startButton.SetMarginEnd(5) restartButton := CreateButton("Restart") notification := CreateLabel("") notification.SetMarginEnd(5) startButton.Connect("clicked", func() { WgUp(config) }) stopButton.Connect("clicked", func() { WgDown(config) }) restartButton.Connect("clicked", func() { WgDownUp(config) }) saveButton.Connect("clicked", func() { SaveConfig(textarea, config) }) menu := CreateHorizontalBox() menu.Add(notification) menu.Add(saveButton) menu.Add(startButton) menu.Add(stopButton) menu.Add(restartButton) menu.SetHAlign(gtk.ALIGN_END) menu.SetMarginEnd(5) menu.SetMarginTop(5) container := CreateVerticalBox() container.Add(menu) container.Add(textarea) scrolledWindow.Add(container) notebook.AppendPage(scrolledWindow, label) } window.Add(body) } func GenerateHeader(window *gtk.ApplicationWindow, app *gtk.Application) { header, err := gtk.HeaderBarNew() ExitIfErr(err, "gtk.HeaderBarNew") header.SetShowCloseButton(true) header.SetTitle(appMainTitle) header.SetSubtitle(appSubTitle) opener, err := gtk.MenuButtonNew() ExitIfErr(err, "gtk.MenuButtonNew") menu := glib.MenuNew() menu.Append("Quit", "app.quit") closeAction := glib.SimpleActionNew("quit", nil) closeAction.Connect("activate", func() { app.Quit() }) opener.SetMenuModel(&menu.MenuModel) header.PackStart(opener) window.SetTitlebar(header) window.SetPosition(gtk.WIN_POS_MOUSE) window.SetDefaultSize(800, 600) window.SetHExpand(true) app.AddAction(closeAction) } func GenerateApplication() *gtk.Application { app, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE) ExitIfErr(err, "gtk.WindowNew") return app } func GenerateWindow(app *gtk.Application) *gtk.ApplicationWindow { window, err := gtk.ApplicationWindowNew(app) ExitIfErr(err, "gtk.ApplicationWindowNew") return window } func RunGui() { app = GenerateApplication() app.Connect("activate", func() { window := GenerateWindow(app) GenerateHeader(window, app) GenerateBody(window, app) window.ShowAll() }) os.Exit(app.Run([]string{})) }