Fossil SCM

Add the "searchable" TH1 command that tests to see if search is enabled on the repository. Intended use: Conditionally display a "Search" button on the menu bar.

drh 2015-02-06 01:44 UTC form-submenu
Commit b8f8f69eeec4d75d20fe96f4f2866e1e0bf49076
1 file changed +60
--- src/th_main.c
+++ src/th_main.c
@@ -365,10 +365,69 @@
365365
Th_Trace("[hascap %#h] => %d<br />\n", argl[1], argv[1], rc);
366366
}
367367
Th_SetResultInt(interp, rc);
368368
return TH_OK;
369369
}
370
+
371
+/*
372
+** TH1 command: searchable STRING...
373
+**
374
+** Return true if searching in any of the document classes identified
375
+** by STRING is enabled for the repository and user has the necessary
376
+** capabilities to perform the search.
377
+**
378
+** Document classes:
379
+**
380
+** c Check-in comments
381
+** d Embedded documentation
382
+** t Tickets
383
+** w Wiki
384
+**
385
+** To be clear, only one of the document classes identified by each STRING
386
+** needs to be searchable in order for that argument to be true. But
387
+** all arguments must be true for this routine to return true. Hence, to
388
+** see if ALL document classes are searchable:
389
+**
390
+** if {[searchable c d t w]} {...}
391
+**
392
+** But to see if ANY document class is searchable:
393
+**
394
+** if {[searchable cdtw]} {...}
395
+**
396
+** This command is useful for enabling or disabling a "Search" entry
397
+** on the menu bar.
398
+*/
399
+static int searchableCmd(
400
+ Th_Interp *interp,
401
+ void *p,
402
+ int argc,
403
+ const char **argv,
404
+ int *argl
405
+){
406
+ int rc = 1, i, j;
407
+ unsigned int searchCap = search_restrict(SRCH_ALL);
408
+ if( argc<2 ){
409
+ return Th_WrongNumArgs(interp, "hascap STRING ...");
410
+ }
411
+ for(i=1; i<argc && rc; i++){
412
+ int match = 0;
413
+ for(j=0; j<argl[i]; j++){
414
+ switch( argv[i][j] ){
415
+ case 'c': match |= searchCap & SRCH_CKIN; break;
416
+ case 'd': match |= searchCap & SRCH_DOC; break;
417
+ case 't': match |= searchCap & SRCH_TKT; break;
418
+ case 'w': match |= searchCap & SRCH_WIKI; break;
419
+ }
420
+ }
421
+ if( !match ) rc = 0;
422
+ }
423
+ if( g.thTrace ){
424
+ Th_Trace("[searchable %#h] => %d<br />\n", argl[1], argv[1], rc);
425
+ }
426
+ Th_SetResultInt(interp, rc);
427
+ return TH_OK;
428
+}
370429
371430
/*
372431
** TH1 command: hasfeature STRING
373432
**
374433
** Return true if the fossil binary has the given compile-time feature
@@ -1419,10 +1478,11 @@
14191478
{"randhex", randhexCmd, 0},
14201479
{"regexp", regexpCmd, 0},
14211480
{"reinitialize", reinitializeCmd, 0},
14221481
{"render", renderCmd, 0},
14231482
{"repository", repositoryCmd, 0},
1483
+ {"searchable", searchableCmd, 0},
14241484
{"setParameter", setParameterCmd, 0},
14251485
{"setting", settingCmd, 0},
14261486
{"styleHeader", styleHeaderCmd, 0},
14271487
{"styleFooter", styleFooterCmd, 0},
14281488
{"tclReady", tclReadyCmd, 0},
14291489
--- src/th_main.c
+++ src/th_main.c
@@ -365,10 +365,69 @@
365 Th_Trace("[hascap %#h] => %d<br />\n", argl[1], argv[1], rc);
366 }
367 Th_SetResultInt(interp, rc);
368 return TH_OK;
369 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
371 /*
372 ** TH1 command: hasfeature STRING
373 **
374 ** Return true if the fossil binary has the given compile-time feature
@@ -1419,10 +1478,11 @@
1419 {"randhex", randhexCmd, 0},
1420 {"regexp", regexpCmd, 0},
1421 {"reinitialize", reinitializeCmd, 0},
1422 {"render", renderCmd, 0},
1423 {"repository", repositoryCmd, 0},
 
1424 {"setParameter", setParameterCmd, 0},
1425 {"setting", settingCmd, 0},
1426 {"styleHeader", styleHeaderCmd, 0},
1427 {"styleFooter", styleFooterCmd, 0},
1428 {"tclReady", tclReadyCmd, 0},
1429
--- src/th_main.c
+++ src/th_main.c
@@ -365,10 +365,69 @@
365 Th_Trace("[hascap %#h] => %d<br />\n", argl[1], argv[1], rc);
366 }
367 Th_SetResultInt(interp, rc);
368 return TH_OK;
369 }
370
371 /*
372 ** TH1 command: searchable STRING...
373 **
374 ** Return true if searching in any of the document classes identified
375 ** by STRING is enabled for the repository and user has the necessary
376 ** capabilities to perform the search.
377 **
378 ** Document classes:
379 **
380 ** c Check-in comments
381 ** d Embedded documentation
382 ** t Tickets
383 ** w Wiki
384 **
385 ** To be clear, only one of the document classes identified by each STRING
386 ** needs to be searchable in order for that argument to be true. But
387 ** all arguments must be true for this routine to return true. Hence, to
388 ** see if ALL document classes are searchable:
389 **
390 ** if {[searchable c d t w]} {...}
391 **
392 ** But to see if ANY document class is searchable:
393 **
394 ** if {[searchable cdtw]} {...}
395 **
396 ** This command is useful for enabling or disabling a "Search" entry
397 ** on the menu bar.
398 */
399 static int searchableCmd(
400 Th_Interp *interp,
401 void *p,
402 int argc,
403 const char **argv,
404 int *argl
405 ){
406 int rc = 1, i, j;
407 unsigned int searchCap = search_restrict(SRCH_ALL);
408 if( argc<2 ){
409 return Th_WrongNumArgs(interp, "hascap STRING ...");
410 }
411 for(i=1; i<argc && rc; i++){
412 int match = 0;
413 for(j=0; j<argl[i]; j++){
414 switch( argv[i][j] ){
415 case 'c': match |= searchCap & SRCH_CKIN; break;
416 case 'd': match |= searchCap & SRCH_DOC; break;
417 case 't': match |= searchCap & SRCH_TKT; break;
418 case 'w': match |= searchCap & SRCH_WIKI; break;
419 }
420 }
421 if( !match ) rc = 0;
422 }
423 if( g.thTrace ){
424 Th_Trace("[searchable %#h] => %d<br />\n", argl[1], argv[1], rc);
425 }
426 Th_SetResultInt(interp, rc);
427 return TH_OK;
428 }
429
430 /*
431 ** TH1 command: hasfeature STRING
432 **
433 ** Return true if the fossil binary has the given compile-time feature
@@ -1419,10 +1478,11 @@
1478 {"randhex", randhexCmd, 0},
1479 {"regexp", regexpCmd, 0},
1480 {"reinitialize", reinitializeCmd, 0},
1481 {"render", renderCmd, 0},
1482 {"repository", repositoryCmd, 0},
1483 {"searchable", searchableCmd, 0},
1484 {"setParameter", setParameterCmd, 0},
1485 {"setting", settingCmd, 0},
1486 {"styleHeader", styleHeaderCmd, 0},
1487 {"styleFooter", styleFooterCmd, 0},
1488 {"tclReady", tclReadyCmd, 0},
1489

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button