123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFPage;
- using ComPDFKit.PDFPage.Edit;
- using Compdfkit_Tools.Edit;
- using Compdfkit_Tools.Helper;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace Compdfkit_Tools.PDFControl
- {
- public partial class ContentEditControl : UserControl, INotifyPropertyChanged
- {
- #region Property
- public PDFViewControl PdfViewControl = new PDFViewControl();
- public PDFContentEditControl pdfContentEditControl = new PDFContentEditControl();
- private CPDFDisplaySettingsControl displaySettingsControl = null;
- private PDFEditEvent pdfTextCreateParam;
- private PDFEditEvent lastPDFEditEvent = null;
- private List<PDFEditEvent> lastPDFEditMultiEvents = null;
- private PanelState panelState = PanelState.GetInstance();
- private KeyEventHandler KeyDownHandler;
- public event PropertyChangedEventHandler PropertyChanged;
- public ICommand CloseTabCommand;
- public ICommand ExpandPropertyPanelCommand;
- public bool CanUndo
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanUndo;
- }
- return false;
- }
- }
- public bool CanRedo
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanRedo;
- }
- return false;
- }
- }
- private bool CanSave
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanSave;
- }
- return false;
- }
- }
- public event EventHandler<bool> OnCanSaveChanged;
- public event EventHandler OnAnnotEditHandler;
- #endregion
- public ContentEditControl()
- {
- InitializeComponent();
- panelState.PropertyChanged += PanelState_PropertyChanged;
- }
-
- private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
- {
- ExpandLeftPanel(panelState.IsLeftPanelExpand);
- }
- else if (e.PropertyName == nameof(PanelState.RightPanel))
- {
- if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
- {
- ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
- }
- else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
- {
- ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
- }
- else
- {
- ExpandRightPropertyPanel(null, Visibility.Collapsed);
- }
- }
- }
- public void ClearPDFEditState(ToggleButton ignoreBtn = null)
- {
- List<ToggleButton> clearBtnList = new List<ToggleButton>()
- {
- PDFTextEditButton,
- PDFImageEditButton
- };
- foreach (ToggleButton item in clearBtnList)
- {
- if (ignoreBtn == item)
- {
- continue;
- }
- item.IsChecked = false;
- }
- }
-
- private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
- {
- ToggleButton senderBtn = sender as ToggleButton;
- if (senderBtn != null && PdfViewControl != null)
- {
- ClearPDFEditState(senderBtn);
- if (senderBtn.IsChecked == true)
- {
- PDFEditEvent createParam = new PDFEditEvent();
- createParam.EditType = CPDFEditType.EditText;
- createParam.IsBold = false;
- createParam.IsItalic = false;
- createParam.FontSize = 14;
- createParam.FontName = "Helvetica";
- createParam.FontColor = Colors.Black;
- createParam.TextAlign = TextAlignType.AlignLeft;
- createParam.Transparency = 255;
- if (PdfViewControl.PDFView != null && PdfViewControl.PDFView.Document != null)
- {
- CPDFDocument pdfDoc = PdfViewControl.PDFView.Document;
- PdfViewControl.PDFView.ToolManager.EnableClickCreate = true;
- PdfViewControl.PDFView.ToolManager.ClickCreateWidth = 100;
- if (pdfDoc.PageCount > 0)
- {
- CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
- CPDFEditPage editPage = pdfPage.GetEditPage();
- editPage.BeginEdit(CPDFEditType.EditText);
- createParam.SystemFontNameList.AddRange(editPage.GetFontList());
- editPage.EndEdit();
- }
- }
-
- PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
- PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
- PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
- PdfViewControl.PDFView?.ReloadDocument();
- PdfViewControl.PDFView?.SetPDFEditParam(createParam);
- pdfContentEditControl.SetPDFTextEditData(createParam);
- panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
- pdfTextCreateParam = createParam;
- }
- else
- {
- PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
- PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
- PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
- PdfViewControl.PDFView?.ReloadDocument();
- pdfContentEditControl.ClearContentControl();
- panelState.RightPanel = PanelState.RightPanelState.None;
- }
- }
- }
- private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
- {
- ToggleButton senderBtn = sender as ToggleButton;
- if (senderBtn != null && PdfViewControl != null)
- {
- panelState.RightPanel = PanelState.RightPanelState.None;
- senderBtn.IsChecked = false;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- ClearPDFEditState(senderBtn);
- PdfViewControl.PDFView?.ClearSelectPDFEdit();
- PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
- PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
- PdfViewControl.PDFView?.ReloadDocument();
-
- PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
- PdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
- }
- }
- }
- public void ExpandLeftPanel(bool isExpand)
- {
- BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- if (isExpand)
- {
- BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
- BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
- }
- else
- {
- BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
- BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
- }
- }
- private void UndoBtn_Click(object sender, RoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- PdfViewControl.PDFView.UndoManager?.Undo();
- }
- }
- private void RedoBtn_Click(object sender, RoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- PdfViewControl.PDFView.UndoManager?.Redo();
- }
- }
- public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
- {
- this.PropertyContainer.Child = displaySettingsControl;
- this.PropertyContainer.Visibility = visibility;
- }
- public void SetBOTAContainer(CPDFBOTABarControl botaControl)
- {
- this.BotaContainer.Child = botaControl;
- }
- public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
- {
- this.displaySettingsControl = displaySettingsControl;
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- PdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
- }
- private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
- {
- PdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
- }
-
- public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
- {
- PropertyContainer.Width = 260;
- PropertyContainer.Child = propertytPanel;
- PropertyContainer.Visibility = visible;
- }
- public void InitWithPDFViewer(CPDFViewer pdfViewer)
- {
- PdfViewControl.PDFView = pdfViewer;
- PDFGrid.Child = PdfViewControl;
- FloatPageTool.InitWithPDFViewer(pdfViewer);
- pdfContentEditControl.InitWithPDFViewer(pdfViewer);
- PdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
- PdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
- PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
- PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
- DataContext = this;
- if(pdfViewer!=null)
- {
- pdfViewer.EnableMultiSelectEdit = true;
- pdfViewer.PDFEditMultiActiveHandler -= PDFEditMultiActiveHandler;
- pdfViewer.PDFEditMultiActiveHandler += PDFEditMultiActiveHandler;
- if (KeyDownHandler != null)
- {
- pdfViewer.RemoveHandler(KeyDownEvent, KeyDownHandler);
- }
- KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
- pdfViewer.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
- }
- }
- private void PDFEditEmptyPanel()
- {
- PropertyContainer.Child = pdfContentEditControl;
- if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
- {
- pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
- }
- else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
- {
- pdfContentEditControl.ClearContentControl();
- }
- }
- else
- {
- pdfContentEditControl.ClearContentControl();
- }
- }
- private void PDFEditMultiActiveHandler(object sender, List<PDFEditEvent> e)
- {
- lastPDFEditEvent = null;
- lastPDFEditMultiEvents = e;
- if(e==null)
- {
- PDFEditEmptyPanel();
- return;
- }
- if(e.Count>1)
- {
- List<CPDFEditType> editList= e.AsEnumerable().Select(x=>x.EditType).Distinct().ToList();
-
- if(editList.Count>1)
- {
- PDFEditEmptyPanel();
- return;
- }
- if (editList[0]==CPDFEditType.EditText)
- {
- pdfContentEditControl.SetPDFTextMultiEditData(e);
- return;
- }
- if (editList[0]==CPDFEditType.EditImage)
- {
- UIElement pageView = sender as UIElement;
- if (pageView != null)
- {
- pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
- }
- pdfContentEditControl.SetPDFImageMultiEditData(e);
- }
- }
- }
- public void PDFView_KeyDown(object sender, KeyEventArgs e)
- {
- if (PdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
- {
- return;
- }
- if (Keyboard.Modifiers == ModifierKeys.Control)
- {
- if (e.Key == Key.Left)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
- e.Handled = true;
- }
- if (e.Key == Key.Right)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
- e.Handled = true;
- }
- if (e.Key == Key.Up)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
- e.Handled = true;
- }
- if (e.Key == Key.Down)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
- e.Handled = true;
- }
- }
- if (Keyboard.Modifiers == ModifierKeys.Shift)
- {
- if (e.Key == Key.Left)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, true);
- e.Handled = true;
- }
- if (e.Key == Key.Right)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, true);
- e.Handled = true;
- }
- if (e.Key == Key.Up)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, true);
- e.Handled = true;
- }
- if (e.Key == Key.Down)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, true);
- e.Handled = true;
- }
- }
- if (Keyboard.Modifiers == ModifierKeys.Alt)
- {
- if (e.SystemKey == Key.Up)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
- e.Handled = true;
- }
- if (e.SystemKey == Key.Down)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
- e.Handled = true;
- }
- }
- if (Keyboard.Modifiers == ModifierKeys.None)
- {
- if (e.Key == Key.Left)
- {
- PdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
- e.Handled = true;
- }
- if (e.Key == Key.Right)
- {
- PdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
- e.Handled = true;
- }
- if (e.Key == Key.Up)
- {
- PdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
- e.Handled = true;
- }
- if (e.Key == Key.Down)
- {
- PdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
- e.Handled = true;
- }
- }
- if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
- {
- if (e.Key == Key.Left)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, true);
- e.Handled = true;
- }
- if (e.Key == Key.Right)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, true);
- e.Handled = true;
- }
- if (e.Key == Key.Up)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, true);
- e.Handled = true;
- }
- if (e.Key == Key.Down)
- {
- PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, true);
- e.Handled = true;
- }
- }
- }
- /// <summary>
- /// Text and Image Selected Event
- /// </summary>
- private void PDFView_PDFEditActiveHandler(object sender, PDFEditEvent e)
- {
- lastPDFEditEvent = e;
- lastPDFEditMultiEvents = null;
- if (e == null)
- {
- PropertyContainer.Child = pdfContentEditControl;
- if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
- {
- pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
- }
- else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
- {
- pdfContentEditControl.ClearContentControl();
- }
- }
- else
- {
- pdfContentEditControl.ClearContentControl();
- }
- return;
- }
- if (e.EditType == CPDFEditType.EditText)
- {
- pdfContentEditControl.SetPDFTextEditData(e, true);
- return;
- }
- if (e.EditType == CPDFEditType.EditImage && PdfViewControl != null)
- {
- UIElement pageView = sender as UIElement;
- if (pageView != null)
- {
- pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
- }
- pdfContentEditControl.SetPDFImageEditData(e);
- return;
- }
- }
- private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- UIElement pageView = sender as UIElement;
- if (pageView != null)
- {
- pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
- }
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- pdfContentEditControl.SetPDFImageEditData(lastPDFEditEvent);
- }
- }
-
- public void ClearViewerControl()
- {
- PDFGrid.Child = null;
- BotaContainer.Child = null;
- PropertyContainer.Child = null;
- displaySettingsControl = null;
- }
-
- #region Property changed
- protected void OnPropertyChanged([CallerMemberName] string name = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
- }
- public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- OnPropertyChanged(e.PropertyName);
- if (e.PropertyName == "CanSave")
- {
- OnCanSaveChanged?.Invoke(this, CanSave);
- }
- }
- #endregion
- #region Context menu
- private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
- {
- if (e == null)
- {
- return;
- }
- if (e.EditType == CPDFEditType.EditText)
- {
- e.Handle = true;
- PDFEditTextContextMenu(sender, e);
- }
- if (e.EditType == CPDFEditType.EditImage)
- {
- e.Handle = true;
- PDFEditImageContextMenu(sender, e);
- }
- if(e.EditType== (CPDFEditType.EditText | CPDFEditType.EditImage))
- {
- e.Handle |= true;
- PDFEditMultiContextMenu(sender, e);
- }
- }
-
- private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
- {
- editCommand.PopupMenu = new ContextMenu();
- if (lastPDFEditEvent != null || lastPDFEditMultiEvents!=null)
- {
- if(PdfViewControl.PDFView.Document.GetPermissionsInfo().AllowsCopying)
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- }
- else
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- if (editCommand.TextAreaCopied)
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
- }
- }
- }
- private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
- {
- editCommand.PopupMenu = new ContextMenu();
- if (lastPDFEditEvent != null)
- {
- MenuItem rotateLeftMenu = new MenuItem();
- rotateLeftMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateLeft");
- rotateLeftMenu.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.Rotate = -90;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- pdfContentEditControl.RefreshThumb();
- }
- };
- editCommand.PopupMenu.Items.Add(rotateLeftMenu);
- MenuItem rotateRightMenu = new MenuItem();
- rotateRightMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateRight");
- rotateRightMenu.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.Rotate = 90;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- pdfContentEditControl.RefreshThumb();
- }
- };
- editCommand.PopupMenu.Items.Add(rotateRightMenu);
- MenuItem replaceMenu = new MenuItem();
- replaceMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Replace");
- replaceMenu.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- PdfViewControl.PDFView?.ClearSelectPDFEdit();
- pdfContentEditControl.RefreshThumb();
- }
- }
- };
- editCommand.PopupMenu.Items.Add(replaceMenu);
- MenuItem exportMenu = new MenuItem();
- exportMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Export");
- exportMenu.Click += (o, p) =>
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PdfViewControl.PDFView.GetSelectedImages();
- if (imageDict != null && imageDict.Count > 0)
- {
- System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
- if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string choosePath = folderBrowser.SelectedPath;
- string openPath = choosePath;
- foreach (int pageIndex in imageDict.Keys)
- {
- List<System.Drawing.Bitmap> imageList = imageDict[pageIndex];
- foreach (System.Drawing.Bitmap image in imageList)
- {
- string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
- openPath = savePath;
- }
- }
- Process.Start("explorer", "/select,\"" + openPath + "\"");
- }
- }
- }
- };
- editCommand.PopupMenu.Items.Add(exportMenu);
- MenuItem opacityMenu = new MenuItem();
- opacityMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Opacity");
- editCommand.PopupMenu.Items.Add(opacityMenu);
- AppendOpacityMenu(opacityMenu);
- MenuItem horizonMirror = new MenuItem();
- horizonMirror.Header = LanguageHelper.CommonManager.GetString("Menu_HFlip");
- horizonMirror.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.HorizontalMirror = true;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- }
- };
- editCommand.PopupMenu.Items.Add(horizonMirror);
- MenuItem verticalMirror = new MenuItem();
- verticalMirror.Header = LanguageHelper.CommonManager.GetString("Menu_VFlip");
- verticalMirror.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.VerticalMirror = true;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- }
- };
- editCommand.PopupMenu.Items.Add(verticalMirror);
- MenuItem cropMenu = new MenuItem();
- cropMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Crop");
- cropMenu.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.ClipImage = true;
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- }
- };
- editCommand.PopupMenu.Items.Add(cropMenu);
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- if (editCommand.TextAreaCopied)
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
- }
- }
- else
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- }
- }
- private void PDFEditMultiContextMenu(object sender, PDFEditCommand editCommand)
- {
- if(editCommand!=null)
- {
- editCommand.PopupMenu = new ContextMenu();
- if (lastPDFEditMultiEvents!=null)
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- if(CustomCommands.PasteMatchStyle.CanExecute(null, (UIElement)sender))
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
- }
- }
- else
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
- if (CustomCommands.PasteMatchStyle.CanExecute(null, (UIElement)sender))
- {
- editCommand.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
- }
- }
- }
- }
-
- private void AppendOpacityMenu(MenuItem parentMenu)
- {
- List<int> opacityList = new List<int>()
- {
- 25,50,75,100
- };
- foreach (int opacity in opacityList)
- {
- MenuItem opacityMenu = new MenuItem();
- opacityMenu.Header = string.Format("{0}%", opacity);
- opacityMenu.Click += (o, p) =>
- {
- if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
- {
- lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
- lastPDFEditEvent.UpdatePDFEditByEventArgs();
- }
- };
- parentMenu.Items.Add(opacityMenu);
- }
- }
- #endregion
- private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
- {
- PdfViewControl.PDFView.UndoManager?.Undo();
- }
- }
- private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanRedo)
- {
- PdfViewControl.PDFView.UndoManager?.Redo();
- }
- }
- }
- }
|