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.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; 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(); diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index e9aa7fed..aee0b7ad 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) { @@ -104,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) { 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 + + + + + +