2017-11-09 02:11:05 +00:00
|
|
|
package editor
|
2017-03-14 01:52:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-01-08 10:23:16 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-05-12 04:07:54 +01:00
|
|
|
"runtime"
|
2018-01-08 10:23:16 +00:00
|
|
|
"strconv"
|
2017-03-14 07:20:31 +00:00
|
|
|
"strings"
|
2017-06-02 10:41:28 +01:00
|
|
|
"sync"
|
2017-03-14 01:52:44 +00:00
|
|
|
|
2018-06-10 14:25:17 +09:00
|
|
|
clipb "github.com/atotto/clipboard"
|
2018-01-08 10:23:16 +00:00
|
|
|
homedir "github.com/mitchellh/go-homedir"
|
2017-03-14 01:52:44 +00:00
|
|
|
"github.com/neovim/go-client/nvim"
|
2017-06-16 08:43:05 +01:00
|
|
|
"github.com/therecipe/qt/core"
|
2018-01-05 08:07:29 +00:00
|
|
|
"github.com/therecipe/qt/gui"
|
2017-06-06 02:42:11 +01:00
|
|
|
"github.com/therecipe/qt/widgets"
|
2018-06-18 17:24:14 +09:00
|
|
|
|
2018-04-30 16:58:26 +09:00
|
|
|
ini "gopkg.in/go-ini/ini.v1"
|
2017-03-14 01:52:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var editor *Editor
|
|
|
|
|
|
|
|
// Highlight is
|
|
|
|
type Highlight struct {
|
|
|
|
foreground *RGBA
|
|
|
|
background *RGBA
|
2018-05-12 22:48:15 +09:00
|
|
|
bold bool
|
|
|
|
italic bool
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Char is
|
|
|
|
type Char struct {
|
2017-06-16 16:28:31 +01:00
|
|
|
normalWidth bool
|
|
|
|
char string
|
|
|
|
highlight Highlight
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Editor is the editor
|
|
|
|
type Editor struct {
|
2018-01-17 10:10:15 +00:00
|
|
|
version string
|
2018-01-08 10:23:16 +00:00
|
|
|
app *widgets.QApplication
|
2018-07-02 13:57:18 +09:00
|
|
|
activity *Activity
|
2018-07-08 17:00:47 +09:00
|
|
|
splitter *widgets.QSplitter
|
2018-01-08 10:23:16 +00:00
|
|
|
workspaces []*Workspace
|
|
|
|
active int
|
|
|
|
nvim *nvim.Nvim
|
|
|
|
window *widgets.QMainWindow
|
|
|
|
wsWidget *widgets.QWidget
|
|
|
|
wsSide *WorkspaceSide
|
2018-06-19 23:18:49 +09:00
|
|
|
deinSide *DeinSide
|
2018-01-08 10:23:16 +00:00
|
|
|
|
2017-05-10 07:28:44 +01:00
|
|
|
statuslineHeight int
|
|
|
|
width int
|
|
|
|
height int
|
|
|
|
tablineHeight int
|
|
|
|
selectedBg *RGBA
|
|
|
|
matchFg *RGBA
|
2018-05-12 15:51:43 +09:00
|
|
|
bgcolor *RGBA
|
|
|
|
fgcolor *RGBA
|
2018-01-08 10:23:16 +00:00
|
|
|
|
|
|
|
stop chan struct{}
|
|
|
|
stopOnce sync.Once
|
2018-01-05 08:07:29 +00:00
|
|
|
|
|
|
|
specialKeys map[core.Qt__Key]string
|
|
|
|
controlModifier core.Qt__KeyboardModifier
|
|
|
|
cmdModifier core.Qt__KeyboardModifier
|
|
|
|
shiftModifier core.Qt__KeyboardModifier
|
|
|
|
altModifier core.Qt__KeyboardModifier
|
|
|
|
metaModifier core.Qt__KeyboardModifier
|
|
|
|
keyControl core.Qt__Key
|
|
|
|
keyCmd core.Qt__Key
|
|
|
|
keyAlt core.Qt__Key
|
|
|
|
keyShift core.Qt__Key
|
2018-04-26 17:41:43 +09:00
|
|
|
|
2018-05-29 23:21:08 +09:00
|
|
|
config *gonvimConfig
|
2017-06-16 08:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type editorSignal struct {
|
|
|
|
core.QObject
|
|
|
|
_ func() `signal:"redrawSignal"`
|
|
|
|
_ func() `signal:"guiSignal"`
|
|
|
|
_ func() `signal:"statuslineSignal"`
|
|
|
|
_ func() `signal:"locpopupSignal"`
|
|
|
|
_ func() `signal:"lintSignal"`
|
|
|
|
_ func() `signal:"gitSignal"`
|
2017-11-09 01:41:26 +00:00
|
|
|
_ func() `signal:"messageSignal"`
|
2017-03-14 01:52:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 23:21:08 +09:00
|
|
|
type gonvimConfig struct {
|
2018-06-16 10:15:40 +09:00
|
|
|
clipboard bool
|
2018-06-24 05:27:58 +09:00
|
|
|
accentColor string
|
2018-07-02 13:57:18 +09:00
|
|
|
showActivity bool
|
|
|
|
activityShadow bool
|
|
|
|
showSide bool
|
|
|
|
restoreSession bool
|
|
|
|
sideShadow bool
|
|
|
|
sideWidth int
|
|
|
|
pathFormat string
|
2018-05-29 23:21:08 +09:00
|
|
|
}
|
|
|
|
|
2017-03-14 01:52:44 +00:00
|
|
|
func (hl *Highlight) copy() Highlight {
|
|
|
|
highlight := Highlight{}
|
|
|
|
if hl.foreground != nil {
|
|
|
|
highlight.foreground = hl.foreground.copy()
|
|
|
|
}
|
|
|
|
if hl.background != nil {
|
|
|
|
highlight.background = hl.background.copy()
|
|
|
|
}
|
2018-05-12 22:48:15 +09:00
|
|
|
highlight.bold = hl.bold
|
|
|
|
highlight.italic = hl.italic
|
|
|
|
|
2017-03-14 01:52:44 +00:00
|
|
|
return highlight
|
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
|
2017-11-09 02:11:05 +00:00
|
|
|
// InitEditor is
|
|
|
|
func InitEditor() {
|
2018-04-26 17:41:43 +09:00
|
|
|
home, err := homedir.Dir()
|
2018-05-29 23:21:08 +09:00
|
|
|
config := newGonvimConfig(home)
|
2018-01-05 08:07:29 +00:00
|
|
|
editor = &Editor{
|
2018-06-05 23:28:02 +09:00
|
|
|
version: "v0.2.3",
|
2018-05-29 23:21:08 +09:00
|
|
|
selectedBg: newRGBA(81, 154, 186, 0.5),
|
|
|
|
matchFg: newRGBA(81, 154, 186, 1),
|
|
|
|
bgcolor: nil,
|
|
|
|
fgcolor: nil,
|
|
|
|
stop: make(chan struct{}),
|
|
|
|
config: config,
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
2018-01-05 08:07:29 +00:00
|
|
|
e := editor
|
|
|
|
e.app = widgets.NewQApplication(0, nil)
|
2018-01-08 10:23:16 +00:00
|
|
|
e.app.ConnectAboutToQuit(func() {
|
|
|
|
editor.cleanup()
|
|
|
|
})
|
2018-01-17 10:03:54 +00:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
e.width = 800
|
|
|
|
e.height = 600
|
2017-06-06 02:42:11 +01:00
|
|
|
|
|
|
|
//create a window
|
2018-01-05 08:07:29 +00:00
|
|
|
e.window = widgets.NewQMainWindow(nil, 0)
|
|
|
|
e.window.SetWindowTitle("Gonvim")
|
|
|
|
e.window.SetContentsMargins(0, 0, 0, 0)
|
|
|
|
e.window.SetMinimumSize2(e.width, e.height)
|
|
|
|
|
|
|
|
e.initSpecialKeys()
|
|
|
|
e.window.ConnectKeyPressEvent(e.keyPress)
|
2018-06-13 21:08:02 +09:00
|
|
|
//e.window.ConnectKeyReleaseEvent(e.keyRelease)
|
2018-01-05 08:07:29 +00:00
|
|
|
e.window.SetAcceptDrops(true)
|
2017-11-19 23:43:24 +09:00
|
|
|
|
2018-05-22 18:41:39 +09:00
|
|
|
// output log
|
|
|
|
// tfile, terr := os.OpenFile("/Users/akiyoshi/test.log", os.O_WRONLY | os.O_CREATE, 0666)
|
|
|
|
// if terr != nil {
|
|
|
|
// panic(terr)
|
|
|
|
// }
|
|
|
|
// defer tfile.Close()
|
|
|
|
|
2017-06-06 02:42:11 +01:00
|
|
|
widget := widgets.NewQWidget(nil, 0)
|
|
|
|
widget.SetContentsMargins(0, 0, 0, 0)
|
2018-05-06 14:49:45 +09:00
|
|
|
|
|
|
|
layout := widgets.NewQBoxLayout(widgets.QBoxLayout__RightToLeft, widget)
|
2018-07-08 17:00:47 +09:00
|
|
|
layout.SetContentsMargins(0, 0, 0, 0)
|
|
|
|
layout.SetSpacing(0)
|
2018-05-06 14:49:45 +09:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
e.wsWidget = widgets.NewQWidget(nil, 0)
|
2018-01-08 10:23:16 +00:00
|
|
|
e.wsSide = newWorkspaceSide()
|
2018-05-24 01:11:51 +09:00
|
|
|
|
2018-06-19 23:18:49 +09:00
|
|
|
sideArea := widgets.NewQScrollArea(nil)
|
|
|
|
sideArea.SetWidgetResizable(true)
|
|
|
|
sideArea.SetVerticalScrollBarPolicy(core.Qt__ScrollBarAsNeeded)
|
2018-07-02 13:57:18 +09:00
|
|
|
sideArea.SetFocusPolicy(core.Qt__ClickFocus)
|
2018-06-19 23:18:49 +09:00
|
|
|
sideArea.SetWidget(e.wsSide.widget)
|
|
|
|
sideArea.SetFrameShape(widgets.QFrame__NoFrame)
|
2018-07-08 17:00:47 +09:00
|
|
|
// sideArea.SetMaximumWidth(e.config.sideWidth)
|
|
|
|
// sideArea.SetMinimumWidth(e.config.sideWidth)
|
|
|
|
// sideArea.SetSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding)
|
2018-06-19 23:18:49 +09:00
|
|
|
e.wsSide.scrollarea = sideArea
|
2018-05-24 01:11:51 +09:00
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
e.workspaces = []*Workspace{}
|
2018-01-11 06:11:34 +00:00
|
|
|
sessionExists := false
|
|
|
|
if err == nil {
|
2018-05-29 23:21:08 +09:00
|
|
|
if e.config.restoreSession == true {
|
2018-04-30 16:58:26 +09:00
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
path := filepath.Join(home, ".gonvim", "sessions", strconv.Itoa(i)+".vim")
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
sessionExists = true
|
|
|
|
ws, err := newWorkspace(path)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
e.workspaces = append(e.workspaces, ws)
|
|
|
|
}
|
|
|
|
}
|
2018-01-11 06:11:34 +00:00
|
|
|
}
|
|
|
|
if !sessionExists {
|
|
|
|
ws, err := newWorkspace("")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
e.workspaces = append(e.workspaces, ws)
|
|
|
|
}
|
2018-01-05 09:13:50 +00:00
|
|
|
|
2018-07-02 13:57:18 +09:00
|
|
|
activityWidget := widgets.NewQWidget(nil, 0)
|
|
|
|
activity := newActivity()
|
|
|
|
activity.widget = activityWidget
|
|
|
|
activityWidget.SetLayout(activity.layout)
|
|
|
|
e.activity = activity
|
|
|
|
e.activity.sideArea.AddWidget(e.wsSide.scrollarea)
|
|
|
|
e.activity.sideArea.SetCurrentWidget(e.wsSide.scrollarea)
|
2018-06-19 23:18:49 +09:00
|
|
|
|
2018-07-08 17:00:47 +09:00
|
|
|
// layout.AddWidget(e.activity.sideArea, 0, 0)
|
|
|
|
|
|
|
|
splitter := widgets.NewQSplitter2(core.Qt__Horizontal, nil)
|
|
|
|
splitter.AddWidget(e.activity.sideArea)
|
|
|
|
splitter.AddWidget(e.wsWidget)
|
|
|
|
splitter.SetSizes([]int{editor.config.sideWidth, editor.width - editor.config.sideWidth})
|
2018-07-10 16:00:42 +09:00
|
|
|
splitter.SetStretchFactor(1, 100)
|
2018-07-08 17:00:47 +09:00
|
|
|
splitter.SetObjectName("splitter")
|
|
|
|
e.splitter = splitter
|
|
|
|
|
|
|
|
layout.AddWidget(splitter, 1, 0)
|
2018-07-02 13:57:18 +09:00
|
|
|
layout.AddWidget(e.activity.widget, 0, 0)
|
2018-06-19 23:18:49 +09:00
|
|
|
e.workspaceUpdate()
|
2018-06-18 17:24:14 +09:00
|
|
|
|
2018-07-02 13:57:18 +09:00
|
|
|
// Drop shadow to Side Bar
|
|
|
|
if e.config.sideShadow == true {
|
|
|
|
go func() {
|
|
|
|
shadow := widgets.NewQGraphicsDropShadowEffect(nil)
|
|
|
|
shadow.SetBlurRadius(60)
|
|
|
|
shadow.SetColor(gui.NewQColor3(0, 0, 0, 35))
|
|
|
|
shadow.SetOffset3(6, 2)
|
|
|
|
e.activity.sideArea.SetGraphicsEffect(shadow)
|
|
|
|
}()
|
|
|
|
}
|
2018-06-24 15:00:06 +09:00
|
|
|
|
2018-07-02 13:57:18 +09:00
|
|
|
// Drop shadow for Activity Bar
|
|
|
|
if e.config.activityShadow == true {
|
|
|
|
go func() {
|
|
|
|
shadow := widgets.NewQGraphicsDropShadowEffect(nil)
|
|
|
|
shadow.SetBlurRadius(60)
|
|
|
|
shadow.SetColor(gui.NewQColor3(0, 0, 0, 35))
|
|
|
|
shadow.SetOffset3(6, 2)
|
|
|
|
e.activity.widget.SetGraphicsEffect(shadow)
|
|
|
|
}()
|
|
|
|
}
|
2018-06-18 17:24:14 +09:00
|
|
|
//
|
|
|
|
|
2018-07-02 13:57:18 +09:00
|
|
|
if e.config.showActivity == false {
|
|
|
|
e.activity.widget.Hide()
|
|
|
|
}
|
2018-06-20 23:34:11 +09:00
|
|
|
if e.config.showSide == false {
|
2018-07-02 13:57:18 +09:00
|
|
|
e.activity.sideArea.Hide()
|
2018-06-20 23:34:11 +09:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
e.wsWidget.ConnectResizeEvent(func(event *gui.QResizeEvent) {
|
|
|
|
for _, ws := range e.workspaces {
|
|
|
|
ws.updateSize()
|
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
})
|
2018-01-05 08:07:29 +00:00
|
|
|
|
2018-05-22 18:41:39 +09:00
|
|
|
// for macos, open file via Finder
|
|
|
|
var macosArg string
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
e.app.ConnectEvent(func(event *core.QEvent) bool {
|
|
|
|
switch event.Type() {
|
|
|
|
case core.QEvent__FileOpen:
|
|
|
|
fileOpenEvent := gui.NewQFileOpenEventFromPointer(event.Pointer())
|
|
|
|
macosArg = fileOpenEvent.File()
|
2018-06-10 14:25:17 +09:00
|
|
|
go e.workspaces[e.active].nvim.Command(fmt.Sprintf(":tabe %s", macosArg))
|
2018-05-22 18:41:39 +09:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
e.window.SetCentralWidget(widget)
|
|
|
|
|
|
|
|
go func() {
|
2018-01-08 10:23:16 +00:00
|
|
|
<-editor.stop
|
2018-05-25 01:00:23 +09:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
e.app.DisconnectEvent()
|
|
|
|
}
|
2018-01-05 08:07:29 +00:00
|
|
|
e.app.Quit()
|
|
|
|
}()
|
|
|
|
|
|
|
|
e.window.Show()
|
2018-01-11 06:11:34 +00:00
|
|
|
// for i := len(e.workspaces) - 1; i >= 0; i-- {
|
|
|
|
// e.active = i
|
|
|
|
// }
|
2018-01-17 10:03:54 +00:00
|
|
|
e.wsWidget.SetFocus2()
|
2018-01-05 08:07:29 +00:00
|
|
|
widgets.QApplication_Exec()
|
|
|
|
}
|
|
|
|
|
2018-05-29 23:21:08 +09:00
|
|
|
func newGonvimConfig(home string) *gonvimConfig {
|
|
|
|
cfg, cfgerr := ini.Load(filepath.Join(home, ".gonvim", "gonvimrc"))
|
2018-07-02 13:57:18 +09:00
|
|
|
var cfgActivityDisplay, cfgSideDisplay, cfgWSRestoresession bool
|
|
|
|
var cfgActivityDropShadow, cfgSideDropShadow bool
|
2018-05-29 23:21:08 +09:00
|
|
|
var cfgWSPath string
|
2018-07-02 13:57:18 +09:00
|
|
|
var cfgSideWidth int
|
2018-06-16 10:15:40 +09:00
|
|
|
var cfgClipBoard bool
|
2018-06-24 05:27:58 +09:00
|
|
|
var cfgAccentColor string
|
2018-05-29 23:21:08 +09:00
|
|
|
var errGetWidth error
|
|
|
|
if cfgerr != nil {
|
2018-07-02 13:57:18 +09:00
|
|
|
cfgActivityDisplay = true
|
|
|
|
cfgActivityDropShadow = true
|
|
|
|
cfgSideDisplay = true
|
|
|
|
cfgSideDropShadow = true
|
2018-05-29 23:21:08 +09:00
|
|
|
cfgWSRestoresession = false
|
|
|
|
cfgWSPath = "minimum"
|
2018-07-02 13:57:18 +09:00
|
|
|
cfgSideWidth = 250
|
2018-06-16 10:15:40 +09:00
|
|
|
cfgClipBoard = true
|
2018-06-24 05:27:58 +09:00
|
|
|
cfgAccentColor = "#519aba"
|
2018-05-29 23:21:08 +09:00
|
|
|
} else {
|
2018-07-02 13:57:18 +09:00
|
|
|
cfgActivityDisplay = cfg.Section("activity").Key("display").MustBool()
|
|
|
|
cfgSideDisplay = cfg.Section("side").Key("display").MustBool()
|
|
|
|
cfgActivityDropShadow = cfg.Section("activity").Key("dropshadow").MustBool()
|
|
|
|
cfgSideDropShadow = cfg.Section("side").Key("dropshadow").MustBool()
|
2018-05-29 23:21:08 +09:00
|
|
|
cfgWSRestoresession = cfg.Section("workspace").Key("restoresession").MustBool()
|
|
|
|
cfgWSPath = cfg.Section("workspace").Key("path").String()
|
|
|
|
if cfgWSPath == "" {
|
|
|
|
cfgWSPath = "minimum"
|
|
|
|
}
|
2018-07-02 13:57:18 +09:00
|
|
|
cfgSideWidth, errGetWidth = cfg.Section("side").Key("width").Int()
|
2018-05-29 23:21:08 +09:00
|
|
|
if errGetWidth != nil {
|
2018-07-02 13:57:18 +09:00
|
|
|
cfgSideWidth = 250
|
2018-05-29 23:21:08 +09:00
|
|
|
}
|
2018-06-16 10:15:40 +09:00
|
|
|
cfgClipBoard = cfg.Section("").Key("clipboard").MustBool()
|
2018-06-24 05:27:58 +09:00
|
|
|
if cfgAccentColor == "" {
|
|
|
|
cfgAccentColor = "#519aba"
|
|
|
|
}
|
2018-05-29 23:21:08 +09:00
|
|
|
}
|
|
|
|
config := &gonvimConfig{
|
|
|
|
restoreSession: cfgWSRestoresession,
|
2018-07-02 13:57:18 +09:00
|
|
|
showActivity: cfgActivityDisplay,
|
|
|
|
showSide: cfgSideDisplay,
|
|
|
|
activityShadow: cfgActivityDropShadow,
|
|
|
|
sideShadow: cfgSideDropShadow,
|
2018-05-29 23:21:08 +09:00
|
|
|
pathFormat: cfgWSPath,
|
2018-07-02 13:57:18 +09:00
|
|
|
sideWidth: cfgSideWidth,
|
2018-06-16 10:15:40 +09:00
|
|
|
clipboard: cfgClipBoard,
|
2018-06-24 05:27:58 +09:00
|
|
|
accentColor: cfgAccentColor,
|
2018-05-29 23:21:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2018-06-24 13:36:41 +09:00
|
|
|
func hexToRGBA(hex string) *RGBA {
|
|
|
|
format := "#%02x%02x%02x"
|
|
|
|
if len(hex) == 4 {
|
|
|
|
format = "#%1x%1x%1x"
|
|
|
|
}
|
|
|
|
var r, g, b uint8
|
|
|
|
n, err := fmt.Sscanf(hex, format, &r, &g, &b)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if n != 3 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
rgba := &RGBA{
|
|
|
|
R: (int)(r),
|
|
|
|
G: (int)(g),
|
|
|
|
B: (int)(b),
|
|
|
|
A: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
return rgba
|
|
|
|
}
|
|
|
|
|
|
|
|
func darkenHex(hex string) string {
|
|
|
|
c := hexToRGBA(hex)
|
|
|
|
d := shiftColor(c, 20)
|
|
|
|
return fmt.Sprintf("#%02x%02x%02x", (int)(d.R*255.0), (int)(d.G*255.0), (int)(d.B*255.0))
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:07:48 +09:00
|
|
|
func isFileExist(filename string) bool {
|
2018-04-30 16:58:26 +09:00
|
|
|
_, err := os.Stat(filename)
|
|
|
|
return err == nil
|
2018-04-19 21:07:48 +09:00
|
|
|
}
|
|
|
|
|
2018-06-13 21:08:02 +09:00
|
|
|
func (e *Editor) copyClipBoard() {
|
|
|
|
go func() {
|
|
|
|
var yankedText string
|
2018-06-16 10:15:40 +09:00
|
|
|
yankedText, _ = e.workspaces[e.active].nvim.CommandOutput("echo getreg()")
|
2018-06-13 21:08:02 +09:00
|
|
|
if yankedText != "" {
|
|
|
|
clipb.WriteAll(yankedText)
|
|
|
|
}
|
|
|
|
}()
|
2018-06-16 10:15:40 +09:00
|
|
|
|
2018-06-13 21:08:02 +09:00
|
|
|
}
|
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
func (e *Editor) workspaceNew() {
|
2018-01-11 06:11:34 +00:00
|
|
|
ws, err := newWorkspace("")
|
2018-01-05 09:13:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-05-20 12:06:29 +09:00
|
|
|
|
2018-05-01 19:50:47 +09:00
|
|
|
//e.active++
|
|
|
|
//e.workspaces = append(e.workspaces, nil)
|
|
|
|
//copy(e.workspaces[e.active+1:], e.workspaces[e.active:])
|
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
e.workspaces = append(e.workspaces, nil)
|
2018-05-01 19:50:47 +09:00
|
|
|
e.active = len(e.workspaces) - 1
|
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
e.workspaces[e.active] = ws
|
2018-01-08 10:23:16 +00:00
|
|
|
e.workspaceUpdate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Editor) workspaceSwitch(index int) {
|
|
|
|
index--
|
|
|
|
if index < 0 || index >= len(e.workspaces) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
e.active = index
|
2018-01-05 09:13:50 +00:00
|
|
|
e.workspaceUpdate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Editor) workspaceNext() {
|
|
|
|
e.active++
|
|
|
|
if e.active >= len(e.workspaces) {
|
|
|
|
e.active = 0
|
|
|
|
}
|
|
|
|
e.workspaceUpdate()
|
|
|
|
}
|
|
|
|
|
2018-01-11 06:11:34 +00:00
|
|
|
func (e *Editor) workspacePrevious() {
|
|
|
|
e.active--
|
|
|
|
if e.active < 0 {
|
|
|
|
e.active = len(e.workspaces) - 1
|
|
|
|
}
|
|
|
|
e.workspaceUpdate()
|
|
|
|
}
|
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
func (e *Editor) workspaceUpdate() {
|
2018-05-20 12:06:29 +09:00
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
for i, ws := range e.workspaces {
|
|
|
|
if i == e.active {
|
|
|
|
ws.hide()
|
|
|
|
ws.show()
|
|
|
|
} else {
|
|
|
|
ws.hide()
|
|
|
|
}
|
|
|
|
}
|
2018-01-08 10:23:16 +00:00
|
|
|
|
|
|
|
for i := 0; i < len(e.wsSide.items) && i < len(e.workspaces); i++ {
|
|
|
|
if i == e.active {
|
|
|
|
e.wsSide.items[i].setActive()
|
2018-06-19 23:18:49 +09:00
|
|
|
//e.wsSide.title.Show()
|
2018-04-30 16:58:26 +09:00
|
|
|
//}
|
2018-01-08 10:23:16 +00:00
|
|
|
} else {
|
|
|
|
e.wsSide.items[i].setInactive()
|
|
|
|
}
|
2018-06-19 23:18:49 +09:00
|
|
|
//e.wsSide.scrollarea.Show()
|
2018-04-30 16:39:39 +09:00
|
|
|
e.wsSide.items[i].setText(e.workspaces[i].cwdlabel)
|
2018-01-08 10:23:16 +00:00
|
|
|
e.wsSide.items[i].show()
|
|
|
|
}
|
2018-05-20 12:06:29 +09:00
|
|
|
|
2018-01-08 10:23:16 +00:00
|
|
|
for i := len(e.workspaces); i < len(e.wsSide.items); i++ {
|
|
|
|
e.wsSide.items[i].hide()
|
|
|
|
}
|
2018-04-26 17:41:43 +09:00
|
|
|
|
2018-06-19 23:18:49 +09:00
|
|
|
//if len(e.workspaces) == 1 || len(e.wsSide.items) == 1 {
|
|
|
|
// if e.config.showSide == false {
|
|
|
|
// //e.wsSide.scrollarea.Hide()
|
|
|
|
// e.wsSide.items[0].hide()
|
|
|
|
// //e.wsSide.title.Hide()
|
|
|
|
// } else {
|
|
|
|
// //e.wsSide.scrollarea.Show()
|
|
|
|
// //e.wsSide.title.Show()
|
|
|
|
// e.wsSide.items[0].setActive()
|
|
|
|
// e.wsSide.items[0].show()
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
2018-01-05 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
func (e *Editor) keyPress(event *gui.QKeyEvent) {
|
|
|
|
input := e.convertKey(event.Text(), event.Key(), event.Modifiers())
|
|
|
|
if input != "" {
|
2018-01-05 09:13:50 +00:00
|
|
|
e.workspaces[e.active].nvim.Input(input)
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
2018-01-05 08:07:29 +00:00
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
func (e *Editor) convertKey(text string, key int, mod core.Qt__KeyboardModifier) string {
|
|
|
|
if mod&core.Qt__KeypadModifier > 0 {
|
|
|
|
switch core.Qt__Key(key) {
|
|
|
|
case core.Qt__Key_Home:
|
|
|
|
return fmt.Sprintf("<%sHome>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_End:
|
|
|
|
return fmt.Sprintf("<%sEnd>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_PageUp:
|
|
|
|
return fmt.Sprintf("<%sPageUp>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_PageDown:
|
|
|
|
return fmt.Sprintf("<%sPageDown>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_Plus:
|
|
|
|
return fmt.Sprintf("<%sPlus>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_Minus:
|
|
|
|
return fmt.Sprintf("<%sMinus>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_multiply:
|
|
|
|
return fmt.Sprintf("<%sMultiply>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_division:
|
|
|
|
return fmt.Sprintf("<%sDivide>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_Enter:
|
|
|
|
return fmt.Sprintf("<%sEnter>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_Period:
|
|
|
|
return fmt.Sprintf("<%sPoint>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_0:
|
|
|
|
return fmt.Sprintf("<%s0>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_1:
|
|
|
|
return fmt.Sprintf("<%s1>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_2:
|
|
|
|
return fmt.Sprintf("<%s2>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_3:
|
|
|
|
return fmt.Sprintf("<%s3>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_4:
|
|
|
|
return fmt.Sprintf("<%s4>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_5:
|
|
|
|
return fmt.Sprintf("<%s5>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_6:
|
|
|
|
return fmt.Sprintf("<%s6>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_7:
|
|
|
|
return fmt.Sprintf("<%s7>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_8:
|
|
|
|
return fmt.Sprintf("<%s8>", e.modPrefix(mod))
|
|
|
|
case core.Qt__Key_9:
|
|
|
|
return fmt.Sprintf("<%s9>", e.modPrefix(mod))
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 08:43:05 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
if text == "<" {
|
|
|
|
return "<lt>"
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
specialKey, ok := e.specialKeys[core.Qt__Key(key)]
|
|
|
|
if ok {
|
|
|
|
return fmt.Sprintf("<%s%s>", e.modPrefix(mod), specialKey)
|
|
|
|
}
|
2017-06-16 08:43:05 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
if text == "\\" {
|
|
|
|
return fmt.Sprintf("<%s%s>", e.modPrefix(mod), "Bslash")
|
|
|
|
}
|
2017-06-16 08:43:05 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
c := ""
|
|
|
|
if mod&e.controlModifier > 0 || mod&e.cmdModifier > 0 {
|
|
|
|
if int(e.keyControl) == key || int(e.keyCmd) == key || int(e.keyAlt) == key || int(e.keyShift) == key {
|
|
|
|
return ""
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
2018-01-05 08:07:29 +00:00
|
|
|
c = string(key)
|
|
|
|
if !(mod&e.shiftModifier > 0) {
|
|
|
|
c = strings.ToLower(c)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c = text
|
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
if c == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2017-06-13 16:15:05 +01:00
|
|
|
|
2018-04-23 00:48:43 +09:00
|
|
|
char := core.NewQChar11(c)
|
2018-01-05 08:07:29 +00:00
|
|
|
if char.Unicode() < 0x100 && !char.IsNumber() && char.IsPrint() {
|
|
|
|
mod &= ^e.shiftModifier
|
2017-07-03 07:14:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
prefix := e.modPrefix(mod)
|
|
|
|
if prefix != "" {
|
|
|
|
return fmt.Sprintf("<%s%s>", prefix, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Editor) modPrefix(mod core.Qt__KeyboardModifier) string {
|
|
|
|
prefix := ""
|
|
|
|
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
|
|
|
|
if mod&e.cmdModifier > 0 {
|
|
|
|
prefix += "D-"
|
2017-07-03 07:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-05 08:07:29 +00:00
|
|
|
|
|
|
|
if mod&e.controlModifier > 0 {
|
|
|
|
prefix += "C-"
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
if mod&e.shiftModifier > 0 {
|
|
|
|
prefix += "S-"
|
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
|
2018-01-05 08:07:29 +00:00
|
|
|
if mod&e.altModifier > 0 {
|
|
|
|
prefix += "A-"
|
|
|
|
}
|
|
|
|
|
|
|
|
return prefix
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Editor) initSpecialKeys() {
|
|
|
|
e.specialKeys = map[core.Qt__Key]string{}
|
|
|
|
e.specialKeys[core.Qt__Key_Up] = "Up"
|
|
|
|
e.specialKeys[core.Qt__Key_Down] = "Down"
|
|
|
|
e.specialKeys[core.Qt__Key_Left] = "Left"
|
|
|
|
e.specialKeys[core.Qt__Key_Right] = "Right"
|
|
|
|
|
|
|
|
e.specialKeys[core.Qt__Key_F1] = "F1"
|
|
|
|
e.specialKeys[core.Qt__Key_F2] = "F2"
|
|
|
|
e.specialKeys[core.Qt__Key_F3] = "F3"
|
|
|
|
e.specialKeys[core.Qt__Key_F4] = "F4"
|
|
|
|
e.specialKeys[core.Qt__Key_F5] = "F5"
|
|
|
|
e.specialKeys[core.Qt__Key_F6] = "F6"
|
|
|
|
e.specialKeys[core.Qt__Key_F7] = "F7"
|
|
|
|
e.specialKeys[core.Qt__Key_F8] = "F8"
|
|
|
|
e.specialKeys[core.Qt__Key_F9] = "F9"
|
|
|
|
e.specialKeys[core.Qt__Key_F10] = "F10"
|
|
|
|
e.specialKeys[core.Qt__Key_F11] = "F11"
|
|
|
|
e.specialKeys[core.Qt__Key_F12] = "F12"
|
|
|
|
e.specialKeys[core.Qt__Key_F13] = "F13"
|
|
|
|
e.specialKeys[core.Qt__Key_F14] = "F14"
|
|
|
|
e.specialKeys[core.Qt__Key_F15] = "F15"
|
|
|
|
e.specialKeys[core.Qt__Key_F16] = "F16"
|
|
|
|
e.specialKeys[core.Qt__Key_F17] = "F17"
|
|
|
|
e.specialKeys[core.Qt__Key_F18] = "F18"
|
|
|
|
e.specialKeys[core.Qt__Key_F19] = "F19"
|
|
|
|
e.specialKeys[core.Qt__Key_F20] = "F20"
|
|
|
|
e.specialKeys[core.Qt__Key_F21] = "F21"
|
|
|
|
e.specialKeys[core.Qt__Key_F22] = "F22"
|
|
|
|
e.specialKeys[core.Qt__Key_F23] = "F23"
|
|
|
|
e.specialKeys[core.Qt__Key_F24] = "F24"
|
|
|
|
e.specialKeys[core.Qt__Key_Backspace] = "BS"
|
|
|
|
e.specialKeys[core.Qt__Key_Delete] = "Del"
|
|
|
|
e.specialKeys[core.Qt__Key_Insert] = "Insert"
|
|
|
|
e.specialKeys[core.Qt__Key_Home] = "Home"
|
|
|
|
e.specialKeys[core.Qt__Key_End] = "End"
|
|
|
|
e.specialKeys[core.Qt__Key_PageUp] = "PageUp"
|
|
|
|
e.specialKeys[core.Qt__Key_PageDown] = "PageDown"
|
|
|
|
|
|
|
|
e.specialKeys[core.Qt__Key_Return] = "Enter"
|
|
|
|
e.specialKeys[core.Qt__Key_Enter] = "Enter"
|
|
|
|
e.specialKeys[core.Qt__Key_Tab] = "Tab"
|
|
|
|
e.specialKeys[core.Qt__Key_Backtab] = "Tab"
|
|
|
|
e.specialKeys[core.Qt__Key_Escape] = "Esc"
|
|
|
|
|
|
|
|
e.specialKeys[core.Qt__Key_Backslash] = "Bslash"
|
|
|
|
e.specialKeys[core.Qt__Key_Space] = "Space"
|
|
|
|
|
|
|
|
goos := runtime.GOOS
|
|
|
|
e.shiftModifier = core.Qt__ShiftModifier
|
|
|
|
e.altModifier = core.Qt__AltModifier
|
|
|
|
e.keyAlt = core.Qt__Key_Alt
|
|
|
|
e.keyShift = core.Qt__Key_Shift
|
|
|
|
if goos == "darwin" {
|
|
|
|
e.controlModifier = core.Qt__MetaModifier
|
|
|
|
e.cmdModifier = core.Qt__ControlModifier
|
|
|
|
e.metaModifier = core.Qt__AltModifier
|
|
|
|
e.keyControl = core.Qt__Key_Meta
|
|
|
|
e.keyCmd = core.Qt__Key_Control
|
|
|
|
} else {
|
|
|
|
e.controlModifier = core.Qt__ControlModifier
|
|
|
|
e.metaModifier = core.Qt__MetaModifier
|
|
|
|
e.keyControl = core.Qt__Key_Control
|
|
|
|
if goos == "linux" {
|
|
|
|
e.cmdModifier = core.Qt__MetaModifier
|
|
|
|
e.keyCmd = core.Qt__Key_Meta
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 02:42:11 +01:00
|
|
|
}
|
2018-01-08 10:23:16 +00:00
|
|
|
|
|
|
|
func (e *Editor) close() {
|
|
|
|
e.stopOnce.Do(func() {
|
|
|
|
close(e.stop)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Editor) cleanup() {
|
|
|
|
home, err := homedir.Dir()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
sessions := filepath.Join(home, ".gonvim", "sessions")
|
|
|
|
os.RemoveAll(sessions)
|
|
|
|
os.MkdirAll(sessions, 0755)
|
2018-01-11 06:11:34 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-e.stop:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2018-01-08 10:23:16 +00:00
|
|
|
for i, ws := range e.workspaces {
|
|
|
|
sessionPath := filepath.Join(sessions, strconv.Itoa(i)+".vim")
|
|
|
|
fmt.Println(sessionPath)
|
|
|
|
fmt.Println(ws.nvim.Command("mksession " + sessionPath))
|
|
|
|
fmt.Println("mksession finished")
|
|
|
|
}
|
|
|
|
}
|