PluginsOptions.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. lblRestart.Text = res.Get("Restart");
  29. btnResetConfig.Text = res.Get("Reset");
  30. res = new MyRes("Forms,PluginsOptions");
  31. tab2.Text = res.Get("");
  32. lblHint.Text = res.Get("Hint");
  33. btnAdd.Text = res.Get("Add");
  34. btnRemove.Text = res.Get("Remove");
  35. lblNote.Text = res.Get("Note");
  36. btnFonts.Text = res.Get("Fonts");
  37. btnExportsMenuEdit.Text = res.Get("ExportsEditor");
  38. res = new MyRes("Forms,UIOptions,RightToLeft");
  39. lblRightToLeft.Text = res.Get("");
  40. cbxRightToLeft.Items.Add(res.Get("Auto"));
  41. cbxRightToLeft.Items.Add(res.Get("No"));
  42. cbxRightToLeft.Items.Add(res.Get("Yes"));
  43. cbxRightToLeft.SelectedIndex = 0;
  44. }
  45. public override void UpdateDpiDependencies()
  46. {
  47. base.UpdateDpiDependencies();
  48. btnUp.Image = this.GetImage(208);
  49. btnDown.Image = this.GetImage(209);
  50. }
  51. private string GetToolTipText(string location)
  52. {
  53. if (location == null || !File.Exists(location)) return "";
  54. FileInfo info = new FileInfo(location);
  55. var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(location);
  56. return info.Name + "\n" +
  57. Res.Get("Forms,PluginsOptions,Description") + " " +
  58. versionInfo.FileDescription + "\n" +
  59. Res.Get("Forms,PluginsOptions,CompanyName") + " " +
  60. versionInfo.CompanyName + "\n" +
  61. Res.Get("Forms,PluginsOptions,Version") + " " +
  62. versionInfo.FileVersion + "\n" +
  63. Res.Get("Forms,PluginsOptions,Date") + " " + info.CreationTime.ToString() + "\n" +
  64. Res.Get("Forms,PluginsOptions,Size") + " " + FileSize.ConvertToString(info.Length) + "\n" +
  65. Res.Get("Forms,PluginsOptions,Path") + "\n" + location;
  66. }
  67. private void AddPlugin(string name)
  68. {
  69. dgPlugins.Rows.Add(this.GetImage(89), Path.GetFileName(name));
  70. string toolTip = GetToolTipText(name);
  71. dgPlugins.Rows[dgPlugins.Rows.Count - 1].Cells[1].Tag = name;
  72. dgPlugins.Rows[dgPlugins.Rows.Count - 1].Cells[0].ToolTipText = toolTip;
  73. dgPlugins.Rows[dgPlugins.Rows.Count - 1].Cells[1].ToolTipText = toolTip;
  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. }
  84. }
  85. }
  86. private void btnRemove_Click(object sender, EventArgs e)
  87. {
  88. if (dgPlugins.SelectedRows.Count == 0)
  89. return;
  90. dgPlugins.Rows.Remove(dgPlugins.SelectedRows[0]);
  91. }
  92. private void btnUp_Click(object sender, EventArgs e)
  93. {
  94. if (dgPlugins.SelectedRows.Count == 0)
  95. return;
  96. DataGridViewRow row = dgPlugins.SelectedRows[0];
  97. int index = row.Index;
  98. if (index > 0)
  99. {
  100. dgPlugins.Rows.Remove(row);
  101. dgPlugins.Rows.Insert(index - 1, row);
  102. row.Selected = true;
  103. }
  104. }
  105. private void btnDown_Click(object sender, EventArgs e)
  106. {
  107. if (dgPlugins.SelectedRows.Count == 0)
  108. return;
  109. DataGridViewRow row = dgPlugins.SelectedRows[0];
  110. int index = row.Index;
  111. if (index < dgPlugins.Rows.Count - 1)
  112. {
  113. dgPlugins.Rows.Remove(row);
  114. dgPlugins.Rows.Insert(index + 1, row);
  115. row.Selected = true;
  116. }
  117. }
  118. private void dgPlugins_SelectedIndexChanged(object sender, EventArgs e)
  119. {
  120. bool enabled = dgPlugins.SelectedRows.Count != 0;
  121. btnRemove.Enabled = enabled;
  122. btnUp.Enabled = enabled;
  123. btnDown.Enabled = enabled;
  124. }
  125. private void btnFonts_Click(object sender, EventArgs e)
  126. {
  127. using (FormsFonts fontsForm = new FormsFonts())
  128. {
  129. if (fontsForm.ShowDialog() == DialogResult.OK)
  130. {
  131. #if !MONO
  132. designer.ActiveReportTab.Editor.UpdateFont();
  133. designer.ActiveReportTab.FRXEditor.UpdateFont();
  134. #endif
  135. }
  136. }
  137. }
  138. private void BtnExportsMenuEdit_Click(object sender, EventArgs e)
  139. {
  140. #if !COMMUNITY
  141. using (ExportsOptionsEditorForm exportsEditorForm = new ExportsOptionsEditorForm())
  142. {
  143. exportsEditorForm.ShowDialog();
  144. }
  145. #endif
  146. }
  147. private void cbxRightToLeft_SelectedIndexChanged(object sender, EventArgs e)
  148. {
  149. lblRestart.Visible = true;
  150. }
  151. private void btnResetConfig_Click(object sender, EventArgs e)
  152. {
  153. lblRestart.Visible = true;
  154. Config.CleanupOnExit = true;
  155. }
  156. private void SetConfigRightToLeft()
  157. {
  158. switch (cbxRightToLeft.SelectedIndex)
  159. {
  160. case 0:
  161. Config.RightToLeft = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft;
  162. break;
  163. case 1:
  164. Config.RightToLeft = false;
  165. break;
  166. case 2:
  167. Config.RightToLeft = true;
  168. break;
  169. default:
  170. Config.RightToLeft = false;
  171. break;
  172. }
  173. }
  174. private void LoadRightToLeft()
  175. {
  176. XmlItem uiOptions = Config.Root.FindItem("UIOptions");
  177. string rtl = uiOptions.GetProp("RightToLeft");
  178. if (!String.IsNullOrEmpty(rtl))
  179. {
  180. switch (rtl)
  181. {
  182. case "Auto":
  183. cbxRightToLeft.SelectedIndex = 0;
  184. break;
  185. case "No":
  186. cbxRightToLeft.SelectedIndex = 1;
  187. break;
  188. case "Yes":
  189. cbxRightToLeft.SelectedIndex = 2;
  190. break;
  191. default:
  192. cbxRightToLeft.SelectedIndex = 1;
  193. break;
  194. }
  195. SetConfigRightToLeft();
  196. }
  197. }
  198. private void SaveRightToLeft()
  199. {
  200. XmlItem uiOptions = Config.Root.FindItem("UIOptions");
  201. switch (cbxRightToLeft.SelectedIndex)
  202. {
  203. case 0:
  204. uiOptions.SetProp("RightToLeft", "Auto");
  205. break;
  206. case 1:
  207. uiOptions.SetProp("RightToLeft", "No");
  208. break;
  209. case 2:
  210. uiOptions.SetProp("RightToLeft", "Yes");
  211. break;
  212. default:
  213. uiOptions.SetProp("RightToLeft", "No");
  214. break;
  215. }
  216. SetConfigRightToLeft();
  217. }
  218. public override void Init()
  219. {
  220. cbxUIStyle.SelectedIndex = (int)designer.UIStyle;
  221. cbxIconPack.SelectedIndex = Config.IconPack;
  222. #if COMMUNITY
  223. btnExportsMenuEdit.Visible = false;
  224. cbRibbon.Visible = false;
  225. #endif
  226. #if MONO
  227. cbRibbon.Enabled = false;
  228. cbWelcome.Enabled = false;
  229. cbWelcome.Enabled = false;
  230. cbDisableHotkeys.Enabled = false;
  231. #else
  232. cbRibbon.Checked = Config.UseRibbon;
  233. cbWelcome.Checked = Config.WelcomeShowOnStartup;
  234. cbWelcome.Visible = Config.WelcomeEnabled;
  235. cbDisableHotkeys.Checked = Config.DisableHotkeys;
  236. #endif
  237. XmlItem pluginsItem = Config.Root.FindItem("Plugins");
  238. for (int i = 0; i < pluginsItem.Count; i++)
  239. {
  240. XmlItem xi = pluginsItem[i];
  241. AddPlugin(xi.GetProp("Name"));
  242. }
  243. lblNote.Width = tab2.Width - lblNote.Left * 2;
  244. lblNote.Height = tab2.Height - lblNote.Top;
  245. dgPlugins_SelectedIndexChanged(this, EventArgs.Empty);
  246. LoadRightToLeft(); // load and apply Right to Left option
  247. lblRestart.Visible = false;
  248. }
  249. public override void Done(DialogResult result)
  250. {
  251. if (result == DialogResult.OK)
  252. {
  253. #if !MONO
  254. //HACK
  255. if (cbRibbon.Checked == true && Config.UseRibbon == false)
  256. {
  257. foreach (Bar bar in designer.DotNetBarManager.Bars)
  258. if (bar is ToolbarBase)
  259. bar.Hide();
  260. }
  261. else if (cbRibbon.Checked == false && Config.UseRibbon == true)
  262. {
  263. foreach (Bar bar in designer.DotNetBarManager.Bars)
  264. if (bar is ToolbarBase)
  265. bar.Show();
  266. }
  267. Config.WelcomeShowOnStartup = cbWelcome.Checked;
  268. Config.UseRibbon = cbRibbon.Checked;
  269. Config.DisableHotkeys = cbDisableHotkeys.Checked;
  270. #endif
  271. Config.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex;
  272. designer.UIStyle = (UIStyle)cbxUIStyle.SelectedIndex;
  273. Config.IconPack = cbxIconPack.SelectedIndex;
  274. XmlItem pluginsItem = Config.Root.FindItem("Plugins");
  275. pluginsItem.Clear();
  276. foreach (DataGridViewRow item in dgPlugins.Rows)
  277. {
  278. XmlItem xi = pluginsItem.Add();
  279. xi.Name = "Plugin";
  280. xi.SetProp("Name", item.Cells[1].Tag.ToString());
  281. }
  282. SaveRightToLeft(); // save and apply Right to Left option
  283. }
  284. }
  285. public PluginsOptions(Designer designer) : base()
  286. {
  287. this.designer = designer;
  288. InitializeComponent();
  289. Localize();
  290. }
  291. }
  292. }