-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathconf.ts
More file actions
718 lines (576 loc) · 27 KB
/
Copy pathconf.ts
File metadata and controls
718 lines (576 loc) · 27 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
// Copyright (C) 2016 Patrick Maué
//
// This file is part of vscode-journal.
//
// vscode-journal is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// vscode-journal is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with vscode-journal. If not, see <http://www.gnu.org/licenses/>.
//
'use strict';
import * as vscode from 'vscode';
import * as os from 'os';
import * as Path from 'path';
import { Util } from '..';
import { isNotNullOrUndefined, isNullOrUndefined } from '../util';
import { HeaderTemplate, InlineTemplate, IWorkspaceConfigReader, ScopedTemplate, SCOPE_DEFAULT } from '../model';
import { IRawConfigProvider, TemplateService } from './template-service';
export { SCOPE_DEFAULT };
export type WeeklySyncConfig = {
enabled: boolean;
anchor: string;
template: string;
sortOrder: "ascending" | "descending";
};
/** types in the settings.json */
type PatternDefinition = {
notes: { path: string; file: string };
entries: { path: string; file: string };
weeks: { path: string; file: string };
weeklyNotes?: { path: string; file: string };
};
export { EntryGranularity, NavigationMode, ScopeDefinitionLite } from '../model/config';
import { EntryGranularity, NavigationMode, ScopeDefinitionLite } from '../model/config';
const defaultPatternDefinition: PatternDefinition =
{
notes: {
path: "${base}/${year}/${month}/${day}",
file: "${input}.${ext}"
},
entries: {
path: "${base}/${year}/${month}",
file: "${day}.${ext}"
},
weeks: {
path: "${base}/${year}",
file: "week_${week}.${ext}"
},
weeklyNotes: {
path: "${base}/${year}/w${week}",
file: "${input}.${ext}"
}
};
type ScopeDefinition = {
"name": string;
"base"?: string;
"patterns": PatternDefinition;
"templates": InlineTemplate[];
};
/**
* Manages access to journal configuration.
*
* Attention: This is an intermediate implementation, still based on the old configuration pre 0.6
*
*/
export class Configuration implements IRawConfigProvider {
private readonly tpl: TemplateService = new TemplateService(this);
constructor(public config: IWorkspaceConfigReader) {
}
/**
* Converts Windows-style absolute paths to a runtime-compatible path when
* the extension is running on a non-Windows host (e.g. WSL remote).
*
* Detection uses both `process.platform` and `vscode.env.remoteName` so that
* the normalization fires whenever the extension host is Linux-based — whether
* that is a native Linux installation, an SSH remote, or a WSL remote session
* where the user stored their journal base path as a Windows drive path.
*/
private normalizeBasePathForRuntime(basePath: string): string {
// Running natively on Windows: separators are already correct.
if (process.platform === 'win32') {
return basePath;
}
// Some configurations accidentally include a leading slash before a
// Windows drive prefix when evaluated remotely: /C:\Users\...
const trimmed = basePath.replace(/^\/+/, '');
const isWindowsAbsPath = /^[a-zA-Z]:[\\/]/.test(trimmed);
if (!isWindowsAbsPath) {
// Not a Windows-style absolute path — nothing to convert.
// Still replace any stray backslashes so mixed-separator strings
// (e.g. from a ${workspaceFolder} expansion) become valid POSIX paths.
return basePath.replace(/\\/g, '/');
}
// Non-Windows remotes (WSL/SSH/containers): map Windows drive path to
// the Linux /mnt/<drive>/... convention used by WSL, avoiding invalid
// mixed paths such as /C:\Users\...\journal/2026/05/20.md.
const drive = trimmed.charAt(0).toLowerCase();
const rest = trimmed.substring(2).replace(/\\/g, '/').replace(/^\/+/, '');
return `/mnt/${drive}/${rest}`;
}
public getLocale(): string {
let locale: string | undefined = this.config.get<string>('locale');
return (isNullOrUndefined(locale) || (locale!.length === 0)) ? vscode.env.language : locale!;
}
/**
* Returns all known scopes in the settings
*/
public getScopes(): string[] {
let res = [SCOPE_DEFAULT];
let scopes: ScopeDefinition[] | undefined = this.config.get<[ScopeDefinition]>("scopes");
if (isNotNullOrUndefined(scopes) && scopes!.length > 0) {
scopes!.map(sd => sd.name).forEach(name => res.push(name));
}
return res;
}
public getScopeDefinitions(): ScopeDefinitionLite[] {
const result = this.config.get<ScopeDefinitionLite[]>('scopes');
return Array.isArray(result) ? result : [];
}
public getNavigationMode(): NavigationMode {
return (this.config.get<string>('navigation.mode') ?? 'existing') as NavigationMode;
}
/**
* The base path, defaults to %USERPROFILE/Journal
*
* Supported variables: ${homeDir}, ${workspaceRoot}, ${workspaceFolder}
*
* @param _scopeId
*/
public getBasePath(_scopeId?: string): string {
let scope: string = this.resolveScope(_scopeId);
const workspaceRoot = vscode.workspace.workspaceFolders?.length && vscode.workspace.workspaceFolders[0].uri.fsPath || '';
if (scope === SCOPE_DEFAULT) {
let base: string | undefined = this.config.get<string>('base');
if (isNotNullOrUndefined(base) && base!.length > 0) {
// resolve homedir
base = base!
.replace("${homeDir}", os.homedir())
.replace("${workspaceRoot}", workspaceRoot)
.replace("${workspaceFolder}", workspaceRoot);
base = this.normalizeBasePathForRuntime(base);
base = Path.normalize(base);
return Path.format(Path.parse(base));
} else {
// let's default to user profile
return Path.join(os.homedir(), "Journal");
}
} else {
// there is scope in the request, let's take the base from the scope definition (if it exists)
let scopes: ScopeDefinition[] | undefined = this.config.get<[ScopeDefinition]>('scopes');
if (isNotNullOrUndefined(scopes)) {
try {
let base: string[] = scopes!.filter(v => v.name === scope)
.map(scopeDefinition => scopeDefinition.base)
.map(scopedBase => {
if (Util.stringIsNotEmpty(scopedBase)) {
scopedBase = scopedBase!
.replace("${homeDir}", os.homedir())
.replace("${workspaceRoot}", workspaceRoot)
.replace("${workspaceFolder}", workspaceRoot);
scopedBase = this.normalizeBasePathForRuntime(scopedBase);
scopedBase = Path.normalize(scopedBase);
return Path.format(Path.parse(scopedBase));
} else { return this.getBasePath(SCOPE_DEFAULT); }
});
if (base.length === 0) { return this.getBasePath(); }
else { return base[0]; } // we always take the first
} catch (error) {
console.error("Failed to resolve base path for scope: " + scope);
// we return to default
return this.getBasePath(SCOPE_DEFAULT);
}
}
}
throw new Error("Failed to resolve base path");
}
/**
* Returns the configured base path with variable substitution but without
* remote-runtime normalization. This is intended for local handoff from a
* remote session so the local client can open paths in its own style.
*/
public getBasePathForLocalOpen(_scopeId?: string): string {
const scope: string = this.resolveScope(_scopeId);
const workspaceRoot = vscode.workspace.workspaceFolders?.length && vscode.workspace.workspaceFolders[0].uri.fsPath || '';
if (scope === SCOPE_DEFAULT) {
let base: string | undefined = this.config.get<string>('base');
if (isNotNullOrUndefined(base) && base!.length > 0) {
base = base!
.replace("${homeDir}", os.homedir())
.replace("${workspaceRoot}", workspaceRoot)
.replace("${workspaceFolder}", workspaceRoot);
return base;
}
return this.getBasePath(SCOPE_DEFAULT);
}
let scopes: ScopeDefinition[] | undefined = this.config.get<[ScopeDefinition]>('scopes');
if (isNotNullOrUndefined(scopes)) {
const base = scopes!
.filter(v => v.name === scope)
.map(scopeDefinition => scopeDefinition.base)
.find(scopedBase => Util.stringIsNotEmpty(scopedBase));
if (Util.stringIsNotEmpty(base)) {
return base!
.replace("${homeDir}", os.homedir())
.replace("${workspaceRoot}", workspaceRoot)
.replace("${workspaceFolder}", workspaceRoot);
}
}
return this.getBasePath(SCOPE_DEFAULT);
}
/**
* Returns true when the configured base path for a scope is a Windows
* absolute path (e.g. C:\\Users\\...).
*/
public isWindowsStyleBaseConfigured(_scopeId?: string): boolean {
const scope = this.resolveScope(_scopeId);
let configuredBase: string | undefined;
if (scope === SCOPE_DEFAULT) {
configuredBase = this.config.get<string>('base');
} else {
configuredBase = this.config
.get<ScopeDefinition[]>('scopes')
?.find(sd => sd.name === scope)
?.base;
}
if (isNullOrUndefined(configuredBase) || configuredBase!.length === 0) {
return false;
}
return /^\/?[a-zA-Z]:[\\/]/.test(configuredBase!);
}
/**
* Configuration of file extension for notes and journal entries. Defaults to "md" for markdown.
*
*
* @param _scopeId
*/
public getFileExtension(_scopeId?: string): string {
if (!isNullOrUndefined(_scopeId)) {
console.error("You requested a scoped file extensions, this is not supported.");
}
let ext: string | undefined = this.config.get<string>('ext');
ext = (isNullOrUndefined(ext) || (ext!.length === 0)) ? 'md' : ext!;
if (ext.startsWith(".")) { ext = ext.substring(1, ext.length); }
return ext!;
}
public isSyntaxHighlightingEnabled(): boolean {
let result = this.config.get<boolean>("syntax-highlighting");
return (isNullOrUndefined(result)) ? false : result!;
}
/**
* Configuration for the path, where the notes are to be placed
*
* Supported variables: homeDir, base, year, month, day, moment
*
* @param _scopeId default or individual
*/
public getNotesPathPattern(_scopeId?: string): string {
let result: string | undefined;
if (this.resolveScope(_scopeId) === SCOPE_DEFAULT) {
result = this.config.get<PatternDefinition>("patterns")?.notes?.path;
} else {
result = this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === _scopeId)?.patterns?.notes?.path;
}
if (isNullOrUndefined(result) || result!.length === 0) {
result = defaultPatternDefinition.notes.path;
}
return result!;
}
/**
* Configuration for the path, where the notes are to be placed
*
* Supported variables: homeDir, base, year, month, day, moment
*
* @param _scopeId default or individual
*/
public async getResolvedNotesPath(date: Date, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getResolvedNotesPath(date, _scopeId);
}
/**
* Configuration for the filename, under which the notes file is stored
*
* Supported variables: year, month, day, df, ext, input
*
* @param _scopeId default or individual
*/
public async getNotesFilePattern(date: Date, input: string, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getNotesFilePattern(date, input, _scopeId);
}
public getEntryGranularity(_scopeId?: string): EntryGranularity {
const raw = this.config.get<string>("entryGranularity");
return raw === "weekly" ? "weekly" : "daily";
}
public getWeeklyNotesPathPatternRaw(_scopeId?: string): string {
let result: string | undefined;
if (this.resolveScope(_scopeId) === SCOPE_DEFAULT) {
result = this.config.get<PatternDefinition>("patterns")?.weeklyNotes?.path;
} else {
result = this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === _scopeId)?.patterns?.weeklyNotes?.path;
}
if (isNullOrUndefined(result) || result!.length === 0) {
result = defaultPatternDefinition.weeklyNotes!.path;
}
return result!;
}
public async getResolvedWeeklyNotesPath(week: number, year: number, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getResolvedWeeklyNotesPath(week, year, _scopeId);
}
public async getWeeklyNotesFilePattern(week: number, year: number, input: string, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getWeeklyNotesFilePattern(week, year, input, _scopeId);
}
/** Returns the raw weeks path template (e.g. "${base}/${year}"), without variable substitution. */
public getWeeksPathPatternRaw(_scopeId?: string): string {
let result: string | undefined;
if (this.resolveScope(_scopeId) === SCOPE_DEFAULT) {
result = this.config.get<PatternDefinition>("patterns")?.weeks?.path;
} else {
result = this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === _scopeId)?.patterns?.weeks?.path;
}
if (isNullOrUndefined(result) || result!.length === 0) {
result = defaultPatternDefinition.weeks.path;
}
return result!;
}
/** Returns the raw weeks file template (e.g. "week_${week}.${ext}"), without variable substitution. */
public getWeeksFilePatternRaw(_scopeId?: string): string {
let result: string | undefined;
if (this.resolveScope(_scopeId) === SCOPE_DEFAULT) {
result = this.config.get<PatternDefinition>("patterns")?.weeks?.file;
} else {
result = this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === _scopeId)?.patterns?.weeks?.file;
}
if (isNullOrUndefined(result) || result!.length === 0) {
result = defaultPatternDefinition.weeks.file;
}
return result!;
}
public getEntryFilePatternRaw(_scopeId?: string): string {
const scope = this.resolveScope(_scopeId);
const result: string | undefined = scope === SCOPE_DEFAULT
? this.config.get<PatternDefinition>("patterns")?.entries?.file
: this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === scope)?.patterns?.entries?.file;
return (isNullOrUndefined(result) || result!.length === 0) ? defaultPatternDefinition.entries.file : result!;
}
public getNotesFilePatternRaw(_scopeId?: string): string {
const scope = this.resolveScope(_scopeId);
const result: string | undefined = scope === SCOPE_DEFAULT
? this.config.get<PatternDefinition>("patterns")?.notes?.file
: this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === scope)?.patterns?.notes?.file;
return (isNullOrUndefined(result) || result!.length === 0) ? defaultPatternDefinition.notes.file : result!;
}
public getWeeklyNotesFilePatternRaw(_scopeId?: string): string {
const scope = this.resolveScope(_scopeId);
const result: string | undefined = scope === SCOPE_DEFAULT
? this.config.get<PatternDefinition>("patterns")?.weeklyNotes?.file
: this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === scope)?.patterns?.weeklyNotes?.file;
return (isNullOrUndefined(result) || result!.length === 0) ? defaultPatternDefinition.weeklyNotes!.file : result!;
}
public getWeekFilePatternRaw(_scopeId?: string): string {
const scope = this.resolveScope(_scopeId);
const result: string | undefined = scope === SCOPE_DEFAULT
? this.config.get<PatternDefinition>("patterns")?.weeks?.file
: this.config.get<ScopeDefinition[]>("scopes")?.filter(sd => sd.name === scope).pop()?.patterns?.weeks?.file;
return (isNullOrUndefined(result) || result!.length === 0) ? defaultPatternDefinition.weeks.file : result!;
}
/** Scoped fallback reads entries.path — preserves existing getWeekPathPattern behavior. */
public getWeekOrEntryPathPatternRaw(_scopeId?: string): string {
const scope = this.resolveScope(_scopeId);
const result: string | undefined = scope === SCOPE_DEFAULT
? this.config.get<PatternDefinition>("patterns")?.weeks?.path
: this.config.get<ScopeDefinition[]>("scopes")?.filter(sd => sd.name === scope).pop()?.patterns?.entries?.path;
return (isNullOrUndefined(result) || result!.length === 0) ? defaultPatternDefinition.entries.path : result!;
}
async getWeekFilePattern(week: Number, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getWeekFilePattern(week, _scopeId);
}
public async getWeekPathPatternForLocalOpen(week: Number, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getWeekPathPatternForLocalOpen(week, _scopeId);
}
async getWeekPathPattern(week: Number, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getWeekPathPattern(week, _scopeId);
}
/**
* Configuration for the path, under which the journal entry file is stored
*
* Supported variables: base, year, month, day, df
*
* @param _scopeId default or individual
*/
public getEntryPathPattern(_scopeId?: string): string {
let result: string | undefined;
if (this.resolveScope(_scopeId) === SCOPE_DEFAULT) {
result = this.config.get<PatternDefinition>("patterns")?.["entries"]?.path;
} else {
result = this.config.get<ScopeDefinition[]>("scopes")?.filter(sd => sd.name === _scopeId).pop()?.patterns?.entries?.path;
}
if (isNullOrUndefined(result) || result!.length === 0) {
result = defaultPatternDefinition.entries.path;
}
return result!;
}
/**
* Configuration for the path, under which the journal entry file is stored
*
* Supported variables: base, year, month, day, df
*
* @param _scopeId default or individual
*/
public async getResolvedEntryPath(date: Date, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getResolvedEntryPath(date, _scopeId);
}
public async getResolvedEntryPathForLocalOpen(date: Date, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getResolvedEntryPathForLocalOpen(date, _scopeId);
}
public async getEntryFilePattern(date: Date, _scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getEntryFilePattern(date, _scopeId);
}
/**
* Output format for calender format of moment.js, see https://momentjs.com/docs/#/displaying/calendar-time/
*
* Used in the quickpicker description. The default also includes the time, which we don't want.
*
* FIXME: Externalise to properties (multilanguage)
*/
public getInputDetailsTimeFormat() {
let labels: string[] = new Array(4);
if (this.getLocale().startsWith("en")) {
labels = ["for today", "for tomorrow", "for yesterday", "last"];
} else if (this.getLocale().startsWith("de")) {
labels = ["für heute", "für morgen", " für gestern", "letzten"];
} else if (this.getLocale().startsWith("fr")) {
labels = ["pour aujourd'hui", "pour demain", "d'hier"];
} else if (this.getLocale().startsWith("es")) {
labels = ["para hoy", "de mañana", "de ayer", "del último"];
}
let config = {
sameDay: `[${labels[0]}]`,
nextDay: `[${labels[1]}]`,
nextWeek: 'dddd',
lastDay: `[${labels[2]}]`,
lastWeek: `[${labels[3]}] dddd`,
sameElse: 'DD/MM/YYYY'
};
return config;
/*
Memo der Seite für morgen hinzufügen
Add memo to the page for tomorrow
Ajouter un mémo à la page pour demain
Añadir un memo a la página de mañana
Añadir un memo a la página de ayer
*/
}
/**
* Helper Method, threshold (maximal age) of files shown in the quick picker
*/
getInputTimeThreshold(): number {
let offset = -60;
let d: Date = new Date();
d.setDate(d.getDate() + offset);
return d.getTime();
}
/**
*
* Retrieves the (scoped) inline template for a journal entry.
*
* Supported variables: localDate, year, month, day, format
*
* Default value is: "# ${localDate}\n\n",
* @param {string} [_scopeId]
* @returns {Q.Promise<FileTemplate>}
* @memberof Configuration
*/
public async getEntryTemplate(date: Date, _scopeId?: string): Promise<HeaderTemplate> {
return this.tpl.getEntryTemplate(date, _scopeId);
}
public async getWeeklyTemplate(week: Number, _scopeId?: string) {
return this.tpl.getWeeklyTemplate(week, _scopeId);
}
public async getNotesTemplate(_scopeId?: string): Promise<HeaderTemplate> {
return this.tpl.getNotesTemplate(_scopeId);
}
/**
* Retrieves the (scoped) file template for a note.
*
* Default value is: "# {content}\n\n",
*
* @param {string} [_scopeId]
* @returns {Q.Promise<FileTemplate>}
* @memberof Configuration
*/
public async getFileLinkInlineTemplate(_scopeId?: string): Promise<InlineTemplate> {
return this.tpl.getFileLinkInlineTemplate(_scopeId);
}
public async getMemoInlineTemplate(_scopeId?: string): Promise<InlineTemplate> {
return this.tpl.getMemoInlineTemplate(_scopeId);
}
public async getTaskInlineTemplate(_scopeId?: string): Promise<InlineTemplate> {
return this.tpl.getTaskInlineTemplate(_scopeId);
}
public getTplTime(): string | undefined {
return this.config.get<string>('tpl-time');
}
public getTimeString(): string | undefined {
return this.tpl.getTimeString();
}
public async getTimeStringTemplate(_scopeId?: string): Promise<ScopedTemplate> {
return this.tpl.getTimeStringTemplate(_scopeId);
}
public isDevelopmentModeEnabled(): boolean {
let dev: boolean | undefined = this.config.get<boolean>('dev');
return (!isNullOrUndefined(dev)) ? dev! : false;
}
public isOpenInNewEditorGroup(): boolean {
let res: boolean | undefined = this.config.get<boolean>('openInNewEditorGroup');
return (!isNullOrUndefined(res)) ? res! : false;
}
public getWeeklySyncConfig(_scopeId?: string): WeeklySyncConfig {
const raw = this.config.get<Partial<WeeklySyncConfig>>("weeklySync") ?? {};
return {
enabled: raw.enabled !== undefined ? raw.enabled : true,
anchor: raw.anchor !== undefined ? raw.anchor : "## Daily Entries",
template: raw.template !== undefined ? raw.template : "- [${weekday}, ${d:MMMM DD}](${link})",
sortOrder: raw.sortOrder === "descending" ? "descending" : "ascending",
};
}
public async getDailyLinkInlineTemplate(_scopeId?: string): Promise<InlineTemplate> {
return this.tpl.getDailyLinkInlineTemplate(_scopeId);
}
/***** PRIVATES *******/
/**
* Returns a valid scope, falls back to default.
*
* @param _scopeId
*/
private resolveScope(_scopeId?: string): string {
return (isNullOrUndefined(_scopeId) || (_scopeId!.length === 0)) ? SCOPE_DEFAULT : _scopeId!;
}
/**
* Returns the inline template from user or workspace settings
* @param _id task, memo, etc.
* @param _defaultValue
* @param _scopeId
*/
public async loadInlineTemplate(_id: string, _defaultValue: string, _scopeId?: string): Promise<InlineTemplate> {
const scope = this.resolveScope(_scopeId);
let pattern: InlineTemplate | undefined;
if (scope === SCOPE_DEFAULT) {
pattern = this.config.get<InlineTemplate[]>("templates")?.find(tpl => tpl.name === _id);
} else {
const scopeDefinition = this.config.get<ScopeDefinition[]>("scopes")?.find(sd => sd.name === scope);
pattern = scopeDefinition?.templates?.find(tpl => tpl.name === _id)
?? this.config.get<InlineTemplate[]>("templates")?.find(tpl => tpl.name === _id);
}
if (Util.isNullOrUndefined(pattern)) {
// #72: legacy config support — moved here so legacy doesn't win when both are set
if (Util.stringIsNotEmpty(this.config.get<string>("tpl-" + _id))) {
return {
name: _id,
scope: SCOPE_DEFAULT,
template: this.config.get<string>("tpl-" + _id)!,
after: Util.stringIsNotEmpty(this.config.get<string>(_id + '-after')) ? this.config.get<string>(_id + '-after')! : ''
};
}
return { name: _id, scope: SCOPE_DEFAULT, template: _defaultValue, after: '' };
}
if (Util.isNullOrUndefined(pattern?.after)) { pattern!.after = ''; }
if (Util.isNullOrUndefined(pattern?.template)) { pattern!.after = _defaultValue; }
return pattern!;
}
}