1
+ import FileCookerPlugin from 'main' ;
2
+ import { Action } from 'src/action/action' ;
3
+ import { AddToCanvasAction } from 'src/action/add-to-canvas-action' ;
4
+ import { DeleteAction } from 'src/action/delete-action' ;
5
+ import { EditFrontMatterAction } from 'src/action/edit-front-matter-action' ;
6
+ import { MoveAction } from 'src/action/move-action' ;
7
+ import { RenameAction } from 'src/action/rename-action' ;
8
+ import { SyncFlomoAction } from 'src/action/sync-flomo-action' ;
9
+ import { ChooseCanvasModal } from 'src/modal/choose-canvas-modal' ;
10
+ import { ChooseFileModal } from 'src/modal/choose-file-modal' ;
11
+ import { ChooseFolderModal } from 'src/modal/choose-folder-modal' ;
12
+ import { SearchResultsReader } from 'src/reader/search-results-reader' ;
13
+ import { Command } from './command' ;
14
+
15
+ export class SearchCommand implements Command {
16
+
17
+ plugin : FileCookerPlugin ;
18
+
19
+ constructor ( plugin : FileCookerPlugin ) {
20
+ this . plugin = plugin ;
21
+ }
22
+
23
+ regist ( ) : void {
24
+ this . registMoveFile ( ) ;
25
+ this . registSyncFlomo ( ) ;
26
+ this . registMergeFile ( ) ;
27
+ this . registDeleteFile ( ) ;
28
+ this . registEditProp ( ) ;
29
+ this . registRenameFile ( ) ;
30
+ // Canvas
31
+ this . registAddFile2Canvas ( ) ;
32
+ }
33
+
34
+ private registRenameFile ( ) {
35
+ this . plugin . addCommand ( {
36
+ id : 'rename-files-in-searchresults' ,
37
+ name : 'Rename files in searchresults ...' ,
38
+ callback : ( ) => {
39
+ new SearchResultsReader ( this . plugin ) . read ( new RenameAction ( this . plugin . app ) ) ;
40
+ }
41
+ } ) ;
42
+ }
43
+
44
+ /**
45
+ * Edit Front Matter
46
+ * https://github.com/lijyze/obsidian-state-switcher/blob/d0a80081b0fcc1b899eed2e3d7e834c2d5703875/src/util.ts#L42
47
+ */
48
+ private registEditProp ( ) {
49
+ let metaedit = this . plugin . app . plugins . plugins [ "metaedit" ] ;
50
+
51
+ this . plugin . addCommand ( {
52
+ id : 'edit-front-matter-in-searchresults-files' ,
53
+ name : 'Edit Front Matter in searchresults files ...' ,
54
+ checkCallback : ( checking : boolean ) => {
55
+ if ( ! checking ) {
56
+ new SearchResultsReader ( this . plugin ) . read ( new EditFrontMatterAction ( this . plugin . app ) ) ;
57
+ }
58
+ return metaedit != null ;
59
+ }
60
+ } ) ;
61
+ }
62
+
63
+ private registDeleteFile ( ) {
64
+ this . plugin . addCommand ( {
65
+ id : 'delete-files-in-searchresults' ,
66
+ name : 'Delete files in searchresults!' ,
67
+ callback : ( ) => {
68
+ new SearchResultsReader ( this . plugin ) . read ( new DeleteAction ( this . plugin . app ) ) ;
69
+ }
70
+ } ) ;
71
+ }
72
+
73
+ private registMergeFile ( ) {
74
+ this . plugin . addCommand ( {
75
+ id : 'merge-files-in-searchresults-to' ,
76
+ name : 'Merge files in searchresults to ...' ,
77
+ callback : ( ) => {
78
+ new ChooseFileModal ( this . plugin . app , new SearchResultsReader ( this . plugin ) ) . open ( ) ;
79
+ }
80
+ } ) ;
81
+ }
82
+
83
+ private registSyncFlomo ( ) {
84
+ this . plugin . addCommand ( {
85
+ id : 'sync-files-in-searchresults-to-flomo' ,
86
+ name : 'Sync files in searchresults to flomo ...' ,
87
+ callback : ( ) => {
88
+ new SearchResultsReader ( this . plugin ) . read ( new SyncFlomoAction ( this . plugin ) ) ;
89
+ }
90
+ } ) ;
91
+ }
92
+
93
+ private registMoveFile ( ) {
94
+ this . plugin . addCommand ( {
95
+ id : 'move-files-in-searchresults-to' ,
96
+ name : 'Move files in searchresults to ...' ,
97
+ callback : ( ) => {
98
+ let actionFunc = ( path : string ) : Action => { return new MoveAction ( this . plugin . app , path ) ; } ;
99
+ new ChooseFolderModal ( this . plugin . app , new SearchResultsReader ( this . plugin ) , actionFunc ) . open ( ) ;
100
+ }
101
+ } ) ;
102
+ }
103
+
104
+ private registAddFile2Canvas ( ) {
105
+ this . plugin . addCommand ( {
106
+ id : "add-files-in-searchresults-to-canvas" ,
107
+ name : "Add files in searchresults to target canvas ..." ,
108
+ callback : ( ) => {
109
+ new ChooseCanvasModal ( this . plugin . app , new SearchResultsReader ( this . plugin ) ) . open ( ) ;
110
+ }
111
+ } ) ;
112
+ }
113
+ }
0 commit comments