From f954ea3f6acd11991a6ba1660d8cd2e150010bba Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 26 May 2021 14:58:05 -0400 Subject: [PATCH 1/4] ensure < and > get escaped properly in XML --- .../DataFormats/Markup/XML/XMLDataFormat.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs index 6c23eacb..b1b1d76c 100644 --- a/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs +++ b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs @@ -44,6 +44,8 @@ namespace UniversalEditor.DataFormats.Markup.XML Settings.Entities.Add("quot", "\""); Settings.Entities.Add("copy", "©"); Settings.Entities.Add("apos", "'"); + Settings.Entities.Add("lt", "<"); + Settings.Entities.Add("gt", ">"); } private XMLDataFormatSettings mvarSettings = new XMLDataFormatSettings(); From 7b1fc4439058a3e8c6d79042d2a42b3022adb885 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 26 May 2021 14:58:55 -0400 Subject: [PATCH 2/4] implement EqualsAny method to check equality with any one of the values in an array --- .../UniversalEditor.Core/ExtensionMethods.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Libraries/UniversalEditor.Core/ExtensionMethods.cs b/Libraries/UniversalEditor.Core/ExtensionMethods.cs index 98e9bd9d..cc21bb48 100644 --- a/Libraries/UniversalEditor.Core/ExtensionMethods.cs +++ b/Libraries/UniversalEditor.Core/ExtensionMethods.cs @@ -118,6 +118,29 @@ namespace UniversalEditor return true; } + /// + /// Returns if is equal + /// to any one of the values in . + /// + /// true, if a match was found; false otherwise. + /// The value to test. + /// + /// An array of items of type to check equality + /// against . + /// + public static bool EqualsAny(this IEquatable value, params T[] anyOf) + { + for (int i = 0; i < anyOf.Length; i++) + { + T any = anyOf[i]; + if (value.Equals(any)) + { + return true; + } + } + return false; + } + public static bool ContainsAny(this string value, params string[] anyOf) { bool result; From c644bb21af063a4d14b2d0537cd4f521c9624d3a Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 26 May 2021 15:00:41 -0400 Subject: [PATCH 3/4] implement FileSystemEditor checking valid filenames with invalid filenames and characters settings --- .../Editors/FileSystem/FileSystemEditor.cs | 32 +++++++++++++++++++ .../FileSystemEditorSettingsGuids.cs | 2 ++ .../FileSystemEditorSettingsProvider.xml | 11 +++++++ 3 files changed, 45 insertions(+) diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index e9aa7fed..5ed1f434 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs @@ -51,6 +51,38 @@ namespace UniversalEditor.Editors.FileSystem private const int DELIVERED_COLUMNS_COUNT = 5; + private string GetInvalidFileNameChars(FileSystemObjectModel fsom) + { + string invalidPathChars = ((UIApplication)Application.Instance).GetSetting(FileSystemEditorSettingsGuids.InvalidPathChars); + return invalidPathChars; + } + private string GetInvalidFileNamesStr(FileSystemObjectModel fsom) + { + string invalidFileNamesStr = ((UIApplication)Application.Instance).GetSetting(FileSystemEditorSettingsGuids.InvalidFileNames); + return invalidFileNamesStr; + } + private string[] GetInvalidFileNames(FileSystemObjectModel fsom) + { + string invalidFileNamesStr = GetInvalidFileNamesStr(fsom); + if (String.IsNullOrEmpty(invalidFileNamesStr)) + return new string[0]; + + string[] invalidFileNames = invalidFileNamesStr.Split(new char[] { ',' }); + return invalidFileNames; + } + private bool CheckValidFileName(FileSystemObjectModel fsom, string filename) + { + string invalidPathChars = GetInvalidFileNameChars(fsom); + string[] invalidFileNames = GetInvalidFileNames(fsom); + + // string[] filePath = filename.Split(fsom.PathSeparators); + string fileTitle = filename; // filePath[filePath.Length - 1]; + + bool containsInvalidFileNames = invalidFileNames.Length > 0 && fileTitle.EqualsAny(invalidFileNames); + bool containsInvalidChars = String.IsNullOrEmpty(invalidPathChars) || fileTitle.ContainsAny(invalidPathChars.ToCharArray()); + return !(containsInvalidFileNames || containsInvalidChars); + } + [EventHandler(nameof(txtPath), "KeyDown")] private void txtPath_KeyDown(object sender, KeyEventArgs e) { diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsGuids.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsGuids.cs index 43080018..8b0bb46d 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsGuids.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsGuids.cs @@ -24,5 +24,7 @@ namespace UniversalEditor.Editors.FileSystem public class FileSystemEditorSettingsGuids { public static Guid SingleClickToOpenItems { get; } = new Guid("{409C4308-BA99-489F-BD33-4122E430709D}"); + public static Guid InvalidPathChars { get; } = new Guid("{2fd5348a-2a74-4cdf-9f07-43011b109bde}"); + public static Guid InvalidFileNames { get; } = new Guid("{bfc2323b-a628-419c-827b-fed169ce176e}"); } } diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsProvider.xml b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsProvider.xml index 70a97fc9..262c9743 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsProvider.xml +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditorSettingsProvider.xml @@ -47,6 +47,17 @@ Search and Preview + + + Editors + File System + Compatibility + + + + + + From 3cbabda4347df0a8cec8a9caddb9dc9ea0de1fd8 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 26 May 2021 15:07:39 -0400 Subject: [PATCH 4/4] support renaming files via CellEdited (requires UWT @ bb6be74) --- .../Editors/FileSystem/FileSystemEditor.glade | 24 ++++++++--------- .../Editors/FileSystem/FileSystemEditor.cs | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/FileSystem/FileSystemEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/FileSystem/FileSystemEditor.glade index a9518a3f..52644660 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/FileSystem/FileSystemEditor.glade +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/FileSystem/FileSystemEditor.glade @@ -1,5 +1,5 @@ - + @@ -17,19 +17,16 @@ - False - - - + False True - False + False vertical True - True + True False @@ -40,14 +37,15 @@ True - True - in + True + in True - True + True tm - 0 + 0 + True multiple @@ -66,7 +64,9 @@ - + + True + 0 diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index 5ed1f434..aee0b7ad 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs @@ -136,6 +136,33 @@ namespace UniversalEditor.Editors.FileSystem ctxTreeView = MakeReference().Contexts[new Guid("{ce094932-77fb-418f-bd98-e3734a670fad}")]; } + [EventHandler(nameof(tv), nameof(ListViewControl.CellEditing))] + private void tv_CellEditing(object sender, CellEditingEventArgs e) + { + FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel; + if (!CheckValidFileName(fsom, e.NewValue?.ToString())) + { + MessageDialog.ShowDialog(String.Format("Invalid file name '{0}' - File names on this file system may not contain the following characters: \r\n\t {1}\r\n\r\nOr be the following file names: \r\n\t{2}", e.NewValue, GetInvalidFileNameChars(fsom), GetInvalidFileNamesStr(fsom)), "Error", MessageDialogButtons.OK, MessageDialogIcon.Error); + e.Cancel = true; + } + } + + [EventHandler(nameof(tv), nameof(ListViewControl.CellEdited))] + private void tv_CellEdited(object sender, CellEditedEventArgs e) + { + IFileSystemObject item = e.Row.GetExtraData("item"); + if (item != null) + { + bool changed = item.Name != e.NewValue.ToString(); + if (changed) + { + BeginEdit(); + item.Name = e.NewValue.ToString(); + EndEdit(); + } + } + } + [EventHandler(nameof(tv), nameof(ListViewControl.GotFocus))] private void tv_GotFocus(object sender, EventArgs e) {