DesignerCommands.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using System.ComponentModel;
  7. using FastReport.Utils;
  8. using FastReport.Data;
  9. using FastReport.Dialog;
  10. using FastReport.Forms;
  11. using FastReport.Code;
  12. using FastReport.Design.ToolWindows;
  13. using FastReport.Design.PageDesigners.Code;
  14. using FastReport.FastQueryBuilder;
  15. namespace FastReport.Design
  16. {
  17. /// <summary>
  18. /// The base class for all designer commands.
  19. /// </summary>
  20. public class DesignerCommand
  21. {
  22. private object sender;
  23. internal Designer Designer { get; }
  24. internal Report ActiveReport
  25. {
  26. get { return Designer.ActiveReport; }
  27. }
  28. internal ReportTab ActiveReportTab
  29. {
  30. get { return Designer.ActiveReportTab; }
  31. }
  32. internal DesignerRestrictions Restrictions
  33. {
  34. get { return Designer.Restrictions; }
  35. }
  36. internal SelectedObjectCollection SelectedObjects
  37. {
  38. get { return Designer.SelectedObjects; }
  39. }
  40. internal SelectedReportComponents SelectedReportComponents
  41. {
  42. get { return Designer.SelectedReportComponents; }
  43. }
  44. internal void SetModified(string action)
  45. {
  46. Designer.SetModified(sender, action);
  47. }
  48. /// <summary>
  49. /// Gets a value indicating that the command is enabled.
  50. /// </summary>
  51. /// <remarks>
  52. /// If you use own controls that invoke designer commands, use this property to refresh
  53. /// the <b>Enabled</b> state of a control that is bound to this command.
  54. /// </remarks>
  55. public bool Enabled
  56. {
  57. get { return GetEnabled(); }
  58. }
  59. /// <summary>
  60. /// Defines a custom action for this command.
  61. /// </summary>
  62. /// <remarks>
  63. /// Using custom action, you can override the standard behavior of this designer's command.
  64. /// </remarks>
  65. /// <example>
  66. /// This example demonstrates how to override the "New..." command behavior.
  67. /// <code>
  68. /// // add an event handler that will be fired when the designer is run
  69. /// Config.DesignerSettings.DesignerLoaded += new EventHandler(DesignerSettings_DesignerLoaded);
  70. ///
  71. /// void DesignerSettings_DesignerLoaded(object sender, EventArgs e)
  72. /// {
  73. /// // override "New..." command behavior
  74. /// (sender as Designer).cmdNew.CustomAction += new EventHandler(cmdNew_CustomAction);
  75. /// }
  76. ///
  77. /// void cmdNew_CustomAction(object sender, EventArgs e)
  78. /// {
  79. /// // show the "Label" wizard instead of standard "Add New Item" dialog
  80. /// Designer designer = sender as Designer;
  81. /// LabelWizard wizard = new LabelWizard();
  82. /// wizard.Run(designer);
  83. /// }
  84. /// </code>
  85. /// </example>
  86. public event EventHandler CustomAction;
  87. /// <summary>
  88. /// Gets a value for the <b>Enabled</b> property.
  89. /// </summary>
  90. /// <returns><b>true</b> if command is enabled.</returns>
  91. protected virtual bool GetEnabled()
  92. {
  93. return true;
  94. }
  95. /// <summary>
  96. /// Invokes the command.
  97. /// </summary>
  98. public virtual void Invoke()
  99. {
  100. }
  101. /// <summary>
  102. /// Invokes the command with specified sender and event args.
  103. /// </summary>
  104. /// <param name="sender">Sender.</param>
  105. /// <param name="e">Event args.</param>
  106. /// <remarks>
  107. /// This method is compatible with standard <see cref="EventHandler"/> and can be passed
  108. /// to the event handler constructor directly.
  109. /// </remarks>
  110. public void Invoke(object sender, EventArgs e)
  111. {
  112. if (CustomAction != null)
  113. CustomAction(Designer, e);
  114. else
  115. {
  116. this.sender = sender;
  117. Invoke();
  118. }
  119. }
  120. internal DesignerCommand(Designer designer)
  121. {
  122. this.Designer = designer;
  123. }
  124. }
  125. /// <summary>
  126. /// Represents the "File|New" command.
  127. /// </summary>
  128. public class NewCommand : DesignerCommand
  129. {
  130. /// <inheritdoc/>
  131. protected override bool GetEnabled()
  132. {
  133. return !Restrictions.DontCreateReport &&
  134. (Designer.MdiMode || ActiveReportTab != null);
  135. }
  136. /// <inheritdoc/>
  137. public override void Invoke()
  138. {
  139. Designer.ValidatorWindow.CancelUpdateErrors();
  140. using (AddNewItemForm form = new AddNewItemForm(Designer))
  141. {
  142. if (form.ShowDialog() == DialogResult.OK)
  143. form.SelectedWizard.Run(Designer);
  144. }
  145. Designer.ValidatorWindow.ShowLoadingProgress();
  146. Designer.ValidatorWindow.UpdateErrors(!PageDesigners.Page.ReportWorkspace.EnableBacklightIntersectingObjects);
  147. }
  148. internal NewCommand(Designer designer)
  149. : base(designer)
  150. {
  151. }
  152. }
  153. /// <summary>
  154. /// Represents the "New Page" toolbar command.
  155. /// </summary>
  156. public class NewPageCommand : DesignerCommand
  157. {
  158. /// <inheritdoc/>
  159. protected override bool GetEnabled()
  160. {
  161. return !Restrictions.DontCreatePage && ActiveReport != null;
  162. }
  163. /// <inheritdoc/>
  164. public override void Invoke()
  165. {
  166. ActiveReportTab.NewReportPage();
  167. }
  168. internal NewPageCommand(Designer designer)
  169. : base(designer)
  170. {
  171. }
  172. }
  173. /// <summary>
  174. /// Represents the "New Dialog" toolbar command.
  175. /// </summary>
  176. public class NewDialogCommand : DesignerCommand
  177. {
  178. /// <inheritdoc/>
  179. protected override bool GetEnabled()
  180. {
  181. return !Restrictions.DontCreatePage && ActiveReport != null;
  182. }
  183. /// <inheritdoc/>
  184. public override void Invoke()
  185. {
  186. ActiveReportTab.NewDialog();
  187. }
  188. internal NewDialogCommand(Designer designer)
  189. : base(designer)
  190. {
  191. }
  192. }
  193. /// <summary>
  194. /// Represents the "File|Open..." command. Also can be used for loading a file
  195. /// from the recent files list.
  196. /// </summary>
  197. public class OpenCommand : DesignerCommand
  198. {
  199. /// <inheritdoc/>
  200. protected override bool GetEnabled()
  201. {
  202. return !Restrictions.DontLoadReport &&
  203. (Designer.MdiMode || ActiveReportTab != null);
  204. }
  205. /// <inheritdoc/>
  206. public override void Invoke()
  207. {
  208. LoadFile("");
  209. }
  210. /// <summary>
  211. /// Loads a specified report file.
  212. /// </summary>
  213. /// <param name="fileName">File to load.</param>
  214. public void LoadFile(string fileName)
  215. {
  216. Designer.ValidatorWindow.CancelUpdateErrors();
  217. ReportTab reportTab = null;
  218. if (Designer.MdiMode)
  219. {
  220. // check if file is already opened
  221. if (!String.IsNullOrEmpty(fileName))
  222. {
  223. foreach (DocumentWindow c in Designer.Documents)
  224. {
  225. if (c is ReportTab && String.Compare((c as ReportTab).Report.FileName, fileName, true) == 0)
  226. {
  227. c.Activate();
  228. return;
  229. }
  230. }
  231. }
  232. Report report = new Report();
  233. report.Designer = Designer;
  234. reportTab = Designer.CreateReportTab(report);
  235. }
  236. else
  237. reportTab = ActiveReportTab;
  238. if (reportTab.LoadFile(fileName))
  239. {
  240. if (Designer.MdiMode)
  241. Designer.AddReportTab(reportTab);
  242. }
  243. else if (Designer.MdiMode)
  244. reportTab.Dispose();
  245. Designer.ValidatorWindow.CancelUpdateErrors();
  246. Designer.ValidatorWindow.ShowLoadingProgress();
  247. Designer.ValidatorWindow.UpdateErrors(!PageDesigners.Page.ReportWorkspace.EnableBacklightIntersectingObjects);
  248. Config.ReportSettings.OnFinishLoadingProgress();
  249. }
  250. internal OpenCommand(Designer designer)
  251. : base(designer)
  252. {
  253. }
  254. }
  255. /// <summary>
  256. /// Represents the "File|Save" command.
  257. /// </summary>
  258. public class SaveCommand : DesignerCommand
  259. {
  260. /// <inheritdoc/>
  261. protected override bool GetEnabled()
  262. {
  263. return !Restrictions.DontSaveReport &&
  264. ActiveReportTab != null &&
  265. ActiveReportTab.Modified;
  266. }
  267. /// <inheritdoc/>
  268. public override void Invoke()
  269. {
  270. ActiveReportTab.SaveFile(false);
  271. }
  272. internal SaveCommand(Designer designer)
  273. : base(designer)
  274. {
  275. }
  276. }
  277. /// <summary>
  278. /// Represents the "File|Save As..." command.
  279. /// </summary>
  280. public class SaveAsCommand : DesignerCommand
  281. {
  282. /// <inheritdoc/>
  283. protected override bool GetEnabled()
  284. {
  285. return !Restrictions.DontSaveReport && ActiveReportTab != null;
  286. }
  287. /// <inheritdoc/>
  288. public override void Invoke()
  289. {
  290. ActiveReportTab.SaveFile(true);
  291. }
  292. internal SaveAsCommand(Designer designer)
  293. : base(designer)
  294. {
  295. }
  296. }
  297. /// <summary>
  298. /// Represents the "File|Save With Random Data..." command.
  299. /// </summary>
  300. public class SaveWithRandomDataCommand : DesignerCommand
  301. {
  302. /// <inheritdoc/>
  303. protected override bool GetEnabled()
  304. {
  305. return !Restrictions.DontSaveReport && ActiveReportTab != null;
  306. }
  307. /// <inheritdoc/>
  308. public override void Invoke()
  309. {
  310. ActiveReportTab.SaveWithRandomData();
  311. }
  312. internal SaveWithRandomDataCommand(Designer designer)
  313. : base(designer)
  314. {
  315. }
  316. }
  317. /// <summary>
  318. /// Represents the "File|Save All" command.
  319. /// </summary>
  320. public class SaveAllCommand : DesignerCommand
  321. {
  322. /// <inheritdoc/>
  323. protected override bool GetEnabled()
  324. {
  325. bool enabled = Designer.MdiMode && Designer.Documents.Count > 0;
  326. if (Designer.Documents.Count == 1 && Designer.Documents[0] is StartPageTab)
  327. enabled = false;
  328. return !Restrictions.DontSaveReport && enabled;
  329. }
  330. /// <inheritdoc/>
  331. public override void Invoke()
  332. {
  333. foreach (DocumentWindow c in Designer.Documents)
  334. {
  335. if (c is ReportTab)
  336. (c as ReportTab).SaveFile(false);
  337. }
  338. }
  339. internal SaveAllCommand(Designer designer)
  340. : base(designer)
  341. {
  342. }
  343. }
  344. /// <summary>
  345. /// Represents the "File|Close" command.
  346. /// </summary>
  347. public class CloseCommand : DesignerCommand
  348. {
  349. /// <inheritdoc/>
  350. protected override bool GetEnabled()
  351. {
  352. return Designer.MdiMode && Designer.Documents.Count > 0;
  353. }
  354. /// <inheritdoc/>
  355. public override void Invoke()
  356. {
  357. if (Designer.ActiveReportTab != null)
  358. Designer.CloseDocument(ActiveReportTab);
  359. else if (Designer.StartPage != null)
  360. Designer.CloseDocument(Designer.StartPage);
  361. }
  362. internal CloseCommand(Designer designer)
  363. : base(designer)
  364. {
  365. }
  366. }
  367. /// <summary>
  368. /// Represents the "Window|Close All" command.
  369. /// </summary>
  370. public class CloseAllCommand : CloseCommand
  371. {
  372. /// <inheritdoc/>
  373. public override void Invoke()
  374. {
  375. int i = 0;
  376. while (i < Designer.Documents.Count)
  377. {
  378. DocumentWindow c = Designer.Documents[i];
  379. if (c is StartPageTab || !Designer.CloseDocument(c))
  380. i++;
  381. }
  382. }
  383. internal CloseAllCommand(Designer designer)
  384. : base(designer)
  385. {
  386. }
  387. }
  388. /// <summary>
  389. /// Represents the "File|Preview..." command.
  390. /// </summary>
  391. public class PreviewCommand : DesignerCommand
  392. {
  393. /// <inheritdoc/>
  394. protected override bool GetEnabled()
  395. {
  396. return !Restrictions.DontPreviewReport && ActiveReport != null;
  397. }
  398. /// <inheritdoc/>
  399. public override void Invoke()
  400. {
  401. Designer.ValidatorWindow.CancelUpdateErrors();
  402. ActiveReportTab.Preview();
  403. Designer.ValidatorWindow.ShowLoadingProgress();
  404. Designer.ValidatorWindow.UpdateErrors(!PageDesigners.Page.ReportWorkspace.EnableBacklightIntersectingObjects);
  405. }
  406. internal PreviewCommand(Designer designer)
  407. : base(designer)
  408. {
  409. }
  410. }
  411. /// <summary>
  412. /// Represents the "File|Page Setup..." command.
  413. /// </summary>
  414. public class PageSettingsCommand : DesignerCommand
  415. {
  416. /// <inheritdoc/>
  417. protected override bool GetEnabled()
  418. {
  419. return !Restrictions.DontChangePageOptions &&
  420. ActiveReport != null &&
  421. ActiveReportTab.ActivePage is ReportPage;
  422. }
  423. /// <inheritdoc/>
  424. public override void Invoke()
  425. {
  426. IHasEditor page = ActiveReportTab.ActivePage as IHasEditor;
  427. if (page.InvokeEditor())
  428. {
  429. SetModified("EditPage");
  430. }
  431. }
  432. internal PageSettingsCommand(Designer designer)
  433. : base(designer)
  434. {
  435. }
  436. }
  437. /// <summary>
  438. /// Represents the "Report|Options..." command.
  439. /// </summary>
  440. public class ReportSettingsCommand : DesignerCommand
  441. {
  442. /// <inheritdoc/>
  443. protected override bool GetEnabled()
  444. {
  445. return !Restrictions.DontChangeReportOptions && ActiveReport != null;
  446. }
  447. /// <inheritdoc/>
  448. public override void Invoke()
  449. {
  450. using (ReportOptionsForm form = new ReportOptionsForm(ActiveReport))
  451. {
  452. ActiveReport.ScriptText = ActiveReportTab.Script;
  453. if (form.ShowDialog() == DialogResult.OK)
  454. {
  455. ActiveReportTab.Script = ActiveReport.ScriptText;
  456. (ActiveReportTab.Plugins.Find("Code") as CodePageDesigner).UpdateLanguage();
  457. SetModified("EditReport");
  458. }
  459. }
  460. }
  461. internal ReportSettingsCommand(Designer designer)
  462. : base(designer)
  463. {
  464. }
  465. }
  466. /// <summary>
  467. /// Represents the "File|Printer Setup..." command.
  468. /// </summary>
  469. public class PrinterSettingsCommand : DesignerCommand
  470. {
  471. /// <inheritdoc/>
  472. protected override bool GetEnabled()
  473. {
  474. return !Restrictions.DontChangeReportOptions && ActiveReport != null;
  475. }
  476. /// <inheritdoc/>
  477. public override void Invoke()
  478. {
  479. using (PrinterSetupForm editor = new PrinterSetupForm())
  480. {
  481. editor.Report = ActiveReport;
  482. if (editor.ShowDialog() == DialogResult.OK)
  483. {
  484. SetModified("EditPrinter");
  485. }
  486. }
  487. }
  488. internal PrinterSettingsCommand(Designer designer)
  489. : base(designer)
  490. {
  491. }
  492. }
  493. /// <summary>
  494. /// Represents the "Edit|Undo" command.
  495. /// </summary>
  496. public class UndoCommand : DesignerCommand
  497. {
  498. /// <inheritdoc/>
  499. protected override bool GetEnabled()
  500. {
  501. return ActiveReport != null && ActiveReportTab.CanUndo;
  502. }
  503. /// <inheritdoc/>
  504. public override void Invoke()
  505. {
  506. Undo(1);
  507. }
  508. /// <summary>
  509. /// Undo several actions.
  510. /// </summary>
  511. /// <param name="actionsCount">Number of actions to undo.</param>
  512. public void Undo(int actionsCount)
  513. {
  514. Designer.ValidatorWindow.CancelUpdateErrors();
  515. ActiveReportTab.Undo(actionsCount);
  516. Designer.ValidatorWindow.UpdateErrors(false);
  517. }
  518. internal UndoCommand(Designer designer)
  519. : base(designer)
  520. {
  521. }
  522. }
  523. /// <summary>
  524. /// Represents the "Edit|Redo" command.
  525. /// </summary>
  526. public class RedoCommand : DesignerCommand
  527. {
  528. /// <inheritdoc/>
  529. protected override bool GetEnabled()
  530. {
  531. return ActiveReport != null && ActiveReportTab.CanRedo;
  532. }
  533. /// <inheritdoc/>
  534. public override void Invoke()
  535. {
  536. Redo(1);
  537. }
  538. /// <summary>
  539. /// Redo several actions.
  540. /// </summary>
  541. /// <param name="actionsCount">Number of actions to redo.</param>
  542. public void Redo(int actionsCount)
  543. {
  544. Designer.ValidatorWindow.CancelUpdateErrors();
  545. ActiveReportTab.Redo(actionsCount);
  546. Designer.ValidatorWindow.UpdateErrors(false);
  547. }
  548. internal RedoCommand(Designer designer)
  549. : base(designer)
  550. {
  551. }
  552. }
  553. /// <summary>
  554. /// Represents the "Edit|Cut" command.
  555. /// </summary>
  556. public class CutCommand : DesignerCommand
  557. {
  558. /// <inheritdoc/>
  559. protected override bool GetEnabled()
  560. {
  561. if (ActiveReportTab != null && ActiveReportTab.ActivePage == null)
  562. return true;
  563. bool enable = ActiveReportTab != null &&
  564. ActiveReportTab.ActivePage != null &&
  565. SelectedObjects.Count > 0;
  566. if (enable)
  567. {
  568. enable = false;
  569. // if at least one object can be copied, allow the operation
  570. foreach (Base c in SelectedObjects)
  571. {
  572. if (c.HasFlag(Flags.CanCopy))
  573. {
  574. enable = true;
  575. break;
  576. }
  577. }
  578. }
  579. return enable;
  580. }
  581. /// <inheritdoc/>
  582. public override void Invoke()
  583. {
  584. Designer.ValidatorWindow.CancelUpdateErrors();
  585. if (ActiveReportTab != null && ActiveReportTab.ActivePage == null)
  586. {
  587. if (ActiveReportTab.IsFRXPageActie)
  588. Designer.FRXEditor.Cut();
  589. else
  590. Designer.Editor.Cut();
  591. }
  592. else if (Enabled)
  593. Designer.Clipboard.Cut();
  594. }
  595. internal CutCommand(Designer designer)
  596. : base(designer)
  597. {
  598. }
  599. }
  600. /// <summary>
  601. /// Represents the "Edit|Copy" command.
  602. /// </summary>
  603. public class CopyCommand : CutCommand
  604. {
  605. /// <inheritdoc/>
  606. public override void Invoke()
  607. {
  608. if (ActiveReportTab != null && ActiveReportTab.ActivePage == null)
  609. {
  610. if (ActiveReportTab.IsFRXPageActie)
  611. Designer.FRXEditor.Copy();
  612. else
  613. Designer.Editor.Copy();
  614. }
  615. else if (Enabled)
  616. Designer.Clipboard.Copy();
  617. }
  618. internal CopyCommand(Designer designer)
  619. : base(designer)
  620. {
  621. }
  622. }
  623. /// <summary>
  624. /// Represents the "Edit|Copy Page" command.
  625. /// </summary>
  626. public class CopyPageCommand : DesignerCommand
  627. {
  628. /// <inheritdoc/>
  629. protected override bool GetEnabled()
  630. {
  631. return !Restrictions.DontCopyPage && ActiveReport != null && ActiveReportTab.ActivePage != null &&
  632. ActiveReport.Pages.Count > 0 && (ActiveReportTab.ActivePage is ReportPage || ActiveReportTab.ActivePage is DialogPage) &&
  633. !ActiveReportTab.ActivePage.IsAncestor;
  634. }
  635. /// <inheritdoc/>
  636. public override void Invoke()
  637. {
  638. if (Enabled)
  639. {
  640. ActiveReportTab.CopyPage();
  641. }
  642. }
  643. internal CopyPageCommand(Designer designer) : base(designer)
  644. {
  645. }
  646. }
  647. /// <summary>
  648. /// Represents the "Edit|Paste" command.
  649. /// </summary>
  650. public class PasteCommand : DesignerCommand
  651. {
  652. /// <inheritdoc/>
  653. protected override bool GetEnabled()
  654. {
  655. if (ActiveReportTab != null && ActiveReportTab.ActivePage == null)
  656. return true;
  657. return ActiveReportTab != null && ActiveReportTab.ActivePage != null && Designer.Clipboard.CanPaste;
  658. }
  659. /// <inheritdoc/>
  660. public override void Invoke()
  661. {
  662. Designer.ValidatorWindow.CancelUpdateErrors();
  663. if (ActiveReportTab != null && ActiveReportTab.ActivePage == null)
  664. {
  665. if (ActiveReportTab.IsFRXPageActie)
  666. Designer.FRXEditor.Paste();
  667. else
  668. Designer.Editor.Paste();
  669. }
  670. else
  671. Designer.Clipboard.Paste();
  672. }
  673. internal PasteCommand(Designer designer)
  674. : base(designer)
  675. {
  676. }
  677. }
  678. /// <summary>
  679. /// Represents the "Format Painter" toolbar command.
  680. /// </summary>
  681. public class FormatPainterCommand : DesignerCommand
  682. {
  683. /// <inheritdoc/>
  684. protected override bool GetEnabled()
  685. {
  686. return ActiveReportTab != null &&
  687. ActiveReportTab.ActivePage != null &&
  688. SelectedReportComponents.Count > 0;
  689. }
  690. /// <inheritdoc/>
  691. public override void Invoke()
  692. {
  693. Designer.FormatPainter = !Designer.FormatPainter;
  694. }
  695. internal FormatPainterCommand(Designer designer)
  696. : base(designer)
  697. {
  698. }
  699. }
  700. /// <summary>
  701. /// Represents the "Edit|Delete" command.
  702. /// </summary>
  703. public class DeleteCommand : DesignerCommand
  704. {
  705. /// <inheritdoc/>
  706. protected override bool GetEnabled()
  707. {
  708. bool enable = SelectedObjects.Count > 0;
  709. if (enable && SelectedObjects.Count == 1 &&
  710. (!SelectedObjects[0].HasFlag(Flags.CanDelete) ||
  711. SelectedObjects[0].HasRestriction(FastReport.Restrictions.DontDelete)))
  712. enable = false;
  713. return enable;
  714. }
  715. /// <inheritdoc/>
  716. public override void Invoke()
  717. {
  718. if (SelectedObjects.IsPageSelected || SelectedObjects.IsReportSelected)
  719. return;
  720. Designer.ValidatorWindow.CancelUpdateErrors();
  721. foreach (Base c in SelectedObjects)
  722. {
  723. if (!c.HasFlag(Flags.CanDelete) || c.HasRestriction(FastReport.Restrictions.DontDelete))
  724. continue;
  725. else
  726. {
  727. if (c.IsAncestor)
  728. {
  729. FRMessageBox.Error(String.Format(Res.Get("Messages,DeleteAncestor"), c.Name));
  730. return;
  731. }
  732. foreach (Base b in c.AllObjects)
  733. {
  734. if (b is SubreportObject) b.Delete();
  735. }
  736. c.Delete();
  737. }
  738. }
  739. SetModified("Delete");
  740. Designer.SelectionChanged(null);
  741. }
  742. internal DeleteCommand(Designer designer)
  743. : base(designer)
  744. {
  745. }
  746. }
  747. /// <summary>
  748. /// Represents the "Edit|Delete Page" command.
  749. /// </summary>
  750. public class DeletePageCommand : DesignerCommand
  751. {
  752. /// <inheritdoc/>
  753. protected override bool GetEnabled()
  754. {
  755. return !Restrictions.DontDeletePage && ActiveReport != null &&
  756. ActiveReportTab.ActivePage != null &&
  757. ActiveReport.Pages.Count > 1 &&
  758. !ActiveReportTab.ActivePage.IsAncestor;
  759. }
  760. /// <inheritdoc/>
  761. public override void Invoke()
  762. {
  763. if (Enabled)
  764. {
  765. ActiveReportTab.DeletePage();
  766. }
  767. }
  768. internal DeletePageCommand(Designer designer)
  769. : base(designer)
  770. {
  771. }
  772. }
  773. /// <summary>
  774. /// Represents the "Edit|Select All" command.
  775. /// </summary>
  776. public class SelectAllCommand : DesignerCommand
  777. {
  778. /// <inheritdoc/>
  779. protected override bool GetEnabled()
  780. {
  781. return ActiveReportTab != null && ActiveReportTab.ActivePage != null;
  782. }
  783. /// <inheritdoc/>
  784. public override void Invoke()
  785. {
  786. if (ActiveReportTab != null)
  787. ActiveReportTab.ActivePageDesigner.SelectAll();
  788. }
  789. internal SelectAllCommand(Designer designer)
  790. : base(designer)
  791. {
  792. }
  793. }
  794. /// <summary>
  795. /// Represents the "Edit|Group" command.
  796. /// </summary>
  797. public class GroupCommand : DesignerCommand
  798. {
  799. /// <inheritdoc/>
  800. protected override bool GetEnabled()
  801. {
  802. return SelectedObjects.Count > 1;
  803. }
  804. /// <inheritdoc/>
  805. public override void Invoke()
  806. {
  807. Dictionary<int, int> groups = new Dictionary<int, int>();
  808. // collect used group indices
  809. ObjectCollection allObjects = ActiveReport.AllObjects;
  810. foreach (Base c in Designer.Objects)
  811. {
  812. if (c is ComponentBase)
  813. {
  814. int index = (c as ComponentBase).GroupIndex;
  815. if (!groups.ContainsKey(index))
  816. groups.Add(index, 0);
  817. }
  818. }
  819. // find index that not in use
  820. int groupIndex;
  821. for (groupIndex = 1; ; groupIndex++)
  822. {
  823. if (!groups.ContainsKey(groupIndex))
  824. break;
  825. }
  826. foreach (Base c in SelectedObjects)
  827. {
  828. ComponentBase obj = c as ComponentBase;
  829. if (obj != null && obj.HasFlag(Flags.CanGroup))
  830. obj.GroupIndex = groupIndex;
  831. }
  832. }
  833. internal GroupCommand(Designer designer)
  834. : base(designer)
  835. {
  836. }
  837. }
  838. /// <summary>
  839. /// Represents the "Edit|Ungroup" command.
  840. /// </summary>
  841. public class UngroupCommand : GroupCommand
  842. {
  843. /// <inheritdoc/>
  844. public override void Invoke()
  845. {
  846. foreach (Base c in SelectedObjects)
  847. {
  848. if (c is ComponentBase)
  849. (c as ComponentBase).GroupIndex = 0;
  850. }
  851. }
  852. internal UngroupCommand(Designer designer)
  853. : base(designer)
  854. {
  855. }
  856. }
  857. /// <summary>
  858. /// Represents the "Edit" command.
  859. /// </summary>
  860. public class EditCommand : DesignerCommand
  861. {
  862. /// <inheritdoc/>
  863. protected override bool GetEnabled()
  864. {
  865. return SelectedObjects.Count == 1 && SelectedObjects[0] is IHasEditor;
  866. }
  867. /// <inheritdoc/>
  868. public override void Invoke()
  869. {
  870. if (!SelectedObjects[0].HasRestriction(FastReport.Restrictions.DontEdit) &&
  871. (SelectedObjects[0] as IHasEditor).InvokeEditor())
  872. SetModified("EditObject");
  873. }
  874. internal EditCommand(Designer designer)
  875. : base(designer)
  876. {
  877. }
  878. }
  879. /// <summary>
  880. /// Represents the "Edit|Find..." command.
  881. /// </summary>
  882. public class FindCommand : DesignerCommand
  883. {
  884. internal bool isReplace;
  885. private void searchForm_FormClosed(object sender, FormClosedEventArgs e)
  886. {
  887. (sender as Form).Dispose();
  888. }
  889. /// <inheritdoc/>
  890. protected override bool GetEnabled()
  891. {
  892. return ActiveReportTab != null;
  893. }
  894. /// <inheritdoc/>
  895. public override void Invoke()
  896. {
  897. SearchReplaceForm form = new SearchReplaceForm(Designer, isReplace);
  898. form.Replace = isReplace;
  899. form.FormClosed += new FormClosedEventHandler(searchForm_FormClosed);
  900. form.Show();
  901. }
  902. internal FindCommand(Designer designer)
  903. : base(designer)
  904. {
  905. isReplace = false;
  906. }
  907. }
  908. /// <summary>
  909. /// Represents the "Edit|Replace..." command.
  910. /// </summary>
  911. public class ReplaceCommand : FindCommand
  912. {
  913. internal ReplaceCommand(Designer designer)
  914. : base(designer)
  915. {
  916. isReplace = true;
  917. }
  918. }
  919. /// <summary>
  920. /// Represents the "Bring To Front" context menu command.
  921. /// </summary>
  922. public class BringToFrontCommand : DesignerCommand
  923. {
  924. /// <inheritdoc/>
  925. protected override bool GetEnabled()
  926. {
  927. bool enable = SelectedObjects.Count > 0;
  928. if (enable && SelectedObjects.Count == 1 && !SelectedObjects[0].HasFlag(Flags.CanChangeOrder))
  929. enable = false;
  930. return enable;
  931. }
  932. /// <inheritdoc/>
  933. public override void Invoke()
  934. {
  935. foreach (Base c in SelectedObjects)
  936. {
  937. c.ZOrder = 1000;
  938. }
  939. SetModified("Change");
  940. }
  941. internal BringToFrontCommand(Designer designer)
  942. : base(designer)
  943. {
  944. }
  945. }
  946. /// <summary>
  947. /// Represents the "Send To Back" context menu command.
  948. /// </summary>
  949. public class SendToBackCommand : BringToFrontCommand
  950. {
  951. /// <inheritdoc/>
  952. public override void Invoke()
  953. {
  954. foreach (Base c in SelectedObjects)
  955. {
  956. c.ZOrder = 0;
  957. }
  958. SetModified("Change");
  959. }
  960. internal SendToBackCommand(Designer designer)
  961. : base(designer)
  962. {
  963. }
  964. }
  965. /// <summary>
  966. /// Represents the "Insert" command.
  967. /// </summary>
  968. /// <remarks>
  969. /// This command has no default action associated with it. Check the <b>Enabled</b> property
  970. /// to see if the insert operation is enabled.
  971. /// </remarks>
  972. public class InsertCommand : DesignerCommand
  973. {
  974. /// <inheritdoc/>
  975. protected override bool GetEnabled()
  976. {
  977. return !Restrictions.DontInsertObject &&
  978. ActiveReportTab != null &&
  979. ActiveReportTab.ActivePage != null;
  980. }
  981. internal InsertCommand(Designer designer)
  982. : base(designer)
  983. {
  984. }
  985. }
  986. /// <summary>
  987. /// Represents the "Insert Band" command.
  988. /// </summary>
  989. /// <remarks>
  990. /// This command has no default action associated with it. Check the <b>Enabled</b> property
  991. /// to see if the insert operation is enabled.
  992. /// </remarks>
  993. public class InsertBandCommand : DesignerCommand
  994. {
  995. /// <inheritdoc/>
  996. protected override bool GetEnabled()
  997. {
  998. return !Restrictions.DontInsertObject && !Restrictions.DontInsertBand && ActiveReportTab != null &&
  999. ActiveReportTab.ActivePage != null && ActiveReportTab.ActivePage is ReportPage;
  1000. }
  1001. internal InsertBandCommand(Designer designer)
  1002. : base(designer)
  1003. {
  1004. }
  1005. }
  1006. /// <summary>
  1007. /// Represents the "Data|Add Data Source..." command.
  1008. /// </summary>
  1009. public class AddDataCommand : DesignerCommand
  1010. {
  1011. /// <inheritdoc/>
  1012. protected override bool GetEnabled()
  1013. {
  1014. return !Restrictions.DontCreateData && ActiveReport != null;
  1015. }
  1016. /// <inheritdoc/>
  1017. public override void Invoke()
  1018. {
  1019. using (DataWizardForm form = new DataWizardForm(ActiveReport))
  1020. {
  1021. /*if (Designer.SelectedObjects.Count == 1 && Designer.SelectedObjects[0] is DataConnectionBase)
  1022. {
  1023. form.Connection = Designer.SelectedObjects[0] as DataConnectionBase;
  1024. form.EditMode = true;
  1025. form.VisiblePanelIndex = 1;
  1026. }*/
  1027. if (form.ShowDialog() == DialogResult.OK)
  1028. SetModified("EditData");
  1029. }
  1030. }
  1031. internal AddDataCommand(Designer designer)
  1032. : base(designer)
  1033. {
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// Represents the "Data|Sort Data Sources" command.
  1038. /// </summary>
  1039. public class SortDataSourcesCommand : DesignerCommand
  1040. {
  1041. /// <inheritdoc/>
  1042. protected override bool GetEnabled()
  1043. {
  1044. return !Restrictions.DontSortDataSources && ActiveReport != null && ActiveReport.Dictionary.DataSources.Count > 1;
  1045. }
  1046. /// <inheritdoc/>
  1047. public override void Invoke()
  1048. {
  1049. ActiveReport.Dictionary.DataSources.Sort();
  1050. SetModified("EditData");
  1051. }
  1052. internal SortDataSourcesCommand(Designer designer) : base(designer)
  1053. {
  1054. }
  1055. }
  1056. /// <summary>
  1057. /// Represents the "Data|Choose Report Data..." command.
  1058. /// </summary>
  1059. public class ChooseDataCommand : DesignerCommand
  1060. {
  1061. /// <inheritdoc/>
  1062. protected override bool GetEnabled()
  1063. {
  1064. return !Restrictions.DontEditData && ActiveReport != null;
  1065. }
  1066. /// <inheritdoc/>
  1067. public override void Invoke()
  1068. {
  1069. using (ReportDataForm form = new ReportDataForm(ActiveReport))
  1070. {
  1071. if (form.ShowDialog() == DialogResult.OK)
  1072. SetModified("SelectData");
  1073. }
  1074. }
  1075. internal ChooseDataCommand(Designer designer)
  1076. : base(designer)
  1077. {
  1078. }
  1079. }
  1080. /// <summary>
  1081. /// Represents the "Recent Files" command.
  1082. /// </summary>
  1083. /// <remarks>
  1084. /// This command has no default action associated with it. Check the <b>Enabled</b> property
  1085. /// to see if the recent files list is enabled.
  1086. /// </remarks>
  1087. public class RecentFilesCommand : DesignerCommand
  1088. {
  1089. /// <inheritdoc/>
  1090. protected override bool GetEnabled()
  1091. {
  1092. return !Restrictions.DontShowRecentFiles &&
  1093. (Designer.MdiMode || ActiveReportTab != null);
  1094. }
  1095. internal void Update(string newFile)
  1096. {
  1097. if (!String.IsNullOrEmpty(newFile))
  1098. {
  1099. if (Designer.RecentFiles.IndexOf(newFile) != -1)
  1100. Designer.RecentFiles.RemoveAt(Designer.RecentFiles.IndexOf(newFile));
  1101. Designer.RecentFiles.Add(newFile);
  1102. while (Designer.RecentFiles.Count > 8)
  1103. Designer.RecentFiles.RemoveAt(0);
  1104. }
  1105. }
  1106. internal RecentFilesCommand(Designer designer)
  1107. : base(designer)
  1108. {
  1109. }
  1110. }
  1111. /// <summary>
  1112. /// Represents the "File|Select Language..." command.
  1113. /// </summary>
  1114. public class SelectLanguageCommand : DesignerCommand
  1115. {
  1116. /// <inheritdoc/>
  1117. public override void Invoke()
  1118. {
  1119. using (SelectLanguageForm form = new SelectLanguageForm())
  1120. {
  1121. if (form.ShowDialog() == DialogResult.OK)
  1122. {
  1123. Designer.Localize();
  1124. }
  1125. }
  1126. }
  1127. internal SelectLanguageCommand(Designer designer)
  1128. : base(designer)
  1129. {
  1130. }
  1131. }
  1132. /// <summary>
  1133. /// Represents the "View|Options..." command.
  1134. /// </summary>
  1135. public class OptionsCommand : DesignerCommand
  1136. {
  1137. /// <inheritdoc/>
  1138. public override void Invoke()
  1139. {
  1140. using (DesignerOptionsForm options = new DesignerOptionsForm(Designer))
  1141. {
  1142. if (options.ShowDialog() == DialogResult.OK)
  1143. {
  1144. Designer.UpdatePlugins(null);
  1145. }
  1146. }
  1147. }
  1148. internal OptionsCommand(Designer designer)
  1149. : base(designer)
  1150. {
  1151. }
  1152. }
  1153. /// <summary>
  1154. /// Represents the "View|Start Page" command.
  1155. /// </summary>
  1156. public class ViewStartPageCommand : DesignerCommand
  1157. {
  1158. /// <inheritdoc/>
  1159. protected override bool GetEnabled()
  1160. {
  1161. return Designer.MdiMode;
  1162. }
  1163. /// <inheritdoc/>
  1164. public override void Invoke()
  1165. {
  1166. foreach (DocumentWindow c in Designer.Documents)
  1167. {
  1168. if (c is StartPageTab)
  1169. {
  1170. c.Activate();
  1171. return;
  1172. }
  1173. }
  1174. Designer.AddStartPageTab();
  1175. }
  1176. internal ViewStartPageCommand(Designer designer)
  1177. : base(designer)
  1178. {
  1179. }
  1180. }
  1181. /// <summary>
  1182. /// Represents the "Select polygon move" command.
  1183. /// </summary>
  1184. public class PolygonSelectModeCommand : DesignerCommand
  1185. {
  1186. private PolyLineObject.PolygonSelectionMode mode;
  1187. /// <inheritdoc/>
  1188. protected override bool GetEnabled()
  1189. {
  1190. return (Designer.SelectedObjects.Count == 1) && (Designer.SelectedObjects[0] is PolyLineObject);
  1191. }
  1192. /// <inheritdoc/>
  1193. public override void Invoke()
  1194. {
  1195. if ((Designer.SelectedObjects.Count == 1) && (Designer.SelectedObjects[0] is PolyLineObject))
  1196. {
  1197. PolyLineObject plobj = (Designer.SelectedObjects[0] as PolyLineObject);
  1198. plobj.SelectionMode = mode;
  1199. Designer.Refresh();
  1200. }
  1201. }
  1202. internal PolygonSelectModeCommand(Designer designer, PolyLineObject.PolygonSelectionMode mode)
  1203. : base(designer)
  1204. {
  1205. this.mode = mode;
  1206. }
  1207. }
  1208. /// <summary>
  1209. /// Represents the "Report|Styles..." command.
  1210. /// </summary>
  1211. public class ReportStylesCommand : DesignerCommand
  1212. {
  1213. /// <inheritdoc/>
  1214. protected override bool GetEnabled()
  1215. {
  1216. return !Restrictions.DontChangeReportOptions && ActiveReport != null;
  1217. }
  1218. /// <inheritdoc/>
  1219. public override void Invoke()
  1220. {
  1221. if (ActiveReport == null)
  1222. return;
  1223. using (StyleEditorForm form = new StyleEditorForm(ActiveReport))
  1224. {
  1225. if (form.ShowDialog() == DialogResult.OK)
  1226. SetModified("ChangeReport");
  1227. }
  1228. }
  1229. internal ReportStylesCommand(Designer designer)
  1230. : base(designer)
  1231. {
  1232. }
  1233. }
  1234. /// <summary>
  1235. /// Represents the "Help|Account" command.
  1236. /// </summary>
  1237. public class AccountCommand : DesignerCommand
  1238. {
  1239. /// <inheritdoc/>
  1240. protected override bool GetEnabled()
  1241. {
  1242. return Auth.AuthService.Instance.IsEnable;
  1243. }
  1244. /// <inheritdoc/>
  1245. public override void Invoke()
  1246. {
  1247. using (Auth.AuthForm authForm = new Auth.AuthForm())
  1248. {
  1249. authForm.ShowDialog();
  1250. }
  1251. }
  1252. internal AccountCommand(Designer designer)
  1253. : base(designer)
  1254. {
  1255. }
  1256. }
  1257. /// <summary>
  1258. /// Represents the "Help|Help Contents..." command.
  1259. /// </summary>
  1260. public class HelpContentsCommand : DesignerCommand
  1261. {
  1262. private string GetHelpUrl()
  1263. {
  1264. string url = "https://www.fast-report.com/public_download/docs/FRNet/online/en/index.html";
  1265. return url;
  1266. }
  1267. /// <inheritdoc/>
  1268. protected override bool GetEnabled()
  1269. {
  1270. return true;
  1271. }
  1272. /// <inheritdoc/>
  1273. public override void Invoke()
  1274. {
  1275. ProcessHelper.StartProcess(GetHelpUrl());
  1276. }
  1277. internal HelpContentsCommand(Designer designer)
  1278. : base(designer)
  1279. {
  1280. }
  1281. }
  1282. /// <summary>
  1283. /// Represents the "Help|About..." command.
  1284. /// </summary>
  1285. public class AboutCommand : DesignerCommand
  1286. {
  1287. /// <inheritdoc/>
  1288. public override void Invoke()
  1289. {
  1290. using (AboutForm form = new AboutForm())
  1291. {
  1292. form.ShowDialog();
  1293. }
  1294. }
  1295. internal AboutCommand(Designer designer)
  1296. : base(designer)
  1297. {
  1298. }
  1299. }
  1300. /// <summary>
  1301. /// Represents the "Show welcome window..." command.
  1302. /// </summary>
  1303. public class WelcomeCommand : DesignerCommand
  1304. {
  1305. /// <inheritdoc/>
  1306. protected override bool GetEnabled()
  1307. {
  1308. return Config.WelcomeEnabled;
  1309. }
  1310. /// <inheritdoc/>
  1311. public override void Invoke()
  1312. {
  1313. using (WelcomeForm form = new WelcomeForm(Designer))
  1314. {
  1315. form.ShowDialog();
  1316. }
  1317. }
  1318. internal WelcomeCommand(Designer designer)
  1319. : base(designer)
  1320. {
  1321. }
  1322. }
  1323. }