using PDF_Master.Helper; using PDF_Master.Model.SettingsDialog; using PDF_Master.Properties; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Master.ViewModels.Dialog { public class SettingsDialogViewModel : BindableBase, IDialogAware { public string Title => ""; public event Action RequestClose; #region 文案 private string _Settings_Preferences = ""; public string Settings_Preferences { get { return _Settings_Preferences; } set { SetProperty(ref _Settings_Preferences, value); } } private string _Settings_General = ""; public string Settings_General { get { return _Settings_General; } set { SetProperty(ref _Settings_General, value); } } private string _Settings_Display = ""; public string Settings_Display { get { return _Settings_Display; } set { SetProperty(ref _Settings_Display, value); } } private string _Settings_Annotation = ""; public string Settings_Annotation { get { return _Settings_Annotation; } set { SetProperty(ref _Settings_Annotation, value); } } private string _Settings_General_Documents = ""; public string Settings_General_Documents { get { return _Settings_General_Documents; } set { SetProperty(ref _Settings_General_Documents, value); } } private string _Settings_General_Open = ""; public string Settings_General_Open { get { return _Settings_General_Open; } set { SetProperty(ref _Settings_General_Open, value); } } private string _Settings_General_Restore = ""; public string Settings_General_Restore { get { return _Settings_General_Restore; } set { SetProperty(ref _Settings_General_Restore, value); } } private string _Settings_General_Maximum = ""; public string Settings_General_Maximum { get { return _Settings_General_Maximum; } set { SetProperty(ref _Settings_General_Maximum, value); } } private string _Settings_General_Auto = ""; public string Settings_General_Auto { get { return _Settings_General_Auto; } set { SetProperty(ref _Settings_General_Auto, value); } } private string _Settings_General_Close = ""; public string Settings_General_Close { get { return _Settings_General_Close; } set { SetProperty(ref _Settings_General_Close, value); } } private string _Settings_General_ASave = ""; public string Settings_General_ASave { get { return _Settings_General_ASave; } set { SetProperty(ref _Settings_General_ASave, value); } } private string _Settings_General_Savedirectly = ""; public string Settings_General_Savedirectly { get { return _Settings_General_Savedirectly; } set { SetProperty(ref _Settings_General_Savedirectly, value); } } private string _Settings_General_Author = ""; public string Settings_General_Author { get { return _Settings_General_Author; } set { SetProperty(ref _Settings_General_Author, value); } } private string _Settings_Display_Default = ""; public string Settings_Display_Default { get { return _Settings_Display_Default; } set { SetProperty(ref _Settings_Display_Default, value); } } private string _Settings_Display_Page = ""; public string Settings_Display_Page { get { return _Settings_Display_Page; } set { SetProperty(ref _Settings_Display_Page, value); } } private string _Settings_Display_Singlepage = ""; public string Settings_Display_Singlepage { get { return _Settings_Display_Singlepage; } set { SetProperty(ref _Settings_Display_Singlepage, value); } } private string _Settings_Display_Singlepagecon = ""; public string Settings_Display_Singlepagecon { get { return _Settings_Display_Singlepagecon; } set { SetProperty(ref _Settings_Display_Singlepagecon, value); } } private string _Settings_Display_Twopage = ""; public string Settings_Display_Twopage { get { return _Settings_Display_Twopage; } set { SetProperty(ref _Settings_Display_Twopage, value); } } private string _Settings_Display_Twopagecon = ""; public string Settings_Display_Twopagecon { get { return _Settings_Display_Twopagecon; } set { SetProperty(ref _Settings_Display_Twopagecon, value); } } private string _Settings_Display_Bookmode = ""; public string Settings_Display_Bookmode { get { return _Settings_Display_Bookmode; } set { SetProperty(ref _Settings_Display_Bookmode, value); } } private string _Settings_Display_Bookmodecon = ""; public string Settings_Display_Bookmodecon { get { return _Settings_Display_Bookmodecon; } set { SetProperty(ref _Settings_Display_Bookmodecon, value); } } private string _Settings_Display_Zoom = ""; public string Settings_Display_Zoom { get { return _Settings_Display_Zoom; } set { SetProperty(ref _Settings_Display_Zoom, value); } } private string _Settings_Display_Fitwidth = ""; public string Settings_Display_Fitwidth { get { return _Settings_Display_Fitwidth; } set { SetProperty(ref _Settings_Display_Fitwidth, value); } } private string _Settings_Display_Fitpage = ""; public string Settings_Display_Fitpage { get { return _Settings_Display_Fitpage; } set { SetProperty(ref _Settings_Display_Fitpage, value); } } private string _Settings_Display_Actualsize = ""; public string Settings_Display_Actualsize { get { return _Settings_Display_Actualsize; } set { SetProperty(ref _Settings_Display_Actualsize, value); } } private string _Settings_Display_LeftPanel = ""; public string Settings_Display_LeftPanel { get { return _Settings_Display_LeftPanel; } set { SetProperty(ref _Settings_Display_LeftPanel, value); } } private string _Settings_Display_Collapse = ""; public string Settings_Display_Collapse { get { return _Settings_Display_Collapse; } set { SetProperty(ref _Settings_Display_Collapse, value); } } private string _Settings_Display_Remember = ""; public string Settings_Display_Remember { get { return _Settings_Display_Remember; } set { SetProperty(ref _Settings_Display_Remember, value); } } private string _Settings_Display_Show = ""; public string Settings_Display_Show { get { return _Settings_Display_Show; } set { SetProperty(ref _Settings_Display_Show, value); } } private string _Settings_Display_Properties = ""; public string Settings_Display_Properties { get { return _Settings_Display_Properties; } set { SetProperty(ref _Settings_Display_Properties, value); } } private string _Settings_Display_Display = ""; public string Settings_Display_Display { get { return _Settings_Display_Display; } set { SetProperty(ref _Settings_Display_Display, value); } } private string _Settings_Display_Auto = ""; public string Settings_Display_Auto { get { return _Settings_Display_Auto; } set { SetProperty(ref _Settings_Display_Auto, value); } } private string _Settings_Display_Manually = ""; public string Settings_Display_Manually { get { return _Settings_Display_Manually; } set { SetProperty(ref _Settings_Display_Manually, value); } } private string _Settings_Display_Background = ""; public string Settings_Display_Background { get { return _Settings_Display_Background; } set { SetProperty(ref _Settings_Display_Background, value); } } private string _Settings_Display_Normal = ""; public string Settings_Display_Normal { get { return _Settings_Display_Normal; } set { SetProperty(ref _Settings_Display_Normal, value); } } private string _Settings_Display_Full = ""; public string Settings_Display_Full { get { return _Settings_Display_Full; } set { SetProperty(ref _Settings_Display_Full, value); } } private string _Settings_Display_Highlight = ""; public string Settings_Display_Highlight { get { return _Settings_Display_Highlight; } set { SetProperty(ref _Settings_Display_Highlight, value); } } private string _Settings_Annotation_Annotation = ""; public string Settings_Annotation_Annotation { get { return _Settings_Annotation_Annotation; } set { SetProperty(ref _Settings_Annotation_Annotation, value); } } private string _Settings_Annotation_Highlight = ""; public string Settings_Annotation_Highlight { get { return _Settings_Annotation_Highlight; } set { SetProperty(ref _Settings_Annotation_Highlight, value); } } private string _Settings_Annotation_Underline = ""; public string Settings_Annotation_Underline { get { return _Settings_Annotation_Underline; } set { SetProperty(ref _Settings_Annotation_Underline, value); } } private string _Settings_Annotation_Strikethrough = ""; public string Settings_Annotation_Strikethrough { get { return _Settings_Annotation_Strikethrough; } set { SetProperty(ref _Settings_Annotation_Strikethrough, value); } } private string _Settings_Annotation_Freehand = ""; public string Settings_Annotation_Freehand { get { return _Settings_Annotation_Freehand; } set { SetProperty(ref _Settings_Annotation_Freehand, value); } } private string _Settings_Annotation_TextBox = ""; public string Settings_Annotation_TextBox { get { return _Settings_Annotation_TextBox; } set { SetProperty(ref _Settings_Annotation_TextBox, value); } } private string _Settings_Annotation_StickyNote = ""; public string Settings_Annotation_StickyNote { get { return _Settings_Annotation_StickyNote; } set { SetProperty(ref _Settings_Annotation_StickyNote, value); } } private string _Settings_Annotation_RectangleBorder = ""; public string Settings_Annotation_RectangleBorder { get { return _Settings_Annotation_RectangleBorder; } set { SetProperty(ref _Settings_Annotation_RectangleBorder, value); } } private string _Settings_Annotation_CircleBorder = ""; public string Settings_Annotation_CircleBorder { get { return _Settings_Annotation_CircleBorder; } set { SetProperty(ref _Settings_Annotation_CircleBorder, value); } } private string _Settings_Annotation_Line = ""; public string Settings_Annotation_Line { get { return _Settings_Annotation_Line; } set { SetProperty(ref _Settings_Annotation_Line, value); } } private string _Settings_Annotation_RectangleFill = ""; public string Settings_Annotation_RectangleFill { get { return _Settings_Annotation_RectangleFill; } set { SetProperty(ref _Settings_Annotation_RectangleFill, value); } } private string _Settings_Annotation_CircleFill = ""; public string Settings_Annotation_CircleFill { get { return _Settings_Annotation_CircleFill; } set { SetProperty(ref _Settings_Annotation_CircleFill, value); } } private string _Settings_Annotation_Text = ""; public string Settings_Annotation_Text { get { return _Settings_Annotation_Text; } set { SetProperty(ref _Settings_Annotation_Text, value); } } private string T_settings_Annotation_Font = ""; public string T_Settings_Annotation_Font { get { return T_settings_Annotation_Font; } set { SetProperty(ref T_settings_Annotation_Font, value); } } private string _Settings_ResetAll = ""; public string Settings_ResetAll { get { return _Settings_ResetAll; } set { SetProperty(ref _Settings_ResetAll, value); } } private string _Settings_Reset = ""; public string Settings_Reset { get { return _Settings_Reset; } set { SetProperty(ref _Settings_Reset, value); } } private string _Settings_Display_DefaultV = ""; public string Settings_Display_DefaultV { get { return _Settings_Display_DefaultV; } set { SetProperty(ref _Settings_Display_DefaultV, value); } } private void InitString() { Settings_Display_DefaultV = App.MainPageLoader.GetString("Settings_Display_DefaultV"); Settings_Annotation_CircleFill = App.MainPageLoader.GetString("Settings_Annotation_CircleFill"); Settings_Annotation_Freehand = App.MainPageLoader.GetString("Settings_Annotation_Freehand"); Settings_Annotation_TextBox = App.MainPageLoader.GetString("Settings_Annotation_TextBox"); Settings_Annotation_Line = App.MainPageLoader.GetString("Settings_Annotation_Line"); Settings_Annotation_StickyNote = App.MainPageLoader.GetString("Settings_Annotation_StickyNote"); Settings_Annotation_RectangleFill = App.MainPageLoader.GetString("Settings_Annotation_RectangleFill"); Settings_Annotation_RectangleBorder = App.MainPageLoader.GetString("Settings_Annotation_RectangleBorder"); Settings_Annotation_CircleBorder = App.MainPageLoader.GetString("Settings_Annotation_CircleBorder"); Settings_Annotation_Text = App.MainPageLoader.GetString("Settings_Annotation_Text"); Settings_Reset = App.MainPageLoader.GetString("Settings_Reset"); Settings_ResetAll = App.MainPageLoader.GetString("Settings_ResetAll"); Settings_Annotation_Strikethrough = App.MainPageLoader.GetString("Settings_Annotation_Strikethrough"); Settings_Annotation_Underline = App.MainPageLoader.GetString("Settings_Annotation_Underline"); Settings_Annotation_Highlight = App.MainPageLoader.GetString("Settings_Annotation_Highlight"); Settings_Annotation_Annotation = App.MainPageLoader.GetString("Settings_Annotation_Annotation"); Settings_Display_Highlight = App.MainPageLoader.GetString("Settings_Display_Highlight"); Settings_Display_Collapse = App.MainPageLoader.GetString("Settings_Display_Collapse"); Settings_Display_Fitwidth = App.MainPageLoader.GetString("Settings_Display_Fitwidth"); Settings_General_Open = App.MainPageLoader.GetString("Settings_General_Open"); Settings_General_Documents = App.MainPageLoader.GetString("Settings_General_Documents"); Settings_Annotation = App.MainPageLoader.GetString("Settings_Annotation"); Settings_Preferences = App.MainPageLoader.GetString("Settings_Preferences"); Settings_General = App.MainPageLoader.GetString("Settings_General"); Settings_Display = App.MainPageLoader.GetString("Settings_Display"); Settings_General_Restore = App.MainPageLoader.GetString("Settings_General_Restore"); Settings_General_Maximum = App.MainPageLoader.GetString("Settings_General_Maximum"); Settings_General_Auto = App.MainPageLoader.GetString("Settings_General_Auto"); Settings_General_Close = App.MainPageLoader.GetString("Settings_General_Close"); Settings_General_ASave = App.MainPageLoader.GetString("Settings_General_ASave"); Settings_General_Savedirectly = App.MainPageLoader.GetString("Settings_General_Savedirectly"); Settings_General_Author = App.MainPageLoader.GetString("Settings_General_Author"); Settings_Display_Default = App.MainPageLoader.GetString("Settings_Display_Default"); Settings_Display_Page = App.MainPageLoader.GetString("Settings_Display_Page"); Settings_Display_Singlepage = App.MainPageLoader.GetString("Settings_Display_Singlepage"); Settings_Display_Singlepagecon = App.MainPageLoader.GetString("Settings_Display_Singlepagecon"); Settings_Display_Twopage = App.MainPageLoader.GetString("Settings_Display_Twopage"); Settings_Display_Fitpage = App.MainPageLoader.GetString("Settings_Display_Fitpage"); Settings_Display_Twopagecon = App.MainPageLoader.GetString("Settings_Display_Twopagecon"); Settings_Display_Bookmode = App.MainPageLoader.GetString("Settings_Display_Bookmode"); Settings_Display_Bookmodecon = App.MainPageLoader.GetString("Settings_Display_Bookmodecon"); Settings_Display_Zoom = App.MainPageLoader.GetString("Settings_Display_Zoom"); Settings_Display_Actualsize = App.MainPageLoader.GetString("Settings_Display_Actualsize"); Settings_Display_LeftPanel = App.MainPageLoader.GetString("Settings_Display_LeftPanel"); Settings_Display_Properties = App.MainPageLoader.GetString("Settings_Display_Properties"); Settings_Display_Show = App.MainPageLoader.GetString("Settings_Display_Show"); Settings_Display_Display = App.MainPageLoader.GetString("Settings_Display_Display"); Settings_Display_Remember = App.MainPageLoader.GetString("Settings_Display_Remember"); Settings_Display_Auto = App.MainPageLoader.GetString("Settings_Display_Auto"); Settings_Display_Normal = App.MainPageLoader.GetString("Settings_Display_Normal"); Settings_Display_Background = App.MainPageLoader.GetString("Settings_Display_Background"); Settings_Display_Manually = App.MainPageLoader.GetString("Settings_Display_Manually"); Settings_Display_Full = App.MainPageLoader.GetString("Settings_Display_Full"); T_Settings_Annotation_Font = App.MainPageLoader.GetString("Settings_Annotation_Annotation_Font"); } #endregion public AnnotateModel Annote { get; set; } public DescriptionModel Descript { get; set; } public InitialVIewModel View { get; set; } public DelegateCommand ResetCommand { get; set; } public DelegateCommand ResetAllCommand { get; set; } public ObservableCollection AnnoteFamilyList { get; set; } public ObservableCollection PageViewList { get; set; } public ObservableCollection ZoomModeList { get; set; } private int noteSelectedIndex; public int NoteSelectedIndex { get { return noteSelectedIndex; } set { SetProperty(ref noteSelectedIndex, value); switch (value) { case 0: Annote.AnchoredFamaily = "Courier"; break; case 1: Annote.AnchoredFamaily = "Helvetica"; break; case 2: Annote.AnchoredFamaily = "Times New Roman"; break; default: break; } } } private int annoteSelectedIndex; public int AnnoteSelectedIndex { get { return annoteSelectedIndex; } set { SetProperty(ref annoteSelectedIndex, value); switch (value) { case 0: Annote.TextFontFamaily = "Courier New"; break; case 1: Annote.TextFontFamaily = "Helvetica"; break; case 2: Annote.TextFontFamaily = "Times New Roman"; break; default: break; } } } private bool lefeSelected; public bool LeftSelected { get { return lefeSelected; } set { SetProperty(ref lefeSelected, value); if(value) { Annote.TextAlign = System.Windows.TextAlignment.Left; } } } private bool centerSelected; public bool CenterSelected { get { return centerSelected; } set { SetProperty(ref centerSelected, value); if (value) { Annote.TextAlign = System.Windows.TextAlignment.Center; } } } private bool rightSelected; public bool RightSelected { get { return rightSelected; } set { SetProperty(ref rightSelected, value); if (value) { Annote.TextAlign = System.Windows.TextAlignment.Right; } } } private bool strechSelected; public bool StrechSelected { get { return strechSelected; } set { SetProperty(ref strechSelected, value); if (value) { Annote.TextAlign = System.Windows.TextAlignment.Justify; } } } private int modeSelectedIndex; //选中的模式 public int ModeSelectedIndex { get { return modeSelectedIndex; } set { SetProperty(ref modeSelectedIndex, value); } } private bool isDefualtApp; /// /// 是否是默认软件 /// public bool IsDefualtApp { get { return isDefualtApp; } set { isDefualtApp = value; } } private bool isSetDefualtAppEnable; /// /// 是否允许设置默认软件 /// public bool IsSetDefualtAppEnable { get { return isSetDefualtAppEnable; } set { SetProperty(ref isSetDefualtAppEnable, value); } } private int pageViewSelectedIndex; public int PageViewSelctedIndex { get { return pageViewSelectedIndex; } set { SetProperty(ref pageViewSelectedIndex, value); View.PageView = (ComPDFKitViewer.ViewMode)(value+1); } } private int zoomModeSelectedIndex ; public int ZoomModeSelectedIndex { get { return zoomModeSelectedIndex; } set { SetProperty(ref zoomModeSelectedIndex, value); switch (value) { case 0: View.ZoomMode = ComPDFKitViewer.FitMode.FitWidth; break; case 1: View.ZoomMode = ComPDFKitViewer.FitMode.FitHeight; break; case 2: View.ZoomMode = ComPDFKitViewer.FitMode.FitSize; break; default: break; } } } private bool autoSaveEnable = true; /// /// 是否允许设置自动保存 /// 未付费用户 不进行自动保存 /// public bool AutoSaveEnable { get { return autoSaveEnable; } set { autoSaveEnable = value; } } public SettingsDialogViewModel() { InitString(); Annote = new AnnotateModel(); Descript = new DescriptionModel(); View = new InitialVIewModel(); PageViewList = new ObservableCollection(); AnnoteFamilyList = new ObservableCollection(); ZoomModeList = new ObservableCollection(); ResetAllCommand = new DelegateCommand(resetAll); ResetCommand = new DelegateCommand(reset); InitAnnoteFamily(); InitPageViews(); InitZoomMode(); //根据缓存还原下拉框 单选等 InitAnnote(); InitView(); //判断是否以管理员身份运行 IsSetDefualtAppEnable = Win32Helper.IsRunAsAdmin(); IsDefualtApp = Win32Helper.IsDefaultApp(); //未付费用户不进行自动保存 if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) { AutoSaveEnable = false; Descript.AutoSave = false; } } private void InitView() { //页面模式下拉框 PageViewSelctedIndex = (int)View.PageView - 1; //缩放模式下拉框 switch (View.ZoomMode) { case ComPDFKitViewer.FitMode.FitWidth: ZoomModeSelectedIndex = 0; break; case ComPDFKitViewer.FitMode.FitHeight: ZoomModeSelectedIndex = 1; break; case ComPDFKitViewer.FitMode.FitSize: zoomModeSelectedIndex = 2; break; case ComPDFKitViewer.FitMode.FitFree: //TODO: break; default: break; } } private void InitAnnote() { //注释对齐方式 switch (Annote.TextAlign) { case System.Windows.TextAlignment.Left: LeftSelected = true; break; case System.Windows.TextAlignment.Right: RightSelected = true; break; case System.Windows.TextAlignment.Center: CenterSelected = true; break; case System.Windows.TextAlignment.Justify: default: StrechSelected = true; break; } //文本注释字体 if(Annote.TextFontFamaily== "Courier New") { AnnoteSelectedIndex = 0; } else if(Annote.TextFontFamaily== "Helvetica") { AnnoteSelectedIndex = 1; } else { AnnoteSelectedIndex = 2; } //便签注释字体 if (Annote.AnchoredFamaily == "Courier") { NoteSelectedIndex = 0; } else if (Annote.AnchoredFamaily == "Helvetica") { NoteSelectedIndex = 1; } else { NoteSelectedIndex = 2; } } private void InitPageViews() { PageViewList.Clear(); PageViewList.Add(Settings_Display_Singlepage); PageViewList.Add(Settings_Display_Singlepagecon); PageViewList.Add(Settings_Display_Twopage); PageViewList.Add(Settings_Display_Twopagecon); PageViewList.Add(Settings_Display_Bookmode); PageViewList.Add(Settings_Display_Bookmodecon); } private void InitZoomMode() { ZoomModeList.Clear(); ZoomModeList.Add(Settings_Display_Fitwidth); ZoomModeList.Add(Settings_Display_Fitpage); ZoomModeList.Add(Settings_Display_Actualsize); } private void InitAnnoteFamily() { AnnoteFamilyList.Clear(); AnnoteFamilyList.Add("Courier New"); AnnoteFamilyList.Add("Arial"); AnnoteFamilyList.Add("Times New Roman"); } /// /// 重置 /// private void reset() { switch (ModeSelectedIndex) { case 0: Descript.Reset(); //未付费用户不进行自动保存 if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) { AutoSaveEnable = false; Descript.AutoSave = false; } break; case 1: View.Reset(); InitView(); break; case 2: Annote.Reset(); InitAnnote(); break; default: break; } } /// /// 全部重置 /// private void resetAll() { View.Reset(); Descript.Reset(); //未付费用户不进行自动保存 if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) { AutoSaveEnable = false; Descript.AutoSave = false; } Annote.Reset(); InitAnnote(); InitView(); } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { try { View.Save(); Annote.Save(); Descript.Save(); Win32Helper.RegisterDefaultApp(IsDefualtApp); Settings.Default.Save(); //弹窗已关闭调用再次关闭方法会异常 //RequestClose.Invoke(new DialogResult()); } catch { } } public void OnDialogOpened(IDialogParameters parameters) { } } }