DesignerCommands.cs 49 KB

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