/
workspace.go
2999 lines (2646 loc) · 69.5 KB
/
workspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package editor
import (
"errors"
"fmt"
"math"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"
"github.com/akiyosi/goneovim/filer"
"github.com/akiyosi/goneovim/util"
"github.com/akiyosi/qt/core"
"github.com/akiyosi/qt/gui"
"github.com/akiyosi/qt/svg"
"github.com/akiyosi/qt/widgets"
shortpath "github.com/akiyosi/short_path"
"github.com/neovim/go-client/nvim"
)
type neovimSignal struct {
core.QObject
_ func() `signal:"stopSignal"`
_ func() `signal:"redrawSignal"`
_ func() `signal:"guiSignal"`
_ func() `signal:"messageSignal"`
_ func() `signal:"lazyLoadSignal"`
}
type ShouldUpdate struct {
minimap bool
cursor bool
globalgrid bool
}
// Workspace is an editor workspace
type Workspace struct {
shouldUpdate *ShouldUpdate
foreground *RGBA
layout2 *widgets.QHBoxLayout
stop chan struct{}
font *Font
cursor *Cursor
tabline *Tabline
screen *Screen
scrollBar *ScrollBar
palette *Palette
popup *PopupMenu
cmdline *Cmdline
message *Message
minimap *MiniMap
fontdialog *widgets.QFontDialog
guiUpdates chan []interface{}
redrawUpdates chan [][]interface{}
signal *neovimSignal
nvim *nvim.Nvim
widget *widgets.QWidget
special *RGBA
background *RGBA
colorscheme string
cwdlabel string
escKeyInNormal string
mode string
cwdBase string
cwd string
escKeyInInsert string
filepath string
screenbg string
mouseScroll string
mouseScrollTemp string
normalMappings []*nvim.Mapping
modeInfo []map[string]interface{}
insertMappings []*nvim.Mapping
viewport [5]int
oldViewport [5]int
height int
maxLineDelta int
maxLine int
rows int
cols int
showtabline int
width int
modeIdx int
pb int
ts int
ph int
winbar *string
optionsetMutex sync.RWMutex
viewportMutex sync.RWMutex
stopOnce sync.Once
fontMutex sync.Mutex
hidden bool
uiAttached bool
uiRemoteAttached bool
isMappingScrollKey bool
hasLazyUI bool
cursorStyleEnabled bool
isDrawTabline bool
isMouseEnabled bool
isTerminalMode bool
}
func newWorkspace() *Workspace {
editor.putLog("initialize workspace")
ws := &Workspace{
stop: make(chan struct{}),
foreground: newRGBA(255, 255, 255, 1),
background: newRGBA(0, 0, 0, 1),
special: newRGBA(255, 255, 255, 1),
shouldUpdate: &ShouldUpdate{},
}
return ws
}
func (ws *Workspace) initUI() {
ws.widget = widgets.NewQWidget(nil, 0)
ws.widget.SetParent(editor.widget)
ws.widget.SetAcceptDrops(true)
ws.widget.ConnectDragEnterEvent(ws.dragEnterEvent)
ws.widget.ConnectDragMoveEvent(ws.dragMoveEvent)
ws.widget.ConnectDropEvent(ws.dropEvent)
// Basic Workspace UI component
// screen
ws.screen = newScreen()
ws.screen.ws = ws
ws.screen.initInputMethodWidget()
// cursor
ws.cursor = initCursorNew()
ws.cursor.SetParent(ws.widget)
ws.cursor.ws = ws
// ws.cursor.setBypassScreenEvent()
// If ExtFooBar is true, then we create a UI component
// tabline
if editor.config.Editor.ExtTabline {
ws.tabline = initTabline()
ws.tabline.ws = ws
ws.tabline.widget.ConnectShowEvent(ws.tabline.showEvent)
}
// cmdline
if editor.config.Editor.ExtCmdline {
ws.cmdline = initCmdline()
ws.cmdline.ws = ws
}
// palette for cmdline
if editor.config.Editor.ExtCmdline {
ws.palette = initPalette()
ws.palette.ws = ws
ws.palette.widget.SetParent(ws.widget)
ws.palette.setColor()
ws.palette.hide()
}
// popupmenu
if editor.config.Editor.ExtPopupmenu {
ws.popup = initPopupmenuNew()
ws.popup.widget.SetParent(ws.widget)
ws.popup.ws = ws
ws.popup.widget.Hide()
}
// messages
if editor.config.Editor.ExtMessages {
ws.message = initMessage()
ws.message.ws = ws
ws.message.widget.SetParent(ws.widget)
ws.signal.ConnectMessageSignal(func() {
ws.message.update()
})
}
if ws.tabline != nil {
ws.isDrawTabline = editor.config.Tabline.Visible && editor.config.Editor.ExtTabline
ws.tabline.connectUI()
}
if ws.message != nil {
ws.message.connectUI()
}
// workspace widget, layouts
layout := widgets.NewQVBoxLayout()
layout.SetContentsMargins(0, 0, 0, 0)
layout.SetSpacing(0)
ws.widget.SetContentsMargins(0, 0, 0, 0)
ws.widget.SetLayout(layout)
ws.widget.SetFocusPolicy(core.Qt__StrongFocus)
ws.widget.SetAttribute(core.Qt__WA_InputMethodEnabled, true)
ws.widget.ConnectInputMethodEvent(ws.InputMethodEvent)
ws.widget.ConnectInputMethodQuery(ws.InputMethodQuery)
// screen widget and scrollBar widget
widget2 := widgets.NewQWidget(nil, 0)
widget2.SetContentsMargins(0, 0, 0, 0)
ws.layout2 = widgets.NewQHBoxLayout()
ws.layout2.SetContentsMargins(0, 0, 0, 0)
ws.layout2.SetSpacing(0)
ws.layout2.AddWidget(ws.screen.widget, 0, 0)
widget2.SetLayout(ws.layout2)
// assemble all neovim ui components
if editor.config.Editor.ExtTabline {
layout.AddWidget(ws.tabline.widget, 0, 0)
}
layout.AddWidget(widget2, 1, 0)
ws.widget.Move2(0, 0)
editor.putLog("assembled workspace UI components")
}
func (ws *Workspace) initFont() {
ws.screen.font = editor.font
ws.screen.fallbackfonts = editor.fallbackfonts
ws.font = ws.screen.font
ws.screen.tooltip.setFont(editor.font)
ws.screen.tooltip.fallbackfonts = editor.fallbackfonts
ws.font.ws = ws
if ws.tabline != nil {
ws.tabline.font = ws.font.qfont
}
}
func (ws *Workspace) lazyLoadUI() {
editor.putLog("Start preparing for deferred drawing UI")
editor.putLog("preparing scrollbar")
// scrollbar
if editor.config.ScrollBar.Visible {
ws.scrollBar = newScrollBar()
ws.scrollBar.ws = ws
}
editor.putLog("preparing minimap")
// minimap
if !editor.config.MiniMap.Disable {
ws.minimap = newMiniMap()
ws.minimap.ws = ws
ws.layout2.AddWidget(ws.minimap.widget, 0, 0)
}
editor.putLog("preparing deferred drawing UI")
if editor.config.ScrollBar.Visible {
ws.layout2.AddWidget(ws.scrollBar.widget, 0, 0)
ws.scrollBar.setColor()
}
editor.putLog("preparing filer")
// Add editor feature
go filer.RegisterPlugin(ws.nvim, editor.config.Editor.FileOpenCmd)
editor.putLog("preparing minimap buffer")
// Asynchronously execute the process for minimap
if !editor.config.MiniMap.Disable {
ws.minimap.startMinimapProc(editor.ctx)
time.Sleep(time.Millisecond * 50)
ws.minimap.mu.Lock()
isMinimapVisible := ws.minimap.visible
ws.minimap.mu.Unlock()
if isMinimapVisible {
ws.minimap.bufUpdate()
ws.minimap.bufSync()
ws.updateSize()
}
}
editor.putLog("Finished preparing the deferred drawing UI.")
}
func (ws *Workspace) initLazyLoadUI() {
editor.isWindowNowActivated = false
ws.widget.ConnectFocusInEvent(func(event *gui.QFocusEvent) {
go ws.nvim.SetFocusUI(true)
})
ws.widget.ConnectFocusOutEvent(func(event *gui.QFocusEvent) {
go ws.nvim.SetFocusUI(false)
})
go func() {
if !editor.doRestoreSessions {
time.Sleep(time.Millisecond * 500)
}
ws.signal.LazyLoadSignal()
if !editor.doRestoreSessions {
time.Sleep(time.Millisecond * 500)
}
editor.signal.SidebarSignal()
// put font debug log
ws.font.putDebugLog()
}()
}
func (ws *Workspace) registerSignal(signal *neovimSignal, redrawUpdates chan [][]interface{}, guiUpdates chan []interface{}) {
ws.signal = signal
ws.redrawUpdates = redrawUpdates
ws.guiUpdates = guiUpdates
ws.signal.ConnectRedrawSignal(func() {
updates := <-ws.redrawUpdates
editor.putLog("Received redraw event from neovim")
ws.handleRedraw(updates)
})
ws.signal.ConnectGuiSignal(func() {
updates := <-ws.guiUpdates
editor.putLog("Received GUI event from neovim")
ws.handleGui(updates)
})
ws.signal.ConnectLazyLoadSignal(func() {
if ws.hasLazyUI {
return
}
if editor.config.Editor.ExtTabline {
ws.tabline.initTab()
}
editor.workspaceUpdate()
ws.hasLazyUI = true
ws.lazyLoadUI()
})
ws.signal.ConnectStopSignal(func() {
workspaces := []*Workspace{}
index := 0
maxworkspaceIndex := len(editor.workspaces) - 1
for i, wse := range editor.workspaces {
if ws != wse {
workspaces = append(workspaces, wse)
} else {
index = i
}
}
if len(workspaces) == 0 {
// TODO
// If nvim is an instance on a remote server, the connection `cmd` can be
// `ssh` or `wsl` command. What kind of exit status should be set?
if ws.uiRemoteAttached || ws.nvim == nil {
editor.close(0)
} else {
editor.close(ws.nvim.ExitCode())
}
return
}
editor.workspaces = workspaces
for i := 0; i < len(editor.side.items); i++ {
if i >= index && i+1 < len(editor.side.items) {
editor.side.items[i].copy(editor.side.items[i+1])
}
if i+1 == len(editor.side.items) {
editor.side.items[i].label.SetText("")
editor.side.items[i].hidden = false
editor.side.items[i].active = false
editor.side.items[i].text = ""
editor.side.items[i].cwdpath = ""
editor.side.items[i].isContentHide = false
content := widgets.NewQListWidget(nil)
content.SetFocusPolicy(core.Qt__NoFocus)
content.SetFrameShape(widgets.QFrame__NoFrame)
content.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
content.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
content.SetIconSize(core.NewQSize2(editor.iconSize*3/4, editor.iconSize*3/4))
editor.side.items[i].content = content
editor.side.items[i].widget.Layout().AddWidget(content)
}
if i == maxworkspaceIndex {
editor.side.items[i].hidden = true
editor.side.items[i].hidden = false
}
editor.side.items[i].setSideItemLabel(i)
}
ws.hide()
if editor.active == index {
if index > 0 {
editor.active--
}
editor.workspaceUpdate()
}
})
}
func (ws *Workspace) bindNvim(nvimCh chan *nvim.Nvim, uiRemoteAttachedCh chan bool, isSetWindowState, isLazyBind bool, file string) {
ws.nvim = <-nvimCh
ws.uiRemoteAttached = <-uiRemoteAttachedCh
// Get nvim options
ws.getGlobalOptions()
// Adjust nvim geometry to fit application window size
ws.uiAttached = true
if len(editor.workspaces) == 1 {
editor.chUiPrepared <- true
}
// Load goneovim's neovim settings
loadHelpDoc(ws.nvim)
loadGinitVim(ws.nvim)
source(ws.nvim, file)
// Initialize lazy load UI
ws.initLazyLoadUI()
}
func (i *WorkspaceSideItem) copy(ii *WorkspaceSideItem) {
i.label.SetText(ii.label.Text())
i.hidden = ii.hidden
i.active = ii.active
i.text = ii.text
i.cwdpath = ii.cwdpath
i.content = ii.content
i.isContentHide = ii.isContentHide
i.widget.Layout().AddWidget(i.content)
}
func (ws *Workspace) hide() {
if ws.hidden {
return
}
ws.hidden = true
ws.widget.Hide()
}
func (ws *Workspace) show() {
if !ws.hidden {
return
}
ws.hidden = false
ws.widget.Show()
ws.widget.SetFocus2Default()
ws.cursor.update()
}
func (ws *Workspace) getGlobalOptions() {
ws.getColorscheme()
ws.getBG()
ws.getKeymaps()
ws.getMousescroll()
}
func (ws *Workspace) getMousescroll() {
msChan := make(chan string, 5)
go func() {
mousescroll := ""
ws.nvim.Option("mousescroll", &mousescroll)
msChan <- mousescroll
}()
select {
case ws.mouseScroll = <-msChan:
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
}
}
func (ws *Workspace) getColorscheme() {
strChan := make(chan string, 5)
go func() {
colorscheme := ""
ws.nvim.Var("colors_name", &colorscheme)
strChan <- colorscheme
}()
select {
case colo := <-strChan:
ws.colorscheme = colo
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
}
}
func (ws *Workspace) getBG() {
strChan := make(chan string, 5)
go func() {
screenbg := "dark"
ws.nvim.Option("background", &screenbg)
strChan <- screenbg
}()
select {
case screenbg := <-strChan:
ws.screenbg = screenbg
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
}
}
func (ws *Workspace) getKeymaps() {
ws.escKeyInInsert = "<Esc>"
ws.escKeyInNormal = "<Esc>"
nmapChan := make(chan []*nvim.Mapping, 5)
imapChan := make(chan []*nvim.Mapping, 5)
// Get user mappings
go func() {
var nmappings, imappings []*nvim.Mapping
var err1, err2 error
nmappings, err1 = ws.nvim.KeyMap("normal")
if err1 != nil {
return
}
nmapChan <- nmappings
imappings, err2 = ws.nvim.KeyMap("insert")
if err2 != nil {
return
}
imapChan <- imappings
}()
// wait to getting user mappings
var ok [2]bool
for {
select {
case nmappings := <-nmapChan:
ws.normalMappings = nmappings
ok[0] = true
case imappings := <-imapChan:
ws.insertMappings = imappings
ok[1] = true
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
ok[0] = true
ok[1] = true
}
if ok[0] && ok[1] {
break
}
}
altkeyCount := 0
metakeyCount := 0
for _, mapping := range ws.insertMappings {
// Check Esc mapping
if strings.EqualFold(mapping.RHS, "<Esc>") || strings.EqualFold(mapping.RHS, "<C-[>") {
if mapping.NoRemap == 1 {
ws.escKeyInInsert = mapping.LHS
}
}
// Count user def alt/meta key mappings
if strings.HasPrefix(mapping.LHS, "<A-") {
altkeyCount++
}
if strings.HasPrefix(mapping.LHS, "<M-") {
metakeyCount++
}
}
for _, mapping := range ws.normalMappings {
if strings.EqualFold(mapping.RHS, "<Esc>") || strings.EqualFold(mapping.RHS, "<C-[>") {
if mapping.NoRemap == 1 {
ws.escKeyInNormal = mapping.LHS
}
}
if strings.EqualFold(mapping.LHS, "<C-y>") || strings.EqualFold(mapping.LHS, "<C-e>") {
ws.isMappingScrollKey = true
}
// Count user def alt/meta key mappings
if strings.HasPrefix(mapping.LHS, "<A-") {
altkeyCount++
}
if strings.HasPrefix(mapping.LHS, "<M-") {
metakeyCount++
}
}
editor.muMetaKey.Lock()
if altkeyCount >= metakeyCount {
editor.prefixToMapMetaKey = "A-"
} else {
editor.prefixToMapMetaKey = "M-"
}
editor.muMetaKey.Unlock()
}
func (ws *Workspace) getNumOfTabs() int {
done := make(chan int, 5)
num := 0
go func() {
tn := 0
ws.nvim.Eval("tabpagenr('$')", &tn)
done <- tn
}()
select {
case tn := <-done:
num = tn
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
}
return num
}
func (ws *Workspace) getCwd() string {
done := make(chan bool, 5)
cwd := ""
go func() {
ws.nvim.Eval("getcwd()", &cwd)
done <- true
}()
select {
case <-done:
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
}
return cwd
}
func (ws *Workspace) nvimEval(s string) (interface{}, error) {
doneChannel := make(chan interface{}, 5)
var result interface{}
go func() {
ws.nvim.Eval(s, &result)
doneChannel <- result
}()
select {
case done := <-doneChannel:
return done, nil
case <-time.After(NVIMCALLTIMEOUT * time.Millisecond):
err := errors.New("neovim busy")
return nil, err
}
}
func (ws *Workspace) handleChangeCwd(cwdinfo map[string]interface{}) {
scope, ok := cwdinfo["scope"]
if !ok {
scope = "global"
}
cwdITF, ok := cwdinfo["cwd"]
if !ok {
return
}
cwd := cwdITF.(string)
switch scope {
case "global":
ws.setCwd(cwd)
case "tab":
ws.setCwdInTab(cwd)
case "window":
ws.setCwdInWin(cwd)
}
}
func (ws *Workspace) setCwd(cwd string) {
if cwd == "" {
cwd = ws.getCwd()
}
ws.cwd = cwd
var labelpath string
switch editor.config.Workspace.PathStyle {
case "name":
labelpath = filepath.Base(cwd)
case "minimum":
labelpath, _ = shortpath.Minimum(cwd)
case "full":
labelpath, _ = filepath.Abs(cwd)
default:
labelpath, _ = filepath.Abs(cwd)
}
ws.cwdlabel = labelpath
ws.cwdBase = filepath.Base(cwd)
if editor.side == nil {
return
}
for i, wse := range editor.workspaces {
if i >= len(editor.side.items) {
return
}
if ws == wse {
path, _ := filepath.Abs(cwd)
sideItem := editor.side.items[i]
if sideItem.cwdpath == path {
continue
}
sideItem.label.SetText(wse.cwdlabel)
sideItem.label.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize-1, 1, false))
sideItem.cwdpath = path
}
}
}
func (ws *Workspace) setCwdInTab(cwd string) {
ws.screen.windows.Range(func(_, winITF interface{}) bool {
win := winITF.(*Window)
if win == nil {
return true
}
if win.grid == 1 {
return true
}
if win.isMsgGrid {
return true
}
if win.isShown() {
win.cwd = cwd
}
return true
})
}
func (ws *Workspace) setCwdInWin(cwd string) {
ws.screen.windows.Range(func(_, winITF interface{}) bool {
win := winITF.(*Window)
if win == nil {
return true
}
if win.grid == 1 {
return true
}
if win.isMsgGrid {
return true
}
if win.grid == ws.cursor.gridid {
win.cwd = cwd
}
return true
})
}
func (ws *Workspace) updateSize() (windowWidth, windowHeight, cols, rows int) {
e := editor
geometry := e.window.Geometry()
width := geometry.Width()
marginWidth := e.window.BorderSize()*4 + e.window.WindowGap()*2
sideWidth := 0
if e.side != nil {
if e.side.widget.IsVisible() {
sideWidth = e.splitter.Sizes()[0] + e.splitter.HandleWidth()
}
}
width -= marginWidth + sideWidth
height := geometry.Height()
marginHeight := e.window.BorderSize() * 4
height -= marginHeight
titlebarHeight := 0
if e.config.Editor.BorderlessWindow && runtime.GOOS != "linux" {
if !e.config.Editor.HideTitlebar {
titlebarHeight = e.window.TitleBar.Height()
}
}
height -= titlebarHeight
tablineHeight := 0
if ws.isDrawTabline && ws.tabline != nil {
if ws.tabline.showtabline != -1 {
ws.tabline.height = ws.tabline.Tabs[0].widget.Height() + (TABLINEMARGIN * 2)
tablineHeight = ws.tabline.height
}
}
scrollbarWidth := 0
if e.config.ScrollBar.Visible {
scrollbarWidth = e.config.ScrollBar.Width
}
minimapWidth := 0
if ws.minimap != nil {
if ws.minimap.visible {
minimapWidth = e.config.MiniMap.Width
}
}
screenWidth := width - scrollbarWidth - minimapWidth
screenHeight := height - tablineHeight
rw := screenWidth - int(math.Ceil(float64(int(float64(screenWidth)/ws.screen.font.cellwidth))*ws.screen.font.cellwidth))
rh := screenHeight % ws.screen.font.lineHeight
screenWidth -= rw
screenHeight -= rh
width -= rw
height -= rh
if width != ws.width || height != ws.height {
ws.width = width
ws.height = height
ws.widget.Resize2(width, height)
if !ws.hidden {
ws.hide()
ws.show()
} else {
ws.show()
ws.hide()
}
}
if ws.screen != nil {
ws.screen.width = screenWidth
ws.screen.height = screenHeight
ws.screen.updateSize()
}
if ws.cursor != nil {
ws.cursor.resize(ws.cursor.width, ws.cursor.height)
ws.cursor.update()
}
if ws.palette != nil {
ws.palette.resize()
}
if ws.message != nil {
ws.message.resize()
}
windowWidth = marginWidth + sideWidth + scrollbarWidth + minimapWidth + ws.screen.width
windowHeight = marginHeight + titlebarHeight + tablineHeight + ws.screen.height
cols = ws.cols
rows = ws.rows
return
}
func (ws *Workspace) updateApplicationWindowSize(cols, rows int) {
e := editor
font := ws.font
if e.window.WindowState() == core.Qt__WindowFullScreen ||
e.window.WindowState() == core.Qt__WindowMaximized {
return
}
appWinWidth := int(math.Ceil(font.cellwidth * float64(cols)))
appWinHeight := int(float64(font.lineHeight) * float64(rows))
marginWidth := e.window.BorderSize()*4 + e.window.WindowGap()*2
sideWidth := 0
if e.side != nil {
if e.side.widget.IsVisible() {
sideWidth = e.splitter.Sizes()[0] + e.splitter.HandleWidth()
}
}
appWinWidth += marginWidth + sideWidth
marginHeight := e.window.BorderSize() * 4
titlebarHeight := 0
if e.config.Editor.BorderlessWindow && runtime.GOOS != "linux" {
if !e.config.Editor.HideTitlebar {
titlebarHeight = e.window.TitleBar.Height()
}
}
appWinHeight += marginHeight + titlebarHeight
tablineHeight := 0
if ws.isDrawTabline && ws.tabline != nil {
if ws.tabline.showtabline != -1 {
ws.tabline.height = ws.tabline.Tabs[0].widget.Height() + (TABLINEMARGIN * 2)
tablineHeight = ws.tabline.height
}
}
scrollbarWidth := 0
if e.config.ScrollBar.Visible {
scrollbarWidth = e.config.ScrollBar.Width
}
minimapWidth := 0
if ws.minimap != nil {
if ws.minimap.visible {
minimapWidth = e.config.MiniMap.Width
}
}
appWinWidth += scrollbarWidth + minimapWidth
appWinHeight += tablineHeight
// Disable size specifications larger than the desktop screen size
desktopRect := e.app.Desktop().AvailableGeometry2(e.window)
desktopWidth := desktopRect.Width()
desktopHeight := desktopRect.Height()
if appWinWidth > desktopWidth {
appWinWidth = desktopWidth
}
if appWinHeight > desktopHeight {
appWinHeight = desktopHeight
}
e.putLog("update app win size::", appWinWidth, appWinHeight)
e.window.Resize2(
appWinWidth,
appWinHeight,
)
return
}
func (e *Editor) updateNotificationPos() {
e.width = e.window.Width()
e.height = e.window.Height()
e.notifyStartPos = core.NewQPoint2(e.width-e.notificationWidth-10, e.height-30)
var x, y int
var newNotifications []*Notification
for _, item := range e.notifications {
x = e.notifyStartPos.X()
y = e.notifyStartPos.Y() - item.widget.Height() - 4
if !item.isHide && !item.isMoved {
item.widget.Move2(x, y)
e.notifyStartPos = core.NewQPoint2(x, y)
}
newNotifications = append(newNotifications, item)
}
e.notifications = newNotifications
}
func handleEvent(update interface{}) (event string, ok bool) {
switch update.(type) {
case string:
event = update.(string)
ok = true
default:
event = ""
ok = false
}
return event, ok
}
func (ws *Workspace) handleRedraw(updates [][]interface{}) {
s := ws.screen
for _, update := range updates {
event, ok := handleEvent(update[0])
if !ok {
continue
}
args := update[1:]
editor.putLog("start ", event)
// // for DEBUG::
// if event == "grid_line" || event == "hl_attr_define" || event == "mode_info_set" {
// fmt.Println(event)
// } else {
// fmt.Println(event, args)
// }
switch event {
// Global Events
case "set_title":
titleStr := (update[1].([]interface{}))[0].(string)
editor.window.SetupTitle(titleStr)
if runtime.GOOS == "linux" {
editor.window.SetWindowTitle(titleStr)
}
case "set_icon":
case "mode_info_set":
ws.modeInfoSet(args)
ws.cursor.modeIdx = 0
case "option_set":
ws.setOption(update)
case "mode_change":
arg := update[len(update)-1].([]interface{})
ws.modeEnablingIME(arg[0].(string))
ws.mode = arg[0].(string)
ws.modeIdx = util.ReflectToInt(arg[1])
if ws.cursor.modeIdx != ws.modeIdx {
ws.cursor.modeIdx = ws.modeIdx
}
ws.disableImeInNormal()
ws.shouldUpdate.cursor = true
// Not used in the current specification.
case "mouse_on":
ws.isMouseEnabled = true
case "mouse_off":
ws.isMouseEnabled = false
// Indicates to the UI that it must stop rendering the cursor. This event
// is misnamed and does not actually have anything to do with busyness.
// NOTE: In goneovim, the wdiget layer of the cursor has special processing,
// so it cannot be hidden straightforwardly.
case "busy_start":
ws.cursor.isBusy = true
ws.shouldUpdate.cursor = true
case "busy_stop":
ws.cursor.isBusy = false
ws.shouldUpdate.cursor = true