forked from wxbool/video-srt-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
1128 lines (1031 loc) · 26.6 KB
/
event.go
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package app
import (
"errors"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"log"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"videosrt/app/aliyun"
"videosrt/app/tool"
"videosrt/app/translate"
)
type MyMainWindow struct {
*walk.MainWindow
}
//创建一个提示消息
func (mw *MyMainWindow) NewInformationTips(title string , message string) {
walk.MsgBox(mw, title , message , walk.MsgBoxIconInformation)
}
//创建一个错误消息
func (mw *MyMainWindow) NewErrormationTips(title string , message string) {
walk.MsgBox(mw, title , message , walk.MsgBoxIconWarning)
}
// 运行 应用设置 Dialog
func(mw *MyMainWindow) RunAppSetingDialog(owner walk.Form , confirmCall func(*AppSetings)) {
var seting *AppSetings
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
seting = Setings.GetCacheAppSetingsData() //查询缓存数据
//fmt.Println( setings )
if seting.MaxConcurrency == 0 {
seting.MaxConcurrency = 2 //默认并发数
}
Dialog{
AssignTo: &dlg,
Title: "软件设置",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "setings",
DataSource: seting,
ErrorPresenter: ToolTipErrorPresenter{},
},
MinSize: Size{450, 220},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "任务处理并发数:",
},
NumberEdit{
Value: Bind("MaxConcurrency", Range{1, 20}),
Decimals: 0,
},
Label{
Text: "文件输出目录:",
},
LineEdit{
Text: Bind("SrtFileDir"),
},
Label{
ColumnSpan: 2,
Text: "说明:\r\n“文件输出目录” 若留空,则默认与媒体文件输出到同一目录下",
TextColor:walk.RGB(190 , 190 , 190),
MinSize:Size{Height:40},
},
Label{
Text: "关闭软件智能分段处理:",
},
CheckBox{
Checked: Bind("CloseIntelligentBlockSwitch"),
},
Label{
Text: "关闭OSS临时文件清理:",
},
CheckBox{
Checked: Bind("CloseAutoDeleteOssTempFile"),
},
Label{
Text: "关闭软件新版本提醒:",
},
CheckBox{
Checked: Bind("CloseNewVersionMessage"),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "保存",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Fatal(err)
return
}
//目录校验
if seting.SrtFileDir != "" {
tmpDir := tool.WinDir(seting.SrtFileDir)
if !tool.DirExists(tmpDir) {
mw.NewErrormationTips("错误" , "目录无效/不存在:" + seting.SrtFileDir)
return;
}
seting.SrtFileDir = tmpDir
}
//设置缓存
Setings.SetCacheAppSetingsData(seting)
//设置回调
confirmCall(seting)
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
// 运行 新建语音引擎 Dialog
func(mw *MyMainWindow) RunSpeechEngineSetingDialog(owner walk.Form , confirmCall func()) {
var engine *AliyunEngineCache
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
engine = new(AliyunEngineCache)
engine.Region = aliyun.ALIYUN_CLOUND_REGION_CHA //默认值
Dialog{
AssignTo: &dlg,
Title: "新建语音引擎",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "engine",
DataSource: engine,
ErrorPresenter: ToolTipErrorPresenter{},
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "名称/别名:",
},
LineEdit{
Text: Bind("Alias"),
},
Label{
Text: "AppKey:",
},
LineEdit{
Text: Bind("AppKey"),
},
Label{
Text: "AccessKeyId:",
},
LineEdit{
Text: Bind("AccessKeyId"),
},
Label{
Text: "AccessKeySecret:",
},
LineEdit{
Text: Bind("AccessKeySecret"),
},
Label{
Text: "服务区域:",
},
ComboBox{
Value: Bind("Region", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetAliyunEngineRegionOptionSelects(),
},
Label{
ColumnSpan: 2,
Text: "说明:\r\n“语音识别” 目前使用的是阿里云语音服务商,请填写相关的引擎配置。",
TextColor:walk.RGB(190 , 190 , 190),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "确定新增",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Print(err)
return
}
//参数验证
if (engine.Alias == "") {
mw.NewErrormationTips("提示" , "请填写 名称/别名")
return
}
if (engine.AppKey == "") {
mw.NewErrormationTips("提示" , "请填写 AppKey")
return
}
if (engine.AccessKeyId == "") {
mw.NewErrormationTips("提示" , "请填写 AccessKeyId")
return
}
if (engine.AccessKeySecret == "") {
mw.NewErrormationTips("提示" , "请填写 AccessKeySecret")
return
}
//去空格
engine.AppKey = strings.TrimSpace(engine.AppKey)
engine.AccessKeyId = strings.TrimSpace(engine.AccessKeyId)
engine.AccessKeySecret = strings.TrimSpace(engine.AccessKeySecret)
//获取缓存数据
localData := Engine.GetCacheAliyunEngineListData()
//生成id
lens := len(localData.Engine)
if lens == 0 {
engine.Id = 1
} else {
engine.Id = localData.Engine[ lens - 1 ].Id + 1
}
//追加数据
localData.Engine = append(localData.Engine , engine)
//缓存数据
Engine.SetCacheAliyunEngineListData(localData)
//调用回调
confirmCall()
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
// 运行 新建[百度]翻译引擎 Dialog
func(mw *MyMainWindow) RunBaiduTranslateEngineSetingDialog(owner walk.Form , confirmCall func()) {
var engine *TranslateEngineStruct
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
engine = new(TranslateEngineStruct)
//默认值
engine.Supplier = TRANSLATE_SUPPLIER_BAIDU
engine.BaiduEngine.AuthenType = translate.ACCOUNT_COMMON_AUTHEN
Dialog{
AssignTo: &dlg,
Title: "新建翻译引擎(百度翻译)",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "engine",
DataSource: engine,
ErrorPresenter: ToolTipErrorPresenter{},
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "名称/别名:",
},
LineEdit{
Text: Bind("Alias"),
},
Label{
Text: "AppId:",
},
LineEdit{
Text: Bind("BaiduEngine.AppId"),
},
Label{
Text: "AppSecret:",
},
LineEdit{
Text: Bind("BaiduEngine.AppSecret"),
},
Label{
Text: "账号认证类型:",
},
ComboBox{
Value: Bind("BaiduEngine.AuthenType", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetBaiduTranslateAuthenTypeOptionsSelects(),
},
TextLabel{
ColumnSpan: 2,
Row: 5,
Text: "\r\n说明:\r\n请填写在 “百度翻译开放平台” 的申请密钥,注意 “标准版” 和 “高级版” 的选择",
TextColor:walk.RGB(190 , 190 , 190),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "确定新增",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Print(err)
return
}
//参数验证
if (engine.Alias == "") {
mw.NewErrormationTips("提示" , "请填写 名称/别名")
return
}
if (engine.BaiduEngine.AppId == "") {
mw.NewErrormationTips("提示" , "请填写 AppId")
return
}
if (engine.BaiduEngine.AppSecret == "") {
mw.NewErrormationTips("提示" , "请填写 AppSecret")
return
}
//去空格
engine.BaiduEngine.AppId = strings.TrimSpace(engine.BaiduEngine.AppId)
engine.BaiduEngine.AppSecret = strings.TrimSpace(engine.BaiduEngine.AppSecret)
//获取缓存数据
localData := Translate.GetCacheTranslateEngineListData()
//生成id
lens := len(localData.Engine)
if lens == 0 {
engine.Id = 1
} else {
engine.Id = localData.Engine[ lens - 1 ].Id + 1
}
//追加数据
localData.Engine = append(localData.Engine , engine)
//缓存数据
Translate.SetCacheTranslateEngineListData(localData)
//调用回调
confirmCall()
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
// 运行 新建[腾讯云]翻译引擎 Dialog
func(mw *MyMainWindow) RunTengxunyunTranslateEngineSetingDialog(owner walk.Form , confirmCall func()) {
var engine *TranslateEngineStruct
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
engine = new(TranslateEngineStruct)
//默认值
engine.Supplier = TRANSLATE_SUPPLIER_TENGXUNYUN
Dialog{
AssignTo: &dlg,
Title: "新建翻译引擎(腾讯云)",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "engine",
DataSource: engine,
ErrorPresenter: ToolTipErrorPresenter{},
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "名称/别名:",
},
LineEdit{
Text: Bind("Alias"),
},
Label{
Text: "SecretId:",
},
LineEdit{
Text: Bind("TengxunyunEngine.SecretId"),
},
Label{
Text: "SecretKey:",
},
LineEdit{
Text: Bind("TengxunyunEngine.SecretKey"),
},
TextLabel{
ColumnSpan: 2,
Row: 5,
Text: "\r\n说明:\r\n请填写 “腾讯云” 创建的子用户密钥",
TextColor:walk.RGB(190 , 190 , 190),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "确定新增",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Print(err)
return
}
//参数验证
if (engine.Alias == "") {
mw.NewErrormationTips("提示" , "请填写 名称/别名")
return
}
if (engine.TengxunyunEngine.SecretId == "") {
mw.NewErrormationTips("提示" , "请填写 SecretId")
return
}
if (engine.TengxunyunEngine.SecretKey == "") {
mw.NewErrormationTips("提示" , "请填写 SecretKey")
return
}
//去空格
engine.TengxunyunEngine.SecretId = strings.TrimSpace(engine.TengxunyunEngine.SecretId)
engine.TengxunyunEngine.SecretKey = strings.TrimSpace(engine.TengxunyunEngine.SecretKey)
//获取缓存数据
localData := Translate.GetCacheTranslateEngineListData()
//生成id
lens := len(localData.Engine)
if lens == 0 {
engine.Id = 1
} else {
engine.Id = localData.Engine[ lens - 1 ].Id + 1
}
//追加数据
localData.Engine = append(localData.Engine , engine)
//缓存数据
Translate.SetCacheTranslateEngineListData(localData)
//调用回调
confirmCall()
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
//运行 Oss对象存储配置 Dialog
func (mw *MyMainWindow) RunObjectStorageSetingDialog(owner walk.Form) {
var oss *AliyunOssCache
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
oss = Oss.GetCacheAliyunOssData() //查询缓存数据
Dialog{
AssignTo: &dlg,
Title: "OSS对象存储设置",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "oss",
DataSource: oss,
ErrorPresenter: ToolTipErrorPresenter{},
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
Text: "Endpoint:",
},
LineEdit{
Text: Bind("Endpoint"),
},
Label{
Text: "AccessKeyId:",
},
LineEdit{
Text: Bind("AccessKeyId"),
},
Label{
Text: "AccessKeySecret:",
},
LineEdit{
Text: Bind("AccessKeySecret"),
},
Label{
Text: "BucketName:",
},
LineEdit{
Text: Bind("BucketName"),
},
Label{
Text: "BucketDomain:",
},
LineEdit{
Text: Bind("BucketDomain"),
},
Label{
ColumnSpan: 2,
Text: "说明:\r\n“OSS对象存储”目前使用的是阿里云服务,请填写相关的服务配置。",
TextColor:walk.RGB(190 , 190 , 190),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "保存",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Fatal(err)
return
}
//参数验证
if (oss.Endpoint == "") {
mw.NewInformationTips("提示" , "请填写 Endpoint")
return
}
if (oss.AccessKeyId == "") {
mw.NewInformationTips("提示" , "请填写 AccessKeyId")
return
}
if (oss.AccessKeySecret == "") {
mw.NewInformationTips("提示" , "请填写 AccessKeySecret")
return
}
if (oss.BucketName == "") {
mw.NewInformationTips("提示" , "请填写 BucketName")
return
}
if (oss.BucketDomain == "") {
mw.NewInformationTips("提示" , "请填写 BucketDomain")
return
}
//去空格
oss.Endpoint = strings.TrimSpace(oss.Endpoint)
oss.AccessKeyId = strings.TrimSpace(oss.AccessKeyId)
oss.AccessKeySecret = strings.TrimSpace(oss.AccessKeySecret)
oss.BucketName = strings.TrimSpace(oss.BucketName)
oss.BucketDomain = strings.TrimSpace(oss.BucketDomain)
//设置缓存
Oss.SetCacheAliyunOssData(oss)
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
//运行 语气词过滤设置 Dialog
func (mw *MyMainWindow) RunGlobalFilterSetingDialog (owner walk.Form , historyWords string , confirmCall func(words string)) {
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
var tmpData = new(AppFilterSetings)
tmpData.GlobalFilter.Words = historyWords
Dialog{
AssignTo: &dlg,
Title: "全局语气词过滤设置",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "filter",
DataSource: tmpData,
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
ColumnSpan: 1,
Text: "过滤语气词:",
},
TextEdit{
ColumnSpan: 1,
MinSize: Size{150, 80},
Text: Bind("GlobalFilter.Words"),
VScroll: true,
},
Label{
ColumnSpan: 2,
Text: "说明:\r\n“过滤语气词” 支持设置多个,请保持每个词语都单独一行",
TextColor:walk.RGB(190 , 190 , 190),
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "保存",
OnClicked: func() {
if err := db.Submit(); err != nil {
log.Fatal(err)
return
}
confirmCall(tmpData.GlobalFilter.Words)
//参数验证
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run( owner )
}
type DefinedRuleTableRows struct {
Id int
Target string //目标规则
Replace string //替换规则
Way int //规则类型
}
type DefinedRuleTableModel struct {
walk.SortedReflectTableModelBase
maxIndex int
items []*DefinedRuleTableRows
}
func NewDefinedRuleTableModel () *DefinedRuleTableModel {
t := new(DefinedRuleTableModel)
return t
}
func (m *DefinedRuleTableModel) Items() interface{} {
return m.items
}
func (m *DefinedRuleTableModel) AddRow (row *DefinedRuleTableRows) {
m.maxIndex++
row.Id = m.maxIndex;
m.items = append(m.items , row)
}
func (m *DefinedRuleTableModel) BatchDelRow (indexs []int) {
id := make([]int , 0)
for row_i , row_v := range m.items {
for _ , op_v := range indexs {
if row_i == op_v {
id = append(id , row_v.Id)
}
}
}
for _ , vid := range id {
m.DelRow(vid)
}
}
func (m *DefinedRuleTableModel) GetRowIndex (index int) *DefinedRuleTableRows {
tmp := new(DefinedRuleTableRows)
for row_i , row_v := range m.items {
if row_i == index {
tmp = row_v
break
}
}
return tmp
}
func (m *DefinedRuleTableModel) DelRow (id int) {
t := len(m.items)
for row_i , row_v := range m.items {
if row_v.Id == id {
if row_i == 0 {
if t <= 1 {
m.items = make([]*DefinedRuleTableRows , 0)
} else {
m.items = m.items[row_i+1:]
}
} else if row_i+1 >= t {
m.items = m.items[:row_i]
} else {
m.items = append(m.items[:row_i] , m.items[row_i+1:]...)
}
break
}
}
}
func (tv *DefinedRuleTableModel) SetAndInitFilterRules (rules []*AppDefinedFilterRule) {
//初始化
tv.maxIndex = 0
tv.items = make([]*DefinedRuleTableRows , 0)
for _ , v := range rules {
tv.maxIndex++
tv.items = append(tv.items , &DefinedRuleTableRows{
Id:tv.maxIndex,
Target:v.Target,
Replace:v.Replace,
Way:v.Way,
})
}
}
func (tv *DefinedRuleTableModel) GetFilterRuleResult () []*AppDefinedFilterRule {
result := make([]*AppDefinedFilterRule , 0)
for _ , v := range tv.items {
result = append(result , &AppDefinedFilterRule{
Target:v.Target,
Replace:v.Replace,
Way:v.Way,
})
}
return result
}
//运行 自定义过滤设置 Dialog
func (mw *MyMainWindow) RunDefinedFilterSetingDialog (owner walk.Form , historyRule []*AppDefinedFilterRule , confirmCall func(rule []*AppDefinedFilterRule)) {
var dlg *walk.Dialog
var acceptPB, cancelPB *walk.PushButton
var tv *walk.TableView
tableModel := NewDefinedRuleTableModel()
tableModel.SetAndInitFilterRules(historyRule)
var currentIndexs []int = make([]int , 0) //选择的项
Dialog{
AssignTo: &dlg,
Title: "自定义过滤设置",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
MinSize: Size{600, 500},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
PushButton{
Text: "新增规则",
OnClicked: func() {
copyRow := new(DefinedRuleTableRows)
if len(currentIndexs) == 1 {
copyRow = tableModel.GetRowIndex(currentIndexs[0])
}
mw.RunNewDefinedFilterRuleDialog(mw , copyRow , func(rule *DefinedRuleTableRows) {
tableModel.AddRow(rule)
tv.SetModel(tableModel)
})
},
},
PushButton{
Text: "删除规则",
OnClicked: func() {
if len(currentIndexs) < 1 {
mw.NewErrormationTips("错误" , "请选择操作的对象")
return
}
tableModel.BatchDelRow(currentIndexs)
tv.SetModel(tableModel)
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
TableView{
Name:"tableView",
AssignTo: &tv,
AlternatingRowBG: true,
NotSortableByHeaderClick: true,
MultiSelection:true,
Columns: []TableViewColumn{
{Title: "编号", DataMember: "Id" , Width:90},
{Title: "类型", DataMember: "Way", Width:90 , FormatFunc: func(value interface{}) string {
switch v := value.(type) {
case int:
if v == FILTER_TYPE_STRING {
return "文本过滤"
}
if v == FILTER_TYPE_REGX {
return "正则过滤"
}
return ""
default:
return ""
}
}},
{Title: "目标规则", DataMember: "Target", Width:165},
{Title: "替换规则", DataMember: "Replace", Width:185},
},
Model: tableModel,
OnSelectedIndexesChanged: func() {
indexs := tv.SelectedIndexes()
if (len(indexs) > 0) {
currentIndexs = indexs
} else {
currentIndexs = []int{}
}
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
HSpacer{},
PushButton{
AssignTo: &acceptPB,
Text: "保存",
OnClicked: func() {
confirmCall(tableModel.GetFilterRuleResult())
//参数验证
dlg.Accept()
},
},
PushButton{
AssignTo: &cancelPB,
Text: "取消",
OnClicked: func() { dlg.Cancel() },
},
},
},
},
}.Run(owner)
}
//新建自定义过滤规则 Dialog
func (mw *MyMainWindow) RunNewDefinedFilterRuleDialog (owner walk.Form , copyRows *DefinedRuleTableRows , confirmCall func(rule *DefinedRuleTableRows)) {
var dlg *walk.Dialog
var db *walk.DataBinder
var acceptPB, cancelPB *walk.PushButton
var tmpData = new(DefinedRuleTableRows)
if copyRows.Id != 0 {
tmpData.Target = copyRows.Target
tmpData.Replace = copyRows.Replace
tmpData.Way = copyRows.Way
} else {
tmpData.Way = 1 //默认
}
Dialog{
AssignTo: &dlg,
Title: "新增自定义过滤规则",
Font:Font{Family: "微软雅黑", PointSize: 9},
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "defined",
DataSource: tmpData,
},
MinSize: Size{500, 300},
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{
ColumnSpan: 1,
Text: "目标规则:",
},
LineEdit{
ColumnSpan: 1,
MinSize: Size{Width:150},
Text: Bind("Target"),
},
Label{
ColumnSpan: 1,
Text: "替换规则:",
},
LineEdit{
ColumnSpan: 1,
MinSize: Size{Width:150},