1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.IO;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
- namespace PRSServer.Forms.WebStyles
- {
- public class WebStyleGrid : DynamicDataGrid<WebStyle>
- {
- public WebStyleGrid()
- {
- ActionColumns.Add(new DynamicImageColumn(Properties.Resources.css.AsBitmapImage(), EditStyleAction));
- OnAfterSave += (sender, items) =>
- {
- foreach (var style in items.Cast<WebStyle>()) SaveToLocalFolder(style);
- };
- OnDoubleClick += (sender, args) =>
- {
- if (SelectedRows.Length == 1) EditWebStyle(SelectedRows[0]);
- args.Handled = true;
- };
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.AddRows = true;
- options.EditRows = true;
- options.DeleteRows = 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();
- }
- }
- }
|