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-11-07 21:11:47 +09:00
|
|
|
"math"
|
2019-02-07 17:33:55 +09:00
|
|
|
"errors"
|
2017-06-07 11:24:42 +01:00
|
|
|
"fmt"
|
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-06 23:19:46 +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
|
2019-11-06 23:19:46 +09:00
|
|
|
detailLabel *widgets.QLabel
|
2017-06-15 15:54:27 +01:00
|
|
|
x int
|
|
|
|
y int
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PopupItem is
|
|
|
|
type PopupItem struct {
|
2019-11-05 11:37:23 -06:00
|
|
|
p *PopupMenu
|
2019-11-05 07:57:32 -06:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
completeMode string
|
|
|
|
|
|
|
|
wordLabel *widgets.QLabel
|
|
|
|
word string
|
|
|
|
wordRequest string
|
|
|
|
|
|
|
|
kind string
|
|
|
|
kindIconWidget *widgets.QWidget
|
2019-02-05 20:21:55 +09:00
|
|
|
kindIcon *svg.QSvgWidget
|
2018-05-04 22:44:42 +09:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
menuLabel *widgets.QLabel
|
|
|
|
menu string
|
|
|
|
menuRequest string
|
2018-05-04 22:44:42 +09:00
|
|
|
|
2019-11-06 23:19:46 +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
|
2019-11-06 23:19:46 +09:00
|
|
|
|
|
|
|
detailText string
|
2017-06-07 11:24:42 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 01:22:00 +09:00
|
|
|
func initPopupmenuNew() *PopupMenu {
|
2019-11-06 23:19:46 +09:00
|
|
|
layout := widgets.NewQHBoxLayout()
|
|
|
|
layout.SetContentsMargins(0, 0, 0, 0)
|
|
|
|
layout.SetSpacing(10)
|
|
|
|
|
|
|
|
widget := widgets.NewQWidget(nil, 0)
|
|
|
|
widget.SetLayout(layout)
|
|
|
|
widget.SetContentsMargins(1, 1, 1, 1)
|
|
|
|
widget.SetMaximumSize2(editor.width, editor.height)
|
|
|
|
|
2019-11-07 21:11:47 +09:00
|
|
|
margin := editor.config.Editor.Linespace/2 + 2
|
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
itemLayout := widgets.NewQGridLayout2()
|
|
|
|
itemLayout.SetSpacing(0)
|
|
|
|
itemLayout.SetContentsMargins(0, editor.iconSize/5, 0, 0)
|
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-05 11:37:23 -06:00
|
|
|
detailLabel := widgets.NewQLabel(nil, 0)
|
2019-11-07 21:11:47 +09:00
|
|
|
detailLabel.SetContentsMargins(margin, margin, margin, margin)
|
2019-11-05 11:37:23 -06:00
|
|
|
detailLabel.SetWordWrap(true)
|
2019-11-05 07:57:32 -06:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
layout.AddLayout(itemLayout, 0)
|
|
|
|
layout.AddWidget(scrollCol, 0, 0)
|
|
|
|
layout.AddWidget(detailLabel, 0, core.Qt__AlignmentFlag(core.Qt__AlignTop | core.Qt__AlignLeft))
|
2019-11-04 16:14:51 -06:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
max := editor.config.Popupmenu.Total
|
2018-05-04 22:44:42 +09:00
|
|
|
|
2019-11-05 11:37:23 -06:00
|
|
|
popup := &PopupMenu{
|
|
|
|
widget: widget,
|
2019-11-06 23:19:46 +09:00
|
|
|
itemLayout: itemLayout,
|
2019-11-05 11:37:23 -06:00
|
|
|
detailLabel: detailLabel,
|
|
|
|
total: max,
|
|
|
|
scrollBar: scrollBar,
|
|
|
|
scrollCol: scrollCol,
|
|
|
|
}
|
2019-11-05 07:57:32 -06:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
var popupItems []*PopupItem
|
2017-06-07 11:24:42 +01:00
|
|
|
for i := 0; i < max; i++ {
|
2019-11-06 23:19:46 +09:00
|
|
|
kindIconWidget := widgets.NewQWidget(nil, 0)
|
2019-02-06 00:04:35 +09:00
|
|
|
kindlayout := widgets.NewQHBoxLayout()
|
|
|
|
kindlayout.SetContentsMargins(editor.iconSize/2, 0, editor.iconSize/2, 0)
|
2019-11-06 23:19:46 +09:00
|
|
|
kindIconWidget.SetLayout(kindlayout)
|
2019-02-05 20:21:55 +09:00
|
|
|
kindIcon := svg.NewQSvgWidget(nil)
|
|
|
|
kindIcon.SetFixedSize2(editor.iconSize, editor.iconSize)
|
2019-02-06 00:04:35 +09:00
|
|
|
kindlayout.AddWidget(kindIcon, 0, 0)
|
2019-02-05 20:21:55 +09:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
word := widgets.NewQLabel(widget, 0)
|
|
|
|
word.SetContentsMargins(1, margin, margin, margin)
|
2019-03-20 23:02:47 +09:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
menu := widgets.NewQLabel(widget, 0)
|
|
|
|
menu.SetContentsMargins(margin, margin, margin, margin)
|
|
|
|
menu.SetObjectName("menulabelpopup")
|
2018-05-04 22:44:42 +09:00
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
info := widgets.NewQLabel(widget, 0)
|
|
|
|
info.SetContentsMargins(margin, margin, margin, margin)
|
|
|
|
|
2019-11-07 21:11:47 +09:00
|
|
|
itemLayout.AddWidget2(kindIconWidget, i, 0, core.Qt__AlignmentFlag(core.Qt__AlignLeft))
|
|
|
|
itemLayout.AddWidget2(word, i, 1, core.Qt__AlignmentFlag(core.Qt__AlignLeft))
|
|
|
|
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-05 11:37:23 -06:00
|
|
|
p: popup,
|
2019-11-06 23:19:46 +09:00
|
|
|
kindIconWidget: kindIconWidget,
|
2019-11-05 11:37:23 -06:00
|
|
|
kindIcon: kindIcon,
|
2019-11-06 23:19:46 +09:00
|
|
|
wordLabel: word,
|
2019-11-05 11:37:23 -06:00
|
|
|
menuLabel: menu,
|
2019-11-06 23:19:46 +09:00
|
|
|
infoLabel: info,
|
2017-06-07 11:24:42 +01:00
|
|
|
}
|
|
|
|
popupItems = append(popupItems, popupItem)
|
|
|
|
}
|
2019-11-05 11:37:23 -06:00
|
|
|
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) {
|
2019-11-05 11:37:23 -06:00
|
|
|
p.detailLabel.SetFont(font.fontNew)
|
2017-06-07 11:31:10 +01:00
|
|
|
for i := 0; i < p.total; i++ {
|
|
|
|
popupItem := p.items[i]
|
2019-11-06 23:19:46 +09:00
|
|
|
popupItem.wordLabel.SetFont(font.fontNew)
|
2018-05-04 22:44:42 +09:00
|
|
|
popupItem.menuLabel.SetFont(font.fontNew)
|
2019-11-06 23:19:46 +09:00
|
|
|
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()
|
|
|
|
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-06 23:19:46 +09:00
|
|
|
p.widget.SetStyleSheet(fmt.Sprintf("* {background-color: rgba(%d, %d, %d, %f); color: %s;} #menulabelpopup { color: %s; }", bg.R, bg.G, bg.B, transparent, fg, inactiveFg))
|
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()
|
|
|
|
inactiveFg := editor.colors.inactiveFg.String()
|
|
|
|
bg := editor.colors.widgetBg
|
|
|
|
p.scrollBar.SetStyleSheet(fmt.Sprintf("background-color: %s;", inactiveFg))
|
2019-11-06 23:19:46 +09:00
|
|
|
p.widget.SetStyleSheet(fmt.Sprintf("* {background-color: rgba(%d, %d, %d, %f); color: %s;} #menulabelpopup { color: %s; }", bg.R, bg.G, bg.B, alpha, fg, inactiveFg))
|
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])
|
2019-06-01 13:20:31 +09:00
|
|
|
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
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
p.detailLabel.SetText("")
|
|
|
|
|
2017-03-14 01:52:44 +00:00
|
|
|
popupItems := p.items
|
2019-11-06 23:19:46 +09:00
|
|
|
itemHeight := p.ws.font.lineHeight
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
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{})
|
|
|
|
popupItem.setItem(item, selected == i)
|
2017-06-15 09:06:45 +01:00
|
|
|
popupItem.show()
|
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
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
popupWidth := editor.iconSize + popupItems[0].wordLabel.Width()
|
2019-06-01 13:20:31 +09:00
|
|
|
|
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
|
|
|
|
2019-06-01 13:20:31 +09:00
|
|
|
if x+popupWidth >= p.ws.screen.widget.Width() {
|
|
|
|
x = p.ws.screen.widget.Width() - popupWidth - 5
|
|
|
|
}
|
|
|
|
win := p.ws.screen.windows[gridid]
|
|
|
|
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-06-01 13:20:31 +09:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PopupMenu) show() {
|
2019-06-01 13:20:31 +09:00
|
|
|
p.widget.Raise()
|
2017-06-16 08:43:05 +01:00
|
|
|
p.widget.Show()
|
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
|
|
|
}
|
2019-11-05 11:37:23 -06:00
|
|
|
|
2017-06-07 11:24:42 +01:00
|
|
|
if selected-p.top >= p.showTotal {
|
|
|
|
p.scroll(selected - p.top - p.showTotal + 1)
|
|
|
|
}
|
2019-11-05 11:37:23 -06:00
|
|
|
|
2017-06-07 11:24:42 +01:00
|
|
|
if selected >= 0 && selected-p.top < 0 {
|
|
|
|
p.scroll(-1)
|
|
|
|
}
|
2019-11-05 11:37:23 -06:00
|
|
|
|
|
|
|
for i := 0; i < p.showTotal; i++ {
|
|
|
|
popupItem := p.items[i]
|
|
|
|
isSelected := selected == i+p.top
|
|
|
|
popupItem.setSelected(isSelected)
|
|
|
|
if isSelected {
|
2019-11-06 23:19:46 +09:00
|
|
|
if editor.config.Popupmenu.ShowDetail {
|
|
|
|
popupItem.p.detailLabel.SetText(popupItem.detailText)
|
|
|
|
popupItem.p.detailLabel.Show()
|
|
|
|
} else {
|
|
|
|
popupItem.p.detailLabel.Hide()
|
|
|
|
}
|
2019-11-05 11:37:23 -06:00
|
|
|
}
|
|
|
|
}
|
2017-06-07 11:24:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PopupMenu) scroll(n int) {
|
|
|
|
p.top += n
|
|
|
|
items := p.rawItems
|
|
|
|
popupItems := p.items
|
|
|
|
for i := 0; i < p.showTotal; i++ {
|
|
|
|
popupItem := popupItems[i]
|
|
|
|
item := items[i+p.top].([]interface{})
|
|
|
|
popupItem.setItem(item, false)
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-11-06 23:19:46 +09: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-06 23:19:46 +09:00
|
|
|
p.kindIconWidget.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()))
|
2019-11-06 23:19:46 +09:00
|
|
|
p.infoLabel.SetStyleSheet(fmt.Sprintf("background-color: %s;", editor.colors.selectedBg.StringTransparent()))
|
2017-06-15 15:54:27 +01:00
|
|
|
} else {
|
2019-11-06 23:19:46 +09:00
|
|
|
p.kindIconWidget.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);")
|
2019-11-06 23:19:46 +09:00
|
|
|
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
|
|
|
}
|
2019-11-06 23:19:46 +09: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-06 23:19:46 +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)
|
|
|
|
|
|
|
|
detailWidth := 0
|
|
|
|
if editor.config.Popupmenu.ShowDetail {
|
|
|
|
detailWidth = editor.config.Popupmenu.DetailWidth
|
|
|
|
}
|
|
|
|
p.p.widget.SetFixedWidth(
|
|
|
|
editor.iconSize + p.wordLabel.Width() + p.menuLabel.Width() + p.infoLabel.Width() + detailWidth,
|
|
|
|
)
|
2017-06-15 15:54:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PopupItem) setSelected(selected bool) {
|
|
|
|
p.selectedRequest = selected
|
2019-11-06 23:19:46 +09:00
|
|
|
p.updateContent()
|
2017-06-15 15:54:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PopupItem) setItem(item []interface{}, selected bool) {
|
2019-11-06 23:19:46 +09:00
|
|
|
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()")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-06 23:19:46 +09:00
|
|
|
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":
|
2019-11-06 23:19:46 +09:00
|
|
|
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":
|
2019-11-06 23:19:46 +09:00
|
|
|
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":
|
2019-11-06 23:19:46 +09:00
|
|
|
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":
|
2019-11-06 23:19:46 +09:00
|
|
|
icon := editor.getSvg("lsp_"+lowerKindText, colorOfKeyword)
|
2019-02-06 00:04:35 +09:00
|
|
|
p.kindIcon.Load2(core.NewQByteArray2(icon, len(icon)))
|
|
|
|
default:
|
2019-11-06 23:19:46 +09:00
|
|
|
completeMode, err := detectVimCompleteMode()
|
2019-02-07 17:33:55 +09:00
|
|
|
if err == nil {
|
2019-11-06 23:19:46 +09:00
|
|
|
p.completeMode = completeMode
|
2019-02-06 00:04:35 +09:00
|
|
|
}
|
2019-11-06 23:19:46 +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":
|
2019-11-06 23:19:46 +09:00
|
|
|
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()
|
2019-11-06 23:19:46 +09:00
|
|
|
p.wordLabel.Hide()
|
2018-05-04 22:44:42 +09:00
|
|
|
p.menuLabel.Hide()
|
2019-11-06 23:19:46 +09:00
|
|
|
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()
|
2019-11-06 23:19:46 +09:00
|
|
|
p.wordLabel.Show()
|
2018-05-04 22:44:42 +09:00
|
|
|
p.menuLabel.Show()
|
2019-11-06 23:19:46 +09:00
|
|
|
p.infoLabel.Show()
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|