-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.qml
More file actions
4317 lines (4000 loc) · 164 KB
/
Copy pathPanel.qml
File metadata and controls
4317 lines (4000 loc) · 164 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
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
import "Model.js" as Model
import "i18n.js" as I18n
Panel {
id: root
moduleName: "taskwarrior-time"
ipcTarget: "taskwarrior-time"
manageIpc: false
property var anchorItem: null
property var hostWidget: null
readonly property var barIdentity: hostWidget || root
property var snapshot: ({
ok: true,
available: true,
tasks: [],
projects: [],
pending: 0,
actionable: 0,
active: null,
label: "\uf0ae",
tooltip: "",
waiting: 0
})
property string viewMode: "tasks" // tasks | projects | about
property string groupBy: setting("defaultGroupBy", "project")
property string expandedUuid: ""
property string pendingDeleteUuid: ""
property string pendingClearProject: ""
property string projectFilter: ""
property int cursorIndex: -1
property bool cursorActive: false
property string busyUuid: ""
property string lastError: ""
property bool formFocused: false
property bool showFilterPanel: false
property int datePickerCount: 0
// Survives ListView delegate teardown. Flat strings — QML `var` maps
// are unreliable across snapshot swaps after deps/status mutations.
property string editUuid: ""
property string editDescription: ""
property string editDetails: ""
property string editWaitingFor: ""
property string editOutcome: ""
property string editPriority: ""
property string editProject: ""
property string editScheduled: ""
property string editDue: ""
property bool editActive: false
property string editBaselineJson: ""
property var pendingEditorClose: null
property string pendingEditorReseedUuid: ""
property var _cmdQueue: []
property bool debugLogging: false
property string debugLogPath: ""
property string debugSessionId: ""
property string uiLanguage: "system" // system | ru | en
property var _logQueue: []
property bool _logFlushScheduled: false
readonly property string pluginVersion: "1.0.0"
readonly property string githubUrl: "https://github.com/DataArchitectPro/taskwarrior-time"
readonly property bool editDirty: {
// Touch every draft field so the binding re-evaluates on edits.
var _ = root.editDescription + "\n" + root.editDetails + "\n" + root.editWaitingFor
+ "\n" + root.editOutcome + "\n" + root.editPriority + "\n" + root.editProject
+ "\n" + root.editScheduled + "\n" + root.editDue
if (!root.editActive || !root.editBaselineJson) return false
return JSON.stringify(root.editValues()) !== root.editBaselineJson
}
function refreshEditBaseline() {
root.editBaselineJson = JSON.stringify(root.editValues())
}
function beginEditFromTask(task) {
if (!task || !task.uuid) return
root.editUuid = String(task.uuid)
root.editDescription = task.description || ""
root.editDetails = String(task.details || "")
root.editWaitingFor = task.waitingFor || ""
root.editOutcome = task.outcome || ""
root.editPriority = task.priority || ""
root.editProject = task.project || ""
root.editScheduled = Model.formatEditableDateTime(task.scheduled)
root.editDue = Model.formatEditableDateTime(task.due)
root.editActive = true
root.refreshEditBaseline()
}
function clearEditBuffer() {
root.editUuid = ""
root.editDescription = ""
root.editDetails = ""
root.editWaitingFor = ""
root.editOutcome = ""
root.editPriority = ""
root.editProject = ""
root.editScheduled = ""
root.editDue = ""
root.editActive = false
root.editBaselineJson = ""
}
function editValues() {
return {
description: root.editDescription,
details: root.editDetails,
waitingFor: root.editWaitingFor,
outcome: root.editOutcome,
priority: root.editPriority,
project: root.editProject,
scheduled: root.editScheduled,
due: root.editDue
}
}
function writeEditValues(values) {
root.editDescription = values.description || ""
root.editDetails = values.details || ""
root.editWaitingFor = values.waitingFor || ""
root.editOutcome = values.outcome || ""
root.editPriority = values.priority || ""
root.editProject = values.project || ""
root.editScheduled = values.scheduled || ""
root.editDue = values.due || ""
root.editActive = true
}
// Bumped after every snapshot apply so the open editor re-applies the
// buffer once the new ListView delegate exists.
property int editRestoreSeq: 0
property bool editGuard: false
// Keep the task list scrolled where the user left it across snapshot
// swaps only when the row model must be replaced (add/delete/reorder).
property real _preserveContentY: -1
property int dataRev: 0
property var rows: []
// After a done/undone toggle, keep the task visible briefly so the user
// sees the new checkbox/strike state even if the filter would hide it.
property var doneHoldUntil: ({})
readonly property int doneHoldMs: 1800
// Theme accent (follows Omarchy / OS theme), same as other active UI chrome.
readonly property color doneCheckColor: Color.accent
readonly property real doneCheckSize: Style.font.title * 2.15
// Priority colors from the active Omarchy theme palette (colors.toml),
// same source Color.urgent / accent use — so they track OS theme switches.
// High=red, Mid=green, Low=blue. Due chips: today=orange, tomorrow=yellow.
property color themeRed: Color.urgent
property color themeGreen: Color.accent
property color themeBlue: Color.accent
property color themeOrange: Color.accent
property color themeYellow: Color.accent
readonly property color priorityHighColor: root.themeRed
readonly property color priorityMiddleColor: root.themeGreen
readonly property color priorityLowColor: root.themeBlue
function priorityColor(priority) {
if (priority === "H") return root.priorityHighColor
if (priority === "M") return root.priorityMiddleColor
if (priority === "L") return root.priorityLowColor
return root.dim
}
function dueMetaColor(task) {
if (!task) return root.dim
var bucket = Model.dueBucket(task)
if (bucket === "overdue") return root.urgent
if (bucket === "today") return root.themeOrange
if (bucket === "tomorrow") return root.themeYellow
return root.dim
}
// Meta strip = table columns (project flex + fixed badge tracks). Empty
// slots keep their width so priority/due/blocked never shift across rows.
FontMetrics {
id: metaCaptionMetrics
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
FontMetrics {
id: metaPriMetrics
font.family: root.fontFamily
font.pixelSize: Style.font.caption
font.bold: true
}
function metaTextWidth(metrics, text) {
return Math.ceil(metrics.boundingRect(String(text || "")).width)
}
readonly property real metaPriWidth: Math.max(
root.metaTextWidth(metaPriMetrics, root.tr("priH")),
root.metaTextWidth(metaPriMetrics, root.tr("priM")),
root.metaTextWidth(metaPriMetrics, root.tr("priL"))
)
readonly property real metaDueWidth: Math.max(
root.metaTextWidth(metaCaptionMetrics, root.tr("dueOverdue")),
root.metaTextWidth(metaCaptionMetrics, root.tr("dueToday")),
root.metaTextWidth(metaCaptionMetrics, root.tr("dueTomorrow")),
root.metaTextWidth(metaCaptionMetrics, "00.00.0000")
)
readonly property real metaBlockedWidth: root.metaTextWidth(metaCaptionMetrics, root.tr("blocked"))
function applyThemePalette(raw) {
var red = ""
var green = ""
var blue = ""
var orange = ""
var yellow = ""
var lines = String(raw || "").split("\n")
for (var i = 0; i < lines.length; i++) {
var match = lines[i].match(/^\s*([A-Za-z0-9_-]+)\s*=\s*["']?(#[0-9A-Fa-f]{6})/)
if (!match) continue
var key = match[1]
var val = match[2]
if (key === "red" || key === "color1") red = val
else if (key === "green" || key === "color2") green = val
else if (key === "blue" || key === "color4") blue = val
else if (key === "orange") orange = val
else if (key === "yellow" || key === "color3") yellow = val
}
root.themeRed = red || Color.urgent
root.themeGreen = green || Color.accent
root.themeBlue = blue || Color.accent
root.themeOrange = orange || yellow || Color.accent
root.themeYellow = yellow || orange || Color.accent
}
FileView {
id: themeColorsFile
path: Color.currentThemePath + "/colors.toml"
watchChanges: true
printErrors: false
onLoaded: root.applyThemePalette(text())
onFileChanged: reload()
onLoadFailed: root.applyThemePalette("")
}
// Theme switches push colors.toml via shell IPC into Color (FileView there
// is startup-only). Reload our palette whenever foundational roles change.
Connections {
target: Color
function onUrgentChanged() { themeColorsFile.reload() }
function onAccentChanged() { themeColorsFile.reload() }
function onForegroundChanged() { themeColorsFile.reload() }
}
function isDoneHoldActive(uuid) {
var until = root.doneHoldUntil[String(uuid || "")]
return !!(until && Date.now() < until)
}
function markDoneHold(uuid) {
var id = String(uuid || "")
if (!id) return
var next = {}
var cur = root.doneHoldUntil || {}
for (var k in cur)
next[k] = cur[k]
next[id] = Date.now() + root.doneHoldMs
root.doneHoldUntil = next
if (doneHoldTimer)
doneHoldTimer.restart()
}
function clearDoneHold(uuid) {
var id = String(uuid || "")
var cur = root.doneHoldUntil || {}
if (!cur[id]) return
var next = {}
for (var k in cur)
if (k !== id) next[k] = cur[k]
root.doneHoldUntil = next
}
function sweepDoneHolds() {
var now = Date.now()
var cur = root.doneHoldUntil || {}
var next = {}
var expired = false
for (var k in cur) {
if (cur[k] > now)
next[k] = cur[k]
else
expired = true
}
if (!expired) {
var any = false
for (var _ in next) { any = true; break }
if (!any && doneHoldTimer)
doneHoldTimer.stop()
return
}
root.doneHoldUntil = next
root.rebuildRows(true)
var left = false
for (var __ in next) { left = true; break }
if (!left && doneHoldTimer)
doneHoldTimer.stop()
}
function applyLocalTaskStatus(uuid, status) {
var id = String(uuid || "")
if (!id) return
function patch(t) {
if (!t || String(t.uuid) !== id) return
t.status = status
if (status === "completed")
t.timerActive = false
}
var tasks = (root.snapshot && root.snapshot.tasks) ? root.snapshot.tasks : []
for (var i = 0; i < tasks.length; i++)
patch(tasks[i])
for (var r = 0; r < root.rows.length; r++) {
if (root.rows[r] && root.rows[r].type === "task")
patch(root.rows[r].task)
}
root.dataRev++
}
function requestEditorRestore() {
if (!root.editActive || !root.expandedUuid) return
if (root.editUuid !== String(root.expandedUuid)) return
root.editRestoreSeq++
}
function restoreListScroll() {
if (root._preserveContentY < 0) return
var y = root._preserveContentY
function apply() {
if (!listView) return
var maxY = Math.max(0, listView.contentHeight - listView.height)
listView.contentY = Math.min(Math.max(0, y), maxY)
}
apply()
Qt.callLater(apply)
}
function currentFilterSpec() {
// Build a fresh object from live properties — do not read `filterSpec`
// from change handlers; QML may still hold a stale binding object.
return {
status: root.filterStatus,
project: root.projectFilter,
priority: root.filterPriority,
due: root.filterDue,
search: root.filterSearch,
blocked: root.filterBlocked,
timer: root.filterTimer
}
}
function rebuildRows(forceReplace) {
var tasks = (root.snapshot && root.snapshot.tasks) ? root.snapshot.tasks : []
var spec = root.currentFilterSpec()
var filtered = []
for (var i = 0; i < tasks.length; i++) {
var task = tasks[i]
if (Model.matchesAdvanced(task, spec))
filtered.push(task)
else if (task && root.isDoneHoldActive(task.uuid))
filtered.push(task)
}
var next = Model.flattenRows(Model.buildGroups(filtered, "pass", root.groupBy, root.tr))
if (!forceReplace && root.rows.length > 0 && Model.patchRowsInPlace(root.rows, next)) {
// Same structure — mutate tasks in place so ListView keeps delegates
// and scroll position (no jump on save / deps).
root.dataRev++
return false
}
// Two-step assign so ListView always notices the model change (JS array
// replacement is unreliable when going empty→non-empty in one shot).
root.rows = []
root.rows = next
root.dataRev++
return true
}
// Advanced filter (defaults ≈ former "All" = open pending/waiting)
property string filterStatus: "open" // all|open|pending|waiting|completed|active
property string filterPriority: "" // "" | H|M|L|__none__
property string filterDue: "" // "" | overdue|today|week|later|none|soon
property string filterSearch: ""
property string filterBlocked: "" // "" | blocked|blocking|clear
property string filterTimer: "" // "" | running|idle
// Add form
property string addDescription: ""
property string addPriority: ""
property string addProject: ""
property string addScheduled: ""
property string addDue: ""
property string addStatus: "waiting"
property string addWaitingFor: ""
property var addDepUuids: []
property bool addStartTimer: false
property bool showAddAdvanced: false
property bool composerExpanded: false
property bool showAddExtras: false // legacy alias — unused
function collapseComposer() {
root.composerExpanded = false
root.showAddAdvanced = false
if (addField && addField.activeFocus)
addField.focus = false
}
function collapseFilterPanel() {
root.showFilterPanel = false
}
function collapseExpandedTask() {
root.requestCloseEditor({ type: "dismiss" })
}
function requestCloseEditor(action) {
action = action || { type: "dismiss" }
if (!root.expandedUuid) {
root.applyEditorClose(action)
return
}
if (!root.editDirty) {
root.applyEditorClose(action)
return
}
root.pendingEditorClose = action
confirmUnsaved.selectedIndex = 0
confirmUnsaved.opened = true
}
function applyEditorClose(action) {
action = action || { type: "dismiss" }
root.pendingEditorClose = null
if (confirmUnsaved) confirmUnsaved.opened = false
if (action.type === "switch" && action.uuid) {
root.expandedUuid = String(action.uuid)
return
}
root.expandedUuid = ""
root.clearEditBuffer()
if (action.thenCompose) {
root.composerExpanded = true
Qt.callLater(function () {
if (addField) addField.forceActiveFocus()
})
}
if (action.thenHide)
root.controller.hide()
}
function confirmUnsavedSave() {
var act = root.pendingEditorClose || { type: "dismiss" }
confirmUnsaved.opened = false
root.pendingEditorClose = null
var uuid = root.editUuid || root.expandedUuid
if (!uuid) {
root.applyEditorClose(act)
return
}
var task = null
for (var i = 0; i < root.rows.length; i++) {
if (root.rows[i] && root.rows[i].type === "task" && root.rows[i].task
&& String(root.rows[i].task.uuid) === String(uuid)) {
task = root.rows[i].task
break
}
}
if (!task)
task = Model.findTask((root.snapshot && root.snapshot.tasks) || [], uuid)
if (!task) {
root.applyEditorClose(act)
return
}
var v = root.editValues()
root.pendingEditorClose = act
root.saveTask(task, v.description, v.project, v.priority, v.scheduled, v.due, v.details)
var follow = root.pendingEditorClose
root.pendingEditorClose = null
if (follow && follow.type === "switch" && follow.uuid)
root.expandedUuid = String(follow.uuid)
else if (follow && follow.thenCompose) {
root.composerExpanded = true
Qt.callLater(function () {
if (addField) addField.forceActiveFocus()
})
} else if (follow && follow.thenHide) {
root.controller.hide()
}
}
function confirmUnsavedContinue() {
confirmUnsaved.opened = false
root.pendingEditorClose = null
if (addField && addField.activeFocus)
addField.focus = false
}
function confirmUnsavedDiscard() {
var act = root.pendingEditorClose || { type: "dismiss" }
confirmUnsaved.opened = false
root.pendingEditorClose = null
root.clearEditBuffer()
root.applyEditorClose(act)
}
function dismissOverlays() {
root.collapseFilterPanel()
root.collapseComposer()
root.collapseExpandedTask()
}
// Close the innermost transient UI on Escape. Returns true if something
// was dismissed (caller should not close the whole panel).
function dismissEscapeOverlay() {
if (confirmUnsaved && confirmUnsaved.opened) return false
if (confirmDelete && confirmDelete.opened) return false
if (confirmClear && confirmClear.opened) return false
function closePicker(field) {
if (field && field.popupOpen) {
field.discardPicker()
return true
}
return false
}
// Only top-level date fields — delegate ids collide with editScheduled/editDue strings.
if (closePicker(addScheduledField) || closePicker(addDueField))
return true
function closeDropdown(dd) {
if (dd && typeof dd.close === "function" && dd.popupOpen) {
dd.close()
return true
}
return false
}
if (closeDropdown(groupDropdown)
|| closeDropdown(filterStatusDropdown)
|| closeDropdown(projectFilterDropdown)
|| closeDropdown(filterPriorityDropdown)
|| closeDropdown(filterDueDropdown)
|| closeDropdown(filterTimerDropdown)
|| closeDropdown(filterBlockedDropdown)
|| closeDropdown(priorityCombo)
|| closeDropdown(projectCombo)
|| closeDropdown(addDepCombo)) {
return true
}
if (root.renameFrom !== "") {
root.cancelRenameProject()
root._refocusKeyCatcher()
return true
}
if (root.showFilterPanel) {
root.collapseFilterPanel()
root._refocusKeyCatcher()
return true
}
if (root.composerExpanded) {
root.collapseComposer()
root._refocusKeyCatcher()
return true
}
if (root.expandedUuid) {
root.collapseExpandedTask()
root._refocusKeyCatcher()
return true
}
return false
}
function _refocusKeyCatcher() {
root.formFocused = false
Qt.callLater(function () {
if (keyCatcher) keyCatcher.forceActiveFocus()
})
}
function escapeFromField(event) {
if (root.dismissEscapeOverlay())
event.accepted = true
}
// Uniform action hotkeys across editor / composer / confirm dialogs:
// Ctrl+Enter — commit (save / add / confirm)
// Esc — cancel (already via dismissEscapeOverlay)
// Ctrl+Delete — destroy (delete task / discard unsaved)
readonly property string hkHintCommit: " · Ctrl+Enter"
readonly property string hkHintCancel: " · Esc"
readonly property string hkHintDestroy: " · Ctrl+Delete"
readonly property bool anyConfirmOpen: !!(
(confirmUnsaved && confirmUnsaved.opened)
|| (confirmDelete && confirmDelete.opened)
|| (confirmClear && confirmClear.opened)
)
function findTaskByUuid(uuid) {
uuid = String(uuid || "")
if (!uuid) return null
for (var i = 0; i < root.rows.length; i++) {
var row = root.rows[i]
if (row && row.type === "task" && row.task && String(row.task.uuid) === uuid)
return row.task
}
return Model.findTask((root.snapshot && root.snapshot.tasks) || [], uuid)
}
function hotkeyCommit() {
if (confirmUnsaved && confirmUnsaved.opened) {
root.confirmUnsavedSave()
return
}
if (confirmDelete && confirmDelete.opened) {
root.confirmDeleteTask()
return
}
if (confirmClear && confirmClear.opened) {
root.confirmClearProjectAction()
return
}
if (root.renameFrom !== "") {
root.renameProject()
return
}
if (root.expandedUuid) {
if (!root.editDirty) return
var task = root.findTaskByUuid(root.expandedUuid)
if (!task) return
var v = root.editValues()
root.saveTask(task, v.description, v.project, v.priority, v.scheduled, v.due, v.details)
return
}
if (root.composerExpanded) {
root.addTask()
return
}
if (root.viewMode === "projects" && newProjectField
&& String(newProjectField.text || "").trim() !== "") {
root.createProjectName()
}
}
function hotkeyDestroy() {
if (confirmUnsaved && confirmUnsaved.opened) {
root.confirmUnsavedDiscard()
return
}
if (confirmDelete && confirmDelete.opened) {
root.confirmDeleteTask()
return
}
if (confirmClear && confirmClear.opened) {
root.confirmClearProjectAction()
return
}
if (root.expandedUuid) {
var task = root.findTaskByUuid(root.expandedUuid)
if (task) root.requestDelete(task)
}
}
function hotkeyCancelConfirm() {
if (confirmUnsaved && confirmUnsaved.opened) {
root.confirmUnsavedContinue()
return
}
if (confirmDelete && confirmDelete.opened) {
confirmDelete.opened = false
root.pendingDeleteUuid = ""
return
}
if (confirmClear && confirmClear.opened) {
confirmClear.opened = false
root.pendingClearProject = ""
}
}
function maybeCollapseComposer() {
Qt.callLater(function () {
if (!root.composerExpanded) return
// Still interacting with the create form (fields, dropdowns, calendars).
if (composerScope && composerScope.activeFocus) return
if (root.datePickerCount > 0) return
if (priorityCombo && priorityCombo.popupOpen) return
if (projectCombo && projectCombo.popupOpen) return
if (addDepCombo && addDepCombo.popupOpen) return
if (addScheduledField && addScheduledField.fieldFocused) return
if (addDueField && addDueField.fieldFocused) return
if (addField && addField.activeFocus) return
if (addDetailsField && addDetailsField.activeFocus) return
if (addWaitingForField && addWaitingForField.activeFocus) return
if (addOutcomeField && addOutcomeField.activeFocus) return
root.collapseComposer()
})
}
onExpandedUuidChanged: {
if (root.expandedUuid) {
root.showFilterPanel = false
root.collapseComposer()
} else {
root.formFocused = false
}
}
onComposerExpandedChanged: {
if (root.composerExpanded)
root.showFilterPanel = false
else
root.formFocused = false
}
onShowFilterPanelChanged: {
if (root.showFilterPanel) {
root.collapseComposer()
root.collapseExpandedTask()
} else {
root.formFocused = false
}
}
onViewModeChanged: {
root.collapseFilterPanel()
root.collapseComposer()
root.collapseExpandedTask()
root.cancelRenameProject()
}
// Project form
property string newProjectName: ""
property string renameFrom: ""
property string renameTo: ""
readonly property string localeName: {
var loc = Qt.locale()
if (loc && loc.uiLanguages && loc.uiLanguages.length > 0)
return String(loc.uiLanguages[0])
return loc ? String(loc.name || "") : ""
}
function tr(key) { return I18n.t(key, root.localeName, root.uiLanguage) }
readonly property bool uiRussian: {
if (root.uiLanguage === "ru") return true
if (root.uiLanguage === "en") return false
var loc = String(root.localeName || "").toLowerCase().replace(/-/g, "_")
var lang = loc.split(".")[0].split("_")[0]
return lang === "ru"
}
// Prefer i18n; if a stale module still returns an old title, override.
readonly property string tasksHeaderTitle: {
var s = root.tr("titleInProgress")
if (s === "titleInProgress" || s === "Tasks in progress" || s === "Задачи в работе" || s === "Tasks")
return "Taskwarrior Time"
return s
}
readonly property color foreground: bar ? bar.foreground : Color.foreground
readonly property color dim: Qt.darker(foreground, 1.45)
readonly property color urgent: bar ? bar.urgent : Color.urgent
readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family
readonly property string helperPath: {
var value = String(Qt.resolvedUrl("bin/taskwarrior-time"))
if (value.indexOf("file://") === 0) return decodeURIComponent(value.substring(7))
return value
}
// projectFilter: "" = all; "__none__" = no project; else project name
readonly property var projectList: (snapshot && snapshot.projects) ? snapshot.projects : []
readonly property var filterSpec: ({
status: root.filterStatus,
project: root.projectFilter,
priority: root.filterPriority,
due: root.filterDue,
search: root.filterSearch,
blocked: root.filterBlocked,
timer: root.filterTimer
})
readonly property int activeFilterCount: Model.countActiveFilters(root.filterSpec)
readonly property bool filterStatusActive: root.filterStatus !== "open"
readonly property bool filterProjectActive: root.projectFilter !== ""
readonly property bool filterPriorityActive: root.filterPriority !== ""
readonly property bool filterDueActive: root.filterDue !== ""
readonly property bool filterTimerActive: root.filterTimer !== ""
readonly property bool filterBlockedActive: root.filterBlocked !== ""
readonly property bool filterSearchActive: String(root.filterSearch || "").trim() !== ""
readonly property color filterActiveColor: Color.accent
readonly property color filterIdleLabelColor: root.dim
function filterFieldFill(active) {
return active ? Style.hoverFillFor(root.foreground, Color.accent) : "transparent"
}
readonly property var filteredTasks: {
var _ = root.dataRev
var tasks = (root.snapshot && root.snapshot.tasks) ? root.snapshot.tasks : []
var spec = root.currentFilterSpec()
var out = []
for (var i = 0; i < tasks.length; i++) {
if (Model.matchesAdvanced(tasks[i], spec)) out.push(tasks[i])
}
return out
}
function setProjectFilter(value) {
var next = (value === "__all__" || value === undefined || value === null) ? "" : String(value)
root.projectFilter = next
if (projectFilterDropdown)
projectFilterDropdown.value = next
}
function clearAdvancedFilters() {
root.filterStatus = "open"
root.filterPriority = ""
root.filterDue = ""
root.filterSearch = ""
root.filterBlocked = ""
root.filterTimer = ""
root.setProjectFilter("")
if (filterStatusDropdown) filterStatusDropdown.value = "open"
if (filterPriorityDropdown) filterPriorityDropdown.value = ""
if (filterDueDropdown) filterDueDropdown.value = ""
if (filterBlockedDropdown) filterBlockedDropdown.value = ""
if (filterTimerDropdown) filterTimerDropdown.value = ""
if (filterSearchField) filterSearchField.text = ""
}
onProjectFilterChanged: {
if (projectFilterDropdown && projectFilterDropdown.value !== root.projectFilter)
projectFilterDropdown.value = root.projectFilter
Qt.callLater(function () { root.rebuildRows(true) })
}
onGroupByChanged: root.rebuildRows(true)
onFilterStatusChanged: Qt.callLater(function () { root.rebuildRows(true) })
onFilterPriorityChanged: Qt.callLater(function () { root.rebuildRows(true) })
onFilterDueChanged: Qt.callLater(function () { root.rebuildRows(true) })
onFilterSearchChanged: Qt.callLater(function () { root.rebuildRows(true) })
onFilterBlockedChanged: Qt.callLater(function () { root.rebuildRows(true) })
onFilterTimerChanged: Qt.callLater(function () { root.rebuildRows(true) })
readonly property var projectFilterOptions: {
var opts = [
{ value: "", label: root.tr("allProjects") },
{ value: "__none__", label: root.tr("projectNone") }
]
for (var i = 0; i < root.projectList.length; i++)
opts.push({ value: root.projectList[i], label: root.projectList[i] })
return opts
}
readonly property string label: snapshot && snapshot.label ? snapshot.label : "\uf0ae"
function open() {
root.controller.show()
refresh()
}
function openFromHotkey() {
root.controller.show()
refresh()
}
function close() {
confirmDelete.opened = false
confirmClear.opened = false
if (confirmUnsaved) confirmUnsaved.opened = false
root.pendingEditorClose = null
root.collapseComposer()
// Closing the panel discards the open editor; ask if dirty.
if (root.expandedUuid && root.editDirty) {
root.pendingEditorClose = { type: "dismiss", thenHide: true }
confirmUnsaved.selectedIndex = 0
confirmUnsaved.opened = true
return
}
root.expandedUuid = ""
root.clearEditBuffer()
root.controller.hide()
}
function toggle() {
if (root.opened) root.close()
else root.openFromHotkey()
}
function switchPanel(direction) {
if (root.bar && typeof root.bar.switchPanelFrom === "function")
return root.bar.switchPanelFrom(root.barIdentity, direction)
return false
}
// Mirror helper MAX_PAYLOAD_BYTES so QML never keeps an oversized snapshot.
readonly property int maxSnapshotChars: 1800000
function applyData(text) {
try {
var raw = String(text || "")
if (raw.length > root.maxSnapshotChars) {
root.lastError = "snapshot exceeds size limit"
root.dlog("snapshot.reject", { bytes: raw.length })
root.editGuard = false
return
}
var data = JSON.parse(raw || "{}")
var reseedUuid = root.pendingEditorReseedUuid
root.pendingEditorReseedUuid = ""
if (listView)
root._preserveContentY = listView.contentY
root.editGuard = true
root.snapshot = data
root.lastError = data.error ? String(data.error) : ""
// Always replace when the list was empty so the first export after
// startup reliably populates ListView.
var replaced = root.rebuildRows(root.rows.length === 0)
var expandedTask = root.expandedUuid
? Model.findTask((data.tasks || []), root.expandedUuid)
: null
root.dlog("snapshot.apply", {
replaced: replaced,
reseed: !!reseedUuid,
tasks: (data.tasks && data.tasks.length) || 0,
error: root.lastError,
expandedUuid: root.expandedUuid,
expandedDepends: expandedTask ? Model.toJsArray(expandedTask.depends) : []
})
if (!replaced)
root._preserveContentY = -1
if (reseedUuid) {
var saved = Model.findTask(data.tasks || [], reseedUuid)
if (saved)
root.beginEditFromTask(saved)
}
Qt.callLater(function () {
if (replaced || reseedUuid)
root.requestEditorRestore()
root.editGuard = false
if (replaced) {
Qt.callLater(function () {
root.restoreListScroll()
root._preserveContentY = -1
})
}
})
} catch (e) {
root.editGuard = false
root._preserveContentY = -1
root.lastError = String(e)
root.dlog("snapshot.error", { error: String(e) })
console.warn("taskwarrior-time: bad JSON", e)
}
}
function refresh() {
// Don't contend with an in-flight mutation for the Taskwarrior lock.
if (cmdProc.running || exportProc.running) return
exportProc.command = [root.helperPath, "export"]
exportProc.running = true
}
function runCmd(args) {
// Serialize against exportProc — Taskwarrior file locks make parallel
// `task` invocations appear to hang for seconds.
if (cmdProc.running || exportProc.running) {
root._cmdQueue = (root._cmdQueue || []).concat([args])
root.dlog("cmd.queue", {
args: root._safeArgs(args),
queueLen: root._cmdQueue.length,
cmdRunning: !!cmdProc.running,
exportRunning: !!exportProc.running
})
return
}
root.dlog("cmd.start", { args: root._safeArgs(args) })
root._cmdStartedAt = Date.now()
cmdProc.command = [root.helperPath].concat(args)
cmdProc.running = true
}
property real _cmdStartedAt: 0
function _safeArgs(args) {
var out = []