examples/mdoutliner: initial work on tab closing

This commit is contained in:
mappu 2024-09-07 13:58:14 +12:00
parent 04692b78f8
commit 9a23c644c1
1 changed files with 10 additions and 2 deletions

View File

@ -23,7 +23,6 @@ type AppWindow struct {
cw *qt.QWidget cw *qt.QWidget
tabs *qt.QTabWidget tabs *qt.QTabWidget
tabData []AppTab
} }
type AppTab struct { type AppTab struct {
@ -100,6 +99,11 @@ func NewAppWindow() *AppWindow {
// Main widgets // Main widgets
ret.tabs = qt.NewQTabWidget2(ret.w.QWidget) ret.tabs = qt.NewQTabWidget2(ret.w.QWidget)
ret.tabs.SetTabsClosable(true)
ret.tabs.OnTabCloseRequested(func() {
ret.handleTabClose(ret.tabs.CurrentIndex()) // FIXME need to get this from the signal
})
ret.w.SetCentralWidget(ret.tabs.QWidget) ret.w.SetCentralWidget(ret.tabs.QWidget)
// Add initial tab // Add initial tab
@ -113,6 +117,10 @@ func NewAppWindow() *AppWindow {
return &ret return &ret
} }
func (a *AppWindow) handleTabClose(tabIndex int) {
a.tabs.RemoveTab(tabIndex)
}
func (a *AppWindow) handleFileOpen() { func (a *AppWindow) handleFileOpen() {
fname := qt.QFileDialog_GetOpenFileName4(a.w.QWidget, "Open markdown file...", "", "Markdown files (*.md *.txt);;All Files (*)") fname := qt.QFileDialog_GetOpenFileName4(a.w.QWidget, "Open markdown file...", "", "Markdown files (*.md *.txt);;All Files (*)")
if fname == "" { if fname == "" {