12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763 |
- using FastReport.Auth;
- using FastReport.Cloud.FastReport;
- using FastReport.Cloud.FastReport.ListViewCloud;
- using FastReport.Data;
- using FastReport.Design.PageDesigners.Code;
- using FastReport.Dialog;
- using FastReport.Forms;
- using FastReport.Utils;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Windows.Forms;
- namespace FastReport.Design
- {
- /// <summary>
- /// The base class for all designer commands.
- /// </summary>
- public class DesignerCommand
- {
- private object sender;
- internal Designer Designer { get; }
- internal Report ActiveReport
- {
- get { return Designer.ActiveReport; }
- }
- internal ReportTab ActiveReportTab
- {
- get { return Designer.ActiveReportTab; }
- }
- internal DesignerRestrictions Restrictions
- {
- get { return Designer.Restrictions; }
- }
- internal SelectedObjectCollection SelectedObjects
- {
- get { return Designer.SelectedObjects; }
- }
- internal SelectedReportComponents SelectedReportComponents
- {
- get { return Designer.SelectedReportComponents; }
- }
- internal void SetModified(string action)
- {
- Designer.SetModified(sender, action);
- }
- /// <summary>
- /// Gets a value indicating that the command is enabled.
- /// </summary>
- /// <remarks>
- /// If you use own controls that invoke designer commands, use this property to refresh
- /// the <b>Enabled</b> state of a control that is bound to this command.
- /// </remarks>
- public bool Enabled
- {
- get { return GetEnabled(); }
- }
- /// <summary>
- /// Defines a custom action for this command.
- /// </summary>
- /// <remarks>
- /// Using custom action, you can override the standard behavior of this designer's command.
- /// </remarks>
- /// <example>
- /// This example demonstrates how to override the "New..." command behavior.
- /// <code>
- /// // add an event handler that will be fired when the designer is run
- /// Config.DesignerSettings.DesignerLoaded += new EventHandler(DesignerSettings_DesignerLoaded);
- ///
- /// void DesignerSettings_DesignerLoaded(object sender, EventArgs e)
- /// {
- /// // override "New..." command behavior
- /// (sender as Designer).cmdNew.CustomAction += new EventHandler(cmdNew_CustomAction);
- /// }
- ///
- /// void cmdNew_CustomAction(object sender, EventArgs e)
- /// {
- /// // show the "Label" wizard instead of standard "Add New Item" dialog
- /// Designer designer = sender as Designer;
- /// LabelWizard wizard = new LabelWizard();
- /// wizard.Run(designer);
- /// }
- /// </code>
- /// </example>
- public event EventHandler CustomAction;
- /// <summary>
- /// Gets a value for the <b>Enabled</b> property.
- /// </summary>
- /// <returns><b>true</b> if command is enabled.</returns>
- protected virtual bool GetEnabled()
- {
- return true;
- }
- /// <summary>
- /// Invokes the command.
- /// </summary>
- public virtual void Invoke()
- {
- }
- /// <summary>
- /// Invokes the command with specified sender and event args.
- /// </summary>
- /// <param name="sender">Sender.</param>
- /// <param name="e">Event args.</param>
- /// <remarks>
- /// This method is compatible with standard <see cref="EventHandler"/> and can be passed
- /// to the event handler constructor directly.
- /// </remarks>
- public void Invoke(object sender, EventArgs e)
- {
- if (CustomAction != null)
- CustomAction(Designer, e);
- else
- {
- this.sender = sender;
- Invoke();
- }
- }
- internal DesignerCommand(Designer designer)
- {
- this.Designer = designer;
- }
- }
- /// <summary>
- /// Represents the "File|New" command.
- /// </summary>
- public class NewCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontCreateReport &&
- (Designer.MdiMode || ActiveReportTab != null);
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (AddNewItemForm form = new AddNewItemForm(Designer))
- {
- if (form.ShowDialog() == DialogResult.OK)
- form.SelectedWizard.Run(Designer);
- }
- }
- internal NewCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "New Page" toolbar command.
- /// </summary>
- public class NewPageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontCreatePage && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.NewReportPage();
- }
- internal NewPageCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "New Dialog" toolbar command.
- /// </summary>
- public class NewDialogCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontCreatePage && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.NewDialog();
- }
- internal NewDialogCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Open..." command. Also can be used for loading a file
- /// from the recent files list.
- /// </summary>
- public class OpenCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontLoadReport &&
- (Designer.MdiMode || ActiveReportTab != null);
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- LoadFile("");
- }
- /// <summary>
- /// Loads a specified report file.
- /// </summary>
- /// <param name="fileName">File to load.</param>
- /// <param name="silent">true to suppress message dialog if load is failed.</param>
- public void LoadFile(string fileName, bool silent = false)
- {
- ReportTab reportTab = null;
- if (Designer.MdiMode)
- {
- // check if file is already opened
- if (!String.IsNullOrEmpty(fileName))
- {
- foreach (DocumentWindow c in Designer.Documents)
- {
- if (c is ReportTab && String.Compare((c as ReportTab).Report.FileName, fileName, true) == 0)
- {
- c.Activate();
- return;
- }
- }
- }
- Report report = new Report();
- report.Designer = Designer;
- reportTab = Designer.CreateReportTab(report);
- }
- else
- reportTab = ActiveReportTab;
- if (reportTab.LoadFile(fileName, silent))
- {
- if (Designer.MdiMode)
- Designer.AddReportTab(reportTab);
- }
- else if (Designer.MdiMode)
- reportTab.Dispose();
- }
- internal OpenCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Open page..." command.
- /// </summary>
- public class OpenPageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontLoadReport &&
- (Designer.MdiMode || ActiveReportTab != null);
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- LoadFile("");
- }
- /// <summary>
- /// Loads report file and paginating it.
- /// </summary>
- /// <param name="fileName">File to load.</param>
- ///
- public void LoadFile(string fileName)
- {
- OpenSaveDialogEventArgs e = new OpenSaveDialogEventArgs(Designer);
- if (String.IsNullOrEmpty(fileName))
- {
- Config.DesignerSettings.OnCustomOpenDialog(Designer, e);
- if (e.Cancel)
- return;
- fileName = e.FileName;
- }
- try
- {
- Report report = new Report();
- report.Load(fileName);
- using (OpenPageForm addPageToReportForm = new OpenPageForm(Designer, report))
- {
- addPageToReportForm.ShowDialog();
- }
- }
- #if !DEBUG
- catch (Exception ex)
- {
- FRMessageBox.Error(String.Format(Res.Get("Messages,CantLoadReport") + "\r\n" + ex.Message, fileName));
- }
- #endif
- finally
- { }
- }
- internal OpenPageCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Open from Cloud..." command. Also can be used for loading a file
- /// from the recent files list.
- /// </summary>
- public class OpenViaCloudCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontLoadReport && (Designer.MdiMode || ActiveReportTab != null);
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- LoadFromInstance(CloudCommands.LoadFile());
- }
- /// <summary>
- /// Loads file from the recent files list.
- /// </summary>
- /// <param name="key">File name.</param>
- /// <param name="id">File ID.</param>
- public async void LoadFile(string key, string id)
- {
- if (!CloudCommands.CheckAuthentication())
- return;
- Config.ReportSettings.OnStartLoadingProgress(Designer.MdiMode ? null : ActiveReportTab);
- try
- {
- LoadFromInstance(await CloudCommands.LoadFile(key, id));
- }
- finally
- {
- Config.ReportSettings.OnFinishLoadingProgress(Designer.MdiMode ? null : ActiveReportTab);
- }
- }
- private void LoadFromInstance(OpeningInstance instance)
- {
- if (instance?.ReportStream != null)
- {
- ReportTab reportTab = null;
- if (Designer.MdiMode)
- {
- Report report = new Report();
- report.Designer = Designer;
- reportTab = Designer.CreateReportTab(report);
- }
- else
- reportTab = ActiveReportTab;
- if (reportTab.LoadFileFromCloud(instance))
- {
- if (Designer.MdiMode)
- Designer.AddReportTab(reportTab);
- }
- else if (Designer.MdiMode)
- reportTab.Dispose();
- }
- }
- internal OpenViaCloudCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Save" command.
- /// </summary>
- public class SaveCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontSaveReport &&
- ActiveReportTab != null &&
- ActiveReportTab.Modified;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.SaveFile(false);
- }
- internal SaveCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Save to Cloud" command.
- /// </summary>
- public class SaveToCloudCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontSaveReport && ActiveReportTab != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- var fileVM = CloudCommands.SaveReportFile(ActiveReport);
- if (fileVM != null)
- {
- ActiveReport.FileName = fileVM.Name;
- ActiveReport.CloudFileInfo = new CloudFileInfo(fileVM);
- Designer.cmdRecentFiles.AddCloudReport(ActiveReport);
- Designer.UpdatePlugins(null);
- ActiveReportTab.UpdateCaption();
- }
- }
- internal SaveToCloudCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Save As..." command.
- /// </summary>
- public class SaveAsCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontSaveReport && ActiveReportTab != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.SaveFile(true);
- }
- internal SaveAsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Save With Random Data..." command.
- /// </summary>
- public class SaveWithRandomDataCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontSaveReport && ActiveReportTab != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.SaveWithRandomData();
- }
- internal SaveWithRandomDataCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Save All" command.
- /// </summary>
- public class SaveAllCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- bool enabled = Designer.MdiMode && Designer.Documents.Count > 0;
- if (Designer.Documents.Count == 1 && Designer.Documents[0] is StartPageTab)
- enabled = false;
- return !Restrictions.DontSaveReport && enabled;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- foreach (DocumentWindow c in Designer.Documents)
- {
- if (c is ReportTab)
- (c as ReportTab).SaveFile(false);
- }
- }
- internal SaveAllCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Close" command.
- /// </summary>
- public class CloseCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return Designer.MdiMode && Designer.Documents.Count > 0;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (Designer.ActiveReportTab != null)
- Designer.CloseDocument(ActiveReportTab);
- else if (Designer.StartPage != null)
- Designer.CloseDocument(Designer.StartPage);
- }
- internal CloseCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Window|Close All" command.
- /// </summary>
- public class CloseAllCommand : CloseCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- int i = 0;
- while (i < Designer.Documents.Count)
- {
- DocumentWindow c = Designer.Documents[i];
- if (c is StartPageTab || !Designer.CloseDocument(c))
- i++;
- }
- }
- internal CloseAllCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Preview..." command.
- /// </summary>
- public class PreviewCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontPreviewReport && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.Preview();
- }
- internal PreviewCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Preview on Cloud..." command.
- /// </summary>
- public class PreviewCloudCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReport != null && ActiveReport.IsOpenedFromCloud;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (ActiveReportTab.Modified)
- ActiveReportTab.SaveFile(false);
- CloudCommands.PreviewReport(ActiveReport);
- }
- internal PreviewCloudCommand(Designer designer) : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Page Setup..." command.
- /// </summary>
- public class PageSettingsCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontChangePageOptions &&
- ActiveReport != null &&
- ActiveReportTab.ActivePage is ReportPage;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- IHasEditor page = ActiveReportTab.ActivePage as IHasEditor;
- if (page.InvokeEditor())
- {
- SetModified("EditPage");
- }
- }
- internal PageSettingsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Report|Options..." command.
- /// </summary>
- public class ReportSettingsCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontChangeReportOptions && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (ReportOptionsForm form = new ReportOptionsForm(ActiveReport))
- {
- ActiveReport.ScriptText = ActiveReportTab.Script;
- if (form.ShowDialog() == DialogResult.OK)
- {
- ActiveReportTab.Script = ActiveReport.ScriptText;
- (ActiveReportTab.Plugins.Find("Code") as CodePageDesigner).UpdateLanguage();
- SetModified("EditReport");
- }
- }
- }
- internal ReportSettingsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Printer Setup..." command.
- /// </summary>
- public class PrinterSettingsCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontChangeReportOptions && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (PrinterSetupForm editor = new PrinterSetupForm())
- {
- editor.Report = ActiveReport;
- if (editor.ShowDialog() == DialogResult.OK)
- {
- SetModified("EditPrinter");
- }
- }
- }
- internal PrinterSettingsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Undo" command.
- /// </summary>
- public class UndoCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReport != null && ActiveReportTab.CanUndo;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- Undo(1);
- }
- /// <summary>
- /// Undo several actions.
- /// </summary>
- /// <param name="actionsCount">Number of actions to undo.</param>
- public void Undo(int actionsCount)
- {
- ActiveReportTab.Undo(actionsCount);
- }
- internal UndoCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Redo" command.
- /// </summary>
- public class RedoCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReport != null && ActiveReportTab.CanRedo;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- Redo(1);
- }
- /// <summary>
- /// Redo several actions.
- /// </summary>
- /// <param name="actionsCount">Number of actions to redo.</param>
- public void Redo(int actionsCount)
- {
- ActiveReportTab.Redo(actionsCount);
- }
- internal RedoCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Cut" command.
- /// </summary>
- public class CutCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- if (ActiveReportTab == null || ActiveReportTab.ActivePageDesigner == null)
- return false;
- return ActiveReportTab.ActivePageDesigner.CanCopy();
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.ActivePageDesigner.Cut();
- }
- internal CutCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Copy" command.
- /// </summary>
- public class CopyCommand : CutCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.ActivePageDesigner.Copy();
- }
- internal CopyCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Copy Page" command.
- /// </summary>
- public class CopyPageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontCopyPage && ActiveReport != null && ActiveReportTab.ActivePage != null &&
- ActiveReport.Pages.Count > 0 && (ActiveReportTab.ActivePage is ReportPage || ActiveReportTab.ActivePage is DialogPage) &&
- !ActiveReportTab.ActivePage.IsAncestor;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (Enabled)
- {
- ActiveReportTab.CopyPage();
- }
- }
- internal CopyPageCommand(Designer designer) : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Paste" command.
- /// </summary>
- public class PasteCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- if (ActiveReportTab == null || ActiveReportTab.ActivePageDesigner == null)
- return false;
- return ActiveReportTab.ActivePageDesigner.CanPaste();
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ActiveReportTab.ActivePageDesigner.Paste();
- }
- internal PasteCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Format Painter" toolbar command.
- /// </summary>
- public class FormatPainterCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReportTab != null &&
- ActiveReportTab.ActivePage != null &&
- SelectedReportComponents.Count > 0;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- Designer.FormatPainter = !Designer.FormatPainter;
- }
- internal FormatPainterCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Delete" command.
- /// </summary>
- public class DeleteCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- bool enable = SelectedObjects.Count > 0;
- bool сanDeleteBand = CanDeleteBand();
- if (enable && SelectedObjects.Count == 1 &&
- (!сanDeleteBand || !SelectedObjects[0].HasFlag(Flags.CanDelete) ||
- SelectedObjects[0].HasRestriction(FastReport.Restrictions.DontDelete)))
- enable = false;
- return enable;
- }
- private bool CanDeleteBand()
- {
- if (SelectedObjects.Count == 0)
- return true;
- int countBands = CountBands();
- if (SelectedObjects[0] is ChildBand)
- return true;
- if (SelectedObjects[0] is BandBase && !(SelectedObjects[0] is ChildBand))
- return countBands > 1;
- return true;
- }
- private int CountBands()
- {
- int count = 0;
- foreach (Base c in Designer.Objects)
- if (c is BandBase && !(c is ChildBand))
- count++;
- return count;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (SelectedObjects.IsPageSelected || SelectedObjects.IsReportSelected)
- return;
- foreach (Base c in SelectedObjects)
- {
- if (!c.HasFlag(Flags.CanDelete) || c.HasRestriction(FastReport.Restrictions.DontDelete))
- continue;
- else
- {
- if (c.IsAncestor)
- {
- FRMessageBox.Error(String.Format(Res.Get("Messages,DeleteAncestor"), c.Name));
- return;
- }
- foreach (Base b in c.AllObjects)
- {
- if (b is SubreportObject) b.Delete();
- }
- c.Delete();
- }
- }
- SetModified("Delete");
- Designer.SelectionChanged(null);
- }
- internal DeleteCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Delete Page" command.
- /// </summary>
- public class DeletePageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontDeletePage && ActiveReport != null &&
- ActiveReportTab.ActivePage != null &&
- ActiveReport.Pages.Count > 1 &&
- !ActiveReportTab.ActivePage.IsAncestor;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (Enabled)
- {
- ActiveReportTab.DeletePage();
- }
- }
- internal DeletePageCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Select All" command.
- /// </summary>
- public class SelectAllCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReportTab != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (ActiveReportTab != null)
- ActiveReportTab.ActivePageDesigner.SelectAll();
- }
- internal SelectAllCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Group" command.
- /// </summary>
- public class GroupCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return SelectedObjects.Count > 1;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- Dictionary<int, int> groups = new Dictionary<int, int>();
- // collect used group indices
- ObjectCollection allObjects = ActiveReport.AllObjects;
- foreach (Base c in Designer.Objects)
- {
- if (c is ComponentBase)
- {
- int index = (c as ComponentBase).GroupIndex;
- if (!groups.ContainsKey(index))
- groups.Add(index, 0);
- }
- }
- // find index that not in use
- int groupIndex;
- for (groupIndex = 1; ; groupIndex++)
- {
- if (!groups.ContainsKey(groupIndex))
- break;
- }
- foreach (Base c in SelectedObjects)
- {
- ComponentBase obj = c as ComponentBase;
- if (obj != null && obj.HasFlag(Flags.CanGroup))
- obj.GroupIndex = groupIndex;
- }
- }
- internal GroupCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Ungroup" command.
- /// </summary>
- public class UngroupCommand : GroupCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- foreach (Base c in SelectedObjects)
- {
- if (c is ComponentBase)
- (c as ComponentBase).GroupIndex = 0;
- }
- }
- internal UngroupCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit" command.
- /// </summary>
- public class EditCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return SelectedObjects.Count == 1 && SelectedObjects[0] is IHasEditor;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (!SelectedObjects[0].HasRestriction(FastReport.Restrictions.DontEdit) &&
- (SelectedObjects[0] as IHasEditor).InvokeEditor())
- SetModified("EditObject");
- }
- internal EditCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Edit|Find..." command.
- /// </summary>
- public class FindCommand : DesignerCommand
- {
- internal bool isReplace;
- private void searchForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- (sender as Form).Dispose();
- }
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReportTab != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- SearchReplaceForm form = new SearchReplaceForm(Designer, isReplace);
- form.Replace = isReplace;
- form.FormClosed += new FormClosedEventHandler(searchForm_FormClosed);
- form.Show();
- }
- internal FindCommand(Designer designer)
- : base(designer)
- {
- isReplace = false;
- }
- }
- /// <summary>
- /// Represents the "Edit|Replace..." command.
- /// </summary>
- public class ReplaceCommand : FindCommand
- {
- internal ReplaceCommand(Designer designer)
- : base(designer)
- {
- isReplace = true;
- }
- }
- /// <summary>
- /// Represents the "Bring To Front" context menu command.
- /// </summary>
- public class BringToFrontCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- bool enable = SelectedObjects.Count > 0;
- if (enable && SelectedObjects.Count == 1 && !SelectedObjects[0].HasFlag(Flags.CanChangeOrder))
- enable = false;
- return enable;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- foreach (Base c in SelectedObjects)
- {
- c.ZOrder = 1000;
- }
- SetModified("Change");
- }
- internal BringToFrontCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Send To Back" context menu command.
- /// </summary>
- public class SendToBackCommand : BringToFrontCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- foreach (Base c in SelectedObjects)
- {
- c.ZOrder = 0;
- }
- SetModified("Change");
- }
- internal SendToBackCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Insert" command.
- /// </summary>
- /// <remarks>
- /// This command has no default action associated with it. Check the <b>Enabled</b> property
- /// to see if the insert operation is enabled.
- /// </remarks>
- public class InsertCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontInsertObject &&
- ActiveReportTab != null &&
- ActiveReportTab.ActivePage != null;
- }
- internal InsertCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Insert Band" command.
- /// </summary>
- /// <remarks>
- /// This command has no default action associated with it. Check the <b>Enabled</b> property
- /// to see if the insert operation is enabled.
- /// </remarks>
- public class InsertBandCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontInsertObject && !Restrictions.DontInsertBand && ActiveReportTab != null &&
- ActiveReportTab.ActivePage != null && ActiveReportTab.ActivePage is ReportPage;
- }
- internal InsertBandCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Data|Add Data Source..." command.
- /// </summary>
- public class AddDataCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontCreateData && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (DataWizardForm form = new DataWizardForm(ActiveReport))
- {
- /*if (Designer.SelectedObjects.Count == 1 && Designer.SelectedObjects[0] is DataConnectionBase)
- {
- form.Connection = Designer.SelectedObjects[0] as DataConnectionBase;
- form.EditMode = true;
- form.VisiblePanelIndex = 1;
- }*/
- if (form.ShowDialog() == DialogResult.OK)
- SetModified("EditData");
- }
- }
- internal AddDataCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Data|Sort Data Sources" command.
- /// </summary>
- public class SortDataSourcesCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- if (Restrictions.DontSortDataSources || ActiveReport == null)
- return false;
- FRCollectionBase dataSources = ActiveReport.Dictionary.DataSources;
- if (Designer.SelectedObjects.Count == 1 && Designer.SelectedObjects[0] is DataConnectionBase conn)
- dataSources = conn.Tables;
- int enabledDataSources = 0;
- foreach (DataSourceBase dataSource in dataSources)
- {
- if (dataSource.Enabled)
- {
- enabledDataSources++;
- if (enabledDataSources > 1)
- return true;
- }
- }
- return false;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (Designer.SelectedObjects.Count == 1 && Designer.SelectedObjects[0] is DataConnectionBase conn)
- conn.Tables.Sort();
- else
- ActiveReport.Dictionary.DataSources.Sort();
- SetModified("EditData");
- }
- internal SortDataSourcesCommand(Designer designer) : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Data|Choose Report Data..." command.
- /// </summary>
- public class ChooseDataCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontEditData && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (ReportDataForm form = new ReportDataForm(ActiveReport))
- {
- if (form.ShowDialog() == DialogResult.OK)
- SetModified("SelectData");
- }
- }
- internal ChooseDataCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Recent Files" command.
- /// </summary>
- /// <remarks>
- /// This command has no default action associated with it. Check the <b>Enabled</b> property
- /// to see if the recent files list is enabled.
- /// </remarks>
- public class RecentFilesCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontShowRecentFiles &&
- (Designer.MdiMode || ActiveReportTab != null);
- }
- internal void Update(string newFile)
- {
- if (!String.IsNullOrEmpty(newFile))
- {
- if (Designer.RecentFiles.IndexOf(newFile) != -1)
- Designer.RecentFiles.RemoveAt(Designer.RecentFiles.IndexOf(newFile));
- Designer.RecentFiles.Add(newFile);
- while (Designer.RecentFiles.Count > 8)
- Designer.RecentFiles.RemoveAt(0);
- }
- }
- internal void AddCloudReport(Report report)
- {
- if (report.CloudFileInfo == null)
- return;
- string fileName = report.CloudFileInfo.FileName;
- string id = report.CloudFileInfo.FileId;
- if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(id))
- {
- if (Designer.CloudReportDictionary.ContainsKey(fileName))
- Designer.CloudReportDictionary.Remove(fileName);
- Designer.CloudReportDictionary.Add(fileName, id);
- DeleteRedundants();
- Update(fileName);
- }
- }
- private void DeleteRedundants()
- {
- if (Designer.CloudReportDictionary.Count > 8)
- {
- var toSkip = Designer.CloudReportDictionary.Count - 8;
- var current = 0;
- var tempDict = new Dictionary<string, string>();
- foreach (var keyValuePair in Designer.CloudReportDictionary)
- {
- if (current >= toSkip)
- {
- tempDict.Add(keyValuePair.Key, keyValuePair.Value);
- }
- current++;
- }
- Designer.CloudReportDictionary = tempDict;
- }
- }
- /// <summary>
- /// Returns true if the file specified is a cloud file.
- /// </summary>
- /// <param name="fileName">File name to check.</param>
- /// <returns>true if file is a cloud file.</returns>
- public bool IsCloudFile(string fileName) => Designer.CloudReportDictionary.Keys.Contains(fileName);
- /// <summary>
- /// Opens a recent file with specified name either from local PC or from cloud.
- /// </summary>
- /// <param name="fileName">File name to open.</param>
- public void LoadFile(string fileName)
- {
- try
- {
- if (IsCloudFile(fileName))
- {
- Designer.cmdOpenViaCloud.LoadFile(fileName, Designer.CloudReportDictionary[fileName]);
- }
- else
- {
- Designer.cmdOpen.LoadFile(fileName, true);
- }
- }
- catch (Exception ex)
- {
- if (FRMessageBox.Confirm(String.Format(Res.Get("Messages,CantLoadReport") + "\r\n" + ex.Message, fileName) + "\r\n\r\n" +
- Res.Get("Messages,RemoveFromRecentFiles"), MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- Designer.RecentFiles.Remove(fileName);
- if (IsCloudFile(fileName))
- Designer.CloudReportDictionary.Remove(fileName);
- }
- }
- Designer.UpdatePlugins(null);
- }
- internal RecentFilesCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "File|Select Language..." command.
- /// </summary>
- public class SelectLanguageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (SelectLanguageForm form = new SelectLanguageForm())
- {
- if (form.ShowDialog() == DialogResult.OK)
- {
- Designer.Localize();
- AuthForm.isFirstLoad = true;
- FRCloudOptions.Instance.ResetBackendHostAndApiKey();
- }
- }
- }
- internal SelectLanguageCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "View|Options..." command.
- /// </summary>
- public class OptionsCommand : DesignerCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (DesignerOptionsForm options = new DesignerOptionsForm(Designer))
- {
- if (options.ShowDialog() == DialogResult.OK)
- {
- Designer.UpdatePlugins(null);
- }
- }
- }
- internal OptionsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "View|Start Page" command.
- /// </summary>
- public class ViewStartPageCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return Designer.MdiMode;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- foreach (DocumentWindow c in Designer.Documents)
- {
- if (c is StartPageTab)
- {
- c.Activate();
- return;
- }
- }
- Designer.AddStartPageTab();
- }
- internal ViewStartPageCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Select polygon move" command.
- /// </summary>
- public class PolygonSelectModeCommand : DesignerCommand
- {
- private PolyLineObject.PolygonSelectionMode mode;
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return (Designer.SelectedObjects.Count == 1) && (Designer.SelectedObjects[0] is PolyLineObject);
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if ((Designer.SelectedObjects.Count == 1) && (Designer.SelectedObjects[0] is PolyLineObject))
- {
- PolyLineObject plobj = (Designer.SelectedObjects[0] as PolyLineObject);
- plobj.SelectionMode = mode;
- Designer.Refresh();
- }
- }
- internal PolygonSelectModeCommand(Designer designer, PolyLineObject.PolygonSelectionMode mode)
- : base(designer)
- {
- this.mode = mode;
- }
- }
- /// <summary>
- /// Represents the "Report|Styles..." command.
- /// </summary>
- public class ReportStylesCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return !Restrictions.DontChangeReportOptions && ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (ActiveReport == null)
- return;
- using (StyleEditorForm form = new StyleEditorForm(ActiveReport))
- {
- if (form.ShowDialog() == DialogResult.OK)
- SetModified("ChangeReport");
- }
- }
- internal ReportStylesCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Report|Validation" command.
- /// </summary>
- public class ReportValidationCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return ActiveReport != null;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- if (ActiveReport == null)
- return;
- List<ValidationError> errors = Validator.ValidateReport(ActiveReport);
- Designer.MessagesWindow.ClearMessages();
- foreach (ValidationError error in errors)
- {
- Designer.MessagesWindow.AddMessage(error.Name + ": " + error.Message, error.Name, error.Level == ValidationError.ErrorLevel.Error);
- }
- Designer.MessagesWindow.Show();
- }
- internal ReportValidationCommand(Designer designer) : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Help|Account" command.
- /// </summary>
- public class AccountCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return Auth.AuthService.Instance.IsEnable;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (Auth.AuthForm authForm = new Auth.AuthForm())
- {
- authForm.ShowDialog();
- }
- }
- internal AccountCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Help|Help Contents..." command.
- /// </summary>
- public class HelpContentsCommand : DesignerCommand
- {
- private string GetHelpUrl()
- {
- string url = "https://www.fast-report.com/public_download/docs/FRNet/online/en/index.html";
- if (CultureInfo.CurrentCulture.Name == "ru-RU")
- {
- url = "https://быстрыеотчеты.рф/public_download/docs/FRNet/online/ru/index.html";
- }
- return url;
- }
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return true;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- ProcessHelper.StartProcess(GetHelpUrl());
- }
- internal HelpContentsCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Help|About..." command.
- /// </summary>
- public class AboutCommand : DesignerCommand
- {
- /// <inheritdoc/>
- public override void Invoke()
- {
- using (AboutForm form = new AboutForm())
- {
- form.ShowDialog();
- }
- }
- internal AboutCommand(Designer designer)
- : base(designer)
- {
- }
- }
- /// <summary>
- /// Represents the "Show welcome window..." command.
- /// </summary>
- public class WelcomeCommand : DesignerCommand
- {
- /// <inheritdoc/>
- protected override bool GetEnabled()
- {
- return Config.WelcomeEnabled;
- }
- /// <inheritdoc/>
- public override void Invoke()
- {
- #if !(WPF || AVALONIA)
- using (WelcomeForm form = new WelcomeForm(Designer))
- {
- form.ShowDialog();
- }
- #endif
- }
- internal WelcomeCommand(Designer designer)
- : base(designer)
- {
- }
- }
- }
|