using System; using System.Globalization; using System.Windows.Forms; using FastReport.Utils; using FastReport.Design; using System.IO; #if !MONO using FastReport.Design.Toolbars; using FastReport.DevComponents.DotNetBar; #endif namespace FastReport.Forms { internal partial class PluginsOptions : DesignerOptionsPage { private Designer designer; private void Localize() { MyRes res = new MyRes("Forms,UIOptions"); tab1.Text = res.Get(""); lblUIStyle.Text = res.Get("Appearance"); cbxUIStyle.Items.AddRange(UIStyleUtils.UIStyleNames); lblIconPack.Text = res.Get("IconPack"); cbxIconPack.Items.Add(res.Get("IconPack,Pack1")); cbxIconPack.Items.Add(res.Get("IconPack,Pack2")); cbRibbon.Text = res.Get("Ribbon"); cbWelcome.Text = res.Get("Welcome"); cbDisableHotkeys.Text = res.Get("DisableHotkeys"); cbxShowProgress.Text = res.Get("ShowProgress"); cbUseCompactMenu.Text = res.Get("UseCompactMenu"); btnResetConfig.Text = res.Get("Reset"); btnShortcut.Text = res.Get("Shortcut"); res = new MyRes("Forms,UIOptions,RightToLeft"); lblRightToLeft.Text = res.Get(""); cbxRightToLeft.Items.Add(res.Get("Auto")); cbxRightToLeft.Items.Add(res.Get("No")); cbxRightToLeft.Items.Add(res.Get("Yes")); cbxRightToLeft.SelectedIndex = 0; res = new MyRes("Forms,SavingPageOptions"); cbAutoSave.Text = res.Get("EnableAutoSave"); res = new MyRes("Forms,PluginsOptions"); tab2.Text = res.Get(""); lblHint.Text = res.Get("Hint"); btnAdd.Text = res.Get("Add"); btnRemove.Text = res.Get("Remove"); btnFonts.Text = res.Get("Fonts"); btnExportsMenuEdit.Text = res.Get("ExportsEditor"); } public override void UpdateDpiDependencies() { base.UpdateDpiDependencies(); btnUp.Image = this.GetImage(208); btnDown.Image = this.GetImage(209); lbPlugins.ItemHeight = this.LogicalToDevice(19); } private string GetToolTipText(string location) { if (location == null || !File.Exists(location)) return ""; FileInfo info = new FileInfo(location); var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(location); return info.Name + "\n" + Res.Get("Forms,PluginsOptions,Description") + " " + versionInfo.FileDescription + "\n" + Res.Get("Forms,PluginsOptions,CompanyName") + " " + versionInfo.CompanyName + "\n" + Res.Get("Forms,PluginsOptions,Version") + " " + versionInfo.FileVersion + "\n" + Res.Get("Forms,PluginsOptions,Date") + " " + info.CreationTime.ToString() + "\n" + Res.Get("Forms,PluginsOptions,Size") + " " + FileSize.ConvertToString(info.Length) + "\n" + Res.Get("Forms,PluginsOptions,Path") + "\n" + location; } private void AddPlugin(string name) { lbPlugins.Items.Add(new FastReport.Controls.ListBoxItem(name, GetToolTipText(name))); } private void btnAdd_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = Res.Get("FileFilters,Assembly"); if (dialog.ShowDialog() == DialogResult.OK) { AddPlugin(dialog.FileName); RestartRequired = true; } } } private void btnRemove_Click(object sender, EventArgs e) { lbPlugins.Items.Remove(lbPlugins.SelectedItem); RestartRequired = true; } private void btnUp_Click(object sender, EventArgs e) { int index = lbPlugins.SelectedIndex; if (index > 0) { Object item = lbPlugins.SelectedItem; lbPlugins.Items.Remove(item); lbPlugins.Items.Insert(index - 1, item); lbPlugins.SelectedItem = item; } } private void btnDown_Click(object sender, EventArgs e) { int index = lbPlugins.SelectedIndex; if (index < lbPlugins.Items.Count - 1) { Object item = lbPlugins.SelectedItem; lbPlugins.Items.Remove(item); lbPlugins.Items.Insert(index + 1, item); lbPlugins.SelectedItem = item; } } private void lbPlugins_SelectedIndexChanged(object sender, EventArgs e) { bool enabled = lbPlugins.SelectedItems.Count != 0; btnRemove.Enabled = enabled; btnUp.Enabled = enabled; btnDown.Enabled = enabled; } private void lbPlugins_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0) this.DrawImageAndText(e, this.GetImage(89), lbPlugins.Items[e.Index].ToString()); } private void btnFonts_Click(object sender, EventArgs e) { using (FormsFonts fontsForm = new FormsFonts()) { if (fontsForm.ShowDialog() == DialogResult.OK) { designer.ActiveReportTab.Editor.UpdateFont(); designer.ActiveReportTab.FRXEditor.UpdateFont(); } } } private void BtnShortCut_Click(object sender, System.EventArgs e) { using (ShortcutsListForm shortCutEditorForm = new ShortcutsListForm()) { if (shortCutEditorForm.ShowDialog() == DialogResult.OK) RestartRequired = true; } } private void BtnExportsMenuEdit_Click(object sender, EventArgs e) { #if !COMMUNITY using (ExportsOptionsEditorForm exportsEditorForm = new ExportsOptionsEditorForm()) { exportsEditorForm.ShowDialog(); } #endif } private void cbxRightToLeft_SelectedIndexChanged(object sender, EventArgs e) { RestartRequired = true; } private void btnResetConfig_Click(object sender, EventArgs e) { RestartRequired = true; Config.CleanupOnExit = true; } private void cbUseCompactMenu_CheckedChanged(object sender, EventArgs e) { #if (WPF || AVALONIA) RestartRequired = true; #endif } private void SetConfigRightToLeft() { switch (cbxRightToLeft.SelectedIndex) { case 0: Config.RightToLeft = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft; break; case 1: Config.RightToLeft = false; break; case 2: Config.RightToLeft = true; break; default: Config.RightToLeft = false; break; } } private void LoadRightToLeft() { XmlItem uiOptions = Config.Root.FindItem("UIOptions"); string rtl = uiOptions.GetProp("RightToLeft"); if (!String.IsNullOrEmpty(rtl)) { switch (rtl) { case "Auto": cbxRightToLeft.SelectedIndex = 0; break; case "No": cbxRightToLeft.SelectedIndex = 1; break; case "Yes": cbxRightToLeft.SelectedIndex = 2; break; default: cbxRightToLeft.SelectedIndex = 1; break; } SetConfigRightToLeft(); } } private void SaveRightToLeft() { XmlItem uiOptions = Config.Root.FindItem("UIOptions"); switch (cbxRightToLeft.SelectedIndex) { case 0: uiOptions.SetProp("RightToLeft", "Auto"); break; case 1: uiOptions.SetProp("RightToLeft", "No"); break; case 2: uiOptions.SetProp("RightToLeft", "Yes"); break; default: uiOptions.SetProp("RightToLeft", "No"); break; } SetConfigRightToLeft(); } public override void Init() { cbxUIStyle.SelectedIndex = (int)designer.UIStyle; cbxIconPack.SelectedIndex = Config.IconPack; cbDisableHotkeys.Checked = Config.DisableHotkeys; #if COMMUNITY btnExportsMenuEdit.Visible = false; cbRibbon.Visible = false; #endif #if MONO cbWelcome.Visible = false; cbDisableHotkeys.CheckedChanged += (s, e) => { RestartRequired = true; }; #else cbRibbon.Checked = Config.UseRibbon; cbWelcome.Checked = Config.WelcomeShowOnStartup; cbWelcome.Visible = Config.WelcomeEnabled; #endif cbxShowProgress.Checked = !Config.DesignerSettings.EmbeddedPreview && Config.ReportSettings.ShowProgress; cbxShowProgress.Enabled = !Config.DesignerSettings.EmbeddedPreview; #if (WPF || AVALONIA) cbRibbon.Checked = Config.UseRibbon; #if WPF cbUseCompactMenu.Visible = true; cbUseCompactMenu.Location = cbWelcome.Location; cbUseCompactMenu.Checked = Config.UseCompactMenu; #endif #endif XmlItem xi = Config.Root.FindItem("Designer").FindItem("Saving"); int minutes = 0; if (!int.TryParse(xi.GetProp("AutoSaveMinutes"), out minutes)) minutes = 5; nudMinutes.Value = minutes; cbAutoSave.Checked = xi.GetProp("EnableAutoSave") != "0"; cbAutoSave.Enabled = !designer.IsPreviewPageDesigner; nudMinutes.Enabled = !designer.IsPreviewPageDesigner; XmlItem pluginsItem = Config.Root.FindItem("Plugins"); for (int i = 0; i < pluginsItem.Count; i++) { AddPlugin(pluginsItem[i].GetProp("Name")); } lbPlugins_SelectedIndexChanged(this, EventArgs.Empty); LoadRightToLeft(); // load and apply Right to Left option } public override void Done(DialogResult result) { if (result == DialogResult.OK) { #if !MONO //HACK if (cbRibbon.Checked == true && Config.UseRibbon == false) { foreach (Bar bar in designer.DotNetBarManager.Bars) if (bar is DesignerToolbarBase) bar.Hide(); } else if (cbRibbon.Checked == false && Config.UseRibbon == true) { foreach (Bar bar in designer.DotNetBarManager.Bars) if (bar is DesignerToolbarBase) bar.Show(); } Config.WelcomeShowOnStartup = cbWelcome.Checked; Config.UseRibbon = cbRibbon.Checked; #endif Config.ReportSettings.ShowProgress = cbxShowProgress.Checked; Config.DisableHotkeys = cbDisableHotkeys.Checked; #if (WPF || AVALONIA) Config.UseRibbon = cbRibbon.Checked; Config.UseCompactMenu = cbUseCompactMenu.Checked; #endif Config.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex; designer.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex; Config.IconPack = cbxIconPack.SelectedIndex; designer.AutoSaveTimer.Enabled = cbAutoSave.Checked; designer.AutoSaveTimer.Interval = (int)nudMinutes.Value * 60000; XmlItem xi = Config.Root.FindItem("Designer").FindItem("Saving"); xi.SetProp("EnableAutoSave", cbAutoSave.Checked ? "1" : "0"); xi.SetProp("AutoSaveMinutes", "" + nudMinutes.Value); XmlItem pluginsItem = Config.Root.FindItem("Plugins"); pluginsItem.Clear(); foreach (object item in lbPlugins.Items) { xi = pluginsItem.Add(); xi.Name = "Plugin"; xi.SetProp("Name", item.ToString()); } SaveRightToLeft(); // save and apply Right to Left option } } public PluginsOptions(Designer designer) : base() { this.designer = designer; InitializeComponent(); Localize(); #if COMMUNITY this.tc1.Controls.Remove(tab2); #endif } } }