akiyosi.goneovim/editor/popupmenu.go

620 lines
15 KiB
Go
Raw Normal View History

2017-11-09 02:11:05 +00:00
package editor
2017-03-14 01:52:44 +00:00
2017-03-14 02:40:16 +00:00
import (
2019-02-07 17:33:55 +09:00
"errors"
2017-06-07 11:24:42 +01:00
"fmt"
2019-11-07 21:46:22 +09:00
"math"
2019-05-27 14:20:31 +09:00
"strconv"
2019-11-04 16:14:51 -06:00
"strings"
2017-03-14 02:40:16 +00:00
2019-02-07 17:33:55 +09:00
"github.com/therecipe/qt/core"
2019-02-05 20:21:55 +09:00
"github.com/therecipe/qt/svg"
2019-02-07 17:33:55 +09:00
"github.com/therecipe/qt/widgets"
2019-03-05 23:09:22 +09:00
2019-11-02 10:54:41 +09:00
"github.com/akiyosi/goneovim/util"
2017-03-14 02:40:16 +00:00
)
2017-03-14 01:52:44 +00:00
// PopupMenu is the popupmenu
type PopupMenu struct {
2018-01-05 08:07:29 +00:00
ws *Workspace
2017-06-15 15:54:27 +01:00
widget *widgets.QWidget
2019-11-07 21:46:22 +09:00
itemLayout *widgets.QGridLayout
2017-06-15 15:54:27 +01:00
items []*PopupItem
rawItems []interface{}
total int
showTotal int
selected int
hidden bool
top int
scrollBar *widgets.QWidget
scrollBarPos int
scrollBarHeight int
scrollCol *widgets.QWidget
detailLabel *widgets.QLabel
2017-06-15 15:54:27 +01:00
x int
y int
2019-11-08 23:22:32 +09:00
hideItemIdx [2]bool
2017-03-14 01:52:44 +00:00
}
// PopupItem is
type PopupItem struct {
p *PopupMenu
2019-11-05 07:57:32 -06:00
completeMode string
wordLabel *widgets.QLabel
word string
wordRequest string
kind string
2019-11-07 21:46:22 +09:00
kindIcon *svg.QSvgWidget
2018-05-04 22:44:42 +09:00
menuLabel *widgets.QLabel
menu string
menuRequest string
2018-05-04 22:44:42 +09:00
infoLabel *widgets.QLabel
info string
infoRequest string
2018-05-04 22:44:42 +09:00
2017-06-15 15:54:27 +01:00
selected bool
selectedRequest bool
2018-05-04 22:44:42 +09:00
2018-05-05 08:51:46 +09:00
kindColor *RGBA
kindBg *RGBA
hidden bool
detailText string
2017-06-07 11:24:42 +01:00
}
2019-10-09 01:22:00 +09:00
func initPopupmenuNew() *PopupMenu {
layout := widgets.NewQHBoxLayout()
layout.SetContentsMargins(0, 0, 0, 0)
layout.SetSpacing(10)
widget := widgets.NewQWidget(nil, 0)
widget.SetLayout(layout)
2019-11-07 23:08:08 +09:00
widget.SetContentsMargins(editor.iconSize/5, 0, 0, editor.iconSize/5)
widget.SetMaximumSize2(editor.width, editor.height)
2019-11-07 21:11:47 +09:00
margin := editor.config.Editor.Linespace/2 + 2
itemLayout := widgets.NewQGridLayout2()
itemLayout.SetSpacing(0)
2019-11-07 23:08:08 +09:00
itemLayout.SetContentsMargins(0, editor.iconSize/5, 0, editor.iconSize/5)
2019-11-04 16:14:51 -06:00
2017-06-07 15:52:17 +01:00
scrollCol := widgets.NewQWidget(nil, 0)
scrollCol.SetContentsMargins(0, 0, 0, 0)
scrollCol.SetFixedWidth(5)
scrollBar := widgets.NewQWidget(scrollCol, 0)
scrollBar.SetFixedWidth(5)
2019-11-04 16:14:51 -06:00
2019-11-07 23:08:08 +09:00
detailLabel := widgets.NewQLabel(widget, 0)
2019-11-07 21:11:47 +09:00
detailLabel.SetContentsMargins(margin, margin, margin, margin)
2019-11-07 23:08:08 +09:00
detailLabel.SetObjectName("detailText")
detailLabel.SetWordWrap(true)
2019-11-05 07:57:32 -06:00
layout.AddLayout(itemLayout, 0)
2019-11-07 21:46:22 +09:00
layout.AddWidget(detailLabel, 0, core.Qt__AlignmentFlag(core.Qt__AlignTop|core.Qt__AlignLeft))
2019-11-07 23:08:08 +09:00
layout.AddWidget(scrollCol, 0, 0)
2019-11-04 16:14:51 -06:00
max := editor.config.Popupmenu.Total
2018-05-04 22:44:42 +09:00
popup := &PopupMenu{
widget: widget,
2019-11-07 21:46:22 +09:00
itemLayout: itemLayout,
detailLabel: detailLabel,
total: max,
scrollBar: scrollBar,
scrollCol: scrollCol,
}
2019-11-05 07:57:32 -06:00
var popupItems []*PopupItem
2017-06-07 11:24:42 +01:00
for i := 0; i < max; i++ {
2019-02-05 20:21:55 +09:00
kindIcon := svg.NewQSvgWidget(nil)
kindIcon.SetFixedSize2(editor.iconSize, editor.iconSize)
2019-11-09 09:41:58 +09:00
kindIcon.SetContentsMargins(margin, margin, margin*2, margin)
2019-02-05 20:21:55 +09:00
word := widgets.NewQLabel(widget, 0)
2019-11-09 09:41:58 +09:00
word.SetContentsMargins(margin*2, margin, margin*2, margin)
2019-11-07 23:08:08 +09:00
word.SetObjectName("wordlabel")
2019-03-20 23:02:47 +09:00
menu := widgets.NewQLabel(widget, 0)
menu.SetContentsMargins(margin, margin, margin, margin)
2018-05-04 22:44:42 +09:00
info := widgets.NewQLabel(widget, 0)
info.SetContentsMargins(margin, margin, margin, margin)
2019-11-09 09:41:58 +09:00
itemLayout.AddWidget2(kindIcon, i, 0, 0)
2019-11-07 21:46:22 +09:00
itemLayout.AddWidget2(word, i, 1, 0)
2019-11-07 21:11:47 +09:00
itemLayout.AddWidget2(menu, i, 2, core.Qt__AlignmentFlag(core.Qt__AlignLeft))
itemLayout.AddWidget2(info, i, 3, core.Qt__AlignmentFlag(core.Qt__AlignLeft))
2017-06-07 11:24:42 +01:00
popupItem := &PopupItem{
2019-11-07 21:46:22 +09:00
p: popup,
kindIcon: kindIcon,
wordLabel: word,
menuLabel: menu,
infoLabel: info,
2017-06-07 11:24:42 +01:00
}
popupItems = append(popupItems, popupItem)
}
popup.items = popupItems
2018-05-06 14:49:45 +09:00
2019-09-11 16:11:02 +09:00
popup.widget.SetGraphicsEffect(util.DropShadow(-2, 6, 40, 200))
2018-05-06 14:49:45 +09:00
2017-06-15 09:06:45 +01:00
return popup
2017-03-14 01:52:44 +00:00
}
2017-06-07 11:31:10 +01:00
func (p *PopupMenu) updateFont(font *Font) {
p.detailLabel.SetFont(font.fontNew)
2017-06-07 11:31:10 +01:00
for i := 0; i < p.total; i++ {
popupItem := p.items[i]
popupItem.wordLabel.SetFont(font.fontNew)
2018-05-04 22:44:42 +09:00
popupItem.menuLabel.SetFont(font.fontNew)
popupItem.infoLabel.SetFont(font.fontNew)
2017-06-07 11:31:10 +01:00
}
}
2018-12-27 21:03:21 +09:00
func (p *PopupMenu) setColor() {
fg := editor.colors.widgetFg.String()
2019-11-07 23:08:08 +09:00
detail := warpColor(editor.colors.widgetFg, 10).String()
2018-12-27 21:03:21 +09:00
inactiveFg := editor.colors.inactiveFg.String()
2019-02-17 18:00:09 +09:00
bg := editor.colors.widgetBg
transparent := transparent()
2019-02-06 00:04:35 +09:00
p.scrollBar.SetStyleSheet(fmt.Sprintf("background-color: %s;", inactiveFg))
2019-11-07 23:08:08 +09:00
p.widget.SetStyleSheet(
fmt.Sprintf(`
* { background-color: rgba(%d, %d, %d, %f); color: %s; }
.QLabel { background-color: rgba(0, 0, 0, 0.0); color: %s; }
#wordlabel { color: %s; }
`,
bg.R, bg.G, bg.B, transparent, fg, inactiveFg, fg,
),
)
p.detailLabel.SetStyleSheet(
fmt.Sprintf(
"* { background-color: rgba(0, 0, 0, 0.0); color: %s; }",
detail,
),
)
2018-12-27 21:03:21 +09:00
}
2019-03-18 00:09:49 +09:00
func (p *PopupMenu) setPumblend(arg interface{}) {
var pumblend int
var err error
switch val := arg.(type) {
case string:
pumblend, err = strconv.Atoi(val)
if err != nil {
return
}
case int32: // can't combine these in a type switch without compile error
pumblend = int(val)
case int64:
pumblend = int(val)
default:
return
}
2019-05-27 14:20:31 +09:00
alpha := float64(100-pumblend) / float64(100)
2019-03-18 00:09:49 +09:00
if alpha < 0 {
alpha = 0
}
fg := editor.colors.widgetFg.String()
2019-11-07 23:08:08 +09:00
detail := warpColor(editor.colors.widgetFg, 10).String()
2019-03-18 00:09:49 +09:00
inactiveFg := editor.colors.inactiveFg.String()
bg := editor.colors.widgetBg
p.scrollBar.SetStyleSheet(fmt.Sprintf("background-color: %s;", inactiveFg))
2019-11-07 23:08:08 +09:00
p.widget.SetStyleSheet(
fmt.Sprintf(`
* { background-color: rgba(%d, %d, %d, %f); color: %s; }
.QLabel { background-color: rgba(0, 0, 0, 0.0); color: %s; }
#wordlabel { color: %s; }
`,
bg.R, bg.G, bg.B, alpha, fg, inactiveFg, fg,
),
)
p.detailLabel.SetStyleSheet(
fmt.Sprintf(
"* { background-color: rgba(0, 0, 0, 0.0); color: %s; }",
detail,
),
)
2018-12-27 21:03:21 +09:00
}
2017-06-15 15:54:27 +01:00
func (p *PopupMenu) showItems(args []interface{}) {
2017-03-14 01:52:44 +00:00
arg := args[0].([]interface{})
items := arg[0].([]interface{})
2019-03-05 23:09:22 +09:00
selected := util.ReflectToInt(arg[1])
row := util.ReflectToInt(arg[2])
2019-06-01 14:14:42 +09:00
col := util.ReflectToInt(arg[3])
gridid := util.ReflectToInt(arg[4])
2017-06-07 11:24:42 +01:00
p.rawItems = items
p.selected = selected
p.top = 0
2017-03-14 01:52:44 +00:00
p.detailLabel.SetText("")
2017-03-14 01:52:44 +00:00
popupItems := p.items
itemHeight := p.ws.font.lineHeight
2019-11-07 21:46:22 +09:00
// Calc the maximum completion items
// where,
// `row` is the anchor position, where the first character of the completed word will be
// `p.ws.screen.height` is the entire screen height
2018-01-05 08:07:29 +00:00
heightLeft := p.ws.screen.height - (row+1)*p.ws.font.lineHeight
2017-06-07 11:24:42 +01:00
total := heightLeft / itemHeight
if total < p.total {
p.showTotal = total
} else {
p.showTotal = p.total
}
2019-11-08 23:22:32 +09:00
itemNum := 0
maxItemLen := 0
2017-06-07 11:24:42 +01:00
for i := 0; i < p.total; i++ {
2017-03-14 01:52:44 +00:00
popupItem := popupItems[i]
2017-06-07 11:24:42 +01:00
if i >= len(items) || i >= total {
2017-06-15 09:06:45 +01:00
popupItem.hide()
2017-03-14 01:52:44 +00:00
continue
}
item := items[i].([]interface{})
2019-11-08 23:22:32 +09:00
itemLen := p.detectItemLen(item)
if itemLen > maxItemLen {
maxItemLen = itemLen
}
2017-03-14 01:52:44 +00:00
popupItem.setItem(item, selected == i)
2017-06-15 09:06:45 +01:00
popupItem.show()
2019-11-08 23:22:32 +09:00
itemNum++
}
switch maxItemLen {
case 3:
p.hideItemIdx = [2]bool{false, true}
case 4:
p.hideItemIdx = [2]bool{false, false}
default:
p.hideItemIdx = [2]bool{true, true}
2017-06-07 11:24:42 +01:00
}
2017-03-14 01:52:44 +00:00
2017-06-07 15:52:17 +01:00
if len(items) > p.showTotal {
2017-06-15 15:54:27 +01:00
p.scrollBarHeight = int(float64(p.showTotal) / float64(len(items)) * float64(itemHeight*p.showTotal))
2017-06-15 09:06:45 +01:00
p.scrollBarPos = 0
2017-06-16 08:43:05 +01:00
p.scrollBar.SetFixedHeight(p.scrollBarHeight)
p.scrollBar.Move2(0, p.scrollBarPos)
p.scrollCol.Show()
2017-06-07 15:52:17 +01:00
} else {
2017-06-16 08:43:05 +01:00
p.scrollCol.Hide()
2017-06-07 15:52:17 +01:00
}
2017-06-09 06:54:41 +01:00
popupWidth := editor.iconSize + popupItems[0].wordLabel.Width()
2019-06-02 01:19:23 +09:00
x := int(float64(col) * p.ws.font.truewidth)
2019-11-04 14:03:37 +09:00
y := row*p.ws.font.lineHeight + p.ws.font.lineHeight
if p.ws.drawTabline {
y += p.ws.tabline.widget.Height()
}
2019-11-05 07:57:32 -06:00
if x+popupWidth >= p.ws.screen.widget.Width() {
x = p.ws.screen.widget.Width() - popupWidth - 5
}
2019-11-07 21:46:22 +09:00
win, ok := p.ws.screen.windows[gridid]
if !ok {
return
}
if win != nil {
2019-06-02 01:19:23 +09:00
x += int(float64(win.pos[0]) * p.ws.font.truewidth)
y += win.pos[1] * p.ws.font.lineHeight
2019-01-08 23:11:13 +09:00
}
2019-11-08 23:22:32 +09:00
p.widget.SetFixedHeight(itemNum * (p.ws.font.lineHeight + editor.config.Editor.Linespace + 2) + 2 + editor.iconSize*2/5)
p.widget.Move2(x, y)
2019-02-11 22:02:09 +09:00
p.hide()
2017-06-15 15:54:27 +01:00
p.show()
}
2019-11-08 23:22:32 +09:00
func (p *PopupMenu) detectItemLen(item []interface{}) int {
itemlen := 0
for _, i := range item {
if i.(string) == "" {
continue
}
itemlen++
}
return itemlen
}
2017-06-15 15:54:27 +01:00
func (p *PopupMenu) show() {
p.widget.Raise()
2017-06-16 08:43:05 +01:00
p.widget.Show()
2019-11-08 23:22:32 +09:00
maxWordLabelLen := 0
isMenuHidden := p.hideItemIdx[0]
isInfoHidden := p.hideItemIdx[1]
for _, item := range p.items {
if item.hidden {
continue
}
if isMenuHidden {
item.menuLabel.Hide()
} else {
item.menuLabel.Show()
}
if isInfoHidden {
item.infoLabel.Hide()
} else {
item.infoLabel.Show()
}
wordLabelLen := int(math.Ceil(p.ws.font.fontMetrics.HorizontalAdvance(item.wordLabel.Text(), -1)))
if wordLabelLen > maxWordLabelLen {
maxWordLabelLen = wordLabelLen
}
}
if isMenuHidden && isInfoHidden {
p.detailLabel.Hide()
} else {
p.detailLabel.Show()
}
menuWidth := 0
if !isMenuHidden {
menuWidth = editor.config.Popupmenu.MenuWidth
}
infoWidth := 0
if !isInfoHidden {
infoWidth = editor.config.Popupmenu.InfoWidth
}
detailWidth := 0
if editor.config.Popupmenu.ShowDetail && !isMenuHidden && !isInfoHidden {
detailWidth = editor.config.Popupmenu.DetailWidth
}
margin := editor.config.Editor.Linespace/2 + 2
p.widget.SetFixedWidth(
editor.iconSize*2 + maxWordLabelLen + menuWidth + infoWidth + detailWidth + 5 + margin*4 + editor.iconSize/5*4,
)
2017-06-15 15:54:27 +01:00
}
func (p *PopupMenu) hide() {
2017-06-16 08:43:05 +01:00
p.widget.Hide()
2017-03-14 01:52:44 +00:00
}
func (p *PopupMenu) selectItem(args []interface{}) {
2019-03-05 23:09:22 +09:00
selected := util.ReflectToInt(args[0].([]interface{})[0])
2017-06-16 10:35:53 +01:00
if selected == -1 && p.top > 0 {
2017-06-15 09:06:45 +01:00
p.scroll(-p.top)
2017-06-07 11:24:42 +01:00
}
2017-06-07 11:24:42 +01:00
if selected-p.top >= p.showTotal {
p.scroll(selected - p.top - p.showTotal + 1)
}
2017-06-07 11:24:42 +01:00
if selected >= 0 && selected-p.top < 0 {
p.scroll(-1)
}
2019-11-08 23:22:32 +09:00
isMenuHidden := p.hideItemIdx[0]
isInfoHidden := p.hideItemIdx[1]
for i := 0; i < p.showTotal; i++ {
popupItem := p.items[i]
isSelected := selected == i+p.top
popupItem.setSelected(isSelected)
if isSelected {
if editor.config.Popupmenu.ShowDetail {
2019-11-08 23:22:32 +09:00
if !(isMenuHidden && isInfoHidden) {
popupItem.p.detailLabel.SetText(popupItem.detailText)
popupItem.p.detailLabel.Show()
}
} else {
popupItem.p.detailLabel.Hide()
}
}
}
2017-06-07 11:24:42 +01:00
}
func (p *PopupMenu) scroll(n int) {
p.top += n
items := p.rawItems
popupItems := p.items
2019-11-08 23:22:32 +09:00
maxItemLen := 0
2017-06-07 11:24:42 +01:00
for i := 0; i < p.showTotal; i++ {
popupItem := popupItems[i]
item := items[i+p.top].([]interface{})
2019-11-08 23:22:32 +09:00
itemLen := p.detectItemLen(item)
if itemLen > maxItemLen {
maxItemLen = itemLen
}
2017-06-07 11:24:42 +01:00
popupItem.setItem(item, false)
2017-03-14 01:52:44 +00:00
}
2019-11-08 23:22:32 +09:00
switch maxItemLen {
case 3:
p.hideItemIdx = [2]bool{false, true}
case 4:
p.hideItemIdx = [2]bool{false, false}
default:
p.hideItemIdx = [2]bool{true, true}
}
2017-06-15 09:06:45 +01:00
p.scrollBarPos = int((float64(p.top) / float64(len(items))) * float64(p.widget.Height()))
2017-06-16 08:43:05 +01:00
p.scrollBar.Move2(0, p.scrollBarPos)
2017-06-15 15:54:27 +01:00
p.hide()
p.show()
2017-03-14 01:52:44 +00:00
}
func (p *PopupItem) updateContent() {
2017-06-15 15:54:27 +01:00
if p.selected != p.selectedRequest {
p.selected = p.selectedRequest
2017-06-08 16:03:55 +01:00
if p.selected {
2019-11-09 09:41:58 +09:00
p.kindIcon.SetStyleSheet(fmt.Sprintf("background-color: %s;", editor.colors.selectedBg.StringTransparent()))
p.wordLabel.SetStyleSheet(fmt.Sprintf("background-color: %s;", editor.colors.selectedBg.StringTransparent()))
2019-10-26 02:47:03 +09:00
p.menuLabel.SetStyleSheet(fmt.Sprintf("background-color: %s;", editor.colors.selectedBg.StringTransparent()))
p.infoLabel.SetStyleSheet(fmt.Sprintf("background-color: %s;", editor.colors.selectedBg.StringTransparent()))
2017-06-15 15:54:27 +01:00
} else {
2019-11-09 09:41:58 +09:00
p.kindIcon.SetStyleSheet("background-color: rgba(0, 0, 0, 0);")
p.wordLabel.SetStyleSheet("background-color: rgba(0, 0, 0, 0);")
2019-10-26 02:47:03 +09:00
p.menuLabel.SetStyleSheet("background-color: rgba(0, 0, 0, 0);")
p.infoLabel.SetStyleSheet("background-color: rgba(0, 0, 0, 0);")
2017-06-08 16:03:55 +01:00
}
2017-03-14 01:52:44 +00:00
}
if p.wordRequest != p.word {
p.word = p.wordRequest
p.menu = p.menuRequest
p.info = p.infoRequest
p.wordLabel.SetText(p.word)
2019-11-07 21:11:47 +09:00
menuLines := strings.Split(p.menuRequest, "\n")
infoLines := strings.Split(p.infoRequest, "\n")
p.menuLabel.SetText(menuLines[0])
p.infoLabel.SetText(infoLines[0])
menuLabelTextLen := math.Ceil(p.p.ws.font.fontMetrics.HorizontalAdvance(menuLines[0], -1))
if len(menuLines) > 1 || len(infoLines) > 1 || menuLabelTextLen > float64(editor.config.Popupmenu.MenuWidth) {
p.detailText = p.menuRequest + "\n" + p.infoRequest
} else {
p.detailText = ""
}
2017-06-15 15:54:27 +01:00
}
2019-11-07 21:46:22 +09:00
p.wordLabel.AdjustSize()
// p.menuLabel.AdjustSize()
// p.infoLabel.AdjustSize()
p.menuLabel.SetFixedWidth(editor.config.Popupmenu.MenuWidth)
p.infoLabel.SetFixedWidth(editor.config.Popupmenu.InfoWidth)
2017-06-15 15:54:27 +01:00
}
func (p *PopupItem) setSelected(selected bool) {
p.selectedRequest = selected
p.updateContent()
2017-06-15 15:54:27 +01:00
}
func (p *PopupItem) setItem(item []interface{}, selected bool) {
word := item[0].(string)
kind := item[1].(string)
menu := item[2].(string)
info := item[3].(string)
p.wordRequest = word
p.menuRequest = menu
p.infoRequest = info
p.setKind(kind, selected)
2017-06-15 15:54:27 +01:00
p.setSelected(selected)
2017-03-14 01:52:44 +00:00
}
2019-02-07 17:33:55 +09:00
func detectVimCompleteMode() (string, error) {
2019-02-05 20:21:55 +09:00
w := editor.workspaces[editor.active]
2019-02-07 17:33:55 +09:00
var isEnableCompleteMode int
var enableCompleteMode interface{}
var kind interface{}
w.nvim.Eval("exists('*complete_mode')", &enableCompleteMode)
switch enableCompleteMode.(type) {
case int64:
isEnableCompleteMode = int(enableCompleteMode.(int64))
case uint64:
isEnableCompleteMode = int(enableCompleteMode.(uint64))
case uint:
isEnableCompleteMode = int(enableCompleteMode.(uint))
case int:
isEnableCompleteMode = enableCompleteMode.(int)
}
if isEnableCompleteMode == 1 {
w.nvim.Eval("complete_mode()", &kind)
if kind != nil {
return kind.(string), nil
} else {
return "", nil
}
}
return "", errors.New("Does not exits complete_mode()")
}
func (p *PopupItem) setKind(kind string, selected bool) {
lowerKindText := strings.ToLower(kind)
hiAttrDef := editor.workspaces[editor.active].screen.highAttrDef
var colorOfFunc, colorOfStatement, colorOfType, colorOfKeyword *RGBA
for _, hi := range hiAttrDef {
switch hi.hlName {
case "Function":
colorOfFunc = hi.fg()
case "Statement":
colorOfStatement = hi.fg()
case "Type":
colorOfType = hi.fg()
case "String":
colorOfKeyword = hi.fg()
default:
continue
}
}
switch lowerKindText {
2017-03-14 07:37:15 +00:00
case "function", "func":
icon := editor.getSvg("lsp_function", colorOfFunc)
2019-02-05 20:21:55 +09:00
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
2017-03-14 07:37:15 +00:00
case "var", "statement", "instance", "param", "import":
icon := editor.getSvg("lsp_variable", colorOfStatement)
2019-02-05 20:21:55 +09:00
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
2019-02-11 22:02:09 +09:00
case "class", "type", "struct":
icon := editor.getSvg("lsp_class", colorOfType)
2019-02-11 22:02:09 +09:00
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
2019-02-17 18:00:09 +09:00
case "const", "module", "keyword", "package":
icon := editor.getSvg("lsp_"+lowerKindText, colorOfKeyword)
2019-02-06 00:04:35 +09:00
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
default:
completeMode, err := detectVimCompleteMode()
2019-02-07 17:33:55 +09:00
if err == nil {
p.completeMode = completeMode
2019-02-06 00:04:35 +09:00
}
switch p.completeMode {
2019-02-07 17:33:55 +09:00
case "keyword",
"whole_line",
"files",
"tags",
"path_defines",
"path_patterns",
"path_dictionary",
"path_thesaurus",
"path_cmdline",
"path_function",
"path_omni",
"path_spell",
"path_eval":
icon := editor.getSvg("vim_"+p.completeMode, nil)
2019-02-06 00:04:35 +09:00
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
default:
icon := editor.getSvg("vim_unknown", nil)
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
}
2017-06-15 15:54:27 +01:00
}
2017-03-14 01:52:44 +00:00
}
func (p *PopupItem) hide() {
2017-06-15 09:06:45 +01:00
if p.hidden {
return
}
p.hidden = true
2019-02-05 20:21:55 +09:00
p.kindIcon.Hide()
p.wordLabel.Hide()
2018-05-04 22:44:42 +09:00
p.menuLabel.Hide()
p.infoLabel.Hide()
2017-06-15 09:06:45 +01:00
}
func (p *PopupItem) show() {
if !p.hidden {
return
}
p.hidden = false
2019-02-05 20:21:55 +09:00
p.kindIcon.Show()
p.wordLabel.Show()
2018-05-04 22:44:42 +09:00
p.menuLabel.Show()
p.infoLabel.Show()
2017-03-14 01:52:44 +00:00
}