PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/AppWorkspace.cs

https://bitbucket.org/tcz001/openpdn
C# | 2447 lines | 1971 code | 392 blank | 84 comment | 288 complexity | b9bd44fe47e89855f6c5b93526aa35c6 MD5 | raw file
Possible License(s): Unlicense

Large files files are truncated, but you can click here to view the full file

  1. /////////////////////////////////////////////////////////////////////////////////
  2. // Paint.NET //
  3. // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
  4. // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
  5. // See src/Resources/Files/License.txt for full licensing and attribution //
  6. // details. //
  7. // . //
  8. /////////////////////////////////////////////////////////////////////////////////
  9. using PaintDotNet.Actions;
  10. using PaintDotNet.Effects;
  11. using PaintDotNet.HistoryFunctions;
  12. using PaintDotNet.HistoryMementos;
  13. using PaintDotNet.SystemLayer;
  14. using PaintDotNet.Tools;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Diagnostics;
  20. using System.Drawing;
  21. using System.Drawing.Drawing2D;
  22. using System.Drawing.Imaging;
  23. using System.Globalization;
  24. using System.IO;
  25. using System.Reflection;
  26. using System.Runtime.Serialization;
  27. using System.Runtime.Serialization.Formatters.Binary;
  28. using System.Security;
  29. using System.Text;
  30. using System.Windows.Forms;
  31. namespace PaintDotNet
  32. {
  33. internal class AppWorkspace
  34. : UserControl,
  35. ISnapObstacleHost
  36. {
  37. private readonly string cursorInfoStatusBarFormat = PdnResources.GetString("StatusBar.CursorInfo.Format");
  38. private readonly string imageInfoStatusBarFormat = PdnResources.GetString("StatusBar.Size.Format");
  39. private Type defaultToolTypeChoice;
  40. private Type globalToolTypeChoice = null;
  41. private bool globalRulersChoice = false;
  42. private AppEnvironment appEnvironment;
  43. private DocumentWorkspace activeDocumentWorkspace;
  44. // if a new workspace is added, and this workspace is not dirty, then it will be removed.
  45. // This keeps track of the last workspace added via CreateBlankDocumentInNewWorkspace (if
  46. // true was passed for its 2nd parameter)
  47. private DocumentWorkspace initialWorkspace;
  48. private List<DocumentWorkspace> documentWorkspaces = new List<DocumentWorkspace>();
  49. private WorkspaceWidgets widgets;
  50. private Panel workspacePanel;
  51. private PdnToolBar toolBar;
  52. private PdnStatusBar statusBar;
  53. private ToolsForm mainToolBarForm;
  54. private LayerForm layerForm;
  55. private HistoryForm historyForm;
  56. private ColorsForm colorsForm;
  57. private MostRecentFiles mostRecentFiles = null;
  58. private const int defaultMostRecentFilesMax = 8;
  59. private SnapObstacleController snapObstacle;
  60. private bool addedToSnapManager = false;
  61. private int ignoreUpdateSnapObstacle = 0;
  62. private int suspendThumbnailUpdates = 0;
  63. public void CheckForUpdates()
  64. {
  65. this.toolBar.MainMenu.CheckForUpdates();
  66. }
  67. public IDisposable SuspendThumbnailUpdates()
  68. {
  69. CallbackOnDispose resumeFn = new CallbackOnDispose(ResumeThumbnailUpdates);
  70. ++this.suspendThumbnailUpdates;
  71. if (this.suspendThumbnailUpdates == 1)
  72. {
  73. Widgets.DocumentStrip.SuspendThumbnailUpdates();
  74. Widgets.LayerControl.SuspendLayerPreviewUpdates();
  75. }
  76. return resumeFn;
  77. }
  78. private void ResumeThumbnailUpdates()
  79. {
  80. --this.suspendThumbnailUpdates;
  81. if (this.suspendThumbnailUpdates == 0)
  82. {
  83. Widgets.DocumentStrip.ResumeThumbnailUpdates();
  84. Widgets.LayerControl.ResumeLayerPreviewUpdates();
  85. }
  86. }
  87. public Type DefaultToolType
  88. {
  89. get
  90. {
  91. return this.defaultToolTypeChoice;
  92. }
  93. set
  94. {
  95. this.defaultToolTypeChoice = value;
  96. Settings.CurrentUser.SetString(SettingNames.DefaultToolTypeName, value.Name);
  97. }
  98. }
  99. public Type GlobalToolTypeChoice
  100. {
  101. get
  102. {
  103. return this.globalToolTypeChoice;
  104. }
  105. set
  106. {
  107. this.globalToolTypeChoice = value;
  108. if (ActiveDocumentWorkspace != null)
  109. {
  110. ActiveDocumentWorkspace.SetToolFromType(value);
  111. }
  112. }
  113. }
  114. public DocumentWorkspace InitialWorkspace
  115. {
  116. set
  117. {
  118. this.initialWorkspace = value;
  119. }
  120. }
  121. public event EventHandler RulersEnabledChanged;
  122. protected virtual void OnRulersEnabledChanged()
  123. {
  124. if (RulersEnabledChanged != null)
  125. {
  126. RulersEnabledChanged(this, EventArgs.Empty);
  127. }
  128. }
  129. public bool RulersEnabled
  130. {
  131. get
  132. {
  133. return this.globalRulersChoice;
  134. }
  135. set
  136. {
  137. if (this.globalRulersChoice != value)
  138. {
  139. this.globalRulersChoice = value;
  140. if (ActiveDocumentWorkspace != null)
  141. {
  142. ActiveDocumentWorkspace.RulersEnabled = value;
  143. }
  144. OnRulersEnabledChanged();
  145. }
  146. }
  147. }
  148. private void DocumentWorkspace_DrawGridChanged(object sender, EventArgs e)
  149. {
  150. DrawGrid = this.activeDocumentWorkspace.DrawGrid;
  151. }
  152. private void ViewConfigStrip_DrawGridChanged(object sender, EventArgs e)
  153. {
  154. DrawGrid = ((ViewConfigStrip)sender).DrawGrid;
  155. }
  156. private bool DrawGrid
  157. {
  158. get
  159. {
  160. return this.Widgets.ViewConfigStrip.DrawGrid;
  161. }
  162. set
  163. {
  164. if (this.Widgets.ViewConfigStrip.DrawGrid != value)
  165. {
  166. this.Widgets.ViewConfigStrip.DrawGrid = value;
  167. }
  168. if (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.DrawGrid != value)
  169. {
  170. this.activeDocumentWorkspace.DrawGrid = value;
  171. }
  172. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
  173. }
  174. }
  175. public event EventHandler UnitsChanged;
  176. protected virtual void OnUnitsChanged()
  177. {
  178. if (UnitsChanged != null)
  179. {
  180. UnitsChanged(this, EventArgs.Empty);
  181. }
  182. }
  183. public MeasurementUnit Units
  184. {
  185. get
  186. {
  187. return this.widgets.ViewConfigStrip.Units;
  188. }
  189. set
  190. {
  191. this.widgets.ViewConfigStrip.Units = value;
  192. }
  193. }
  194. public SnapObstacle SnapObstacle
  195. {
  196. get
  197. {
  198. if (this.snapObstacle == null)
  199. {
  200. // HACK: for some reason retrieving the ClientRectangle can raise a VisibleChanged event
  201. // so we initially pass in Rectangle.Empty for the rectangle bounds
  202. this.snapObstacle = new SnapObstacleController(
  203. this.Name,
  204. Rectangle.Empty,
  205. SnapRegion.Interior,
  206. true);
  207. this.snapObstacle.EnableSave = false;
  208. PdnBaseForm pdbForm = FindForm() as PdnBaseForm;
  209. pdbForm.Moving += new MovingEventHandler(ParentForm_Moving);
  210. pdbForm.Move += new EventHandler(ParentForm_Move);
  211. pdbForm.ResizeEnd += new EventHandler(ParentForm_ResizeEnd);
  212. pdbForm.Layout += new LayoutEventHandler(ParentForm_Layout);
  213. pdbForm.SizeChanged += new EventHandler(ParentForm_SizeChanged);
  214. UpdateSnapObstacle();
  215. }
  216. return this.snapObstacle;
  217. }
  218. }
  219. private void ParentForm_Move(object sender, EventArgs e)
  220. {
  221. UpdateSnapObstacle();
  222. }
  223. private void ParentForm_SizeChanged(object sender, EventArgs e)
  224. {
  225. UpdateSnapObstacle();
  226. }
  227. private void ParentForm_Layout(object sender, LayoutEventArgs e)
  228. {
  229. UpdateSnapObstacle();
  230. }
  231. private void ParentForm_ResizeEnd(object sender, EventArgs e)
  232. {
  233. UpdateSnapObstacle();
  234. }
  235. private void ParentForm_Moving(object sender, MovingEventArgs e)
  236. {
  237. UpdateSnapObstacle();
  238. }
  239. private void SuspendUpdateSnapObstacle()
  240. {
  241. ++this.ignoreUpdateSnapObstacle;
  242. }
  243. private void ResumeUpdateSnapObstacle()
  244. {
  245. --this.ignoreUpdateSnapObstacle;
  246. }
  247. private void UpdateSnapObstacle()
  248. {
  249. if (this.ignoreUpdateSnapObstacle > 0)
  250. {
  251. return;
  252. }
  253. if (this.snapObstacle == null)
  254. {
  255. return;
  256. }
  257. if (!this.addedToSnapManager)
  258. {
  259. SnapManager sm = SnapManager.FindMySnapManager(this);
  260. if (sm != null)
  261. {
  262. SnapObstacle so = this.SnapObstacle;
  263. if (!this.addedToSnapManager)
  264. {
  265. sm.AddSnapObstacle(this.SnapObstacle);
  266. this.addedToSnapManager = true;
  267. FindForm().Shown += new EventHandler(AppWorkspace_Shown);
  268. }
  269. }
  270. }
  271. if (this.snapObstacle != null)
  272. {
  273. Rectangle clientRect;
  274. if (ActiveDocumentWorkspace != null)
  275. {
  276. clientRect = ActiveDocumentWorkspace.VisibleViewRectangle;
  277. }
  278. else
  279. {
  280. clientRect = this.workspacePanel.ClientRectangle;
  281. }
  282. Rectangle screenRect = this.workspacePanel.RectangleToScreen(clientRect);
  283. this.snapObstacle.SetBounds(screenRect);
  284. this.snapObstacle.Enabled = this.Visible && this.Enabled;
  285. }
  286. }
  287. private void AppWorkspace_Shown(object sender, EventArgs e)
  288. {
  289. UpdateSnapObstacle();
  290. }
  291. protected override void OnLayout(LayoutEventArgs levent)
  292. {
  293. UpdateSnapObstacle();
  294. base.OnLayout(levent);
  295. }
  296. protected override void OnLocationChanged(EventArgs e)
  297. {
  298. UpdateSnapObstacle();
  299. base.OnLocationChanged(e);
  300. }
  301. protected override void OnSizeChanged(EventArgs e)
  302. {
  303. UpdateSnapObstacle();
  304. base.OnSizeChanged(e);
  305. }
  306. protected override void OnEnabledChanged(EventArgs e)
  307. {
  308. UpdateSnapObstacle();
  309. base.OnEnabledChanged(e);
  310. }
  311. protected override void OnVisibleChanged(EventArgs e)
  312. {
  313. UpdateSnapObstacle();
  314. base.OnVisibleChanged(e);
  315. }
  316. public void ResetFloatingForms()
  317. {
  318. ResetFloatingForm(Widgets.ToolsForm);
  319. ResetFloatingForm(Widgets.HistoryForm);
  320. ResetFloatingForm(Widgets.LayerForm);
  321. ResetFloatingForm(Widgets.ColorsForm);
  322. }
  323. public void ResetFloatingForm(FloatingToolForm ftf)
  324. {
  325. SnapManager sm = SnapManager.FindMySnapManager(this);
  326. if (ftf == Widgets.ToolsForm)
  327. {
  328. sm.ParkObstacle(Widgets.ToolsForm, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  329. }
  330. else if (ftf == Widgets.HistoryForm)
  331. {
  332. sm.ParkObstacle(Widgets.HistoryForm, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Right);
  333. }
  334. else if (ftf == Widgets.LayerForm)
  335. {
  336. sm.ParkObstacle(Widgets.LayerForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Right);
  337. }
  338. else if (ftf == Widgets.ColorsForm)
  339. {
  340. sm.ParkObstacle(Widgets.ColorsForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  341. }
  342. else
  343. {
  344. throw new ArgumentException();
  345. }
  346. }
  347. private Set<Triple<Assembly, Type, Exception>> effectLoadErrors = new Set<Triple<Assembly, Type, Exception>>();
  348. public void ReportEffectLoadError(Triple<Assembly, Type, Exception> error)
  349. {
  350. lock (this.effectLoadErrors)
  351. {
  352. if (!this.effectLoadErrors.Contains(error))
  353. {
  354. this.effectLoadErrors.Add(error);
  355. }
  356. }
  357. }
  358. public static string GetLocalizedEffectErrorMessage(Assembly assembly, Type type, Exception exception)
  359. {
  360. IPluginSupportInfo supportInfo;
  361. string typeName;
  362. if (type != null)
  363. {
  364. typeName = type.FullName;
  365. supportInfo = PluginSupportInfo.GetPluginSupportInfo(type);
  366. }
  367. else if (exception is TypeLoadException)
  368. {
  369. TypeLoadException asTlex = exception as TypeLoadException;
  370. typeName = asTlex.TypeName;
  371. supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  372. }
  373. else
  374. {
  375. supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  376. typeName = null;
  377. }
  378. return GetLocalizedEffectErrorMessage(assembly, typeName, supportInfo, exception);
  379. }
  380. public static string GetLocalizedEffectErrorMessage(Assembly assembly, string typeName, Exception exception)
  381. {
  382. IPluginSupportInfo supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  383. return GetLocalizedEffectErrorMessage(assembly, typeName, supportInfo, exception);
  384. }
  385. private static string GetLocalizedEffectErrorMessage(Assembly assembly, string typeName, IPluginSupportInfo supportInfo, Exception exception)
  386. {
  387. string fileName = assembly.Location;
  388. string shortErrorFormat = PdnResources.GetString("EffectErrorMessage.ShortFormat");
  389. string fullErrorFormat = PdnResources.GetString("EffectErrorMessage.FullFormat");
  390. string notSuppliedText = PdnResources.GetString("EffectErrorMessage.InfoNotSupplied");
  391. string errorText;
  392. if (supportInfo == null)
  393. {
  394. errorText = string.Format(
  395. shortErrorFormat,
  396. fileName ?? notSuppliedText,
  397. typeName ?? notSuppliedText,
  398. exception.ToString());
  399. }
  400. else
  401. {
  402. errorText = string.Format(
  403. fullErrorFormat,
  404. fileName ?? notSuppliedText,
  405. typeName ?? supportInfo.DisplayName ?? notSuppliedText,
  406. (supportInfo.Version ?? new Version()).ToString(),
  407. supportInfo.Author ?? notSuppliedText,
  408. supportInfo.Copyright ?? notSuppliedText,
  409. (supportInfo.WebsiteUri == null ? notSuppliedText : supportInfo.WebsiteUri.ToString()),
  410. exception.ToString());
  411. }
  412. return errorText;
  413. }
  414. public IList<Triple<Assembly, Type, Exception>> GetEffectLoadErrors()
  415. {
  416. return this.effectLoadErrors.ToArray();
  417. }
  418. public void RunEffect(Type effectType)
  419. {
  420. // TODO: this is kind of a hack
  421. this.toolBar.MainMenu.RunEffect(effectType);
  422. }
  423. public PdnToolBar ToolBar
  424. {
  425. get
  426. {
  427. return this.toolBar;
  428. }
  429. }
  430. private ImageResource FileNewIcon
  431. {
  432. get
  433. {
  434. return PdnResources.GetImageResource("Icons.MenuFileNewIcon.png");
  435. }
  436. }
  437. private ImageResource ImageFromDiskIcon
  438. {
  439. get
  440. {
  441. return PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png");
  442. }
  443. }
  444. public MostRecentFiles MostRecentFiles
  445. {
  446. get
  447. {
  448. if (this.mostRecentFiles == null)
  449. {
  450. this.mostRecentFiles = new MostRecentFiles(defaultMostRecentFilesMax);
  451. }
  452. return this.mostRecentFiles;
  453. }
  454. }
  455. private void DocumentWorkspace_DocumentChanging(object sender, EventArgs<Document> e)
  456. {
  457. UI.SuspendControlPainting(this);
  458. }
  459. private void DocumentWorkspace_DocumentChanged(object sender, EventArgs e)
  460. {
  461. UpdateDocInfoInStatusBar();
  462. UI.ResumeControlPainting(this);
  463. Invalidate(true);
  464. }
  465. private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
  466. {
  467. this.activeDocumentWorkspace.Document.CoordinatesToStrings(this.Units, x, y, out xString, out yString, out unitsString);
  468. }
  469. private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
  470. {
  471. SuspendLayout();
  472. if (this.activeDocumentWorkspace == null ||
  473. this.activeDocumentWorkspace.Document == null)
  474. {
  475. this.statusBar.CursorInfoText = string.Empty;
  476. }
  477. else
  478. {
  479. string xString;
  480. string yString;
  481. string units;
  482. CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
  483. string cursorText = string.Format(
  484. CultureInfo.InvariantCulture,
  485. this.cursorInfoStatusBarFormat,
  486. xString,
  487. units,
  488. yString,
  489. units);
  490. this.statusBar.CursorInfoText = cursorText;
  491. }
  492. ResumeLayout(false);
  493. }
  494. private void UpdateDocInfoInStatusBar()
  495. {
  496. if (this.activeDocumentWorkspace == null ||
  497. this.activeDocumentWorkspace.Document == null)
  498. {
  499. this.statusBar.ImageInfoStatusText = string.Empty;
  500. }
  501. else if (this.activeDocumentWorkspace != null &&
  502. this.activeDocumentWorkspace.Document != null)
  503. {
  504. string widthString;
  505. string heightString;
  506. string units;
  507. CoordinatesToStrings(
  508. this.activeDocumentWorkspace.Document.Width,
  509. this.activeDocumentWorkspace.Document.Height,
  510. out widthString,
  511. out heightString,
  512. out units);
  513. string imageText = string.Format(
  514. CultureInfo.InvariantCulture,
  515. this.imageInfoStatusBarFormat,
  516. widthString,
  517. units,
  518. heightString,
  519. units);
  520. this.statusBar.ImageInfoStatusText = imageText;
  521. }
  522. }
  523. [Browsable(false)]
  524. public WorkspaceWidgets Widgets
  525. {
  526. get
  527. {
  528. return this.widgets;
  529. }
  530. }
  531. [Browsable(false)]
  532. public AppEnvironment AppEnvironment
  533. {
  534. get
  535. {
  536. return this.appEnvironment;
  537. }
  538. }
  539. [Browsable(false)]
  540. public DocumentWorkspace ActiveDocumentWorkspace
  541. {
  542. get
  543. {
  544. return this.activeDocumentWorkspace;
  545. }
  546. set
  547. {
  548. if (value != this.activeDocumentWorkspace)
  549. {
  550. if (value != null &&
  551. this.documentWorkspaces.IndexOf(value) == -1)
  552. {
  553. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  554. }
  555. bool focused = false;
  556. if (this.activeDocumentWorkspace != null)
  557. {
  558. focused = this.activeDocumentWorkspace.Focused;
  559. }
  560. UI.SuspendControlPainting(this);
  561. OnActiveDocumentWorkspaceChanging();
  562. this.activeDocumentWorkspace = value;
  563. OnActiveDocumentWorkspaceChanged();
  564. UI.ResumeControlPainting(this);
  565. Refresh();
  566. if (value != null)
  567. {
  568. value.Focus();
  569. }
  570. }
  571. }
  572. }
  573. private void ActiveDocumentWorkspace_FirstInputAfterGotFocus(object sender, EventArgs e)
  574. {
  575. this.toolBar.DocumentStrip.EnsureItemFullyVisible(this.toolBar.DocumentStrip.SelectedDocumentIndex);
  576. }
  577. public DocumentWorkspace[] DocumentWorkspaces
  578. {
  579. get
  580. {
  581. return this.documentWorkspaces.ToArray();
  582. }
  583. }
  584. public DocumentWorkspace AddNewDocumentWorkspace()
  585. {
  586. if (this.initialWorkspace != null)
  587. {
  588. if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
  589. {
  590. this.globalToolTypeChoice = this.initialWorkspace.GetToolType();
  591. RemoveDocumentWorkspace(this.initialWorkspace);
  592. this.initialWorkspace = null;
  593. }
  594. }
  595. DocumentWorkspace dw = new DocumentWorkspace();
  596. dw.AppWorkspace = this;
  597. this.documentWorkspaces.Add(dw);
  598. this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
  599. return dw;
  600. }
  601. public Image GetDocumentWorkspaceThumbnail(DocumentWorkspace dw)
  602. {
  603. this.toolBar.DocumentStrip.SyncThumbnails();
  604. Image[] images = this.toolBar.DocumentStrip.DocumentThumbnails;
  605. DocumentWorkspace[] documents = this.toolBar.DocumentStrip.DocumentList;
  606. for (int i = 0; i < documents.Length; ++i)
  607. {
  608. if (documents[i] == dw)
  609. {
  610. return images[i];
  611. }
  612. }
  613. throw new ArgumentException("The requested DocumentWorkspace doesn't exist in this AppWorkspace");
  614. }
  615. public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
  616. {
  617. int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace);
  618. if (dwIndex == -1)
  619. {
  620. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  621. }
  622. bool removingCurrentDW;
  623. if (this.ActiveDocumentWorkspace == documentWorkspace)
  624. {
  625. removingCurrentDW = true;
  626. this.globalToolTypeChoice = documentWorkspace.GetToolType();
  627. }
  628. else
  629. {
  630. removingCurrentDW = false;
  631. }
  632. documentWorkspace.SetTool(null);
  633. // Choose new active DW if removing the current DW
  634. if (removingCurrentDW)
  635. {
  636. if (this.documentWorkspaces.Count == 1)
  637. {
  638. this.ActiveDocumentWorkspace = null;
  639. }
  640. else if (dwIndex == 0)
  641. {
  642. this.ActiveDocumentWorkspace = this.documentWorkspaces[1];
  643. }
  644. else
  645. {
  646. this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1];
  647. }
  648. }
  649. this.documentWorkspaces.Remove(documentWorkspace);
  650. this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
  651. if (this.initialWorkspace == documentWorkspace)
  652. {
  653. this.initialWorkspace = null;
  654. }
  655. // Clean up the DocumentWorkspace
  656. Document document = documentWorkspace.Document;
  657. documentWorkspace.Document = null;
  658. document.Dispose();
  659. documentWorkspace.Dispose();
  660. documentWorkspace = null;
  661. }
  662. private void UpdateHistoryButtons()
  663. {
  664. if (ActiveDocumentWorkspace == null)
  665. {
  666. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Undo, false);
  667. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Redo, false);
  668. }
  669. else
  670. {
  671. if (ActiveDocumentWorkspace.History.UndoStack.Count > 1)
  672. {
  673. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Undo, true);
  674. }
  675. else
  676. {
  677. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Undo, false);
  678. }
  679. if (ActiveDocumentWorkspace.History.RedoStack.Count > 0)
  680. {
  681. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Redo, true);
  682. }
  683. else
  684. {
  685. widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Redo, false);
  686. }
  687. }
  688. }
  689. private void HistoryChangedHandler(object sender, EventArgs e)
  690. {
  691. UpdateHistoryButtons();
  692. // some actions change the document size: make sure we update our status bar panel
  693. // TODO: shouldn't this be handled by our DocumentWorkspace.DocumentChanged handler...?
  694. UpdateDocInfoInStatusBar();
  695. }
  696. public event EventHandler ActiveDocumentWorkspaceChanging;
  697. protected virtual void OnActiveDocumentWorkspaceChanging()
  698. {
  699. SuspendUpdateSnapObstacle();
  700. if (ActiveDocumentWorkspaceChanging != null)
  701. {
  702. ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
  703. }
  704. if (this.activeDocumentWorkspace != null)
  705. {
  706. this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
  707. ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  708. this.activeDocumentWorkspace.RulersEnabledChanged -= this.DocumentWorkspace_RulersEnabledChanged;
  709. this.activeDocumentWorkspace.DocumentMouseEnter -= this.DocumentMouseEnterHandler;
  710. this.activeDocumentWorkspace.DocumentMouseLeave -= this.DocumentMouseLeaveHandler;
  711. this.activeDocumentWorkspace.DocumentMouseMove -= this.DocumentMouseMoveHandler;
  712. this.activeDocumentWorkspace.DocumentMouseDown -= this.DocumentMouseDownHandler;
  713. this.activeDocumentWorkspace.Scroll -= this.DocumentWorkspace_Scroll;
  714. this.activeDocumentWorkspace.Layout -= this.DocumentWorkspace_Layout;
  715. this.activeDocumentWorkspace.DrawGridChanged -= this.DocumentWorkspace_DrawGridChanged;
  716. this.activeDocumentWorkspace.DocumentClick -= this.DocumentClick;
  717. this.activeDocumentWorkspace.DocumentMouseUp -= this.DocumentMouseUpHandler;
  718. this.activeDocumentWorkspace.DocumentKeyPress -= this.DocumentKeyPress;
  719. this.activeDocumentWorkspace.DocumentKeyUp -= this.DocumenKeyUp;
  720. this.activeDocumentWorkspace.DocumentKeyDown -= this.DocumentKeyDown;
  721. this.activeDocumentWorkspace.History.Changed -= HistoryChangedHandler;
  722. this.activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
  723. this.activeDocumentWorkspace.DocumentChanging -= DocumentWorkspace_DocumentChanging;
  724. this.activeDocumentWorkspace.DocumentChanged -= DocumentWorkspace_DocumentChanged;
  725. this.activeDocumentWorkspace.Selection.Changing -= SelectedPathChangingHandler;
  726. this.activeDocumentWorkspace.Selection.Changed -= SelectedPathChangedHandler;
  727. this.activeDocumentWorkspace.ScaleFactorChanged -= ZoomChangedHandler;
  728. this.activeDocumentWorkspace.ZoomBasisChanged -= DocumentWorkspace_ZoomBasisChanged;
  729. this.activeDocumentWorkspace.Visible = false;
  730. this.historyForm.HistoryControl.HistoryStack = null;
  731. this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
  732. this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
  733. if (this.activeDocumentWorkspace.Tool != null)
  734. {
  735. while (this.activeDocumentWorkspace.Tool.IsMouseEntered)
  736. {
  737. this.activeDocumentWorkspace.Tool.PerformMouseLeave();
  738. }
  739. }
  740. Type toolType = this.activeDocumentWorkspace.GetToolType();
  741. if (toolType != null)
  742. {
  743. this.globalToolTypeChoice = this.activeDocumentWorkspace.GetToolType();
  744. }
  745. }
  746. ResumeUpdateSnapObstacle();
  747. UpdateSnapObstacle();
  748. }
  749. public event EventHandler ActiveDocumentWorkspaceChanged;
  750. protected virtual void OnActiveDocumentWorkspaceChanged()
  751. {
  752. SuspendUpdateSnapObstacle();
  753. if (this.activeDocumentWorkspace == null)
  754. {
  755. this.toolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Print, false);
  756. this.toolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Save, false);
  757. }
  758. else
  759. {
  760. this.activeDocumentWorkspace.SuspendLayout();
  761. this.toolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Print, true);
  762. this.toolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Save, true);
  763. this.activeDocumentWorkspace.BackColor = System.Drawing.SystemColors.ControlDark;
  764. this.activeDocumentWorkspace.Dock = System.Windows.Forms.DockStyle.Fill;
  765. this.activeDocumentWorkspace.DrawGrid = this.DrawGrid;
  766. this.activeDocumentWorkspace.PanelAutoScroll = true;
  767. this.activeDocumentWorkspace.RulersEnabled = this.globalRulersChoice;
  768. this.activeDocumentWorkspace.TabIndex = 0;
  769. this.activeDocumentWorkspace.TabStop = false;
  770. this.activeDocumentWorkspace.RulersEnabledChanged += this.DocumentWorkspace_RulersEnabledChanged;
  771. this.activeDocumentWorkspace.DocumentMouseEnter += this.DocumentMouseEnterHandler;
  772. this.activeDocumentWorkspace.DocumentMouseLeave += this.DocumentMouseLeaveHandler;
  773. this.activeDocumentWorkspace.DocumentMouseMove += this.DocumentMouseMoveHandler;
  774. this.activeDocumentWorkspace.DocumentMouseDown += this.DocumentMouseDownHandler;
  775. this.activeDocumentWorkspace.Scroll += this.DocumentWorkspace_Scroll;
  776. this.activeDocumentWorkspace.DrawGridChanged += this.DocumentWorkspace_DrawGridChanged;
  777. this.activeDocumentWorkspace.DocumentClick += this.DocumentClick;
  778. this.activeDocumentWorkspace.DocumentMouseUp += this.DocumentMouseUpHandler;
  779. this.activeDocumentWorkspace.DocumentKeyPress += this.DocumentKeyPress;
  780. this.activeDocumentWorkspace.DocumentKeyUp += this.DocumenKeyUp;
  781. this.activeDocumentWorkspace.DocumentKeyDown += this.DocumentKeyDown;
  782. if (this.workspacePanel.Controls.Contains(this.activeDocumentWorkspace))
  783. {
  784. this.activeDocumentWorkspace.Visible = true;
  785. }
  786. else
  787. {
  788. this.activeDocumentWorkspace.Dock = DockStyle.Fill;
  789. this.workspacePanel.Controls.Add(this.activeDocumentWorkspace);
  790. }
  791. this.activeDocumentWorkspace.Layout += this.DocumentWorkspace_Layout;
  792. this.toolBar.ViewConfigStrip.ScaleFactor = this.activeDocumentWorkspace.ScaleFactor;
  793. this.toolBar.ViewConfigStrip.ZoomBasis = this.activeDocumentWorkspace.ZoomBasis;
  794. this.activeDocumentWorkspace.AppWorkspace = this;
  795. this.activeDocumentWorkspace.History.Changed += HistoryChangedHandler;
  796. this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
  797. this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
  798. this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
  799. this.activeDocumentWorkspace.Selection.Changing += SelectedPathChangingHandler;
  800. this.activeDocumentWorkspace.Selection.Changed += SelectedPathChangedHandler;
  801. this.activeDocumentWorkspace.ScaleFactorChanged += ZoomChangedHandler;
  802. this.activeDocumentWorkspace.ZoomBasisChanged += DocumentWorkspace_ZoomBasisChanged;
  803. this.activeDocumentWorkspace.Units = this.widgets.ViewConfigStrip.Units;
  804. this.historyForm.HistoryControl.HistoryStack = this.ActiveDocumentWorkspace.History;
  805. this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
  806. this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
  807. this.toolBar.ViewConfigStrip.RulersEnabled = this.activeDocumentWorkspace.RulersEnabled;
  808. this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
  809. this.activeDocumentWorkspace.SetToolFromType(this.globalToolTypeChoice);
  810. UpdateSelectionToolbarButtons();
  811. UpdateHistoryButtons();
  812. UpdateDocInfoInStatusBar();
  813. this.activeDocumentWorkspace.ResumeLayout();
  814. this.activeDocumentWorkspace.PerformLayout();
  815. this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
  816. ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  817. }
  818. if (ActiveDocumentWorkspaceChanged != null)
  819. {
  820. ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
  821. }
  822. UpdateStatusBarContextStatus();
  823. ResumeUpdateSnapObstacle();
  824. UpdateSnapObstacle();
  825. }
  826. public AppWorkspace()
  827. {
  828. SuspendLayout();
  829. // initialize!
  830. InitializeComponent();
  831. InitializeFloatingForms();
  832. this.mainToolBarForm.ToolsControl.SetTools(DocumentWorkspace.ToolInfos);
  833. this.mainToolBarForm.ToolsControl.ToolClicked += new ToolClickedEventHandler(this.MainToolBar_ToolClicked);
  834. this.toolBar.ToolChooserStrip.SetTools(DocumentWorkspace.ToolInfos);
  835. this.toolBar.ToolChooserStrip.ToolClicked += new ToolClickedEventHandler(this.MainToolBar_ToolClicked);
  836. this.toolBar.AppWorkspace = this;
  837. // init the Widgets container
  838. this.widgets = new WorkspaceWidgets(this);
  839. this.widgets.ViewConfigStrip = this.toolBar.ViewConfigStrip;
  840. this.widgets.CommonActionsStrip = this.toolBar.CommonActionsStrip;
  841. this.widgets.ToolConfigStrip = this.toolBar.ToolConfigStrip;
  842. this.widgets.ToolsForm = this.mainToolBarForm;
  843. this.widgets.LayerForm = this.layerForm;
  844. this.widgets.HistoryForm = this.historyForm;
  845. this.widgets.ColorsForm = this.colorsForm;
  846. this.widgets.StatusBarProgress = this.statusBar;
  847. this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
  848. // Load our settings and initialize the AppEnvironment
  849. LoadSettings();
  850. // hook into Environment *Changed events
  851. AppEnvironment.PrimaryColorChanged += PrimaryColorChangedHandler;
  852. AppEnvironment.SecondaryColorChanged += SecondaryColorChangedHandler;
  853. AppEnvironment.ShapeDrawTypeChanged += ShapeDrawTypeChangedHandler;
  854. AppEnvironment.GradientInfoChanged += GradientInfoChangedHandler;
  855. AppEnvironment.ToleranceChanged += OnEnvironmentToleranceChanged;
  856. AppEnvironment.AlphaBlendingChanged += AlphaBlendingChangedHandler;
  857. AppEnvironment.FontInfo = this.toolBar.ToolConfigStrip.FontInfo;
  858. AppEnvironment.TextAlignment = this.toolBar.ToolConfigStrip.FontAlignment;
  859. AppEnvironment.AntiAliasingChanged += Environment_AntiAliasingChanged;
  860. AppEnvironment.FontInfoChanged += Environment_FontInfoChanged;
  861. AppEnvironment.FontSmoothingChanged += Environment_FontSmoothingChanged;
  862. AppEnvironment.TextAlignmentChanged += Environment_TextAlignmentChanged;
  863. AppEnvironment.PenInfoChanged += Environment_PenInfoChanged;
  864. AppEnvironment.BrushInfoChanged += Environment_BrushInfoChanged;
  865. AppEnvironment.ColorPickerClickBehaviorChanged += Environment_ColorPickerClickBehaviorChanged;
  866. AppEnvironment.ResamplingAlgorithmChanged += Environment_ResamplingAlgorithmChanged;
  867. AppEnvironment.SelectionCombineModeChanged += Environment_SelectionCombineModeChanged;
  868. AppEnvironment.FloodModeChanged += Environment_FloodModeChanged;
  869. AppEnvironment.SelectionDrawModeInfoChanged += Environment_SelectionDrawModeInfoChanged;
  870. this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
  871. this.toolBar.ToolConfigStrip.ToleranceChanged += OnToolBarToleranceChanged;
  872. this.toolBar.ToolConfigStrip.FontAlignmentChanged += ToolConfigStrip_TextAlignmentChanged;
  873. this.toolBar.ToolConfigStrip.FontInfoChanged += ToolConfigStrip_FontTextChanged;
  874. this.toolBar.ToolConfigStrip.FontSmoothingChanged += ToolConfigStrip_FontSmoothingChanged;
  875. this.toolBar.ToolConfigStrip.RelinquishFocus += RelinquishFocusHandler2;
  876. this.toolBar.CommonActionsStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  877. this.toolBar.CommonActionsStrip.MouseWheel += OnToolStripMouseWheel;
  878. this.toolBar.CommonActionsStrip.ButtonClick += CommonActionsStrip_ButtonClick;
  879. this.toolBar.ViewConfigStrip.DrawGridChanged += ViewConfigStrip_DrawGridChanged;
  880. this.toolBar.ViewConfigStrip.RulersEnabledChanged += ViewConfigStrip_RulersEnabledChanged;
  881. this.toolBar.ViewConfigStrip.ZoomBasisChanged += ViewConfigStrip_ZoomBasisChanged;
  882. this.toolBar.ViewConfigStrip.ZoomScaleChanged += ViewConfigStrip_ZoomScaleChanged;
  883. this.toolBar.ViewConfigStrip.ZoomIn += ViewConfigStrip_ZoomIn;
  884. this.toolBar.ViewConfigStrip.ZoomOut += ViewConfigStrip_ZoomOut;
  885. this.toolBar.ViewConfigStrip.UnitsChanged += ViewConfigStrip_UnitsChanged;
  886. this.toolBar.ViewConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  887. this.toolBar.ViewConfigStrip.MouseWheel += OnToolStripMouseWheel;
  888. this.toolBar.ToolConfigStrip.BrushInfoChanged += DrawConfigStrip_BrushChanged;
  889. this.toolBar.ToolConfigStrip.ShapeDrawTypeChanged += DrawConfigStrip_ShapeDrawTypeChanged;
  890. this.toolBar.ToolConfigStrip.PenInfoChanged += DrawConfigStrip_PenChanged;
  891. this.toolBar.ToolConfigStrip.GradientInfoChanged += ToolConfigStrip_GradientInfoChanged;
  892. this.toolBar.ToolConfigStrip.AlphaBlendingChanged += OnDrawConfigStripAlphaBlendingChanged;
  893. this.toolBar.ToolConfigStrip.AntiAliasingChanged += DrawConfigStrip_AntiAliasingChanged;
  894. this.toolBar.ToolConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  895. this.toolBar.ToolConfigStrip.ColorPickerClickBehaviorChanged += ToolConfigStrip_ColorPickerClickBehaviorChanged;
  896. this.toolBar.ToolConfigStrip.ResamplingAlgorithmChanged += ToolConfigStrip_ResamplingAlgorithmChanged;
  897. this.toolBar.ToolConfigStrip.SelectionCombineModeChanged += ToolConfigStrip_SelectionCombineModeChanged;
  898. this.toolBar.ToolConfigStrip.FloodModeChanged += ToolConfigStrip_FloodModeChanged;
  899. this.toolBar.ToolConfigStrip.SelectionDrawModeInfoChanged += ToolConfigStrip_SelectionDrawModeInfoChanged;
  900. this.toolBar.ToolConfigStrip.SelectionDrawModeUnitsChanging += ToolConfigStrip_SelectionDrawModeUnitsChanging;
  901. this.toolBar.ToolConfigStrip.MouseWheel += OnToolStripMouseWheel;
  902. this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  903. this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
  904. this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
  905. // Synchronize
  906. AppEnvironment.PerformAllChanged();
  907. this.globalToolTypeChoice = this.defaultToolTypeChoice;
  908. this.toolBar.ToolConfigStrip.ToolBarConfigItems = ToolBarConfigItems.None;
  909. this.layerForm.LayerControl.AppWorkspace = this;
  910. ResumeLayout();
  911. PerformLayout();
  912. }
  913. private void ToolConfigStrip_ColorPickerClickBehaviorChanged(object sender, EventArgs e)
  914. {
  915. this.appEnvironment.ColorPickerClickBehavior = this.widgets.ToolConfigStrip.ColorPickerClickBehavior;
  916. }
  917. private void Environment_ColorPickerClickBehaviorChanged(object sender, EventArgs e)
  918. {
  919. this.widgets.ToolConfigStrip.ColorPickerClickBehavior = this.appEnvironment.ColorPickerClickBehavior;
  920. }
  921. private void ToolConfigStrip_ResamplingAlgorithmChanged(object sender, EventArgs e)
  922. {
  923. this.appEnvironment.ResamplingAlgorithm = this.widgets.ToolConfigStrip.ResamplingAlgorithm;
  924. }
  925. private void Environment_ResamplingAlgorithmChanged(object sender, EventArgs e)
  926. {
  927. this.widgets.ToolConfigStrip.ResamplingAlgorithm = this.appEnvironment.ResamplingAlgorithm;
  928. }
  929. private void ToolConfigStrip_SelectionCombineModeChanged(object sender, EventArgs e)
  930. {
  931. this.appEnvironment.SelectionCombineMode = this.widgets.ToolConfigStrip.SelectionCombineMode;
  932. }
  933. private void Environment_SelectionCombineModeChanged(object sender, EventArgs e)
  934. {
  935. this.widgets.ToolConfigStrip.SelectionCombineMode = this.appEnvironment.SelectionCombineMode;
  936. }
  937. private void ToolConfigStrip_FloodModeChanged(object sender, EventArgs e)
  938. {
  939. this.appEnvironment.FloodMode = this.widgets.ToolConfigStrip.FloodMode;
  940. }
  941. private void Environment_FloodModeChanged(object sender, EventArgs e)
  942. {
  943. this.widgets.ToolConfigStrip.FloodMode = this.appEnvironment.FloodMode;
  944. }
  945. private void ToolConfigStrip_SelectionDrawModeInfoChanged(object sender, EventArgs e)
  946. {
  947. this.appEnvironment.SelectionDrawModeInfo = this.widgets.ToolConfigStrip.SelectionDrawModeInfo;
  948. }
  949. private void Environment_SelectionDrawModeInfoChanged(object sender, EventArgs e)
  950. {
  951. this.widgets.ToolConfigStrip.SelectionDrawModeInfo = this.appEnvironment.SelectionDrawModeInfo;
  952. }
  953. private sealed class ToolConfigStrip_SelectionDrawModeUnitsChangeHandler
  954. {
  955. private ToolConfigStrip toolConfigStrip;
  956. private Document activeDocument;
  957. private MeasurementUnit oldUnits;
  958. public ToolConfigStrip_SelectionDrawModeUnitsChangeHandler(ToolConfigStrip toolConfigStrip, Document activeDocument)
  959. {
  960. this.toolConfigStrip = toolConfigStrip;
  961. this.activeDocument = activeDocument;
  962. this.oldUnits = toolConfigStrip.SelectionDrawModeInfo.Units;
  963. }
  964. public void Initialize()
  965. {
  966. this.toolConfigStrip.SelectionDrawModeUnitsChanged += ToolConfigStrip_SelectionDrawModeUnitsChanged;
  967. }
  968. public void ToolConfigStrip_SelectionDrawModeUnitsChanged(object sender, EventArgs e)
  969. {
  970. try
  971. {
  972. SelectionDrawModeInfo sdmi = this.toolConfigStrip.SelectionDrawModeInfo;
  973. MeasurementUnit newUnits = sdmi.Units;
  974. double oldWidth = sdmi.Width;
  975. double oldHeight = sdmi.Height;
  976. double newWidth;
  977. double newHeight;
  978. newWidth = Document.ConvertMeasurement(oldWidth, this.oldUnits, this.activeDocument.DpuUnit, this.activeDocument.DpuX, newUnits);
  979. newHeight = Document.ConvertMeasurement(oldHeight, this.oldUnits, this.activeDocument.DpuUnit, this.activeDocument.DpuY, newUnits);
  980. SelectionDrawModeInfo newSdmi = sdmi.CloneWithNewWidthAndHeight(newWidth, newHeight);
  981. this.toolConfigStrip.SelectionDrawModeInfo = newSdmi;
  982. }
  983. finally
  984. {
  985. this.toolConfigStrip.SelectionDrawModeUnitsChanged -= ToolConfigStrip_SelectionDrawModeUnitsChanged;
  986. }
  987. }
  988. }
  989. private void ToolConfigStrip_SelectionDrawModeUnitsChanging(object sender, EventArgs e)
  990. {
  991. if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Document != null)
  992. {
  993. ToolConfigStrip_SelectionDrawModeUnitsChangeHandler tcsSdmuch = new ToolConfigStrip_SelectionDrawModeUnitsChangeHandler(
  994. this.toolBar.ToolConfigStrip, this.ActiveDocumentWorkspace.Document);
  995. tcsSdmuch.Initialize();
  996. }
  997. }
  998. private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
  999. {
  1000. bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
  1001. this.widgets.ToolsForm.Enabled = enableThem;
  1002. this.widgets.HistoryForm.Enabled = enableThem;
  1003. this.widgets.LayerForm.Enabled = enableThem;
  1004. this.widgets.ColorsForm.Enabled = enableThem;
  1005. this.widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Paste, enableThem);
  1006. UpdateHistoryButtons();
  1007. UpdateDocInfoInStatusBar();
  1008. UpdateCursorInfoInStatusBar(0, 0);
  1009. }
  1010. public void SaveSettings()
  1011. {
  1012. Settings.CurrentUser.SetBoolean(SettingNames.Rulers, this.globalRulersChoice);
  1013. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, this.DrawGrid);
  1014. Settings.CurrentUser.SetString(SettingNames.DefaultToolTypeName, this.defaultToolTypeChoice.Name);
  1015. this.MostRecentFiles.SaveMruList();
  1016. }
  1017. private void LoadDefaultToolType()
  1018. {
  1019. string defaultToolTypeName = Settings.CurrentUser.GetString(SettingNames.DefaultToolTypeName, Tool.DefaultToolType.Name);
  1020. ToolInfo[] tis = DocumentWorkspace.ToolInfos;
  1021. ToolInfo ti = Array.Find(
  1022. tis,
  1023. delegate(ToolInfo check)
  1024. {
  1025. if (string.Compare(defaultToolTypeName, check.ToolType.Name, StringComparison.InvariantCultureIgnoreCase) == 0)
  1026. {
  1027. return true;
  1028. }
  1029. else
  1030. {
  1031. return false;
  1032. }
  1033. });
  1034. if (ti == null)
  1035. {
  1036. this.defaultToolTypeChoice = Tool.DefaultToolType;
  1037. }
  1038. else
  1039. {
  1040. this.defaultToolTypeChoice = ti.ToolType;
  1041. }
  1042. }
  1043. public void LoadSettings()
  1044. {
  1045. try
  1046. {
  1047. LoadDefaultToolType();
  1048. this.globalToolTypeChoice = this.defaultToolTypeChoice;
  1049. this.globalRulersChoice = Settings.CurrentUser.GetBoolean(SettingNames.Rule

Large files files are truncated, but you can click here to view the full file