11import { getSettings } from '../Config/Settings' ;
22import type { IQuery } from '../IQuery' ;
3- import { QueryLayoutOptions } from '../Layout/QueryLayoutOptions' ;
4- import { TaskLayoutComponent , TaskLayoutOptions } from '../Layout/TaskLayoutOptions' ;
3+ import { QueryLayoutOptions , parseQueryShowHideOptions } from '../Layout/QueryLayoutOptions' ;
4+ import { TaskLayoutOptions , parseTaskShowHideOptions } from '../Layout/TaskLayoutOptions' ;
55import { errorMessageForException } from '../lib/ExceptionTools' ;
66import { logging } from '../lib/logging' ;
77import { expandPlaceholders } from '../Scripting/ExpandPlaceholders' ;
@@ -27,24 +27,23 @@ export class Query implements IQuery {
2727
2828 private _limit : number | undefined = undefined ;
2929 private _taskGroupLimit : number | undefined = undefined ;
30- private _taskLayoutOptions : TaskLayoutOptions = new TaskLayoutOptions ( ) ;
31- private _queryLayoutOptions : QueryLayoutOptions = new QueryLayoutOptions ( ) ;
32- private _filters : Filter [ ] = [ ] ;
30+ private readonly _taskLayoutOptions : TaskLayoutOptions = new TaskLayoutOptions ( ) ;
31+ private readonly _queryLayoutOptions : QueryLayoutOptions = new QueryLayoutOptions ( ) ;
32+ private readonly _filters : Filter [ ] = [ ] ;
3333 private _error : string | undefined = undefined ;
34- private _sorting : Sorter [ ] = [ ] ;
35- private _grouping : Grouper [ ] = [ ] ;
34+ private readonly _sorting : Sorter [ ] = [ ] ;
35+ private readonly _grouping : Grouper [ ] = [ ] ;
3636 private _ignoreGlobalQuery : boolean = false ;
3737
38- private readonly hideOptionsRegexp =
39- / ^ ( h i d e | s h o w ) ( t a s k c o u n t | b a c k l i n k | p r i o r i t y | c a n c e l l e d d a t e | c r e a t e d d a t e | s t a r t d a t e | s c h e d u l e d d a t e | d o n e d a t e | d u e d a t e | r e c u r r e n c e r u l e | e d i t b u t t o n | p o s t p o n e b u t t o n | u r g e n c y | t a g s | d e p e n d s o n | i d | o n c o m p l e t i o n | t r e e ) / i;
38+ private readonly hideOptionsRegexp = / ^ ( h i d e | s h o w ) + ( .* ) / i;
4039 private readonly shortModeRegexp = / ^ s h o r t / i;
4140 private readonly fullModeRegexp = / ^ f u l l / i;
4241 private readonly explainQueryRegexp = / ^ e x p l a i n / i;
4342 private readonly ignoreGlobalQueryRegexp = / ^ i g n o r e g l o b a l q u e r y / i;
4443
4544 logger = logging . getLogger ( 'tasks.Query' ) ;
4645 // Used internally to uniquely log each query execution in the console.
47- private _queryId : string = '' ;
46+ private readonly _queryId : string ;
4847
4948 private readonly limitRegexp = / ^ l i m i t ( g r o u p s ) ? ( t o ) ? ( \d + ) ( t a s k s ? ) ? / i;
5049
@@ -304,70 +303,19 @@ ${statement.explainStatement(' ')}
304303
305304 private parseHideOptions ( line : string ) : void {
306305 const hideOptionsMatch = line . match ( this . hideOptionsRegexp ) ;
307- if ( hideOptionsMatch !== null ) {
308- const hide = hideOptionsMatch [ 1 ] . toLowerCase ( ) === 'hide' ;
309- const option = hideOptionsMatch [ 2 ] . toLowerCase ( ) ;
310-
311- switch ( option ) {
312- case 'tree' :
313- // WARNING: undocumented, and not yet ready for release.
314- this . _queryLayoutOptions . hideTree = hide ;
315- break ;
316- case 'task count' :
317- this . _queryLayoutOptions . hideTaskCount = hide ;
318- break ;
319- case 'backlink' :
320- this . _queryLayoutOptions . hideBacklinks = hide ;
321- break ;
322- case 'postpone button' :
323- this . _queryLayoutOptions . hidePostponeButton = hide ;
324- break ;
325- case 'priority' :
326- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . Priority , ! hide ) ;
327- break ;
328- case 'cancelled date' :
329- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . CancelledDate , ! hide ) ;
330- break ;
331- case 'created date' :
332- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . CreatedDate , ! hide ) ;
333- break ;
334- case 'start date' :
335- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . StartDate , ! hide ) ;
336- break ;
337- case 'scheduled date' :
338- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . ScheduledDate , ! hide ) ;
339- break ;
340- case 'due date' :
341- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . DueDate , ! hide ) ;
342- break ;
343- case 'done date' :
344- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . DoneDate , ! hide ) ;
345- break ;
346- case 'recurrence rule' :
347- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . RecurrenceRule , ! hide ) ;
348- break ;
349- case 'edit button' :
350- this . _queryLayoutOptions . hideEditButton = hide ;
351- break ;
352- case 'urgency' :
353- this . _queryLayoutOptions . hideUrgency = hide ;
354- break ;
355- case 'tags' :
356- this . _taskLayoutOptions . setTagsVisibility ( ! hide ) ;
357- break ;
358- case 'id' :
359- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . Id , ! hide ) ;
360- break ;
361- case 'depends on' :
362- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . DependsOn , ! hide ) ;
363- break ;
364- case 'on completion' :
365- this . _taskLayoutOptions . setVisibility ( TaskLayoutComponent . OnCompletion , ! hide ) ;
366- break ;
367- default :
368- this . setError ( 'do not understand hide/show option' , new Statement ( line , line ) ) ;
369- }
306+ if ( hideOptionsMatch === null ) {
307+ return ;
308+ }
309+ const hide = hideOptionsMatch [ 1 ] . toLowerCase ( ) === 'hide' ;
310+ const option = hideOptionsMatch [ 2 ] . toLowerCase ( ) ;
311+
312+ if ( parseQueryShowHideOptions ( this . _queryLayoutOptions , option , hide ) ) {
313+ return ;
314+ }
315+ if ( parseTaskShowHideOptions ( this . _taskLayoutOptions , option , ! hide ) ) {
316+ return ;
370317 }
318+ this . setError ( 'do not understand hide/show option' , new Statement ( line , line ) ) ;
371319 }
372320
373321 private parseFilter ( line : string , statement : Statement ) {
0 commit comments