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 { /// /// The base class for all designer commands. /// 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); } /// /// Gets a value indicating that the command is enabled. /// /// /// If you use own controls that invoke designer commands, use this property to refresh /// the Enabled state of a control that is bound to this command. /// public bool Enabled { get { return GetEnabled(); } } /// /// Defines a custom action for this command. /// /// /// Using custom action, you can override the standard behavior of this designer's command. /// /// /// This example demonstrates how to override the "New..." command behavior. /// /// // 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); /// } /// /// public event EventHandler CustomAction; /// /// Gets a value for the Enabled property. /// /// true if command is enabled. protected virtual bool GetEnabled() { return true; } /// /// Invokes the command. /// public virtual void Invoke() { } /// /// Invokes the command with specified sender and event args. /// /// Sender. /// Event args. /// /// This method is compatible with standard and can be passed /// to the event handler constructor directly. /// 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; } } /// /// Represents the "File|New" command. /// public class NewCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontCreateReport && (Designer.MdiMode || ActiveReportTab != null); } /// 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) { } } /// /// Represents the "New Page" toolbar command. /// public class NewPageCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontCreatePage && ActiveReport != null; } /// public override void Invoke() { ActiveReportTab.NewReportPage(); } internal NewPageCommand(Designer designer) : base(designer) { } } /// /// Represents the "New Dialog" toolbar command. /// public class NewDialogCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontCreatePage && ActiveReport != null; } /// public override void Invoke() { ActiveReportTab.NewDialog(); } internal NewDialogCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Open..." command. Also can be used for loading a file /// from the recent files list. /// public class OpenCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontLoadReport && (Designer.MdiMode || ActiveReportTab != null); } /// public override void Invoke() { LoadFile(""); } /// /// Loads a specified report file. /// /// File to load. /// true to suppress message dialog if load is failed. 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) { } } /// /// Represents the "File|Open page..." command. /// public class OpenPageCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontLoadReport && (Designer.MdiMode || ActiveReportTab != null); } /// public override void Invoke() { LoadFile(""); } /// /// Loads report file and paginating it. /// /// File to load. /// 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) { } } /// /// Represents the "File|Open from Cloud..." command. Also can be used for loading a file /// from the recent files list. /// public class OpenViaCloudCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontLoadReport && (Designer.MdiMode || ActiveReportTab != null); } /// public override void Invoke() { LoadFromInstance(CloudCommands.LoadFile()); } /// /// Loads file from the recent files list. /// /// File name. /// File ID. 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) { } } /// /// Represents the "File|Save" command. /// public class SaveCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontSaveReport && ActiveReportTab != null && ActiveReportTab.Modified; } /// public override void Invoke() { ActiveReportTab.SaveFile(false); } internal SaveCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Save to Cloud" command. /// public class SaveToCloudCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontSaveReport && ActiveReportTab != null; } /// 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) { } } /// /// Represents the "File|Save As..." command. /// public class SaveAsCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontSaveReport && ActiveReportTab != null; } /// public override void Invoke() { ActiveReportTab.SaveFile(true); } internal SaveAsCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Save With Random Data..." command. /// public class SaveWithRandomDataCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontSaveReport && ActiveReportTab != null; } /// public override void Invoke() { ActiveReportTab.SaveWithRandomData(); } internal SaveWithRandomDataCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Save All" command. /// public class SaveAllCommand : DesignerCommand { /// 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; } /// 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) { } } /// /// Represents the "File|Close" command. /// public class CloseCommand : DesignerCommand { /// protected override bool GetEnabled() { return Designer.MdiMode && Designer.Documents.Count > 0; } /// 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) { } } /// /// Represents the "Window|Close All" command. /// public class CloseAllCommand : CloseCommand { /// 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) { } } /// /// Represents the "File|Preview..." command. /// public class PreviewCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontPreviewReport && ActiveReport != null; } /// public override void Invoke() { ActiveReportTab.Preview(); } internal PreviewCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Preview on Cloud..." command. /// public class PreviewCloudCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReport != null && ActiveReport.IsOpenedFromCloud; } /// public override void Invoke() { if (ActiveReportTab.Modified) ActiveReportTab.SaveFile(false); CloudCommands.PreviewReport(ActiveReport); } internal PreviewCloudCommand(Designer designer) : base(designer) { } } /// /// Represents the "File|Page Setup..." command. /// public class PageSettingsCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontChangePageOptions && ActiveReport != null && ActiveReportTab.ActivePage is ReportPage; } /// public override void Invoke() { IHasEditor page = ActiveReportTab.ActivePage as IHasEditor; if (page.InvokeEditor()) { SetModified("EditPage"); } } internal PageSettingsCommand(Designer designer) : base(designer) { } } /// /// Represents the "Report|Options..." command. /// public class ReportSettingsCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontChangeReportOptions && ActiveReport != null; } /// 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) { } } /// /// Represents the "File|Printer Setup..." command. /// public class PrinterSettingsCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontChangeReportOptions && ActiveReport != null; } /// 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) { } } /// /// Represents the "Edit|Undo" command. /// public class UndoCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReport != null && ActiveReportTab.CanUndo; } /// public override void Invoke() { Undo(1); } /// /// Undo several actions. /// /// Number of actions to undo. public void Undo(int actionsCount) { ActiveReportTab.Undo(actionsCount); } internal UndoCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Redo" command. /// public class RedoCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReport != null && ActiveReportTab.CanRedo; } /// public override void Invoke() { Redo(1); } /// /// Redo several actions. /// /// Number of actions to redo. public void Redo(int actionsCount) { ActiveReportTab.Redo(actionsCount); } internal RedoCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Cut" command. /// public class CutCommand : DesignerCommand { /// protected override bool GetEnabled() { if (ActiveReportTab == null || ActiveReportTab.ActivePageDesigner == null) return false; return ActiveReportTab.ActivePageDesigner.CanCopy(); } /// public override void Invoke() { ActiveReportTab.ActivePageDesigner.Cut(); } internal CutCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Copy" command. /// public class CopyCommand : CutCommand { /// public override void Invoke() { ActiveReportTab.ActivePageDesigner.Copy(); } internal CopyCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Copy Page" command. /// public class CopyPageCommand : DesignerCommand { /// 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; } /// public override void Invoke() { if (Enabled) { ActiveReportTab.CopyPage(); } } internal CopyPageCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Paste" command. /// public class PasteCommand : DesignerCommand { /// protected override bool GetEnabled() { if (ActiveReportTab == null || ActiveReportTab.ActivePageDesigner == null) return false; return ActiveReportTab.ActivePageDesigner.CanPaste(); } /// public override void Invoke() { ActiveReportTab.ActivePageDesigner.Paste(); } internal PasteCommand(Designer designer) : base(designer) { } } /// /// Represents the "Format Painter" toolbar command. /// public class FormatPainterCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReportTab != null && ActiveReportTab.ActivePage != null && SelectedReportComponents.Count > 0; } /// public override void Invoke() { Designer.FormatPainter = !Designer.FormatPainter; } internal FormatPainterCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Delete" command. /// public class DeleteCommand : DesignerCommand { /// 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; } /// 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) { } } /// /// Represents the "Edit|Delete Page" command. /// public class DeletePageCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontDeletePage && ActiveReport != null && ActiveReportTab.ActivePage != null && ActiveReport.Pages.Count > 1 && !ActiveReportTab.ActivePage.IsAncestor; } /// public override void Invoke() { if (Enabled) { ActiveReportTab.DeletePage(); } } internal DeletePageCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Select All" command. /// public class SelectAllCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReportTab != null; } /// public override void Invoke() { if (ActiveReportTab != null) ActiveReportTab.ActivePageDesigner.SelectAll(); } internal SelectAllCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Group" command. /// public class GroupCommand : DesignerCommand { /// protected override bool GetEnabled() { return SelectedObjects.Count > 1; } /// public override void Invoke() { Dictionary groups = new Dictionary(); // 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) { } } /// /// Represents the "Edit|Ungroup" command. /// public class UngroupCommand : GroupCommand { /// public override void Invoke() { foreach (Base c in SelectedObjects) { if (c is ComponentBase) (c as ComponentBase).GroupIndex = 0; } } internal UngroupCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit" command. /// public class EditCommand : DesignerCommand { /// protected override bool GetEnabled() { return SelectedObjects.Count == 1 && SelectedObjects[0] is IHasEditor; } /// public override void Invoke() { if (!SelectedObjects[0].HasRestriction(FastReport.Restrictions.DontEdit) && (SelectedObjects[0] as IHasEditor).InvokeEditor()) SetModified("EditObject"); } internal EditCommand(Designer designer) : base(designer) { } } /// /// Represents the "Edit|Find..." command. /// public class FindCommand : DesignerCommand { internal bool isReplace; private void searchForm_FormClosed(object sender, FormClosedEventArgs e) { (sender as Form).Dispose(); } /// protected override bool GetEnabled() { return ActiveReportTab != null; } /// 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; } } /// /// Represents the "Edit|Replace..." command. /// public class ReplaceCommand : FindCommand { internal ReplaceCommand(Designer designer) : base(designer) { isReplace = true; } } /// /// Represents the "Bring To Front" context menu command. /// public class BringToFrontCommand : DesignerCommand { /// protected override bool GetEnabled() { bool enable = SelectedObjects.Count > 0; if (enable && SelectedObjects.Count == 1 && !SelectedObjects[0].HasFlag(Flags.CanChangeOrder)) enable = false; return enable; } /// public override void Invoke() { foreach (Base c in SelectedObjects) { c.ZOrder = 1000; } SetModified("Change"); } internal BringToFrontCommand(Designer designer) : base(designer) { } } /// /// Represents the "Send To Back" context menu command. /// public class SendToBackCommand : BringToFrontCommand { /// public override void Invoke() { foreach (Base c in SelectedObjects) { c.ZOrder = 0; } SetModified("Change"); } internal SendToBackCommand(Designer designer) : base(designer) { } } /// /// Represents the "Insert" command. /// /// /// This command has no default action associated with it. Check the Enabled property /// to see if the insert operation is enabled. /// public class InsertCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontInsertObject && ActiveReportTab != null && ActiveReportTab.ActivePage != null; } internal InsertCommand(Designer designer) : base(designer) { } } /// /// Represents the "Insert Band" command. /// /// /// This command has no default action associated with it. Check the Enabled property /// to see if the insert operation is enabled. /// public class InsertBandCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontInsertObject && !Restrictions.DontInsertBand && ActiveReportTab != null && ActiveReportTab.ActivePage != null && ActiveReportTab.ActivePage is ReportPage; } internal InsertBandCommand(Designer designer) : base(designer) { } } /// /// Represents the "Data|Add Data Source..." command. /// public class AddDataCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontCreateData && ActiveReport != null; } /// 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) { } } /// /// Represents the "Data|Sort Data Sources" command. /// public class SortDataSourcesCommand : DesignerCommand { /// 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; } /// 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) { } } /// /// Represents the "Data|Choose Report Data..." command. /// public class ChooseDataCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontEditData && ActiveReport != null; } /// public override void Invoke() { using (ReportDataForm form = new ReportDataForm(ActiveReport)) { if (form.ShowDialog() == DialogResult.OK) SetModified("SelectData"); } } internal ChooseDataCommand(Designer designer) : base(designer) { } } /// /// Represents the "Recent Files" command. /// /// /// This command has no default action associated with it. Check the Enabled property /// to see if the recent files list is enabled. /// public class RecentFilesCommand : DesignerCommand { /// 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(); foreach (var keyValuePair in Designer.CloudReportDictionary) { if (current >= toSkip) { tempDict.Add(keyValuePair.Key, keyValuePair.Value); } current++; } Designer.CloudReportDictionary = tempDict; } } /// /// Returns true if the file specified is a cloud file. /// /// File name to check. /// true if file is a cloud file. public bool IsCloudFile(string fileName) => Designer.CloudReportDictionary.Keys.Contains(fileName); /// /// Opens a recent file with specified name either from local PC or from cloud. /// /// File name to open. 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) { } } /// /// Represents the "File|Select Language..." command. /// public class SelectLanguageCommand : DesignerCommand { /// 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) { } } /// /// Represents the "View|Options..." command. /// public class OptionsCommand : DesignerCommand { /// public override void Invoke() { using (DesignerOptionsForm options = new DesignerOptionsForm(Designer)) { if (options.ShowDialog() == DialogResult.OK) { Designer.UpdatePlugins(null); } } } internal OptionsCommand(Designer designer) : base(designer) { } } /// /// Represents the "View|Start Page" command. /// public class ViewStartPageCommand : DesignerCommand { /// protected override bool GetEnabled() { return Designer.MdiMode; } /// 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) { } } /// /// Represents the "Select polygon move" command. /// public class PolygonSelectModeCommand : DesignerCommand { private PolyLineObject.PolygonSelectionMode mode; /// protected override bool GetEnabled() { return (Designer.SelectedObjects.Count == 1) && (Designer.SelectedObjects[0] is PolyLineObject); } /// 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; } } /// /// Represents the "Report|Styles..." command. /// public class ReportStylesCommand : DesignerCommand { /// protected override bool GetEnabled() { return !Restrictions.DontChangeReportOptions && ActiveReport != null; } /// 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) { } } /// /// Represents the "Report|Validation" command. /// public class ReportValidationCommand : DesignerCommand { /// protected override bool GetEnabled() { return ActiveReport != null; } /// public override void Invoke() { if (ActiveReport == null) return; List 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) { } } /// /// Represents the "Help|Account" command. /// public class AccountCommand : DesignerCommand { /// protected override bool GetEnabled() { return Auth.AuthService.Instance.IsEnable; } /// public override void Invoke() { using (Auth.AuthForm authForm = new Auth.AuthForm()) { authForm.ShowDialog(); } } internal AccountCommand(Designer designer) : base(designer) { } } /// /// Represents the "Help|Help Contents..." command. /// 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; } /// protected override bool GetEnabled() { return true; } /// public override void Invoke() { ProcessHelper.StartProcess(GetHelpUrl()); } internal HelpContentsCommand(Designer designer) : base(designer) { } } /// /// Represents the "Help|About..." command. /// public class AboutCommand : DesignerCommand { /// public override void Invoke() { using (AboutForm form = new AboutForm()) { form.ShowDialog(); } } internal AboutCommand(Designer designer) : base(designer) { } } /// /// Represents the "Show welcome window..." command. /// public class WelcomeCommand : DesignerCommand { /// protected override bool GetEnabled() { return Config.WelcomeEnabled; } /// public override void Invoke() { #if !(WPF || AVALONIA) using (WelcomeForm form = new WelcomeForm(Designer)) { form.ShowDialog(); } #endif } internal WelcomeCommand(Designer designer) : base(designer) { } } }