chr
2025-03-04 3f62d18e4361cd1d7a49c126765d95b2ad9c8246
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
using log4net;
using PdmSwPlugin.Commmon.Util.UI;
using PdmSwPlugin.Common.Util;
using PdmSwPlugin.Common.Util.Http;
using PdmSwPlugin.PropertySetting.Interface;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using PdmSwPlugin.Common.Interface;
using PdmSwPlugin.Common;
using PdmSwPlugin.PropertySetting.Entity;
using PdmSwPlugin.PropertySetting.Panel;
using System.Windows.Threading;
using PdmSwPlugin.Common.Setting;
using System.IO;
using System.Runtime.InteropServices;
 
namespace PdmSwPlugin.PropertySetting
{
 
    /// <summary>
    /// CommonSettingControl.xaml 的交互逻辑
    /// </summary>
    [PdmSwPlugin(Title = "属性设置")]
    public partial class SettingControl : UserControl, ISwAppSetter, INotifyPropertyChanged
        , IActiveDocChangeHandler, ITabControlSelectionChangeHandler
    {
        private static ILog Logger = LogManager.GetLogger("PropertySetting");
 
        #region 不能公用的东西,真有你的啊C#
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
        public void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
        {
            old = @new;
            if (propertyName != null)
            {
                RaisePropertyChanged(propertyName);
            }
        }
        #endregion
 
        public readonly Dictionary<string, UserControl> controlCache = new Dictionary<string, UserControl>();
 
        #region 属性
        public SldWorks SwApp { get; private set; }
        /// <summary>
        /// 激活的文档
        /// </summary>
        public ModelDoc2 activeDoc { set; get; }
        /// <summary>
        /// 上次读取的文档
        /// </summary>
        public ModelDoc2 LastReadDoc { get; set; }
        /// <summary>
        /// 当前读取的文档
        /// </summary>
        public ModelDoc2 ReadDoc { get; set; }
        /// <summary>
        /// 当前读取的组件
        /// </summary>
        public Component2 ReadComponent { get; set; }
 
        private HttpClient Client { get; set; }
 
        Dictionary<string, JgjType> settings;
        #endregion
 
        #region UI绑定
        private string _readDocPath;
        public string ReadDocPath
        {
            get => _readDocPath;
            set => RaiseAndSetIfChanged(ref _readDocPath, value);
        }
        #endregion
        private HttpClientCreator clientCreator { get; set; }
 
        private UserControl ActiveOpter { get; set; }
 
        public SettingControl()
        {
            clientCreator = new HttpClientCreator(new HttpConfig(PluginSetting.Instance.BaseAddress));
            InitializeComponent();
            DataContext = this;
        }
 
        public SettingControl(SldWorks SwApp) : this()
        {
            this.SwApp = SwApp;
        }
 
        public void InitPropertyData()
        {
            if (Client == null)
            {
                Client = clientCreator.GetClient();
            }
            DefaultPanel defaultPanel = new DefaultPanel();
            controlCache.Add("default", defaultPanel);
 
            JgjPartPanel jgjPart = new JgjPartPanel();
            controlCache.Add("jgjPart", jgjPart);
 
            JgjModulePanel jgjModule = new JgjModulePanel();
            controlCache.Add("jgjModule", jgjModule);
 
            var stPart = new StandardPartPanel();
            controlCache.Add("standardPart", stPart);
 
            var stModule = new StandardModulePanel();
            controlCache.Add("standardModule", stModule);
            LoadComboxItemSource();
            Refresh_Click(null, null);
        }
 
        private void Jgj_SinglePropertyChanged(object sender, string name, object value)
        {
            // CustomPropertyUtil.SetCustomProperties(ReadDoc, name, (string)value);
        }
 
        /// <summary>
        /// 从服务器加载各种选项
        /// </summary>
        private void LoadComboxItemSource()
        {
            try
            {
                Result<Dictionary<string, JgjType>> res = Client.GetSyncAction<Dictionary<string, JgjType>>("design/rule/openApi/test");
                Dictionary<string, JgjType> datas = res.HandleResult();
                settings = datas;
                foreach (var key in controlCache.Keys)
                {
                    (controlCache[key] as IPropertyOpt).SetSettings(settings);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Request Jgj properties failed.", ex);
                this.Error($"请求加工件属性失败!{ex.Message}");
            }
        }
 
        private void UpdateActiveDoc()
        {
            if (activeDoc != null)
            {
                DetachDocNotify(activeDoc);
            }
 
            activeDoc = SwApp.ActiveDoc;
            if (activeDoc != null)
            {
                AttachDocNotify(activeDoc);
                int docType = activeDoc.GetType();
                if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
                {
                    activeDoc.ClearSelection2(true);
                }
            }
            UpdateUI(activeDoc);
        }
 
        /// <summary>
        /// 附加一些插件范围内的事件
        /// </summary>
        /// <param name="doc"></param>
        private void AttachDocNotify(ModelDoc2 doc)
        {
            int docType = doc.GetType();
            if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                AssemblyDoc ass = doc as AssemblyDoc;
                ass.UserSelectionPostNotify += Ass_UserSelectionPostNotify;
                ass.DestroyNotify2 += ActiveDocDestroyNotify2;
            }
            else if (docType == (int)swDocumentTypes_e.swDocPART)
            {
                PartDoc part = doc as PartDoc;
                part.DestroyNotify2 += ActiveDocDestroyNotify2;
            }
            else if (docType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                DrawingDoc draw = doc as DrawingDoc;
                draw.DestroyNotify2 += ActiveDocDestroyNotify2;
            }
        }
 
        /// <summary>
        /// 移除插件范围内的一些事件
        /// </summary>
        /// <param name="doc"></param>
        private void DetachDocNotify(ModelDoc2 doc)
        {
            try
            {
                int docType = doc.GetType();
                if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
                {
                    AssemblyDoc ass = doc as AssemblyDoc;
                    ass.UserSelectionPostNotify -= Ass_UserSelectionPostNotify;
                    ass.DestroyNotify2 -= ActiveDocDestroyNotify2;
                }
                else if (docType == (int)swDocumentTypes_e.swDocPART)
                {
                    PartDoc part = doc as PartDoc;
                    part.DestroyNotify2 -= ActiveDocDestroyNotify2;
                }
                else if (docType == (int)swDocumentTypes_e.swDocDRAWING)
                {
                    DrawingDoc draw = doc as DrawingDoc;
                    draw.DestroyNotify2 -= ActiveDocDestroyNotify2;
                }
            }
            catch (COMException e)
            {
                // 如果sw把不是装配体/零件体/工程图的文档关了,有时会报这个问题,留个日志不报错了
                Logger.Warn("COMObject detach event failed.", e);
                activeDoc = null;
            }
        }
 
        private int ActiveDocDestroyNotify2(int DestroyType)
        {
            if (activeDoc == null)
            {
                return 0;
            }
            DetachDocNotify(activeDoc);
            activeDoc = null;
            ReadComponent = null;
            UpdateUI(null);
            return 0;
        }
 
        public void UpdateUI(ModelDoc2 doc)
        {
            AlertSaveWindow();
            LastReadDoc = ReadDoc;
            ReadDoc = doc;
            Dispatcher.Invoke(() =>
            {
                SwitchVisiable();
                // LoadDocProperties();
            });
        }
 
        /// <summary>
        /// 判断是否需要弹窗提示保存
        /// </summary>
        public void AlertSaveWindow()
        {
            IPropertyOpt opt = ActiveOpter as IPropertyOpt;
            if (opt != null && opt.GetDocChanged())
            {
                // 历史文档直接重置
                string fullName = Path.GetFileName(ReadDocPath);
                if (NameUtil.IsHistoryDoc(fullName))
                {
                    opt.ResetProperty(out string errMsg);
                    return;
                }
 
                string Message = $"{fullName}属性发生变更,是否保存?";
                if (SwApp.SendMsgToUser2(Message, (int)swMessageBoxIcon_e.swMbWarning
                   , (int)swMessageBoxBtn_e.swMbYesNo) == (int)swMessageBoxResult_e.swMbHitYes)
                {
                    SaveDoc(true);
                }
                else
                {
                    opt.ResetProperty(out string errMsg);
                }
            }
        }
 
        private int Ass_UserSelectionPostNotify()
        {
            var swSelMgr = (SelectionMgr)activeDoc.SelectionManager;
            var i = swSelMgr.GetSelectedObjectCount2(-1);
            if (i > 0)
            {
                try
                {
                    Component2 component = swSelMgr.GetSelectedObjectsComponent4(1, -1);
                    ModelDoc2 doc = activeDoc;
                    ReadComponent = null;
                    if (component != null)
                    {
                        doc = component.IGetModelDoc();
                        ReadComponent = component;
                    }
                    UpdateUI(doc);
                }
                catch (Exception ex)
                {
                    Logger.Error("Ass Change Component Error.", ex);
                    this.Error($"刷新属性失败!{ex.Message}");
                }
            }
            return 1;
        }
 
        /// <summary>
        /// 根据激活的文档类型,变更属性可视
        /// </summary>
        private void SwitchVisiable()
        {
            HashSet<string> skipName = new HashSet<string> {
                NameConstant.materialCode
            };
 
            IPropertyOpt last = ActiveOpter as IPropertyOpt;
            string contentKey = "default";
            int? docType = ReadDoc?.GetType();
            UserControl control;
            IPropertyOpt newOne;
            Dictionary<string, string> properties;
            if (docType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                ReadDocPath = ReadDoc.GetPathName();
                contentKey = "default";
                control = controlCache[contentKey];
                newOne = control as IPropertyOpt;
                newOne.SetProperties(null, "当前不支持工程图", true, out _);
            }
            else if (docType == (int)swDocumentTypes_e.swDocPART)
            {
                ReadDocPath = ReadDoc.GetPathName();
                properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, null, skipName);
                string fileType = properties.Get(NameConstant.docType);
                /*if (fileType == "加工件" || fileType == "模组")
                {
                    contentKey = "jgjPart";
                }*/
                if (BomIniterHolder.Instance.IsJgj(ReadDoc))
                {
                    contentKey = "jgjPart";
                }
                else
                {
                    contentKey = "standardPart";
                }
                control = controlCache[contentKey];
                newOne = control as IPropertyOpt;
                newOne.SetProperties(ReadDoc, properties, true, out _);
            }
            else if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                ReadDocPath = ReadDoc.GetPathName();
                if (ReadDoc.IsOpenedViewOnly())
                {
                    contentKey = "default";
                    control = controlCache[contentKey];
                    newOne = control as IPropertyOpt;
                    newOne.SetProperties(null, "当前处于只读模式", true, out _);
                }
                else if (ReadDoc.IsOpenedReadOnly())
                {
                    contentKey = "default";
                    control = controlCache[contentKey];
                    newOne = control as IPropertyOpt;
                    newOne.SetProperties(null, "当前处于只读模式", true, out _);
                }
                else
                {
                    // !Equals(LastReadDoc, ReadDoc)
                    properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, null, skipName);
                    string fileType = properties.Get(NameConstant.docType);
                    /*if (fileType == "加工件" || fileType == "模组")
                    {
                        contentKey = "jgjPart";
                    }*/
                    if (BomIniterHolder.Instance.IsJgj(ReadDoc))
                    {
                        contentKey = "jgjModule";
                    }
                    else
                    {
                        contentKey = "standardModule";
                    }
                    control = controlCache[contentKey];
                    newOne = control as IPropertyOpt;
                    newOne.SetProperties(ReadDoc, properties, true, out _);
                }
            }
            else
            {
                contentKey = "default";
                control = controlCache[contentKey];
                newOne = control as IPropertyOpt;
 
                string PathName = ReadComponent?.GetPathName();
                if (PathName == null)
                {
                    ReadDocPath = "";
                    newOne.SetProperties(ReadDoc, "请打开一个文档", true, out _);
                }
                else
                {
                    ReadDocPath = PathName;
                    string name = Path.GetFileNameWithoutExtension(PathName);
                    newOne.SetProperties(ReadDoc, $"【{name}】未找到文档,请检查是否被压缩或轻量化", true, out _);
                }
            }
            if (last != null)
            {
                last.UpdateProperty -= Jgj_SinglePropertyChanged;
                last = null;
            }
            ActiveOpter = control;
            contentPanel.Children.Clear();
            newOne.UpdateProperty += Jgj_SinglePropertyChanged;
            contentPanel.Children.Add(control);
        }
 
        /// <summary>
        /// 根据激活的文档类型,变更属性可视
        /// </summary>
        private void SwitchVisiable2()
        {
            HashSet<string> skipName = new HashSet<string> {
                NameConstant.materialCode
            };
 
            IPropertyOpt last = ActiveOpter as IPropertyOpt;
            string contentKey = "default";
            int? docType = ReadDoc?.GetType();
            UserControl control;
            IPropertyOpt newOne;
            Dictionary<string, string> properties;
            if (docType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                ReadDocPath = ReadDoc.GetPathName();
 
                control = new DefaultPanel();
                newOne = control as IPropertyOpt;
                newOne.SetSettings(settings);
                newOne.SetProperties(null, "当前不支持工程图", true, out _);
            }
            else if (docType == (int)swDocumentTypes_e.swDocPART)
            {
                ReadDocPath = ReadDoc.GetPathName();
                properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, null, skipName);
                string fileType = properties.Get(NameConstant.docType);
                /*if (fileType == "加工件" || fileType == "模组")
                {
                    contentKey = "jgjPart";
                }*/
                if (BomIniterHolder.Instance.IsJgj(ReadDoc))
                {
                    control = new JgjPartPanel();
                }
                else
                {
                    control = new StandardPartPanel();
                }
                newOne = control as IPropertyOpt;
                newOne.SetSettings(settings);
                newOne.SetProperties(ReadDoc, properties, true, out _);
            }
            else if (docType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                ReadDocPath = ReadDoc.GetPathName();
                // !Equals(LastReadDoc, ReadDoc)
                properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, null, skipName);
                string fileType = properties.Get(NameConstant.docType);
                /*if (fileType == "加工件" || fileType == "模组")
                {
                    contentKey = "jgjPart";
                }*/
                if (BomIniterHolder.Instance.IsJgj(ReadDoc))
                {
                    control = new JgjModulePanel();
                }
                else
                {
                    control = new StandardModulePanel();
                }
                newOne = control as IPropertyOpt;
                newOne.SetSettings(settings);
                newOne.SetProperties(ReadDoc, properties, true, out _);
            }
            else
            {
                control = new DefaultPanel();
                newOne = control as IPropertyOpt;
 
                string PathName = ReadComponent?.GetPathName();
                if (PathName == null)
                {
                    ReadDocPath = "";
                    newOne.SetSettings(settings);
                    newOne.SetProperties(ReadDoc, "请打开一个文档", true, out _);
                }
                else
                {
                    ReadDocPath = PathName;
                    string name = Path.GetFileNameWithoutExtension(PathName);
                    newOne.SetSettings(settings);
                    newOne.SetProperties(ReadDoc, $"【{name}】未找到文档,请检查是否被压缩或轻量化", true, out _);
                }
            }
            if (last != null)
            {
                last.UpdateProperty -= Jgj_SinglePropertyChanged;
                last = null;
            }
            ActiveOpter = control;
            contentPanel.Children.Clear();
            newOne.UpdateProperty += Jgj_SinglePropertyChanged;
            contentPanel.Children.Add(control);
        }
 
        /// <summary>
        /// 从激活的文档中读取参数
        /// </summary>
        private void LoadDocProperties()
        {
            IPropertyOpt opt = ActiveOpter as IPropertyOpt;
            string ErrMsg = null;
            if (ReadDoc == null)
            {
                string PathName = ReadComponent?.GetPathName();
                if (PathName == null)
                {
                    ReadDocPath = "";
                    opt.SetProperties(ReadDoc, "请打开一个文档", true, out ErrMsg);
                    return;
                }
                ReadDocPath = PathName;
                string name = Path.GetFileNameWithoutExtension(PathName);
                opt.SetProperties(ReadDoc, $"【{name}】未找到文档,请检查是否被压缩或轻量化", true, out ErrMsg);
                return;
            }
            int docType = ReadDoc.GetType();
            ReadDocPath = ReadDoc.GetPathName();
            if (docType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                opt.SetProperties(null, "当前不支持工程图", true, out ErrMsg);
                return;
            }
            HashSet<string> skipName = new HashSet<string> {
                NameConstant.materialCode
            };
            Dictionary<string, string> properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, null, skipName);
            opt.SetProperties(ReadDoc, properties, !Equals(LastReadDoc, ReadDoc), out ErrMsg);
        }
 
        private void ClearDocProperties()
        {
            IPropertyOpt opt = ActiveOpter as IPropertyOpt;
            opt.ClearAllProperties(out string ErrMsg);
        }
 
        /// <summary>
        /// 将属性设置进文档,注意,并没有保存
        /// </summary>
        /// <param name="doc">文档</param>
        private void SetDocProperty(ModelDoc2 doc, Dictionary<string, string> props)
        {
            CustomPropertyUtil.SetCustomProperties(doc, props);
        }
 
        public void SetSwApp(SldWorks SwApp)
        {
            this.SwApp = SwApp;
        }
 
 
        private void SaveDoc(bool qiaoqiaode)
        {
 
            int errors = 0, warnings = 0;
 
            if ((ActiveOpter as IPropertyOpt).SaveDoc(ref errors, ref warnings))
            {
                // if (!qiaoqiaode) this.Info("保存成功");
            }
        }
 
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (ReadDoc == null)
            {
                return;
            }
            SaveDoc(false);
        }
 
        public void RefreshData()
        {
            MaskAdorner.ShowMask(content, "属性加载中,请稍候...");
            Task.Run(() =>
            {
                try
                {
                    UpdateActiveDoc();
                }
                catch (COMException come)
                {
                    // 频繁关闭会抛出这个异常,不管了
                    Logger.Warn("Read property COMObject failed.", come);
                }
                catch (Exception ex)
                {
                    Logger.Error($"读取参数异常,文件:[{ReadDocPath}]!", ex);
                    this.Error($"读取参数异常:{ex.Message}");
                }
                finally
                {
                    MaskAdorner.HideMask(content);
                }
            });
        }
 
        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            RefreshData();
        }
 
        private void LoadComboBox_Click(object sender, RoutedEventArgs e)
        {
            MaskAdorner.ShowMask(content, "加载MES设置,请稍候...");
            Task.Run(() =>
            {
                try
                {
                    LoadComboxItemSource();
                }
                finally
                {
                    MaskAdorner.HideMask(content);
                }
            });
        }
 
        private void PropertySettingControl_Initialized(object sender, EventArgs e)
        {
            InitPropertyData();
        }
 
        /// <summary>
        /// 激活的文档变更触发
        /// </summary>
        /// <param name="lastDoc"></param>
        /// <param name="doc"></param>
        /// <param name="comp"></param>
        public void OnSwActiveDocChange(ModelDoc2 lastDoc, ModelDoc2 doc, Component2 comp)
        {
            // CurrentChanged();
            RefreshData();
        }
 
        public void OnSwActiveDocSaved(ModelDoc2 doc, Component2 comp)
        {
            // 读取文件,设置参数
            // LoadDocProperties();
        }
 
        public void OnCustomPropertyChange(string propName, string Configuration, string oldValue, string NewValue, int valueType)
        {
            if (oldValue == NewValue)
            {
                return;
            }
            IPropertyOpt opt = ActiveOpter as IPropertyOpt;
            opt.UpdateSingleProperty(propName, NewValue);
        }
 
        public void OnDocDestroy(ModelDoc2 doc)
        {
 
        }
 
        public void AfterDocDestroy()
        {
 
        }
 
        public void OnTabControlSelectionChange(object sender, SelectionChangedEventArgs e)
        {
            if (e.RemovedItems == null)
            {
                return;
            }
 
            foreach (object obj in e.RemovedItems)
            {
                if (obj is TabItem item)
                {
                    if (item.Content == this)
                    {
                        AlertSaveWindow();
                        break;
                    }
                }
                else
                {
                    return;
                }
            }
        }
 
        public void DisabledHandler()
        {
            
        }
    }
}