-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdjustableTabWindow.xml
More file actions
1422 lines (1292 loc) · 52.2 KB
/
AdjustableTabWindow.xml
File metadata and controls
1422 lines (1292 loc) · 52.2 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<TriggerPackage />
<TimerPackage />
<AliasPackage />
<ActionPackage />
<ScriptPackage>
<Script isActive="yes" isFolder="no">
<name>AdjustableTabWindow</name>
<packageName></packageName>
<script>-- Adjustable TabWindow
-- TabWindow code by Mudlet Wiki
-- other functions
-- by Edru 10th October 2020
-- https://github.com/Edru2/AdjustableTabWindow
Adjustable = Adjustable or {}
Adjustable.TabWindow = Adjustable.TabWindow or Geyser.Container:new({name = "AdjustableTabWindowClass"})
local tab_pos = nil
function Adjustable.TabWindow:createBaseContainers()
self.tabBar = self.tabBar or Geyser.Label:new({
name = self.name.."tabBar",
x = 0, y = 0,
width = "100%",
height = self.tabBarHeight,
},self)
self.tabBar:setStyleSheet(self.tabBarStyle)
self.header = self.header or Geyser.HBox:new({
name = self.name.."header",
x = 0, y = 0,
width = "100%",
height = "100%",
},self.tabBar)
self.overlay = self.overlay or Geyser.Label:new({
name = self.name.."overlay",
x = 0, y = 0,
width = "100%",
height = "100%",
},self.tabBar)
self.overlay:setStyleSheet(self.overlayStyle)
self.overlay:setMoveCallback(function(event) self:onOverlayMove(event) end)
self.overlay:setOnLeave(function(event) self:onOverlayLeave(event) end)
self.overlay:setClickCallback(function(event) self:onOverlayClick(event) end)
self.overlay:hide()
self.footerContainer = self.footerContainer or Geyser.Container:new({
name = self.name.."footerContainer",
x = 0, y = self.tabBarHeight,
width = "100%",
height = "-0",
},self)
self.footer = self.footer or Geyser.Label:new({
name = self.name.."footer",
x = 0, y = self.gap,
width = "100%",
height = "-0",
},self.footerContainer)
self.footer:setStyleSheet(self.footerStyle)
end
local function setTabToolTip(tab)
-- put ToolTip on Label if TabText is to long to display
local w,h = calcFontSize(tab.adjLabel.fontSize)
local txt_width = #tab.tabText * w
if tab.adjLabel:get_width() < txt_width then
tab.adjLabel:setToolTip(tab.tabText)
else
tab.adjLabel:resetToolTip()
end
end
-- function to create new tabs in tabs table or to rewrite/readjust them
function Adjustable.TabWindow:createTabs()
for k,v in ipairs(self.tabs) do
self[v.."center"] = self[v.."center"] or Geyser.Label:new({
name = v.."center",
x = 0, y = 0,
width = "100%",
height = "100%",
},self.footer)
self[v.."center"]:setStyleSheet(self.centerStyle)
local tabText = self[v] and self[v].tabText or v
self[v] = self[v] or Adjustable.Container:new({
name = self.name.." Tab: "..v,
tabname = v,
origin = self,
noLimit = true,
tabText = tabText,
padding = 0,
locked = true,
autoSave = false,
autoLoad = false,
raiseOnClick = false,
adjLabelstyle = self.inactiveTabStyle,
titleTxtColor = self.tabTxtColor
}, self.header)
self[v]:setTitle("", self.TabTxtColor)
self[v].titleText = "&nbsp;&nbsp;"..tabText
self[v].adjLabel:echo(tabText, self.TabTxtColor)
self[v]:newLockStyle("tab",
function(self)
self.Inside:resize("-"..self.padding,"-"..self.padding)
self.Inside:move(self.padding, self.padding*2)
end)
self[v].lockStyle = "tab"
self[v].unlockContainer = function()
Adjustable.Container.unlockContainer(self[v])
self[v]:setTitle("", self.tabTxtColor)
self[v].titleText = ("&nbsp;&nbsp;"..self[v].tabText)
self[v].adjLabel:echo(self[v].tabText, "nocolor", "c")
end
Adjustable.TabWindow.allTabs[v] = self
self[v]:newCustomItem("Tabify", function() Adjustable.TabWindow.allTabs[v]:createTempWindow(self[v]) end)
self[v].reposition = self.reposition
local delIndex = table.index_of(Adjustable.Container.all_windows, self[v].name)
if delIndex then
table.remove(Adjustable.Container.all_windows, delIndex)
end
Adjustable.Container.all[self[v].name] = nil
self[v].adjLabelstyle = self.inactiveTabStyle
self[v].titleTxtColor = self.tabTxtColor
self[v].adjLabel:setStyleSheet(self.inactiveTabStyle)
self[v].adjLabel:echo(self[v].tabText, "nocolor", "c")
self[v].adjLabel:setClickCallback(function(event) self:onClick(v, event) end)
self[v].adjLabel:setReleaseCallback(function(event) self:onRelease(v, event) end)
self[v].adjLabel:setMoveCallback(function(event) self:onMove(v, event) end)
self[v].adjLabel:setDoubleClickCallback(function(event) self:onDoubleClick(v, event) end)
self[v].minimizeLabel:setClickCallback(function() self:onMinimizeClick(v) end)
self[v].minimizeLabel:echo("<center>🗗</center>")
self[v].minLabel:setClickCallback(function() self:onMinimizeClick(v) end)
self[v.."center"]:hide()
-- put ToolTip on Label if TabText is to long to display
setTabToolTip(self[v])
end
end
--- Sets the amount of space to use between the tabs and the consoles
-- @tparam number gap Number of pixels to keep between the tabs and consoles
function Adjustable.TabWindow:setGap(gap)
local gapNumber = tonumber(gap)
local gapType = type(gap)
assert(gapType == "number", "gap expected as number, got " .. gapType)
self.gap = gapNumber
self.footer:move(0, gapNumber)
end
--- Sets the height of the tabs in pixels/percent
-- @tparam number tabHeight the height of the tabs for the object, in pixels/percent
function Adjustable.TabWindow:setTabHeight(tabHeight)
self.tabBarHeight = tabHeight
self.tabBar:resize("100%", tabHeight)
self.footerContainer:move(0, tabHeight)
self.footerContainer:resize("100%", "-0")
end
--- Sets the CSS to use for the tab box which contains the tabs for the object
-- @tparam string css The css styling to use for the tab box
function Adjustable.TabWindow:setTabBarCSS(css)
local cssType = type(css)
assert(cssType == "string", "css as string expected, got " .. cssType)
self.tabBarStyle = css
self.tabBar:setStyleSheet(self.tabBarStyle)
end
--- Sets the color to use for the tab box background
-- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b}
function Adjustable.TabWindow:setTabBarColor(color)
self.tabBarColor = color
self.tabBarStyle = ""
self.tabBar:setStyleSheet(self.tabBarStyle)
self.tabBar:setColor(self.tabBarColor)
end
--- Sets the FG color for the active tab
-- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b}
function Adjustable.TabWindow:setActiveTabFGColor(color)
local found
local add_css
local r, g, b = Geyser.Color.parse(color)
local rgb = string.format("rgb(%s, %s, %s)",r,g,b)
self.activeTabFGColor = color
self.activeTabStyle, found = string.gsub(" "..self.activeTabStyle, "(%scolor:).-(;)","%1"..rgb.."%2")
if found == 0 then
if string.match(self.activeTabStyle,"QLabel{") then
add_css = "\nQLabel{color:"..rgb..";}"
else
add_css = "\ncolor:"..rgb..";"
end
self.activeTabStyle = self.activeTabStyle..add_css
end
self:adjustTabStyle()
end
--- Sets the FG color for the inactive tab
-- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b}
function Adjustable.TabWindow:setInactiveTabFGColor(color)
local found
local add_css
self.inactiveTabFGColor = color
local r, g, b = Geyser.Color.parse(color)
local rgb = string.format("rgb(%s, %s, %s)",r,g,b)
self.inactiveTabStyle, found = string.gsub(" "..self.inactiveTabStyle, "(%scolor:).-(;)","%1"..rgb.."%2")
if found == 0 then
if string.match(self.inactiveTabStyle,"QLabel{") then
add_css = "\nQLabel{color:"..rgb..";}"
elseif string.match(self.inactiveTabStyle,"QLabel::!hover{") then
add_css = ""
self.inactiveTabStyle = string.gsub(self.inactiveTabStyle, "(QLabel::!.-)(})","%1".."color:"..rgb..";".."%2")
else
add_css = "\ncolor:"..rgb..";"
end
self.inactiveTabStyle = self.inactiveTabStyle..add_css
end
self:adjustTabStyle()
end
--- Sets the BG color for the active tab.
-- <br>NOTE: If you set CSS for the active tab, it will override this setting.
-- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b}
function Adjustable.TabWindow:setActiveTabBGColor(color)
self.activeTabBGColor = color
local r, g, b = Geyser.Color.parse(color)
local rgba = string.format("rgba(%s, %s, %s, %s)",r,g,b,"100%%")
self.activeTabStyle = string.gsub(self.activeTabStyle, "(background%-color:.-).-(;)","%1 "..rgba.."%2")
self:adjustTabStyle()
end
--- Sets the BG color for the inactive tab.
-- <br>NOTE: If you set CSS for the inactive tab, it will override this setting.
-- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b}
function Adjustable.TabWindow:setInactiveTabBGColor(color)
self.inactiveTabBGColor = color
local r, g, b = Geyser.Color.parse(color)
local rgba = string.format("rgba(%s, %s, %s, %s)",r,g,b,"100%%")
self.inactiveTabStyle = string.gsub(self.inactiveTabStyle, "(background%-color:.-).-(;)","%1 "..rgba.."%2")
self:adjustTabStyle()
end
function Adjustable.TabWindow:adjustTabStyle()
local abg_rgb = string.match(self.activeTabBGColor, "%d+.-%d+.-%d+")
local ibg_rgb = string.match(self.inactiveTabBGColor, "%d+.-%d+.-%d+")
for k,v in ipairs(self.tabs) do
if v == self.current then
self[v].adjLabelstyle = self.activeTabStyle
self[v].adjLabel:setStyleSheet(self.activeTabStyle)
if abg_rgb then
self[v].adjLabel:setColor("<"..abg_rgb..">")
else
self[v].adjLabel:setColor(self.activeTabBGColor)
end
else
self[v].adjLabelstyle = self.inactiveTabStyle
self[v].adjLabel:setStyleSheet(self.inactiveTabStyle)
if ibg_rgb then
self[v].adjLabel:setColor("<"..ibg_rgb..">")
else
self[v].adjLabel:setColor(self.inactiveTabBGColor)
end
end
end
end
--- sets the font for all tabs
--- @tparam string font the font to use.
function Adjustable.TabWindow:setTabFont(font)
self.tabFont = font
for k,v in ipairs(self.tabs) do
self[v].adjLabel:setFont(font)
end
end
--- sets the font for a single tab. If you use setTabFont this will be overridden
--- @tparam string tabName the tab to change the font of
--- @tparam string font the font to use for that tab
function Adjustable.TabWindow:setSingleTabFont(tabName, font)
local funcName = "EMCO:setSingleTabFont(tabName, font)"
if not table.contains(self.tabs, tabName) then
error("tabName must be an existing tab")
end
self[tabName].adjLabel:setFont(font)
end
-- finds the right position to drop the tab into
function Adjustable.TabWindow:findPosition(tab)
local myWindow = Adjustable.TabWindow.currentWindow or self
local x, w = myWindow.get_x(), myWindow.get_width()
local total = w/#myWindow.tabs
local tab_x = tab.get_x() - x
local position = (tab_x/total) + 1
position = math.floor(position + 0.5)
if position < 1 then
position = 1
end
if position > #myWindow.tabs then
position = #myWindow.tabs + 1
end
return position
end
-- checks if 2 elements collide
local function checkCollision(x1,y1,w1,h1, x2,y2,w2,h2)
if x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1 then
return true
end
end
local function getFloatingWindows()
local floatingWindows = {}
for k,v in pairs(Adjustable.TabWindow.allTabs) do
if v[k].floating then
floatingWindows[k] = v[k]
end
end
return floatingWindows
end
-- checks if your tab collides with one of the tabwindows
function Adjustable.TabWindow:checkMultiCollision(tab)
local floatingWindows = getFloatingWindows()
local x1, y1, w1, h1 = tab:get_x(), tab:get_y(), tab:get_width(), tab:get_height()
for k,v in pairs(floatingWindows) do
local x2, y2, w2, h2 = v:get_x(), v:get_y(), v:get_width(), v:get_height()
if checkCollision(x1,y1,w1,h1, x2,y2,w2,h2) and v.windowname == self.windowname and not(v.hidden or v.auto_hidden) and not (v == tab) and not v.locked then
return "floating", v
end
end
for k,v in pairs(Adjustable.TabWindow.all) do
local x2, y2, w2, h2 = v:get_x(), v:get_y(), v:get_width(), v:get_height()
if checkCollision(x1,y1,w1,h1, x2,y2,w2,h2) and v.windowname == self.windowname and not(v.hidden or v.auto_hidden) then
return "TabWindow", v
end
end
end
-- onMove function
-- contains all the functionality to move the tab (collision check, make space ...)
function Adjustable.TabWindow:onMove(tab, event)
self[tab]:onMove(self[tab].adjLabel, event)
self[tab].adjLabel:setAlignment("c")
if self[tab].floating or not Adjustable.TabWindow.clicked then
return
end
local result, value = self:checkMultiCollision(self[tab])
if Adjustable.TabWindow.currentWindow and Adjustable.TabWindow.currentWindow ~= value and not Adjustable.TabWindow.currentWindow.floating then
-- reset the tab space
self:makeSpace(Adjustable.TabWindow.currentWindow, nil, true)
end
if result == "TabWindow" then
Adjustable.TabWindow.currentWindow = value
tab_pos = value:findPosition(self[tab])
self:makeSpace(value, tab_pos)
return
end
if result == "floating" and not(value.locked) then
Adjustable.TabWindow.currentWindow = value
return
end
if Adjustable.TabWindow.currentWindow then
Adjustable.TabWindow.currentWindow = nil
end
end
--- Transforms a floating Tab into a temporary TabWindow
-- @tparam tab the tab which will be transformed
function Adjustable.TabWindow:createTempWindow(tab, tempName)
if tab and not(tab.floating) then
return
end
local rnd_nr = 0
for i=0,#Adjustable.TabWindow.all_windows do
if not Adjustable.TabWindow.all["tempTabWindow"..i] then
rnd_nr = i
break
end
end
local window = tab and tab.windowname ~= "main" and Geyser.windowList[tab.windowname.."Container"].windowList[tab.windowname] or Geyser
local tempWindowName = tempName and "tempWindow"..string.match(tempName,"%d+") or "tempWindow"..rnd_nr
local tempTabWindowName = tempName or "tempTabWindow"..rnd_nr
local x, y, width, height = 0,0,100,100
if tab then
x, y, width, height = tab:get_x(), tab:get_y(), tab:get_width(), tab:get_height()
end
local tempWindowConf = { name = tempWindowName,
titleText = "",
x = x,
y = y,
width = width,
height = height,
autoSave = false,
autoLoad = false,
}
tempWindowConf = table.union(tempWindowConf, self.tempWindowConf)
local windowCont = Adjustable.Container:new(tempWindowConf)
windowCont:move(x, y)
windowCont:resize(width, height)
table.remove(Adjustable.Container.all_windows, table.index_of(Adjustable.Container.all_windows, windowCont.name ))
Adjustable.Container.all[windowCont.name] = nil
local tabWindow = Adjustable.TabWindow:new({
name = tempTabWindowName,
x = 0,
y = 0,
width = "100%",
height = "100%",
tabTxtColor = self.tabTxtColor,
tabPadding = self.tabPadding,
activeTabFGColor = self.activeTabFGColor,
inactiveTabFGColor = self.inactiveTabFGColor,
activeTabBGColor = self.activeTabBGColor,
inactiveTabBGColor = self.inactiveTabBGColor,
tabBarColor = self.tabBarColor,
tabBarStyle = self.tabBarStyle,
color1 = self.color1,
color2 = self.color2,
tabBarHeight = self.tabBarHeight,
footerStyle = self.footerStyle,
centerStyle = self.centerStyle,
inactiveTabStyle = self.inactiveTabStyle,
activeTabStyle = self.activeTabStyle,
chosenTabStyle = self.chosenTabStyle,
overlayStyle = self.overlayStyle,
gap = self.gap,
temporary = true
}, windowCont)
--save name to get the style on loading
tabWindow.tempStyle = self.tempStyle or self.name
if tab then
self:restoreTab(tab.tabname, tabWindow)
tab.tempWindow = windowCont
tab.tempTabWindow = tabWindow
tab.tempWindow:changeContainer(window)
tab.tempWindow:setPercent(true, true)
end
windowCont:show()
windowCont.tabWindow = tabWindow
return windowCont
end
-- mouse movement on the overlay label
function Adjustable.TabWindow:onOverlayMove(event)
Adjustable.TabWindow.currentWindow = self
local tab = Adjustable.TabWindow.clickedTab.name
if Adjustable.TabWindow.clickedTab ~= self.header.windowList[tab] then
-- need to feed values to findPosition
local fakeTab = {}
fakeTab.get_x = function() return event.x + self.header.get_x() end
tab_pos = self:findPosition(fakeTab)
self:makeSpace(self, tab_pos)
end
end
-- reset tabspace after mouse leaves overlay label and resets the currentWindow
function Adjustable.TabWindow:onOverlayLeave(event)
Adjustable.TabWindow.currentWindow = nil
if not(Adjustable.TabWindow.doubleClick) then
return
end
local tab = Adjustable.TabWindow.clickedTab.name
if Adjustable.TabWindow.clickedTab ~= self.header.windowList[tab] then
self:makeSpace(nil, nil, true)
end
end
-- reset the Overlay label to be hidden
local function resetOverlay()
local tab = Adjustable.TabWindow.clickedTab
if Adjustable.TabWindow.overlayTimer then
killTimer(Adjustable.TabWindow.overlayTimer)
Adjustable.TabWindow.overlayTimer = nil
end
for k,v in pairs(Adjustable.TabWindow.all) do
v.overlay:setStyleSheet("background-color: rgba(0,0,0,0%);")
v.overlay:hide()
end
if Adjustable.TabWindow.currentWindow then
Adjustable.TabWindow.currentWindow:makeSpace(nil, nil, true)
end
Adjustable.TabWindow.doubleClick = nil
tab_pos = nil
-- reset Style if overlay is resetet without action
if tab then
tab.adjLabel:setStyleSheet(tab.adjLabelstyle)
end
if Adjustable.TabWindow.MouseEventID then
killAnonymousEventHandler(Adjustable.TabWindow.MouseEventID)
Adjustable.TabWindow.MouseEventID = nil
end
end
-- handles on overlay click event
function Adjustable.TabWindow:onOverlayClick(event)
Adjustable.TabWindow.doubleClick = nil
local tab = Adjustable.TabWindow.clickedTab
local container = Adjustable.TabWindow.allTabs[tab.tabname] or self
tab.adjLabel:setStyleSheet(container.activeTabStyle)
if container[tab.tabname].floating then
container:restoreTab(tab.tabname, self)
self:addTab(tab.tabname, tab_pos)
else
container:onRelease(tab.tabname, event)
end
resetOverlay()
end
-- if clicked on the minimize label the tab will be
-- restored to be in a tabwindow again
function Adjustable.TabWindow:onMinimizeClick(tab)
local result, value = self:checkMultiCollision(self[tab])
if result == "floating" then
value = nil
end
self:restoreTab(tab, value)
end
-- activates the tab tab (doesn't deactivate the previous tab)
-- @see Adjustable.TabWindow:deactivateTab()
function Adjustable.TabWindow:activateTab(tab)
self:deactivateTab()
tab = self[tab] and tab or self.tabs[1]
self.current = tab
if self.current then
self[tab].adjLabelstyle = self.activeTabStyle
self[tab].adjLabel:setStyleSheet(self.activeTabStyle)
self[self.current.."center"]:show()
end
self:raiseAll()
end
-- deactivates and hides the current active tab
function Adjustable.TabWindow:deactivateTab()
if self.current and self[self.current] then
self[self.current].adjLabelstyle = self.inactiveTabStyle
self[self.current].adjLabel:setStyleSheet(self.inactiveTabStyle)
self[self.current.."center"]:hide()
end
end
-- handles click event on tab
function Adjustable.TabWindow:onClick(tab, event)
if Adjustable.TabWindow.doubleClick then
return
end
Adjustable.TabWindow.currentWindow = self
Adjustable.TabWindow.clicked = true
Adjustable.TabWindow.clickedTab = self[tab]
if event.button == "LeftButton" and not self[tab].floating then
self[tab]:resize(self[tab].get_width(),self[tab].get_height())
self[tab].container = Geyser
-- set minimized to true to prevent resizing
self[tab].minimized = true
self[tab]:unlockContainer()
self[tab]:onClick(self[tab].adjLabel, event)
self[tab].exitLabel:hide()
self[tab].minimizeLabel:hide()
Adjustable.TabWindow.clicked = true
Adjustable.TabWindow.clickedTab = self[tab]
self[tab].adjLabel:echo(self[tab].tabText, "nocolor", "c")
end
if self[tab].floating then
self[tab]:onClick(self[tab].adjLabel, event)
end
if not self[tab].floating then
self:activateTab(tab)
self[tab].adjLabel:raise(false)
end
end
-- handles double click event on getAreaTable
-- activates the tab overlay
function Adjustable.TabWindow:onDoubleClick(tab, event)
Adjustable.TabWindow.currentWindow = self
Adjustable.TabWindow.doubleClick = true
Adjustable.TabWindow.clickedTab = self[tab]
self[tab].adjLabel:setStyleSheet(self.chosenTabStyle)
for k,v in pairs(Adjustable.TabWindow.all) do
v.overlay:show()
v.overlay:raise()
v.overlay:setStyleSheet(v.overlayStyle)
end
Adjustable.TabWindow.overlayTimer = Adjustable.TabWindow.overlayTimer or tempTimer(10, function() resetOverlay() end )
Adjustable.TabWindow.MouseEventID = Adjustable.TabWindow.MouseEventID or registerAnonymousEventHandler("sysWindowMousePressEvent", "Adjustable.TabWindow.onMouseClick", true)
end
-- handles the mouseclick event
-- used for sending windows to the main or userwindow after using doubleclick on a tab
function Adjustable.TabWindow.onMouseClick( event, button, x, y, windowname )
local newContainer = Geyser
if windowname ~= "main" then
newContainer = Geyser.windowList[windowname.."Container"].windowList[windowname]
end
local tab = Adjustable.TabWindow.clickedTab
local container = Adjustable.TabWindow.allTabs[tab.tabname]
container:transformTabContainer(tab.tabname)
local width, height = math.min(newContainer.get_width(), tab:get_width()), math.min(newContainer.get_height(), tab:get_height())
tab:changeContainer(newContainer)
tab:raiseAll()
local x = math.min(newContainer.get_width() - width, math.max(0, x - width/2))
local y = math.min(newContainer.get_height() - height, math.max(0, y))
tab:move(x, y)
tab:resize(width, height)
tab:setPercent(true,true)
killAnonymousEventHandler(Adjustable.TabWindow.MouseEventID)
Adjustable.TabWindow.MouseEventID = nil
resetOverlay()
end
-- transforms the tab to a window
function Adjustable.TabWindow:transformTabContainer(tab)
local myWindow = Adjustable.TabWindow.allTabs[tab] or self
local container = self[tab]
if container.windowname == "main" then
Geyser:add(container)
else
Geyser.windowList[container.windowname.."Container"].windowList[container.windowname]:add(container)
end
container:unlockContainer()
container:resize(self.get_width(), self.get_height())
container:add(self[tab.."center"])
myWindow:removeTab(tab)
myWindow:createTabs()
container:setPadding(self.tabPadding)
container:show()
container:raiseAll()
myWindow[tab].floating = true
container.raiseOnClick = true
container.adjLabel:echo(self[tab].tabText, "nocolor", "c")
container.adjLabel:resetToolTip()
container.minimized = false
container:setPercent(true, true)
myWindow:activateTab(tab)
if #myWindow.tabs > 0 then
myWindow:activateTab(myWindow.tabs[1])
else
myWindow.current = nil
end
local found
container.adjLabelstyle, found = string.gsub(self.activeTabStyle, "(qproperty%-alignment%:.-).-(;)","%1 'AlignTop' %2")
if found == 0 then
container.adjLabelstyle = container.adjLabelstyle.."\nqproperty-alignment: 'AlignTop' ;\n"
end
container.adjLabel:setStyleSheet(container.adjLabelstyle)
self[tab.."center"]:show()
end
--restores the window to be a tab again
function Adjustable.TabWindow:restoreTab(tab, myWindow)
myWindow = myWindow or self
local container = self[tab]
container.container:remove(container)
container:remove(self[tab.."center"])
container:setPadding(0)
container:lockContainer()
container:detach()
container:disconnect()
container.adjLabel:echo(self[tab].tabText, "nocolor", "c")
self:changeTabContainer(tab, myWindow)
self[tab].floating = false
container.raiseOnClick = false
tempTimer(0, function() myWindow:activateTab(tab) end)
end
-- function to make a gap where the tab can be dropped in
function Adjustable.TabWindow:makeSpace(myWindow, position, resetSpace)
myWindow = myWindow or self
position = position or #myWindow.header.windows
if position < 1 then position = 1 end
local current_Tab = Adjustable.TabWindow.clickedTab or {}
local total_count = #myWindow.header.windows + 1
-- close the space if resetSpace is true
if resetSpace then
position = -1
total_count = total_count -1
end
if myWindow == self and current_Tab.name and not(Adjustable.TabWindow.doubleClick) then
total_count = total_count -1
end
local new_width = myWindow.get_width() / total_count
local new_x = 0
local counter = 1
for k,v in ipairs(myWindow.header.windows) do
if v ~= current_Tab.name then
if counter == position then
new_x = new_x + new_width
end
myWindow.header.windowList[v]:resize(new_width)
myWindow.header.windowList[v]:move(new_x)
new_x = new_x + new_width
counter = counter + 1
end
end
end
-- function to change the parent window of the tab
function Adjustable.TabWindow:changeTabContainer(tab, myWindow, position)
if self ~= myWindow or self[tab].floating then
myWindow[tab] = self[tab]
myWindow[tab.."center"] = self[tab.."center"]
self[tab].container = not(self[tab].floating) and self.header or Geyser
self[tab.."center"]:changeContainer(myWindow.footer)
self[tab]:changeContainer(myWindow.header)
if not (self[tab].floating) then
self:removeTab(tab)
self:createTabs()
end
myWindow:createTabs()
myWindow[tab]:show()
if not(myWindow.hidden or myWindow.auto_hidden) then
myWindow:show()
end
end
myWindow:addTab(tab, position)
if self.current then
self[self.current]:show()
end
if #self.tabs > 0 then
if not (self[tab].floating) then
self:activateTab(self.tabs[1])
end
else
self.current = nil
end
myWindow:activateTab(tab)
end
-- handles the release event
function Adjustable.TabWindow:onRelease(tab, event, position)
if Adjustable.TabWindow.doubleClick then
return
end
local myWindow = Adjustable.TabWindow.currentWindow or self
local floating = self[tab].floating
if event.button == "LeftButton" and Adjustable.TabWindow.currentWindow and myWindow.type == "adjustabletabwindow" and not floating then
self[tab]:lockContainer()
self[tab].container = self.header
self[tab]:onRelease(self[tab].adjLabel, event)
self[tab].adjLabel:echo(self[tab].tabText, "nocolor", "c")
tab_pos = tab_pos or myWindow:findPosition(self[tab])
if myWindow ~= self then
self:changeTabContainer(tab, myWindow)
end
myWindow:addTab(tab, tab_pos)
myWindow:raiseAll()
end
if event.button == "LeftButton" and myWindow.type == "adjustablecontainer" then
local tabname = myWindow.tabname
local tabwindow = Adjustable.TabWindow.allTabs[tabname]
local mytab = tabwindow[tabname]
local tempWindow = tabwindow:createTempWindow(mytab)
self:changeTabContainer(tab, tempWindow.tabWindow)
tempTimer(0, function() tempWindow.tabWindow:activateTab(tab) end)
tempWindow:raiseAll()
self[tab]:onRelease(self[tab].adjLabel, event)
Adjustable.TabWindow.currentWindow = tempWindow.tabWindow
end
if event.button == "LeftButton" and not(Adjustable.TabWindow.currentWindow) and not floating then
self:transformTabContainer(tab)
self[tab]:onRelease(self[tab].adjLabel, event)
end
if floating then
self[tab]:onRelease(self[tab].adjLabel, event)
end
Adjustable.TabWindow.clicked = false
Adjustable.TabWindow.currentWindow = nil
if not (Adjustable.TabWindow.doubleClick) then
Adjustable.TabWindow.clickedTab = nil
end
tab_pos = nil
end
-- change the text a tab displays
function Adjustable.TabWindow:setTabText(which, text)
assert(type(which) == "string" or type(which) == "number", "setTabText: bad argument #1 type (tab name/position as string or number expected, got "..type(which).."!)")
assert(type(text) == "string", "setTabText: bad argument #2 type (tab text as string expected, got "..type(text).."!)")
if not (type(which) == "number" and which <= #self.tabs) then
which = table.index_of(self.tabs, which)
end
if which then
self[self.tabs[which]]:setTitle("")
self[self.tabs[which]].titleText = "&nbsp;&nbsp;"..text
self[self.tabs[which]].tabText = text
self[self.tabs[which]].adjLabel:echo(text, "nocolor", "c")
setTabToolTip(self[self.tabs[which]])
return true
end
return nil, "setTabText: Couldn't find tab to set a new text"
end
-- removes a tab (this won't be saved)
function Adjustable.TabWindow:removeTab(which)
assert(type(which) == "string" or type(which) == "number", "removeTab: bad argument #1 type (tab name/position as string or number expected, got "..type(which).."!)")
local index
if type(which) == "number" and which <= #self.tabs then
index = which
else
index = table.index_of(self.tabs, which)
end
if index then
local tabname = self.tabs[index]
self[tabname]:hide()
self.header:remove(self[tabname])
self.header:organize()
table.remove(self.tabs, index)
self:activateTab(self.tabs[1])
if self.temporary then
-- destroy empty tempTabWindow
if table.is_empty(self.tabs) then
self[tabname].tempWindow:changeContainer("main")
Adjustable.TabWindow.all[self.name] = nil
table.remove(Adjustable.TabWindow.all_windows, table.index_of(Adjustable.TabWindow.all_windows, self))
self[tabname].tempWindow:detach()
self[tabname].tempWindow:disconnect()
self[tabname].tempWindow:hide()
-- delete all references to this tab to avoid it being sent to nirwana if restored
for k,v in pairs (Adjustable.TabWindow.allTabs) do
if v.name == self.name then
local styleOrigin = Adjustable.TabWindow.all[self.tempStyle]
Adjustable.TabWindow.allTabs[k] = styleOrigin
styleOrigin[k] = styleOrigin[k] or self[k]
styleOrigin[k.."center"] = styleOrigin[k.."center"] or self[k.."center"]
styleOrigin[k].minimizeLabel:setClickCallback(function() styleOrigin[k]:onMinimizeClick(k) end)
styleOrigin[k].minLabel:setClickCallback(function() styleOrigin[k]:onMinimizeClick(k) end)
end
end
end
self[tabname].tempWindow = nil
self[tabname].tempTabWindow = nil
end
return true
end
return nil, "removeTab: Couldn't find tab to remove"
end
-- adds a tab (this won't be saved)
function Adjustable.TabWindow:addTab(name, pos)
assert(type(name) == "string", "addTab: bad argument #1 type (tab name as string expected, got "..type(name).."!)")
pos = pos or #self.tabs
pos = pos > #self.tabs and #self.tabs or pos
assert(type(pos) == "number", "addTab: bad argument #2 type (tab position as number expected, got "..type(pos).."!)")
--check if tabName exists already
local index = table.index_of(self.tabs, name)
-- check if postion is valid
if pos < 1 and #self.tabs ~= 0 then
return nil, "addTab: not a valid position"
end
pos = index and pos > #self.tabs and #self.tabs or not(index) and pos == #self.tabs and pos + 1 or pos
-- if tab exists and is at the same position already, do nothing
if index == pos then
self.header:organize()
return true
end
-- if tab exists and position is different, then change the position
if index then
table.remove(self.tabs, index)
table.remove(self.header.windows, index)
end
table.insert(self.tabs, pos, name)
-- if tab is new create a new Label
if not index then
self:createTabs()
end
--If the container isn't the right one change it (useful if removed in one adj tabwindow and added to another)
self[name.."center"]:changeContainer(self.footer)
self[name]:changeContainer(self.header)
local headername = self[name].name
-- if name is already in windows delete it to put it into the right position
local headerIndex = table.index_of(self.header.windows, headername)
if headerIndex then
table.remove(self.header.windows, headerIndex)
end
table.insert(self.header.windows, pos, headername)
self.header.windowList[headername] = self[name]
self[name]:show()
self.header:organize()
self:activateTab(name)
if self.temporary then
self[name].tempWindow = self.container.container
self[name].tempTabWindow = self
end
-- put ToolTip on Label if TabText is to long to display
setTabToolTip(self[name])
return true
end
function Adjustable.TabWindow:addToTabWindow(container)
local name = container.name
self:addTab(name)
container:detach()
container:disconnect()
container:changeContainer(self[name.."center"])
container:resize("100%","100%")
container:move(0,0)
self[name].tabified = true
if container.type == "adjustablecontainer" then
container:lockContainer("full")
if container.autoSave then
container:disableAutoSave()
end
local titleText = string.gsub(container.titleText, "&nbsp;", "")
self:setTabText(name, titleText)
self:createTabs()
end
end
--transforms adjcontainer to a floating tab
function Adjustable.TabWindow:tabify(container)
local x, y, width, height = container:get_x(), container:get_y(), container:get_width(), container:get_height()
local parent = container.container
self:addToTabWindow(container)
self:transformTabContainer(container.name)
self[container.name]:move(x,y)
self[container.name]:resize(width,height)
self[container.name]:changeContainer(parent)
self:createTempWindow(self[container.name])
end
function Adjustable.TabWindow:addTabifyMenu(adjcontainer)
if adjcontainer.type ~= "adjustablecontainer" then
return "not an adjustable container"
end
adjcontainer:newCustomItem("Tabify", function() self:tabify(adjcontainer) end)
end
--- saves your container settings
-- like tab position and some other variables in your Mudlet Profile Dir/ Adjustable.TabWindow
-- to be reliable it is important that every Adjustable.TabWindow has an unique 'name'
-- @see Adjustable.TabWindow:load
function Adjustable.TabWindow:save(slot, dir)
if type(self) ~= "table" then
dir = slot
slot = self
end
assert(slot == nil or type(slot) == "string" or type(slot) == "number", "Adjustable.TabWindow.save: bad argument #1 type (slot as string or number expected, got "..type(slot).."!)")
assert(dir == nil or type(dir) == "string" , "Adjustable.TabWindow.save: bad argument #2 type (directory as string expected, got "..type(dir).."!)")
dir = dir or self.defaultDir
slot = slot or ""
local saveDir = string.format("%s%s%s.lua", dir, "TabWindowTabs", slot)
local mytable = {}
-- save fixed tabs
for k,v in pairs(Adjustable.TabWindow.all) do
mytable[k] = {}
mytable[k].tabs = v.tabs
mytable[k].current = v.current
mytable[k].temporary = v.temporary
end
-- save floating tabs, tempTabWindows and tabified containers
for k,v in pairs(Adjustable.TabWindow.allTabs) do
--floating tabs