123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using PDF_Office.Properties;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Office.ViewModels.EditTools.Background
- {
- public class BackgroundTemplateListFileContentViewModel : BindableBase,INavigationAware
- {
- public ObservableCollection<BackgroundItem> backgroundModFileCollection = new ObservableCollection<BackgroundItem>();
- public ObservableCollection<BackgroundItem> BackgroundModFileCollection
- {
- get { return backgroundModFileCollection; }
- set
- {
- backgroundModFileCollection = value;
- RaisePropertyChanged();
- }
- }
- private Visibility _createTemplateVisible;
- public Visibility CreateTemplateVisible
- {
- get { return _createTemplateVisible; }
- set { SetProperty(ref _createTemplateVisible, value); }
- }
- public DelegateCommand AddTemplateCommand { get; set; }
- public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
- BackgroundTemplateListFileContentViewModel()
- {
- AddTemplateCommand = new DelegateCommand(AddTemplate);
- DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
- InitBackgroundTemplateList();
- }
- private void CheckTemplateListIsEmpty(List<BackgroundItem> backgroundTemplateList)
- {
- if (backgroundTemplateList.Count() == 0)
- {
- CreateTemplateVisible = Visibility.Visible;
- }
- else
- {
- CreateTemplateVisible = Visibility.Collapsed;
- }
- }
- private void GetBackgroundSource()
- {
- List<BackgroundItem> backgroundModFileTemplateList = new List<BackgroundItem>();
- for (int temp = 0; temp < Settings.Default.BackgroundTemplateList.Count; temp++)
- {
- if (Settings.Default.BackgroundTemplateList[temp].type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
- {
- backgroundModFileTemplateList.Add(Settings.Default.BackgroundTemplateList[temp]);
- }
- }
- BackgroundModFileCollection = new ObservableCollection<BackgroundItem>(backgroundModFileTemplateList);
- CheckTemplateListIsEmpty(backgroundModFileTemplateList);
- }
- private void InitBackgroundTemplateList()
- {
- if (Settings.Default.BackgroundTemplateList == null)
- {
- Settings.Default.BackgroundTemplateList = new BackgroundTemplateList();
- }
- GetBackgroundSource();
- }
- private void UpdateBackgroundSources()
- {
- int count = backgroundModFileCollection.Count + backgroundModFileCollection.Count;
- List<BackgroundItem> backgroundModFileTemplateList = new List<BackgroundItem>();
- for (int temp = 0; temp < Settings.Default.BackgroundTemplateList.Count; temp++)
- {
- if (Settings.Default.BackgroundTemplateList[temp].type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
- {
- backgroundModFileTemplateList.Add(Settings.Default.BackgroundTemplateList[temp]);
- }
- }
- BackgroundModFileCollection = new ObservableCollection<BackgroundItem>(backgroundModFileTemplateList);
- CheckTemplateListIsEmpty(backgroundModFileTemplateList);
- }
- public void AddTemplate()
- {
- var backgroundItem = new BackgroundItem();
- backgroundItem.pageRange = "0";
- backgroundItem.type = ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE;
- backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
- Settings.Default.BackgroundTemplateList.Add(backgroundItem);
- Settings.Default.Save();
- UpdateBackgroundSources();
- }
- public void DeleteTemplateItem(object e)
- {
- var btn = e as System.Windows.Controls.Button;
- if (btn == null)
- {
- return;
- }
- var template = btn.DataContext as BackgroundItem;
- if (template == null)
- {
- return;
- }
- Settings.Default.AppProperties.NeedToDeletePath.Add(template.previeImagePath);
- Settings.Default.AppProperties.NeedToDeletePath.Add(template.imagepath);
- Settings.Default.BackgroundTemplateList.Remove(template);
- Settings.Default.Save();
- BackgroundModFileCollection.Remove(template);
- UpdateBackgroundSources();
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- }
- }
- }
|