PluginsOptions.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Forms;
  4. using FastReport.Utils;
  5. using FastReport.Design;
  6. using System.IO;
  7. #if !MONO
  8. using FastReport.Design.Toolbars;
  9. using FastReport.DevComponents.DotNetBar;
  10. #endif
  11. namespace FastReport.Forms
  12. {
  13. internal partial class PluginsOptions : DesignerOptionsPage
  14. {
  15. private Designer designer;
  16. private void Localize()
  17. {
  18. MyRes res = new MyRes("Forms,UIOptions");
  19. tab1.Text = res.Get("");
  20. lblUIStyle.Text = res.Get("Appearance");
  21. cbxUIStyle.Items.AddRange(UIStyleUtils.UIStyleNames);
  22. lblIconPack.Text = res.Get("IconPack");
  23. cbxIconPack.Items.Add(res.Get("IconPack,Pack1"));
  24. cbxIconPack.Items.Add(res.Get("IconPack,Pack2"));
  25. cbRibbon.Text = res.Get("Ribbon");
  26. cbWelcome.Text = res.Get("Welcome");
  27. cbDisableHotkeys.Text = res.Get("DisableHotkeys");
  28. cbxShowProgress.Text = res.Get("ShowProgress");
  29. cbUseCompactMenu.Text = res.Get("UseCompactMenu");
  30. btnResetConfig.Text = res.Get("Reset");
  31. btnShortcut.Text = res.Get("Shortcut");
  32. res = new MyRes("Forms,UIOptions,RightToLeft");
  33. lblRightToLeft.Text = res.Get("");
  34. cbxRightToLeft.Items.Add(res.Get("Auto"));
  35. cbxRightToLeft.Items.Add(res.Get("No"));
  36. cbxRightToLeft.Items.Add(res.Get("Yes"));
  37. cbxRightToLeft.SelectedIndex = 0;
  38. res = new MyRes("Forms,SavingPageOptions");
  39. cbAutoSave.Text = res.Get("EnableAutoSave");
  40. res = new MyRes("Forms,PluginsOptions");
  41. tab2.Text = res.Get("");
  42. lblHint.Text = res.Get("Hint");
  43. btnAdd.Text = res.Get("Add");
  44. btnRemove.Text = res.Get("Remove");
  45. btnFonts.Text = res.Get("Fonts");
  46. btnExportsMenuEdit.Text = res.Get("ExportsEditor");
  47. }
  48. public override void UpdateDpiDependencies()
  49. {
  50. base.UpdateDpiDependencies();
  51. btnUp.Image = this.GetImage(208);
  52. btnDown.Image = this.GetImage(209);
  53. lbPlugins.ItemHeight = this.LogicalToDevice(19);
  54. }
  55. private string GetToolTipText(string location)
  56. {
  57. if (location == null || !File.Exists(location)) return "";
  58. FileInfo info = new FileInfo(location);
  59. var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(location);
  60. return info.Name + "\n" +
  61. Res.Get("Forms,PluginsOptions,Description") + " " +
  62. versionInfo.FileDescription + "\n" +
  63. Res.Get("Forms,PluginsOptions,CompanyName") + " " +
  64. versionInfo.CompanyName + "\n" +
  65. Res.Get("Forms,PluginsOptions,Version") + " " +
  66. versionInfo.FileVersion + "\n" +
  67. Res.Get("Forms,PluginsOptions,Date") + " " + info.CreationTime.ToString() + "\n" +
  68. Res.Get("Forms,PluginsOptions,Size") + " " + FileSize.ConvertToString(info.Length) + "\n" +
  69. Res.Get("Forms,PluginsOptions,Path") + "\n" + location;
  70. }
  71. private void AddPlugin(string name)
  72. {
  73. lbPlugins.Items.Add(new FastReport.Controls.ListBoxItem(name, GetToolTipText(name)));
  74. }
  75. private void btnAdd_Click(object sender, EventArgs e)
  76. {
  77. using (OpenFileDialog dialog = new OpenFileDialog())
  78. {
  79. dialog.Filter = Res.Get("FileFilters,Assembly");
  80. if (dialog.ShowDialog() == DialogResult.OK)
  81. {
  82. AddPlugin(dialog.FileName);
  83. RestartRequired = true;
  84. }
  85. }
  86. }
  87. private void btnRemove_Click(object sender, EventArgs e)
  88. {
  89. lbPlugins.Items.Remove(lbPlugins.SelectedItem);
  90. RestartRequired = true;
  91. }
  92. private void btnUp_Click(object sender, EventArgs e)
  93. {
  94. int index = lbPlugins.SelectedIndex;
  95. if (index > 0)
  96. {
  97. Object item = lbPlugins.SelectedItem;
  98. lbPlugins.Items.Remove(item);
  99. lbPlugins.Items.Insert(index - 1, item);
  100. lbPlugins.SelectedItem = item;
  101. }
  102. }
  103. private void btnDown_Click(object sender, EventArgs e)
  104. {
  105. int index = lbPlugins.SelectedIndex;
  106. if (index < lbPlugins.Items.Count - 1)
  107. {
  108. Object item = lbPlugins.SelectedItem;
  109. lbPlugins.Items.Remove(item);
  110. lbPlugins.Items.Insert(index + 1, item);
  111. lbPlugins.SelectedItem = item;
  112. }
  113. }
  114. private void lbPlugins_SelectedIndexChanged(object sender, EventArgs e)
  115. {
  116. bool enabled = lbPlugins.SelectedItems.Count != 0;
  117. btnRemove.Enabled = enabled;
  118. btnUp.Enabled = enabled;
  119. btnDown.Enabled = enabled;
  120. }
  121. private void lbPlugins_DrawItem(object sender, DrawItemEventArgs e)
  122. {
  123. e.DrawBackground();
  124. if (e.Index >= 0)
  125. this.DrawImageAndText(e, this.GetImage(89), lbPlugins.Items[e.Index].ToString());
  126. }
  127. private void btnFonts_Click(object sender, EventArgs e)
  128. {
  129. using (FormsFonts fontsForm = new FormsFonts())
  130. {
  131. if (fontsForm.ShowDialog() == DialogResult.OK)
  132. {
  133. designer.ActiveReportTab.Editor.UpdateFont();
  134. designer.ActiveReportTab.FRXEditor.UpdateFont();
  135. }
  136. }
  137. }
  138. private void BtnShortCut_Click(object sender, System.EventArgs e)
  139. {
  140. using (ShortcutsListForm shortCutEditorForm = new ShortcutsListForm())
  141. {
  142. if (shortCutEditorForm.ShowDialog() == DialogResult.OK)
  143. RestartRequired = true;
  144. }
  145. }
  146. private void BtnExportsMenuEdit_Click(object sender, EventArgs e)
  147. {
  148. #if !COMMUNITY
  149. using (ExportsOptionsEditorForm exportsEditorForm = new ExportsOptionsEditorForm())
  150. {
  151. exportsEditorForm.ShowDialog();
  152. }
  153. #endif
  154. }
  155. private void cbxRightToLeft_SelectedIndexChanged(object sender, EventArgs e)
  156. {
  157. RestartRequired = true;
  158. }
  159. private void btnResetConfig_Click(object sender, EventArgs e)
  160. {
  161. RestartRequired = true;
  162. Config.CleanupOnExit = true;
  163. }
  164. private void cbUseCompactMenu_CheckedChanged(object sender, EventArgs e)
  165. {
  166. #if (WPF || AVALONIA)
  167. RestartRequired = true;
  168. #endif
  169. }
  170. private void SetConfigRightToLeft()
  171. {
  172. switch (cbxRightToLeft.SelectedIndex)
  173. {
  174. case 0:
  175. Config.RightToLeft = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft;
  176. break;
  177. case 1:
  178. Config.RightToLeft = false;
  179. break;
  180. case 2:
  181. Config.RightToLeft = true;
  182. break;
  183. default:
  184. Config.RightToLeft = false;
  185. break;
  186. }
  187. }
  188. private void LoadRightToLeft()
  189. {
  190. XmlItem uiOptions = Config.Root.FindItem("UIOptions");
  191. string rtl = uiOptions.GetProp("RightToLeft");
  192. if (!String.IsNullOrEmpty(rtl))
  193. {
  194. switch (rtl)
  195. {
  196. case "Auto":
  197. cbxRightToLeft.SelectedIndex = 0;
  198. break;
  199. case "No":
  200. cbxRightToLeft.SelectedIndex = 1;
  201. break;
  202. case "Yes":
  203. cbxRightToLeft.SelectedIndex = 2;
  204. break;
  205. default:
  206. cbxRightToLeft.SelectedIndex = 1;
  207. break;
  208. }
  209. SetConfigRightToLeft();
  210. }
  211. }
  212. private void SaveRightToLeft()
  213. {
  214. XmlItem uiOptions = Config.Root.FindItem("UIOptions");
  215. switch (cbxRightToLeft.SelectedIndex)
  216. {
  217. case 0:
  218. uiOptions.SetProp("RightToLeft", "Auto");
  219. break;
  220. case 1:
  221. uiOptions.SetProp("RightToLeft", "No");
  222. break;
  223. case 2:
  224. uiOptions.SetProp("RightToLeft", "Yes");
  225. break;
  226. default:
  227. uiOptions.SetProp("RightToLeft", "No");
  228. break;
  229. }
  230. SetConfigRightToLeft();
  231. }
  232. public override void Init()
  233. {
  234. cbxUIStyle.SelectedIndex = (int)designer.UIStyle;
  235. cbxIconPack.SelectedIndex = Config.IconPack;
  236. cbDisableHotkeys.Checked = Config.DisableHotkeys;
  237. #if COMMUNITY
  238. btnExportsMenuEdit.Visible = false;
  239. cbRibbon.Visible = false;
  240. #endif
  241. #if MONO
  242. cbWelcome.Visible = false;
  243. cbDisableHotkeys.CheckedChanged += (s, e) => { RestartRequired = true; };
  244. #else
  245. cbRibbon.Checked = Config.UseRibbon;
  246. cbWelcome.Checked = Config.WelcomeShowOnStartup;
  247. cbWelcome.Visible = Config.WelcomeEnabled;
  248. #endif
  249. cbxShowProgress.Checked = !Config.DesignerSettings.EmbeddedPreview && Config.ReportSettings.ShowProgress;
  250. cbxShowProgress.Enabled = !Config.DesignerSettings.EmbeddedPreview;
  251. #if (WPF || AVALONIA)
  252. cbRibbon.Checked = Config.UseRibbon;
  253. #if WPF
  254. cbUseCompactMenu.Visible = true;
  255. cbUseCompactMenu.Location = cbWelcome.Location;
  256. cbUseCompactMenu.Checked = Config.UseCompactMenu;
  257. #endif
  258. #endif
  259. XmlItem xi = Config.Root.FindItem("Designer").FindItem("Saving");
  260. int minutes = 0;
  261. if (!int.TryParse(xi.GetProp("AutoSaveMinutes"), out minutes))
  262. minutes = 5;
  263. nudMinutes.Value = minutes;
  264. cbAutoSave.Checked = xi.GetProp("EnableAutoSave") != "0";
  265. cbAutoSave.Enabled = !designer.IsPreviewPageDesigner;
  266. nudMinutes.Enabled = !designer.IsPreviewPageDesigner;
  267. XmlItem pluginsItem = Config.Root.FindItem("Plugins");
  268. for (int i = 0; i < pluginsItem.Count; i++)
  269. {
  270. AddPlugin(pluginsItem[i].GetProp("Name"));
  271. }
  272. lbPlugins_SelectedIndexChanged(this, EventArgs.Empty);
  273. LoadRightToLeft(); // load and apply Right to Left option
  274. }
  275. public override void Done(DialogResult result)
  276. {
  277. if (result == DialogResult.OK)
  278. {
  279. #if !MONO
  280. //HACK
  281. if (cbRibbon.Checked == true && Config.UseRibbon == false)
  282. {
  283. foreach (Bar bar in designer.DotNetBarManager.Bars)
  284. if (bar is DesignerToolbarBase)
  285. bar.Hide();
  286. }
  287. else if (cbRibbon.Checked == false && Config.UseRibbon == true)
  288. {
  289. foreach (Bar bar in designer.DotNetBarManager.Bars)
  290. if (bar is DesignerToolbarBase)
  291. bar.Show();
  292. }
  293. Config.WelcomeShowOnStartup = cbWelcome.Checked;
  294. Config.UseRibbon = cbRibbon.Checked;
  295. #endif
  296. Config.ReportSettings.ShowProgress = cbxShowProgress.Checked;
  297. Config.DisableHotkeys = cbDisableHotkeys.Checked;
  298. #if (WPF || AVALONIA)
  299. Config.UseRibbon = cbRibbon.Checked;
  300. Config.UseCompactMenu = cbUseCompactMenu.Checked;
  301. #endif
  302. Config.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex;
  303. designer.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex;
  304. Config.IconPack = cbxIconPack.SelectedIndex;
  305. designer.AutoSaveTimer.Enabled = cbAutoSave.Checked;
  306. designer.AutoSaveTimer.Interval = (int)nudMinutes.Value * 60000;
  307. XmlItem xi = Config.Root.FindItem("Designer").FindItem("Saving");
  308. xi.SetProp("EnableAutoSave", cbAutoSave.Checked ? "1" : "0");
  309. xi.SetProp("AutoSaveMinutes", "" + nudMinutes.Value);
  310. XmlItem pluginsItem = Config.Root.FindItem("Plugins");
  311. pluginsItem.Clear();
  312. foreach (object item in lbPlugins.Items)
  313. {
  314. xi = pluginsItem.Add();
  315. xi.Name = "Plugin";
  316. xi.SetProp("Name", item.ToString());
  317. }
  318. SaveRightToLeft(); // save and apply Right to Left option
  319. }
  320. }
  321. public PluginsOptions(Designer designer) : base()
  322. {
  323. this.designer = designer;
  324. InitializeComponent();
  325. Localize();
  326. #if COMMUNITY
  327. this.tc1.Controls.Remove(tab2);
  328. #endif
  329. }
  330. }
  331. }