@@ -17,20 +17,24 @@ struct EditInfoView: View {
17
17
18
18
@Query ( IOCategory . all) var categories : [ IOCategory ]
19
19
20
+ @State private var showSheet = false
21
+
20
22
// Inspector
21
23
@State var isShowInspector = false
22
24
enum InspectorType {
23
25
case category, customSearch
24
26
}
25
27
@State var inspectorType : InspectorType = . category
28
+ @AppStorage ( SPC . isShowInspector) var asIsShowInspector : Bool = false
29
+ @AppStorage ( SPC . inspectorType) var asInspectorType : Int = 0
26
30
27
31
// Tab
28
32
@State var selectedTab = 1
29
33
30
34
@State var isStopLoadingWeb = false
31
35
// webarchive
32
36
@State var savingDataTrigger = false
33
-
37
+
34
38
// 图集
35
39
@State var selectedPhotos = [ PhotosPickerItem] ( )
36
40
@State var addWebImageUrl = " "
@@ -119,8 +123,35 @@ struct EditInfoView: View {
119
123
info. category? . updateDate = Date . now
120
124
} )
121
125
Button ( " 管理分类 " , action: manageCate)
126
+ Button ( " 自定检索 " ) {
127
+ showSheet = true
128
+ }
129
+ . help ( " command + s " )
130
+ . sheet ( isPresented: $showSheet, content: {
131
+ ScrollView ( . vertical) {
132
+ ForEach ( parseSearchTerms ( ) , id: \. self) { term in
133
+ HStack {
134
+ ForEach ( term, id: \. self) { oneTerm in
135
+ if oneTerm. description. hasPrefix ( " 《 " ) {
136
+ Text ( oneTerm)
137
+ . bold ( )
138
+ } else {
139
+ Button ( oneTerm) {
140
+ showSheet = false
141
+ info. des = oneTerm + " \n " + info. des
142
+ }
143
+ }
144
+ }
145
+ Spacer ( )
146
+ }
147
+ . padding ( . leading, 1 )
148
+ }
149
+ }
150
+ . padding ( 20 )
151
+ } )
152
+ . keyboardShortcut ( KeyEquivalent ( " s " ) , modifiers: . command)
153
+
122
154
Button ( " 管理自定检索 " , action: manageCustomSearch)
123
-
124
155
}
125
156
}
126
157
// MARK: Tab 切换
@@ -277,10 +308,58 @@ struct EditInfoView: View {
277
308
isShowInspector. toggle ( )
278
309
}
279
310
}
311
+ . onAppear ( perform: {
312
+ _ = parseSearchTerms ( )
313
+ // AppStorage
314
+ if asInspectorType == 0 {
315
+ inspectorType = . category
316
+ } else if asInspectorType == 1 {
317
+ inspectorType = . customSearch
318
+ }
319
+ isShowInspector = asIsShowInspector
320
+ } )
321
+ . onChange ( of: term) { oldValue, newValue in
322
+ _ = parseSearchTerms ( )
323
+ }
324
+ . onChange ( of: isShowInspector) { oldValue, newValue in
325
+ asIsShowInspector = newValue
326
+ }
327
+ . onChange ( of: inspectorType) { oldValue, newValue in
328
+ if newValue == InspectorType . category {
329
+ asInspectorType = 0
330
+ } else if newValue == InspectorType . customSearch {
331
+ asInspectorType = 1
332
+ }
333
+ }
280
334
Spacer ( )
281
335
} // end VStack
282
336
}
283
337
338
+ // MARK: 自定检索
339
+ @AppStorage ( SPC . customSearchTerm) var term = " "
340
+ @State private var searchTerms : [ [ String ] ] = [ [ String] ] ( )
341
+ func parseSearchTerms( ) -> [ [ String ] ] {
342
+ let terms = term. trimmingCharacters ( in: . whitespacesAndNewlines) . split ( separator: " \n " )
343
+ var sterms = [ [ String] ] ( )
344
+ for t in terms {
345
+ if t. isEmpty == false {
346
+ let tWithoutWhitespaces = t. trimmingCharacters ( in: . whitespaces)
347
+ if tWithoutWhitespaces. hasPrefix ( " // " ) { continue }
348
+ let ts = t. trimmingCharacters ( in: . whitespaces) . split ( separator: " , " )
349
+ var lineTs = [ String] ( )
350
+ if ts. count > 1 {
351
+ for oneT in ts {
352
+ lineTs. append ( String ( oneT. trimmingCharacters ( in: . whitespaces) ) )
353
+ }
354
+ } else {
355
+ lineTs. append ( String ( tWithoutWhitespaces) )
356
+ }
357
+ sterms. append ( lineTs)
358
+ } // end if
359
+ } // end for
360
+ searchTerms = sterms
361
+ return sterms
362
+ }
284
363
285
364
// MARK: 数据管理
286
365
func tabSwitch( ) {
0 commit comments