liuaoran 2 лет назад
Родитель
Сommit
d90feb6fc5

+ 6 - 1
PDF Office/EventAggregators/EditToolsEvent.cs

@@ -43,6 +43,10 @@ namespace PDF_Office.EventAggregators
     {
     }
 
+    public class SaveBackgroundToTemplateListEvent : PubSubEvent<BackgroundInfo>
+    {
+    }
+
     public class ConfirmEditToolsBackgroundEvent : PubSubEvent<EnumColorOrFile>
     {
     }
@@ -67,7 +71,8 @@ namespace PDF_Office.EventAggregators
     {
     }
 
-    public class SaveBackgroundTemplate : PubSubEvent<BackgroundInfo>
+    public class SaveBackgroundTemplateEvent : PubSubEvent<EnumColorOrFile>
     {
     }
+     
 }

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -302,6 +302,7 @@
       <DesignTime>True</DesignTime>
       <AutoGen>True</AutoGen>
     </Compile>
+    <Compile Include="Settings.cs" />
     <Compile Include="ViewModels\BOTA\BookmarkContentViewModel.cs" />
     <Compile Include="ViewModels\Dialog\BOTA\AddBookmarkDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\BOTA\BookmarkInfoDialogViewModel.cs" />

+ 28 - 0
PDF Office/Settings.cs

@@ -0,0 +1,28 @@
+namespace PDF_Office.Properties {
+    
+    
+    // 通过此类可以处理设置类的特定事件: 
+    //  在更改某个设置的值之前将引发 SettingChanging 事件。
+    //  在更改某个设置的值之后将引发 PropertyChanged 事件。
+    //  在加载设置值之后将引发 SettingsLoaded 事件。
+    //  在保存设置值之前将引发 SettingsSaving 事件。
+    internal sealed partial class Settings {
+        
+        public Settings() {
+            // // 若要为保存和更改设置添加事件处理程序,请取消注释下列行: 
+            //
+            // this.SettingChanging += this.SettingChangingEventHandler;
+            //
+            // this.SettingsSaving += this.SettingsSavingEventHandler;
+            //
+        }
+        
+        private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
+            // 在此处添加用于处理 SettingChangingEvent 事件的代码。
+        }
+        
+        private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
+            // 在此处添加用于处理 SettingsSaving 事件的代码。
+        }
+    }
+}

+ 12 - 7
PDF Office/ViewModels/EditTools/Background/BackgroundContentViewModel.cs

@@ -24,8 +24,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         private ViewContentViewModel viewContentViewModel;
 
-        public string TemplateListName = "BackgroundTemplateListBaseContent";
-        public string CreateName = "BackgroundCreateBaseContent";
+        public string TemplateListBaseName = "BackgroundTemplateListBaseContent";
+        public string CreateBaseName = "BackgroundCreateBaseContent";
 
         public string CreateModColorName = "BackgroundCreateColorContent";
         public string CreateModFileName = "BackgroundCreateFileContent";
@@ -127,14 +127,19 @@ namespace PDF_Office.ViewModels.EditTools.Background
         {
             if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
             {
-                EnterSelectedContent(TemplateListName);
+                EnterSelectedContent(TemplateListBaseName);
             }
             else
             {
-                EnterSelectedContent(CreateName);
+                EnterSelectedContent(CreateBaseName);
             }
         }
 
