OutLineControlViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKitViewer.PdfViewer;
  5. using PDF_Office.Model;
  6. using PDF_Office.Model.BOTA;
  7. using Prism.Commands;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. namespace PDF_Office.ViewModels.BOTA
  21. {
  22. class OutLineControlViewModel : BindableBase, INavigationAware
  23. {
  24. private string PageDefaultName = "";
  25. //缩略图相关全局变量,减少内存申请次数
  26. private WriteableBitmap WirteBitmap;
  27. private byte[] bmpData;
  28. private CPDFViewer PDFViewer;
  29. public ObservableCollection<OutlineNode> Outlinelist { get; set; }
  30. private bool isInsertHead = false;
  31. /// <summary>
  32. /// 是否为插入最顶部
  33. /// </summary>
  34. public bool IsInsertHead
  35. {
  36. get { return isInsertHead; }
  37. set
  38. {
  39. SetProperty(ref isInsertHead, value);
  40. }
  41. }
  42. private bool isOnDrop = false;
  43. public bool IsOnDrop
  44. {
  45. get { return isOnDrop; }
  46. set { isOnDrop = value; }
  47. }
  48. public DelegateCommand<ObservableCollection<OutlineNode>> CollapseAllCommand { get; set; }
  49. public DelegateCommand<ObservableCollection<OutlineNode>> ExpandAllCommand { get; set; }
  50. public DelegateCommand DeleteAllCommand { get; set; }
  51. public DelegateCommand<OutlineNode> DowngradeCommand { get; set; }
  52. public OutLineControlViewModel()
  53. {
  54. Outlinelist = new ObservableCollection<OutlineNode>();
  55. DeleteAllCommand = new DelegateCommand(DeleteAll);
  56. CollapseAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(CollapseAll);
  57. ExpandAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(ExpandAll);
  58. }
  59. public bool IsNavigationTarget(NavigationContext navigationContext)
  60. {
  61. return true;
  62. }
  63. public void OnNavigatedFrom(NavigationContext navigationContext)
  64. {
  65. return;
  66. }
  67. public void OnNavigatedTo(NavigationContext navigationContext)
  68. {
  69. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  70. if (PDFViewer == null)
  71. {
  72. return;
  73. }
  74. List<CPDFOutline> datasource = PDFViewer.Document.GetOutlineList();
  75. Outlinelist.Clear();
  76. foreach (CPDFOutline item in datasource)
  77. {
  78. OutlineNode dto = ConvertCPDFToOutlineNode(item, null, false);
  79. if (dto != null)
  80. {
  81. Outlinelist.Add(dto);
  82. }
  83. }
  84. PDFViewer.GetCreateOutLineInfo();
  85. }
  86. /// <summary>
  87. /// 更新大纲数据,并保存状态设置为true
  88. /// </summary>
  89. public void Updata(bool IsMoveData)
  90. {
  91. PDFViewer.Document.ReleaseOutlineList();
  92. ObservableCollection<OutlineNode> list = new ObservableCollection<OutlineNode>();
  93. List<CPDFOutline> datasource = PDFViewer.Document.GetOutlineList();
  94. //遍历,转换UI状态存入临时数组
  95. foreach (CPDFOutline item in datasource)
  96. {
  97. OutlineNode dto = ConvertCPDFToOutlineNode(item, null, IsMoveData);
  98. if (dto != null)
  99. {
  100. list.Add(dto);
  101. }
  102. }
  103. //清空绑定数组,并填充新数据
  104. Outlinelist.Clear();
  105. foreach (OutlineNode item in list)
  106. {
  107. Outlinelist.Add(item);
  108. }
  109. PDFViewer.UndoManager.CanSave = true;
  110. }
  111. /// <summary>
  112. /// 设置当前大纲对象的Title
  113. /// </summary>
  114. public bool SetTitle(CPDFOutline cPDFOutline, string Title)
  115. {
  116. if (cPDFOutline == null)
  117. {
  118. return false;
  119. }
  120. return cPDFOutline.SetTitle(Title);
  121. }
  122. /// <summary>
  123. /// 跳转到指定位置或者URL动作
  124. /// </summary>
  125. public void GoToPage(TreeViewItem treeViewItem)
  126. {
  127. OutlineNode outline = treeViewItem.DataContext as OutlineNode;
  128. if (outline == null)
  129. {
  130. return;
  131. }
  132. CPDFAction action = outline.Outline.GetAction();
  133. if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
  134. {
  135. PDFViewer.ProcessAction(action);
  136. }
  137. else
  138. {
  139. Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outline.PageIndex) - 1);
  140. PDFViewer.GoToPage(Convert.ToInt32(outline.PageIndex) - 1, new Point(size.Width - outline.PositionX, size.Height - outline.PositionY));
  141. }
  142. }
  143. /// <summary>
  144. /// 收起所有展开
  145. /// </summary>
  146. public void CollapseAll(ObservableCollection<OutlineNode> outlineNodes)
  147. {
  148. foreach (var item in outlineNodes)
  149. {
  150. item.IsExpanded = false;
  151. if (item.Chlidlist.Count > 0)
  152. {
  153. CollapseAll(item.Chlidlist);
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// 展开所有大纲
  159. /// </summary>
  160. public void ExpandAll(ObservableCollection<OutlineNode> outlineNodes)
  161. {
  162. foreach (var item in outlineNodes)
  163. {
  164. item.IsExpanded = true;
  165. if (item.Chlidlist.Count > 0)
  166. {
  167. ExpandAll(item.Chlidlist);
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// 更改目标位置
  173. /// </summary>
  174. public void ChangeOutLineDestination(OutlineNode outline)
  175. {
  176. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  177. CPDFDestination info = new CPDFDestination();
  178. info.PageIndex = textSelectNodes[0].PageIndex;
  179. Size size = PDFViewer.Document.GetPageSize(textSelectNodes[0].PageIndex);
  180. info.Position_X = (float)(size.Width - textSelectNodes[0].StartPoint.X);
  181. info.Position_Y = (float)(size.Height - textSelectNodes[0].StartPoint.Y);
  182. outline.Outline.SetDestination(PDFViewer.Document, info);
  183. Updata(false);
  184. }
  185. /// <summary>
  186. /// 添加大纲
  187. /// </summary>
  188. public int AddOutLine(OutlineNode outline)
  189. {
  190. int ItemIndex = 0;
  191. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  192. CPDFDestination info = new CPDFDestination();
  193. if (textSelectNodes.Count <= 0)
  194. {
  195. //SDK出错了
  196. return -1;
  197. }
  198. info.PageIndex = textSelectNodes[0].PageIndex;
  199. Size size = PDFViewer.Document.GetPageSize(info.PageIndex);
  200. info.Position_X = (float)(size.Width - textSelectNodes[0].StartPoint.X);
  201. info.Position_Y = (float)(size.Height - textSelectNodes[0].StartPoint.Y);
  202. CPDFOutline dto = null;
  203. //当前有选中大纲列表
  204. if (outline != null)
  205. {
  206. CPDFOutline parentoutline = outline.Outline.GetParent();
  207. if (parentoutline == null)
  208. {
  209. //获取父级失败,直接添加在根节点最下方
  210. PDFViewer.Document.GetOutlineList();
  211. CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
  212. if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
  213. {
  214. //SDK出错了
  215. return -1;
  216. }
  217. ItemIndex = parent.ChildList.Count;
  218. }
  219. else
  220. {
  221. //获取父节点成功,添加在父节点中选中项下方
  222. int index = GetOutlinesIndexFormParent(parentoutline, outline.Outline);
  223. parentoutline.InsertChildAtIndex(PDFViewer.Document, index, ref dto);
  224. ItemIndex = index + 1;
  225. }
  226. }
  227. else
  228. {
  229. //未选中数据,直接添加在根节点最下方
  230. PDFViewer.Document.GetOutlineList();
  231. CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
  232. if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
  233. {
  234. //SDK出错了
  235. return -1;
  236. }
  237. ItemIndex = parent.ChildList.Count;
  238. }
  239. ///当前没有选中文字
  240. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  241. {
  242. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  243. if (!dto.SetTitle(addPageName))
  244. {
  245. //SDK出错了
  246. return -1;
  247. }
  248. }
  249. else
  250. {
  251. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  252. if (!dto.SetTitle(addPageName))
  253. {
  254. //SDK出错了
  255. return -1;
  256. }
  257. }
  258. dto.SetDestination(PDFViewer.Document, info);
  259. Updata(false);
  260. return ItemIndex;
  261. }
  262. /// <summary>
  263. /// 添加大纲到子节点的最后一位
  264. /// </summary>
  265. public int InsertParentOutline(OutlineNode outline)
  266. {
  267. int ItemIndex = 0;
  268. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  269. CPDFDestination info = new CPDFDestination();
  270. if (textSelectNodes.Count <= 0)
  271. {
  272. //SDK出错了
  273. return -1;
  274. }
  275. info.PageIndex = textSelectNodes[0].PageIndex;
  276. info.Position_X = (float)textSelectNodes[0].StartPoint.X;
  277. info.Position_Y = (float)textSelectNodes[0].StartPoint.Y;
  278. CPDFOutline dto = null;
  279. CPDFOutline parent = outline.Outline.GetParent();
  280. if (parent != null)
  281. {
  282. CPDFOutline trueparent = parent.GetParent();
  283. if (trueparent != null)
  284. {
  285. ItemIndex = GetOutlinesIndexFormParent(trueparent, parent);
  286. if (!trueparent.InsertChildAtIndex(PDFViewer.Document, ItemIndex, ref dto))
  287. {
  288. return -1;
  289. }
  290. ItemIndex = ItemIndex + 1;
  291. }
  292. }
  293. ///当前没有选中文字
  294. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  295. {
  296. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  297. if (!dto.SetTitle(addPageName))
  298. {
  299. //SDK出错了
  300. return -1;
  301. }
  302. }
  303. else
  304. {
  305. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  306. if (!dto.SetTitle(addPageName))
  307. {
  308. //SDK出错了
  309. return -1;
  310. }
  311. }
  312. dto.SetDestination(PDFViewer.Document, info);
  313. Updata(false);
  314. return ItemIndex;
  315. }
  316. /// <summary>
  317. /// 添加大纲到父节点的下一位
  318. /// </summary>
  319. public int InsertChlidOutline(OutlineNode outline)
  320. {
  321. int ItemIndex = 0;
  322. if (outline == null)
  323. {
  324. return -1;
  325. }
  326. if (outline.Outline.ChildList != null)
  327. {
  328. ItemIndex = outline.Outline.ChildList.Count;
  329. }
  330. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  331. CPDFDestination info = new CPDFDestination();
  332. if (textSelectNodes.Count <= 0)
  333. {
  334. //SDK出错了
  335. return -1;
  336. }
  337. info.PageIndex = textSelectNodes[0].PageIndex;
  338. info.Position_X = (float)textSelectNodes[0].StartPoint.X;
  339. info.Position_Y = (float)textSelectNodes[0].StartPoint.Y;
  340. CPDFOutline dto = null;
  341. if (!outline.Outline.InsertChildAtIndex(PDFViewer.Document, ItemIndex, ref dto))
  342. {
  343. return -1;
  344. }
  345. ///当前没有选中文字
  346. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  347. {
  348. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  349. if (!dto.SetTitle(addPageName))
  350. {
  351. //SDK出错了
  352. return -1;
  353. }
  354. }
  355. else
  356. {
  357. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  358. if (!dto.SetTitle(addPageName))
  359. {
  360. //SDK出错了
  361. return -1;
  362. }
  363. }
  364. dto.SetDestination(PDFViewer.Document, info);
  365. Updata(false);
  366. return ItemIndex;
  367. }
  368. /// <summary>
  369. /// 删除所有大纲
  370. /// </summary>
  371. public void DeleteAll()
  372. {
  373. foreach (var item in Outlinelist)
  374. {
  375. item.Outline.RemoveFromParent(this.PDFViewer.Document);
  376. }
  377. Updata(false);
  378. }
  379. /// <summary>
  380. /// 升级当前大纲
  381. /// </summary>
  382. public void Downgrade(OutlineNode outline)
  383. {
  384. if (outline != null)
  385. {
  386. CPDFOutline parent = outline.Outline.GetParent();
  387. int index = GetOutlinesIndexFormParent(parent, outline.Outline);
  388. CPDFOutline newparent = parent.ChildList[index - 2];
  389. int insertindex = newparent.ChildList.Count;
  390. newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, insertindex);
  391. Updata(false);
  392. }
  393. }
  394. /// <summary>
  395. /// 降级当前大纲
  396. /// </summary>
  397. public void Upgrade(OutlineNode outline)
  398. {
  399. if (outline != null)
  400. {
  401. CPDFOutline parent = outline.Outline.GetParent();
  402. CPDFOutline newparent = parent.GetParent();
  403. int index = GetOutlinesIndexFormParent(parent.GetParent(), parent);
  404. newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, index);
  405. Updata(false);
  406. }
  407. }
  408. /// <summary>
  409. /// 删除当前大纲
  410. /// </summary>
  411. public void RemoveOutline(OutlineNode outline)
  412. {
  413. outline.Outline.RemoveFromParent(PDFViewer.Document);
  414. Updata(false);
  415. }
  416. /// <summary>
  417. /// 移动大纲到目标节点
  418. /// </summary>
  419. /// <param name="target">目标节点</param>
  420. /// <param name="soure">需要插入的数据</param>
  421. /// <returns></returns>
  422. public bool MoveOutLine(OutlineNode target, OutlineNode soure)
  423. {
  424. bool Tag = true;
  425. if (IsInsertHead)
  426. {
  427. CPDFOutline root = PDFViewer.Document.GetOutlineRoot();
  428. if (root != null)
  429. {
  430. Tag = root.MoveChildAtIndex(PDFViewer.Document, soure.Outline, 0);
  431. }
  432. }
  433. else
  434. {
  435. if (target.IsInsertNextLayer)
  436. {
  437. target.IsExpanded = true;
  438. Tag = target.Outline.MoveChildAtIndex(PDFViewer.Document, soure.Outline, target.Outline.ChildList.Count);
  439. }
  440. else
  441. {
  442. CPDFOutline parent = target.Outline.GetParent();
  443. if (parent != null && parent.ChildList.Count > 0)
  444. {
  445. int index = parent.ChildList.IndexOf(target.Outline);
  446. int sourceindex = parent.ChildList.IndexOf(soure.Outline);
  447. //源数据不在目标节点树中的情况
  448. if (sourceindex == -1)
  449. {
  450. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index + 1);
  451. }
  452. //分向上和向下移动
  453. else if (sourceindex > index)
  454. {
  455. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index + 1);
  456. }
  457. else
  458. {
  459. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index);
  460. }
  461. }
  462. }
  463. }
  464. return Tag;
  465. }
  466. /// <summary>
  467. /// 获取对应大纲所需的缩略图数据
  468. /// </summary>
  469. public WriteableBitmap LoadPreview(OutlineNode outlineNode)
  470. {
  471. CPDFPage page = PDFViewer.Document.PageAtIndex(Convert.ToInt32(outlineNode.PageIndex) - 1);
  472. Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outlineNode.PageIndex) - 1);
  473. Point zoomXY = new Point(outlineNode.PositionX * outlineNode.Zoom, outlineNode.PositionY * outlineNode.Zoom);
  474. //数据校验,暂不确定SDK会不会给垃圾值。说是从底层返回的。
  475. if (zoomXY.X > size.Width || zoomXY.X < 0)
  476. {
  477. zoomXY.X = 0;
  478. }
  479. if (zoomXY.Y > size.Height || zoomXY.Y < 0)
  480. {
  481. zoomXY.Y = 0;
  482. }
  483. Size zoomSize = new Size((int)(size.Width * outlineNode.Zoom), (int)(size.Height * outlineNode.Zoom));
  484. bmpData = new byte[(int)(zoomSize.Width * zoomSize.Height * 4)];
  485. WirteBitmap = new WriteableBitmap((int)zoomSize.Width, (int)zoomSize.Height, 96, 96, PixelFormats.Bgra32, null);
  486. if (!page.IsValid())
  487. {
  488. return null;
  489. }
  490. page.RenderPageBitmapWithMatrix((float)outlineNode.Zoom, new Rect(zoomXY.X, zoomXY.Y, zoomSize.Width, zoomSize.Height), 0xFFFFFFFF, bmpData, 1, true);
  491. WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)zoomSize.Width, (int)zoomSize.Height), bmpData, WirteBitmap.BackBufferStride, 0);
  492. WirteBitmap.Freeze();
  493. return WirteBitmap;
  494. }
  495. /// <summary>
  496. /// 将PDF对象转换为自定义数据类型,并存储
  497. /// </summary>
  498. private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent, bool IsMoveData)
  499. {
  500. OutlineNode node = new OutlineNode();
  501. if (outline != null)
  502. {
  503. node.IsInsertNextLayer = false;
  504. node.IsInsertCurrentLayer = false;
  505. node.IsExpanded = false;
  506. node.IsSelected = false;
  507. node.Outline = outline;
  508. node.CanUp = outline.Level == 0 ? false : true;
  509. node.CanAddParent = outline.Level == 0 ? false : true;
  510. CPDFAction action = outline.GetAction();
  511. if (action != null)
  512. {
  513. if (action.ActionType != C_ACTION_TYPE.ACTION_TYPE_URI)
  514. {
  515. CPDFDestination cPDFDestination = outline.GetDestination(PDFViewer.Document);
  516. if (cPDFDestination != null)
  517. {
  518. //存储大纲相关属性
  519. node.PageIndex = (cPDFDestination.PageIndex + 1).ToString();
  520. node.PositionX = cPDFDestination.Position_X;
  521. node.PositionY = cPDFDestination.Position_Y;
  522. if (cPDFDestination.Zoom <= 0)
  523. {
  524. node.Zoom = 1;
  525. }
  526. else
  527. {
  528. node.Zoom = cPDFDestination.Zoom;
  529. }
  530. }
  531. else
  532. {
  533. node.PageIndex = "";
  534. node.PositionX = 0;
  535. node.PositionY = 0;
  536. node.Zoom = 1;
  537. }
  538. }
  539. else
  540. {
  541. node.PageIndex = "";
  542. node.PositionX = 0;
  543. node.PositionY = 0;
  544. node.Zoom = 1;
  545. }
  546. }
  547. else
  548. {
  549. node.PageIndex = "";
  550. node.PositionX = 0;
  551. node.PositionY = 0;
  552. node.Zoom = 1;
  553. }
  554. if (parent != null)
  555. {
  556. node.Parent = parent;
  557. }
  558. if (Outlinelist != null && Outlinelist.Count > 0)
  559. {
  560. OutlineNode oldnode = FindOutlineFromDto(Outlinelist, node.Outline, IsMoveData);
  561. if (oldnode != null)
  562. {
  563. node.IsExpanded = oldnode.IsExpanded;
  564. node.IsSelected = oldnode.IsSelected;
  565. }
  566. }
  567. node.Chlidlist = new ObservableCollection<OutlineNode>();
  568. if (outline.ChildList.Count > 0)
  569. {
  570. foreach (CPDFOutline item in outline.ChildList)
  571. {
  572. node.Chlidlist.Add(ConvertCPDFToOutlineNode(item, node, IsMoveData));
  573. }
  574. }
  575. else
  576. {
  577. node.CanDown = false;
  578. }
  579. }
  580. return node;
  581. }
  582. /// <summary>
  583. /// 从当前列表中找到和SDK大纲对象相同的数据
  584. /// </summary>
  585. public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline, bool IsMoveData)
  586. {
  587. foreach (OutlineNode item in list)
  588. {
  589. CPDFOutline parent = outline.GetParent();
  590. CPDFOutline PARENT = item.Outline.GetParent();
  591. int i = GetIndexFromParent(parent.ChildList, outline);
  592. int I = GetIndexFromParent(PARENT.ChildList, item.Outline);
  593. if (IsMoveData)
  594. {
  595. if (item.Outline.Title == outline.Title)
  596. {
  597. return item;
  598. }
  599. else if (item.Chlidlist.Count > 0)
  600. {
  601. OutlineNode retdto = FindOutlineFromDto(item.Chlidlist, outline, IsMoveData);
  602. if (retdto != null)
  603. {
  604. return retdto;
  605. }
  606. }
  607. }
  608. else
  609. {
  610. if (item.Outline.Title == outline.Title && i == I && outline.Level == item.Outline.Level && ((parent.Title == PARENT.Title) || (parent.Title == null && PARENT.Title == null)))
  611. {
  612. return item;
  613. }
  614. else if (item.Chlidlist.Count > 0)
  615. {
  616. OutlineNode retdto = FindOutlineFromDto(item.Chlidlist, outline, IsMoveData);
  617. if (retdto != null)
  618. {
  619. return retdto;
  620. }
  621. }
  622. }
  623. }
  624. return null;
  625. }
  626. /// <summary>
  627. /// 从当前列表中找到对应的OutlineNode对象
  628. /// </summary>
  629. public OutlineNode FindOutlineFromList(ObservableCollection<OutlineNode> list, OutlineNode outline, int outlineindex)
  630. {
  631. //如果传入比对数据为null,则返回最后一项
  632. if (outline == null)
  633. {
  634. return list.Last();
  635. }
  636. int index = list.IndexOf(outline);
  637. if (index >= 0)
  638. {
  639. if (outlineindex <= index)
  640. {
  641. return list[index];
  642. }
  643. else
  644. {
  645. return list[outlineindex - 1];
  646. }
  647. }
  648. else
  649. {
  650. foreach (var item in list)
  651. {
  652. OutlineNode node = FindOutlineFromList(item.Chlidlist, outline, outlineindex);
  653. if (node != null)
  654. {
  655. return node;
  656. }
  657. }
  658. }
  659. return null;
  660. }
  661. private int GetIndexFromParent(List<CPDFOutline> parentlist, CPDFOutline outline)
  662. {
  663. for (int i = 0; i < parentlist.Count; i++)
  664. {
  665. if (parentlist[i] == outline)
  666. {
  667. return i;
  668. }
  669. }
  670. return -1;
  671. }
  672. private int GetOutlinesIndexFormParent(CPDFOutline parentoutline, CPDFOutline outline)
  673. {
  674. if (parentoutline != null)
  675. {
  676. if (parentoutline.ChildList.Count > 0)
  677. {
  678. for (int i = 0; i < parentoutline.ChildList.Count; i++)
  679. {
  680. if (parentoutline.ChildList[i] == outline)
  681. {
  682. return i + 1;
  683. }
  684. }
  685. }
  686. return parentoutline.ChildList.Count;
  687. }
  688. return 0;
  689. }
  690. }
  691. }