// Called when a new view is opened func (t *qmlfrontend) onNew(v *backend.View) { fv := &frontendView{bv: v} v.Buffer().AddCallback(fv.bufferChanged) v.Settings().AddOnChange("blah", fv.onChange) fv.Title.Text = v.Buffer().FileName() if len(fv.Title.Text) == 0 { fv.Title.Text = "untitled" } w2 := t.windows[v.Window()] w2.views = append(w2.views, fv) tabs := w2.window.ObjectByName("tabs") tab := tabs.Call("addTab", "", limeViewComponent).(qml.Object) try_now := func() { item := tab.Property("item").(qml.Object) if item.Addr() == 0 { // Happens as the item isn't actually loaded until we switch to the tab. // Hence connecting to the loaded signal return } item.Set("myView", fv) } tab.On("loaded", try_now) try_now() }
// Called when a new view is opened func (t *qmlfrontend) onNew(v *backend.View) { fv := &frontendView{bv: v} v.Buffer().AddObserver(fv) v.Settings().AddOnChange("blah", fv.onChange) fv.Title.Text = v.Buffer().FileName() if len(fv.Title.Text) == 0 { fv.Title.Text = "untitled" } w2 := t.windows[v.Window()] w2.views = append(w2.views, fv) tabs := w2.window.ObjectByName("tabs") tab := tabs.Call("addTab", "", limeViewComponent).(qml.Object) try_now := func() { item := tab.Property("item").(qml.Object) if item.Addr() == 0 { // Happens as the item isn't actually loaded until we switch to the tab. // Hence connecting to the loaded signal return } item.Set("myView", fv) item.Set("fontSize", v.Settings().Get("font_size", 12).(float64)) item.Set("fontFace", v.Settings().Get("font_face", "Helvetica").(string)) } tab.On("loaded", try_now) try_now() tabs.Set("currentIndex", tabs.Property("count").(int)-1) }
// called when a view is closed func (t *qmlfrontend) onClose(v *backend.View) { w2 := t.windows[v.Window()] for i := range w2.views { if w2.views[i].bv == v { w2.window.ObjectByName("tabs").Call("removeTab", i) copy(w2.views[i:], w2.views[i+1:]) w2.views = w2.views[:len(w2.views)-1] return } } log4go.Error("Couldn't find closed view...") }
// called when a view has loaded func (t *qmlfrontend) onLoad(v *backend.View) { w2 := t.windows[v.Window()] i := 0 for i, _ = range w2.views { if w2.views[i].bv == v { break } } v2 := w2.views[i] v2.Title.Text = v.Buffer().FileName() t.qmlChanged(v2, &v2.Title) }
// called when a view has loaded func (t *qmlfrontend) onLoad(v *backend.View) { w2 := t.windows[v.Window()] i := 0 for i, _ = range w2.views { if w2.views[i].bv == v { break } } v2 := w2.views[i] v2.Title.Text = v.Buffer().FileName() tabs := w2.window.ObjectByName("tabs") tab := tabs.Call("getTab", i).(qml.Object) tab.Set("title", v2.Title.Text) }