WebStyleGrid.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. using InABox.WPF;
  8. using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
  9. namespace PRSServer.Forms.WebStyles
  10. {
  11. public class WebStyleGrid : DynamicDataGrid<WebStyle>
  12. {
  13. public WebStyleGrid()
  14. {
  15. ActionColumns.Add(new DynamicImageColumn(Properties.Resources.css.AsBitmapImage(), EditStyleAction));
  16. OnAfterSave += (sender, items) =>
  17. {
  18. foreach (var style in items.Cast<WebStyle>()) SaveToLocalFolder(style);
  19. };
  20. OnDoubleClick += (sender, args) =>
  21. {
  22. if (SelectedRows.Length == 1) EditWebStyle(SelectedRows[0]);
  23. args.Handled = true;
  24. };
  25. }
  26. protected override void DoReconfigure(DynamicGridOptions options)
  27. {
  28. base.DoReconfigure(options);
  29. options.AddRows = true;
  30. options.EditRows = true;
  31. options.DeleteRows = true;
  32. }
  33. private bool EditStyleAction(CoreRow arg)
  34. {
  35. if (arg != null) EditWebStyle(arg);
  36. return false;
  37. }
  38. private static void SaveToLocalFolder(WebStyle style)
  39. {
  40. if (CoreUtils.GetVersion() == "???")
  41. File.WriteAllText(
  42. string.Format("{0}/WebBackup/Styles/{1}_{2}.css",
  43. Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
  44. style.Code,
  45. style.ID
  46. ),
  47. style.Style
  48. );
  49. }
  50. private void EditWebStyle(CoreRow arg)
  51. {
  52. var style = LoadItem(arg);
  53. var editor = new ScriptEditor(style.Style, SyntaxLanguage.CSS, $"Style: {style}");
  54. editor.OnSave += (e, args) =>
  55. {
  56. style.Style = editor.Script;
  57. SaveToLocalFolder(style);
  58. SaveItem(style);
  59. };
  60. editor.Show();
  61. }
  62. }
  63. }