Merge branch 'pre-commit'
This commit is contained in:
commit
889a5d97fb
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<!-- Generated with glade 3.38.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkTreeStore" id="tm">
|
||||
@ -17,19 +17,16 @@
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
</child>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="txtPath">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -40,14 +37,15 @@
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="tv">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="model">tm</property>
|
||||
<property name="search_column">0</property>
|
||||
<property name="search-column">0</property>
|
||||
<property name="rubber-banding">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection">
|
||||
<property name="mode">multiple</property>
|
||||
@ -66,7 +64,9 @@
|
||||
</attributes>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="editable">True</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
|
||||
@ -118,6 +118,29 @@ namespace UniversalEditor
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see langword="true" /> if <paramref name="value" /> is equal
|
||||
/// to any one of the values in <paramref name="anyOf" />.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if a match was found; <c>false</c> otherwise.</returns>
|
||||
/// <param name="value">The value to test.</param>
|
||||
/// <param name="anyOf">
|
||||
/// An array of items of type <typeparamref name="T" /> to check equality
|
||||
/// against <paramref name="value" />.
|
||||
/// </param>
|
||||
public static bool EqualsAny<T>(this IEquatable<T> 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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<string>(FileSystemEditorSettingsGuids.InvalidPathChars);
|
||||
return invalidPathChars;
|
||||
}
|
||||
private string GetInvalidFileNamesStr(FileSystemObjectModel fsom)
|
||||
{
|
||||
string invalidFileNamesStr = ((UIApplication)Application.Instance).GetSetting<string>(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<IFileSystemObject>("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)
|
||||
{
|
||||
|
||||
@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,17 @@
|
||||
<Part>Search and Preview</Part>
|
||||
</Path>
|
||||
</SettingsGroup>
|
||||
<SettingsGroup ID="{e8c41127-956e-49a4-a409-deb62590d4be}">
|
||||
<Path>
|
||||
<Part>Editors</Part>
|
||||
<Part>File System</Part>
|
||||
<Part>Compatibility</Part>
|
||||
</Path>
|
||||
<Settings>
|
||||
<TextSetting ID="{2fd5348a-2a74-4cdf-9f07-43011b109bde}" Name="InvalidPathChars" Title="Invalid filename characters" Value="/<>:"\\|?*" />
|
||||
<TextSetting ID="{bfc2323b-a628-419c-827b-fed169ce176e}" Name="InvalidFileNames" Title="Invalid filenames" Value="CON,PRN,AUX,NUL,COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8,COM9,LPT1,LPT2,LPT3,LPT4,LPT5,LPT6,LPT7,LPT8,LPT9" />
|
||||
</Settings>
|
||||
</SettingsGroup>
|
||||
</SettingsProvider>
|
||||
</SettingsProviders>
|
||||
</ApplicationFramework>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user