+        public void SaveBackgroundTemplate()
+        {
+            
+        }
+
         public void SetCurrentCreateMod(string currentCreateModName)
         {
             if (currentCreateModName == CreateModColorName)
@@ -163,11 +168,11 @@ namespace PDF_Office.ViewModels.EditTools.Background
         {
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.PDFViewer, PDFViewer);
-            if (SelectedContentName == TemplateListName)
+            if (SelectedContentName == TemplateListBaseName)
             {
                 param.Add("CurrentCreateModName", CurrentCreateMod);
             }
-            else if (SelectedContentName == CreateName)
+            else if (SelectedContentName == CreateBaseName)
             {
                 param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
             }
@@ -187,7 +192,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
         {
             navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
-            EnterSelectedContent(TemplateListName);
+            EnterSelectedContent(TemplateListBaseName);
             EnterDocumentContent();
         }
 

+ 8 - 1
PDF Office/ViewModels/EditTools/Background/BackgroundCreateBaseContentViewModel.cs

@@ -70,7 +70,14 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void SaveToTemplateList()
         {
-
+            if (CurrentCreateModName == "BackgroundCreateColorContent")
+            {
+                this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(EnumColorOrFile.StatusColor);
+            }
+            if (CurrentCreateModName == "BackgroundCreateFileContent")
+            {
+                this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(EnumColorOrFile.StatusFile);
+            }
         }
 
         public void EnterTemplateList()

+ 25 - 0
PDF Office/ViewModels/EditTools/Background/BackgroundCreateColorContentViewModel.cs

@@ -4,12 +4,15 @@ using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Model.EditTools.Background;
+using PDF_Office.Properties;
+using PDFSettings;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Linq;
 using System.Text;
@@ -28,6 +31,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
         private string RedColorBtn = "RedColorBtn";
         private string GreenColorBtn = "GreenColorBtn";
 
+
+
         private List<string> _rotationList = new List<string>();
         public List<string> RotationList
         {
@@ -158,6 +163,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             BackgroundInfo.BackgroundVertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
             InitLocationButtonMatrix();
             eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Subscribe(ConfirmEditTools);
+            eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Subscribe(SaveBackgroundTemplate);
         }
 
         public void InitComponent()
@@ -240,10 +246,29 @@ namespace PDF_Office.ViewModels.EditTools.Background
         {
             if (enumColorOrFile == EnumColorOrFile.StatusColor)
             {
+
                 eventAggregator.GetEvent<SetBackgroundEvent>().Publish(BackgroundInfo);
             }
         }
 
+        public void SaveCurrentTemplate()
+        {
+                var backgroundItem = new BackgroundItem();
+                backgroundItem.pageRange = "0";
+                backgroundItem.type = ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR;
+                backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
+                Settings.Default.BackgroundTemplateList.Add(backgroundItem);
+                Settings.Default.Save();
+                this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
+        }
+
+        public void SaveBackgroundTemplate(EnumColorOrFile enumColorOrFile)
+        {
+            if(enumColorOrFile == EnumColorOrFile.StatusColor)
+            {
+                SaveCurrentTemplate();
+            }
+        }
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;

+ 11 - 12
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListColorContentViewModel.cs

@@ -1,6 +1,8 @@
-using PDF_Office.Properties;
+using PDF_Office.EventAggregators;
+using PDF_Office.Properties;
 using PDFSettings;
 using Prism.Commands;
+using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
@@ -18,7 +20,9 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
     public class BackgroundTemplateListColorContentViewModel : BindableBase, INavigationAware
     {
-        public ObservableCollection<BackgroundItem> backgroundModcolorCollection = new ObservableCollection<BackgroundItem>();
+        private readonly IEventAggregator eventAggregator;
+
+        private ObservableCollection<BackgroundItem> backgroundModcolorCollection = new ObservableCollection<BackgroundItem>();
         public ObservableCollection<BackgroundItem> BackgroundModColorCollection
         {
             get { return backgroundModcolorCollection; }
@@ -39,12 +43,11 @@ namespace PDF_Office.ViewModels.EditTools.Background
         public DelegateCommand AddTemplateCommand { get; set; }
         public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
 
-        BackgroundTemplateListColorContentViewModel()
+        BackgroundTemplateListColorContentViewModel(IEventAggregator eventAggregator)
         {
+            this.eventAggregator = eventAggregator;
             AddTemplateCommand = new DelegateCommand(AddTemplate);
             DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
-
-            InitBackgroundTemplateList();
         }
 
         private void CheckTemplateListIsEmpty(List<BackgroundItem> backgroundTemplateList)
@@ -100,13 +103,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void AddTemplate()
         {
-            var backgroundItem = new BackgroundItem();
-            backgroundItem.pageRange = "0";
-            backgroundItem.type = ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR;
-            backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
-            Settings.Default.BackgroundTemplateList.Add(backgroundItem);
-            Settings.Default.Save();
-            UpdateBackgroundSources();
+            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusCreate);
         }
 
         public void DeleteTemplateItem(object e)
@@ -143,6 +140,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+            InitBackgroundTemplateList();
+
         }
     }
 }

+ 1 - 2
PDF Office/Views/EditTools/Background/BackgroundTemplateListColorContent.xaml

@@ -10,8 +10,7 @@
              d:DesignHeight="632"
              d:DesignWidth="260">
     <Grid Background="#F3F3F3">
-        <ListBox Name="TextWatermarkListbox" 
-                                Width="240" 
+        <ListBox           Width="240" 
                                 BorderThickness="0"
                                 ScrollViewer.CanContentScroll="True"
                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"

+ 1 - 1
PDF Office/Views/EditTools/Background/BackgroundTemplateListFileContent.xaml

@@ -55,7 +55,7 @@
                 </DataTemplate>
             </ListBox.ItemTemplate>
         </ListBox>
-        <Grid Width="140" Height="155" Margin="64,153,56,324" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
+        <Grid Width="140" Height="155" Margin="64,153,56,323" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
             <StackPanel Orientation="Vertical">
                 <Label Height="87" Width="87" HorizontalAlignment="Center" Background="BlueViolet"></Label>
                 <TextBlock Height="24" FontSize="14" Text="请先创建一个背景模板" Margin="0,8,0,0" VerticalAlignment="Center" ></TextBlock>