From fcea1c89a3dad2c175a2c511f02608498e44d272 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Tue, 17 May 2022 10:46:00 +0300 Subject: [PATCH] bug fixing --- editView.go | 2 +- imageView.go | 13 ++++++++-- session.go | 1 + sessionUtils.go | 8 +++++- tabsLayout.go | 66 ++++++++++++++++++++++++++--------------------- textView.go | 9 +++---- viewsContainer.go | 7 ++++- 7 files changed, 67 insertions(+), 39 deletions(-) diff --git a/editView.go b/editView.go index 33074a2..2cad6e5 100644 --- a/editView.go +++ b/editView.go @@ -538,7 +538,7 @@ func (edit *editViewData) handleCommand(self View, command string, data DataObje return edit.viewData.handleCommand(self, command, data) } -// GetText returns a text of the subview. +// GetText returns a text of the EditView subview. // If the second argument (subviewID) is "" then a text of the first argument (view) is returned. func GetText(view View, subviewID string) string { if subviewID != "" { diff --git a/imageView.go b/imageView.go index 9e411fe..e8004ee 100644 --- a/imageView.go +++ b/imageView.go @@ -266,8 +266,17 @@ func GetImageViewSource(view View, subviewID string) string { // GetImageViewAltText returns an alternative text description of an ImageView subview. // If the second argument (subviewID) is "" then a left position of the first argument (view) is returned func GetImageViewAltText(view View, subviewID string) string { - if text, ok := stringProperty(view, AltText, view.Session()); ok { - return text + if subviewID != "" { + view = ViewByID(view, subviewID) + } + + if view != nil { + if value := view.getRaw(AltText); value != nil { + if text, ok := value.(string); ok { + text, _ = view.Session().GetString(text) + return text + } + } } return "" } diff --git a/session.go b/session.go index 28b8774..56fca9e 100644 --- a/session.go +++ b/session.go @@ -264,6 +264,7 @@ func (session *sessionData) setContent(content SessionContent, self Session) boo session.content = content session.rootView = content.CreateRootView(self) if session.rootView != nil { + session.rootView.setParentID("ruiRootView") return true } } diff --git a/sessionUtils.go b/sessionUtils.go index 990db24..e9d7d02 100644 --- a/sessionUtils.go +++ b/sessionUtils.go @@ -29,7 +29,13 @@ func updateCSSStyle(htmlID string, session Session) { func updateInnerHTML(htmlID string, session Session) { if !session.ignoreViewUpdates() { - if view := session.viewByHTMLID(htmlID); view != nil { + var view View + if htmlID == "ruiRootView" { + view = session.RootView() + } else { + view = session.viewByHTMLID(htmlID) + } + if view != nil { script := allocStringBuilder() defer freeStringBuilder(script) diff --git a/tabsLayout.go b/tabsLayout.go index 8aecb8d..6a105a6 100644 --- a/tabsLayout.go +++ b/tabsLayout.go @@ -214,6 +214,11 @@ func (tabsLayout *tabsLayoutData) set(tag string, value interface{}) bool { tabsLayout.tabCloseListener = listeners case Current: + if current, ok := value.(int); ok && current < 0 { + tabsLayout.remove(Current) + return true + } + oldCurrent := tabsLayout.currentItem() if !tabsLayout.setIntProperty(Current, value) { return false @@ -611,7 +616,6 @@ func (tabsLayout *tabsLayoutData) Append(view View) { } defer tabsLayout.propertyChangedEvent(Current) } - updateInnerHTML(tabsLayout.htmlID(), tabsLayout.session) } } @@ -621,7 +625,7 @@ func (tabsLayout *tabsLayoutData) Insert(view View, index int) { tabsLayout.views = []View{} } if view != nil { - if current := tabsLayout.currentItem(); current >= int(index) { + if current := tabsLayout.currentItem(); current >= index { tabsLayout.properties[Current] = current + 1 defer tabsLayout.propertyChangedEvent(Current) } @@ -638,40 +642,46 @@ func (tabsLayout *tabsLayoutData) RemoveView(index int) View { tabsLayout.views = []View{} return nil } - i := int(index) + count := len(tabsLayout.views) - if i >= count { + if index < 0 || index >= count { return nil } - var view View - if count == 1 { - view = tabsLayout.views[0] - tabsLayout.views = []View{} - for _, listener := range tabsLayout.tabListener { - listener(tabsLayout, 0, 0) - } - tabsLayout.propertyChangedEvent(Current) - - } else { - current := tabsLayout.currentItem() - removeCurrent := (i == current) - if i < current || (removeCurrent && i == count-1) { - tabsLayout.properties[Current] = current - 1 - for _, listener := range tabsLayout.tabListener { - listener(tabsLayout, current-1, current) - } - defer tabsLayout.propertyChangedEvent(Current) - } - view = tabsLayout.viewsContainerData.RemoveView(index) - } - + view := tabsLayout.views[index] + view.setParentID("") view.SetChangeListener(Title, nil) view.SetChangeListener(Icon, nil) view.SetChangeListener(TabCloseButton, nil) + + current := tabsLayout.currentItem() + if index < current || (index == current && current > 0) { + current-- + } + + if len(tabsLayout.views) == 1 { + tabsLayout.views = []View{} + current = -1 + } else if index == 0 { + tabsLayout.views = tabsLayout.views[1:] + } else if index == count-1 { + tabsLayout.views = tabsLayout.views[:index] + } else { + tabsLayout.views = append(tabsLayout.views[:index], tabsLayout.views[index+1:]...) + } + + updateInnerHTML(tabsLayout.parentHTMLID(), tabsLayout.session) + tabsLayout.propertyChangedEvent(Content) + + delete(tabsLayout.properties, Current) + tabsLayout.set(Current, current) return view } +func (tabsLayout *tabsLayoutData) currentID() string { + return fmt.Sprintf("%s-%d", tabsLayout.htmlID(), tabsLayout.currentItem()) +} + func (tabsLayout *tabsLayoutData) htmlProperties(self View, buffer *strings.Builder) { tabsLayout.viewsContainerData.htmlProperties(self, buffer) buffer.WriteString(` data-inactiveTabStyle="`) @@ -679,9 +689,7 @@ func (tabsLayout *tabsLayoutData) htmlProperties(self View, buffer *strings.Buil buffer.WriteString(`" data-activeTabStyle="`) buffer.WriteString(tabsLayout.activeTabStyle()) buffer.WriteString(`" data-current="`) - buffer.WriteString(tabsLayout.htmlID()) - buffer.WriteRune('-') - buffer.WriteString(strconv.Itoa(tabsLayout.currentItem())) + buffer.WriteString(tabsLayout.currentID()) buffer.WriteRune('"') } diff --git a/textView.go b/textView.go index c366569..41ed5c9 100644 --- a/textView.go +++ b/textView.go @@ -141,12 +141,11 @@ func textToJS(text string) string { } func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) { - if value, ok := stringProperty(textView, Text, textView.Session()); ok { - if !GetNotTranslate(textView, "") { - value, _ = textView.session.GetString(value) + if value := textView.getRaw(Text); value != nil { + if text, ok := value.(string); ok { + text, _ = textView.session.GetString(text) + buffer.WriteString(textToJS(text)) } - - buffer.WriteString(textToJS(value)) } } diff --git a/viewsContainer.go b/viewsContainer.go index 0730238..a74d859 100644 --- a/viewsContainer.go +++ b/viewsContainer.go @@ -44,7 +44,12 @@ func (container *viewsContainerData) Views() []View { if container.views == nil { container.views = []View{} } - return container.views + if count := len(container.views); count > 0 { + views := make([]View, count) + copy(views, container.views) + return views + } + return []View{} } // Append appends a view to the end of the list of a view children