|
@@ -643,13 +643,20 @@ namespace PDF_Master.ViewModels.PageEdit
|
|
|
|
|
|
int index = ListSelectedIndex;
|
|
|
|
|
|
-
|
|
|
- DoRemoveSelectedPages(indexList);
|
|
|
+
|
|
|
+ bool isDiscryptied = GetDocumentIsDiscryptied(fileName, null, out CPDFDocument doc, out string password);
|
|
|
|
|
|
-
|
|
|
- var result = await InsertFromFile(index, fileName);
|
|
|
+ if (isDiscryptied)
|
|
|
+ {
|
|
|
+
|
|
|
+ DoRemoveSelectedPages(indexList);
|
|
|
+
|
|
|
+
|
|
|
+ var result = await InsertFromFile(index, fileName, password);
|
|
|
+
|
|
|
+ ReloadAfterOption(true, false, Tuple.Create(insertIndex - 1, insertIndex + pageCount));
|
|
|
+ }
|
|
|
|
|
|
- ReloadAfterOption(true, false, Tuple.Create(insertIndex - 1, insertIndex + pageCount));
|
|
|
IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
|
}
|
|
@@ -1135,7 +1142,7 @@ namespace PDF_Master.ViewModels.PageEdit
|
|
|
|
|
|
private bool CanReverseFileCommandExcute()
|
|
|
{
|
|
|
- if (ListSelectedIndex > 0 && IsMultiSelected)
|
|
|
+ if (ListSelectedIndex >= 0 && IsMultiSelected)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
@@ -2138,13 +2145,68 @@ namespace PDF_Master.ViewModels.PageEdit
|
|
|
|
|
|
public async Task<bool> InsertFromFile(int insertIndex, string filePath, string oldPassWord = null, bool isFromUndoRedo = false)
|
|
|
{
|
|
|
- CPDFDocument doc = CPDFDocument.InitWithFilePath(filePath);
|
|
|
+ bool IsLocked = GetDocumentIsDiscryptied(filePath, oldPassWord, out CPDFDocument doc, out string password);
|
|
|
+
|
|
|
+ if (IsLocked == false)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int pageCount = doc.PageCount;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var insertresult = PDFViewer.Document.ImportPagesAtIndex(doc, "1-" + pageCount, insertIndex);
|
|
|
+ if (!insertresult)
|
|
|
+ {
|
|
|
+ ShowToast();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.Release();
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < pageCount; i++)
|
|
|
+ {
|
|
|
+ var item = GetNewPageEditItem(i);
|
|
|
+ PageEditItems.Insert(insertIndex + i, item);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ await Task.Delay(200);
|
|
|
+ List<int> pageRange = new List<int>();
|
|
|
+ for (int i = 0; i < pageCount; i++)
|
|
|
+ {
|
|
|
+ pageRange.Add(insertIndex + i + 1);
|
|
|
+ }
|
|
|
+ NotifyUIToRefresh(pageRange);
|
|
|
+
|
|
|
+
|
|
|
+ if (!isFromUndoRedo)
|
|
|
+ {
|
|
|
+
|
|
|
+ PageEditHistory history = new PageEditHistory();
|
|
|
+ history.Type = ActionType.InsertFromFile;
|
|
|
+ history.InsertIndex = insertIndex;
|
|
|
+ history.InsertFilePath = filePath;
|
|
|
+ history.InsertFilePassWord = password;
|
|
|
+ history.InsertPageCount = pageCount;
|
|
|
+ history.viewmodel = this;
|
|
|
+ PDFViewer.UndoManager.AddHistory(history);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool GetDocumentIsDiscryptied(string filePath, string oldPassWord, out CPDFDocument doc, out string password)
|
|
|
+ {
|
|
|
+ doc = CPDFDocument.InitWithFilePath(filePath);
|
|
|
+ password = "";
|
|
|
if (doc == null)
|
|
|
{
|
|
|
ShowToast();
|
|
|
return false;
|
|
|
}
|
|
|
- string password = "";
|
|
|
+
|
|
|
if (doc.IsLocked)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(oldPassWord))
|
|
@@ -2197,50 +2259,6 @@ namespace PDF_Master.ViewModels.PageEdit
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- int pageCount = doc.PageCount;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- var insertresult = PDFViewer.Document.ImportPagesAtIndex(doc, "1-" + pageCount, insertIndex);
|
|
|
- if (!insertresult)
|
|
|
- {
|
|
|
- ShowToast();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- doc.Release();
|
|
|
-
|
|
|
-
|
|
|
- for (int i = 0; i < pageCount; i++)
|
|
|
- {
|
|
|
- var item = GetNewPageEditItem(i);
|
|
|
- PageEditItems.Insert(insertIndex + i, item);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- await Task.Delay(200);
|
|
|
- List<int> pageRange = new List<int>();
|
|
|
- for (int i = 0; i < pageCount; i++)
|
|
|
- {
|
|
|
- pageRange.Add(insertIndex + i + 1);
|
|
|
- }
|
|
|
- NotifyUIToRefresh(pageRange);
|
|
|
-
|
|
|
-
|
|
|
- if (!isFromUndoRedo)
|
|
|
- {
|
|
|
-
|
|
|
- PageEditHistory history = new PageEditHistory();
|
|
|
- history.Type = ActionType.InsertFromFile;
|
|
|
- history.InsertIndex = insertIndex;
|
|
|
- history.InsertFilePath = filePath;
|
|
|
- history.InsertFilePassWord = password;
|
|
|
- history.InsertPageCount = pageCount;
|
|
|
- history.viewmodel = this;
|
|
|
- PDFViewer.UndoManager.AddHistory(history);
|
|
|
- }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -2551,8 +2569,6 @@ namespace PDF_Master.ViewModels.PageEdit
|
|
|
await Task.Delay(30);
|
|
|
TbPageRange = "";
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|