12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.IO;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
- namespace PRSServer.Forms.WebStyles
- {
- public class WebStyleGrid : DynamicDataGrid<WebStyle>
- {
- public WebStyleGrid()
- {
- Options.AddRange(DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows);
- ActionColumns.Add(new DynamicActionColumn(Properties.Resources.css.AsBitmapImage(), EditStyleAction));
- OnAfterSave += (sender, items) =>
- {
- foreach (var style in items) SaveToLocalFolder(style);
- };
- OnDoubleClick += (sender, args) =>
- {
- if (SelectedRows.Length == 1) EditWebStyle(SelectedRows[0]);
- args.Handled = true;
- };
- }
- private bool EditStyleAction(CoreRow arg)
- {
- if (arg != null) EditWebStyle(arg);
- return false;
- }
- private static void SaveToLocalFolder(WebStyle style)
- {
- if (CoreUtils.GetVersion() == "???")
- File.WriteAllText(
- string.Format("{0}/WebBackup/Styles/{1}_{2}.css",
- Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
- style.Code,
- style.ID
- ),
- style.Style
- );
- }
- private void EditWebStyle(CoreRow arg)
- {
- var style = LoadItem(arg);
- var editor = new ScriptEditor(style.Style, SyntaxLanguage.CSS, $"Style: {style}");
- editor.OnSave += (e, args) =>
- {
- style.Style = editor.Script;
- SaveToLocalFolder(style);
- SaveItem(style);
- };
- editor.Show();
- }
- }
- }
|