package ui import ( "fmt" "go_dreamfactory/cmd/v2/lib/common" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/sirupsen/logrus" ) var toolWin *ToolWindowImpl type ToolWindow interface { WindowInterface } type ToolWindowImpl struct { UIImpl parent fyne.Window w fyne.Window tb *toolBar //工具条 sb *statusBar //状态栏 at *appContainer //tabs } func NewToolWindow(ui *UIImpl, parent fyne.Window) ToolWindow { mw := &ToolWindowImpl{ UIImpl: *ui, parent: parent, } toolWin = mw mw.sb = newStatusBar() toolbar := widget.NewToolbar( widget.NewToolbarAction(theme.ContentCopyIcon(), func() { openApp2(mw.at, common.TOOLBAR_GEN) }), widget.NewToolbarAction(theme.ContentAddIcon(), func() { openApp2(mw.at, common.TOOLBAR_PB) }), widget.NewToolbarAction(theme.DownloadIcon(), func() { openApp2(mw.at, common.TOOLBAR_SEC) }), widget.NewToolbarAction(theme.MailSendIcon(), func() { openApp2(mw.at, common.TOOLBAR_TERM) }), widget.NewToolbarAction(theme.ComputerIcon(), func() { openApp2(mw.at, common.TOOLBAR_PING) }), widget.NewToolbarAction(theme.SettingsIcon(), func() { openApp2(mw.at, common.TOOLBAR_MGODB) }), widget.NewToolbarSpacer(), widget.NewToolbarAction(theme.HelpIcon(), func() { showAbout() }), ) mw.tb = newToolBar(toolbar) mw.at = newAppContainer(toolRegister, nil, ui.obs) return mw } func (ui *ToolWindowImpl) CreateWindow(title string, width, height float32, _ bool) { w := ui.app.NewWindow(fmt.Sprintf("工具箱 %s %s", title, ui.app.Metadata().Version)) ui.AddWindow("tool", w) ui.w = w // content content := container.NewBorder(ui.tb.toolbar, ui.sb.widget, nil, nil, ui.at) ui.w.SetContent(content) appName, err := ui.at.openDefaultApp(common.TOOLBAR_WEL) if err != nil { logrus.WithField("appName", appName).Error(err) } w.Resize(fyne.NewSize(width, height)) // w.SetMaster() w.Canvas().SetOnTypedKey(func(ke *fyne.KeyEvent) { switch ke.Name { case fyne.KeyEscape: { w.Close() ui.parent.Show() } } }) w.CenterOnScreen() w.SetCloseIntercept(func() { ui.parent.Show() w.Close() }) w.Show() }