preliminary implementation of strongly-typed Selection and deletion in FileSystemEditor
This commit is contained in:
parent
91a68472c5
commit
2a64f97317
@ -19,6 +19,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniversalEditor
|
||||
{
|
||||
public abstract class Selection
|
||||
@ -41,4 +43,49 @@ namespace UniversalEditor
|
||||
Content = null;
|
||||
}
|
||||
}
|
||||
public abstract class Selection<TObjectModel, TSelection> : Selection where TObjectModel : ObjectModel
|
||||
{
|
||||
public override object Content
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SelectedItems.Count == 0)
|
||||
return null;
|
||||
if (SelectedItems.Count == 1)
|
||||
return SelectedItems[0];
|
||||
return SelectedItems.ToArray();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
SelectedItems.Clear();
|
||||
}
|
||||
else if (value is TSelection)
|
||||
{
|
||||
SelectedItems.Clear();
|
||||
SelectedItems.Add((TSelection)value);
|
||||
}
|
||||
else if (value is TSelection[])
|
||||
{
|
||||
SelectedItems = new List<TSelection>((TSelection[])value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TObjectModel ObjectModel { get; private set; } = default(TObjectModel);
|
||||
public TSelection SelectedItem { get { return SelectedItems[0]; } set { SelectedItems.Clear(); SelectedItems.Add(value); } }
|
||||
public List<TSelection> SelectedItems { get; private set; } = new List<TSelection>();
|
||||
|
||||
protected Selection(TObjectModel objectModel, TSelection selectedItem)
|
||||
{
|
||||
ObjectModel = objectModel;
|
||||
SelectedItem = selectedItem;
|
||||
}
|
||||
protected Selection(TObjectModel objectModel, TSelection[] selectedItems)
|
||||
{
|
||||
ObjectModel = objectModel;
|
||||
SelectedItems = new List<TSelection>(selectedItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -587,5 +587,17 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(IFileSystemObject fso)
|
||||
{
|
||||
if (fso is File)
|
||||
{
|
||||
fso.Parent.Files.Remove(fso as File);
|
||||
}
|
||||
else if (fso is Folder)
|
||||
{
|
||||
fso.Parent.Folders.Remove(fso as Folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,6 +264,8 @@ namespace UniversalEditor.UserInterface
|
||||
sel.Delete();
|
||||
}
|
||||
EndEdit();
|
||||
|
||||
OnObjectModelChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -181,7 +181,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
IFileSystemObject[] sels = GetSelectedItems();
|
||||
if (sels.Length > 0)
|
||||
{
|
||||
Selections.Add(new FileSystemSelection(this, GetSelectedItems()));
|
||||
Selections.Add(new FileSystemSelection(ObjectModel as FileSystemObjectModel, GetSelectedItems()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
while (tv.SelectedRows.Count > 0)
|
||||
{
|
||||
if (tv.SelectedRows[0].GetExtraData<IFileSystemObject>("item") == sel.Items[0])
|
||||
if (tv.SelectedRows[0].GetExtraData<IFileSystemObject>("item") == sel.SelectedItem)
|
||||
{
|
||||
tm.Rows.Remove(tv.SelectedRows[0]);
|
||||
break;
|
||||
@ -623,18 +623,18 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
|
||||
fileList.Add(fso);
|
||||
}
|
||||
return new FileSystemSelection(this, fileList.ToArray());
|
||||
return new FileSystemSelection(ObjectModel as FileSystemObjectModel, fileList.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (content is IFileSystemObject)
|
||||
{
|
||||
return new FileSystemSelection(this, content as IFileSystemObject);
|
||||
return new FileSystemSelection(ObjectModel as FileSystemObjectModel, content as IFileSystemObject);
|
||||
}
|
||||
else if (content is IFileSystemObject[])
|
||||
{
|
||||
IFileSystemObject[] items = (IFileSystemObject[])content;
|
||||
return new FileSystemSelection(this, items);
|
||||
return new FileSystemSelection(ObjectModel as FileSystemObjectModel, items);
|
||||
/*
|
||||
tv.SelectedRows.Clear();
|
||||
for (int i = 0; i < tv.Model.Rows.Count; i++)
|
||||
@ -767,7 +767,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
for (int i = 0; i < e.NewItems.Count; i++)
|
||||
{
|
||||
FileSystemSelection sel = (e.NewItems[i] as FileSystemSelection);
|
||||
IFileSystemObject[] objs = (sel.Content as IFileSystemObject[]);
|
||||
IFileSystemObject[] objs = sel.SelectedItems.ToArray();
|
||||
|
||||
for (int j = 0; j < tv.Model.Rows.Count; j++)
|
||||
{
|
||||
@ -796,7 +796,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
TreeModelRow row = tv.SelectedRows[i];
|
||||
if (row == null) continue;
|
||||
|
||||
Selections.Add(new FileSystemSelection(this, row.GetExtraData<IFileSystemObject>("item")));
|
||||
Selections.Add(new FileSystemSelection(ObjectModel as FileSystemObjectModel, row.GetExtraData<IFileSystemObject>("item")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,29 +23,21 @@ using UniversalEditor.UserInterface;
|
||||
|
||||
namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
internal class FileSystemSelection : Selection
|
||||
internal class FileSystemSelection : Selection<FileSystemObjectModel, IFileSystemObject>
|
||||
{
|
||||
public IFileSystemObject[] Items { get; set; } = null;
|
||||
public override object Content
|
||||
protected override void DeleteInternal()
|
||||
{
|
||||
get => Items;
|
||||
set
|
||||
foreach (IFileSystemObject fso in SelectedItems)
|
||||
{
|
||||
Items = (value is IFileSystemObject[] ? (value as IFileSystemObject[]) : null);
|
||||
ObjectModel.Delete(fso);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeleteInternal()
|
||||
internal FileSystemSelection(FileSystemObjectModel objectModel, IFileSystemObject item) : base(objectModel, item)
|
||||
{
|
||||
}
|
||||
|
||||
internal FileSystemSelection(FileSystemEditor parent, IFileSystemObject item)
|
||||
internal FileSystemSelection(FileSystemObjectModel objectModel, IFileSystemObject[] item) : base(objectModel, item)
|
||||
{
|
||||
Items = new IFileSystemObject[] { item };
|
||||
}
|
||||
internal FileSystemSelection(FileSystemEditor parent, IFileSystemObject[] items)
|
||||
{
|
||||
Items = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,11 +51,23 @@ namespace UniversalEditor.Editors.PropertyList
|
||||
|
||||
protected override Selection CreateSelectionInternal(object content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return null;
|
||||
}
|
||||
public override void UpdateSelections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (TreeModelRow row in tv.SelectedRows)
|
||||
{
|
||||
Group group = row.GetExtraData<Group>("group");
|
||||
Property property = row.GetExtraData<Property>("property");
|
||||
if (group != null)
|
||||
{
|
||||
Selections.Add(new PropertyListSelection(ObjectModel as PropertyListObjectModel, group));
|
||||
}
|
||||
else if (property != null)
|
||||
{
|
||||
Selections.Add(new PropertyListSelection(ObjectModel as PropertyListObjectModel, property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnCreated(EventArgs e)
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
//
|
||||
// PropertyListSelection.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using UniversalEditor.ObjectModels.PropertyList;
|
||||
|
||||
namespace UniversalEditor.Editors.PropertyList
|
||||
{
|
||||
public class PropertyListSelection : Selection<PropertyListObjectModel, PropertyListItem>
|
||||
{
|
||||
public PropertyListSelection(PropertyListObjectModel objectModel, PropertyListItem item) : base(objectModel, item)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DeleteInternal()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,6 +137,7 @@
|
||||
<Compile Include="EditorPropertiesPanel.cs" />
|
||||
<Compile Include="Editors\FileSystem\FileSystemEditorSettingsGuids.cs" />
|
||||
<Compile Include="MultipleDocumentErrorHandling.cs" />
|
||||
<Compile Include="Editors\PropertyList\PropertyListSelection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user