Preliminary support for selections and editor-dependent cut/copy/paste
This commit is contained in:
parent
823936008a
commit
59476f2718
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor.DataFormats.PropertyList.XML;
|
||||
using UniversalEditor.ObjectModels.PropertyList;
|
||||
@ -15,19 +17,76 @@ namespace UniversalEditor.UserInterface
|
||||
/// </summary>
|
||||
public abstract class Editor : UniversalWidgetToolkit.Container
|
||||
{
|
||||
public EditorSelection.EditorSelectionCollection Selections { get; } = new EditorSelection.EditorSelectionCollection();
|
||||
public abstract void UpdateSelections();
|
||||
public EditorSelection[] GetSelections()
|
||||
{
|
||||
UpdateSelections();
|
||||
|
||||
EditorSelection[] sels = new EditorSelection[Selections.Count];
|
||||
for (int i = 0; i < Selections.Count; i++)
|
||||
{
|
||||
sels[i] = Selections[i];
|
||||
}
|
||||
return sels;
|
||||
}
|
||||
|
||||
protected abstract EditorSelection CreateSelectionInternal(object content);
|
||||
public EditorSelection CreateSelection(object content)
|
||||
{
|
||||
return CreateSelectionInternal(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the selected content to the Universal Editor clipboard.
|
||||
/// Copies the content of all selections to the system clipboard, and then clears the content.
|
||||
/// </summary>
|
||||
public abstract void Copy();
|
||||
public void Cut()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
EditorSelection[] sels = GetSelections();
|
||||
foreach (EditorSelection sel in sels)
|
||||
{
|
||||
if (sel.Content != null)
|
||||
{
|
||||
sb.Append(sel.Content.ToString());
|
||||
}
|
||||
sel.Content = null;
|
||||
}
|
||||
Clipboard.Default.SetText(sb.ToString());
|
||||
}
|
||||
/// <summary>
|
||||
/// Pastes the content from the Universal Editor clipboard, overwriting any selected content.
|
||||
/// Copies the content of all selections to the system clipboard.
|
||||
/// </summary>
|
||||
public abstract void Paste();
|
||||
public void Copy()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
EditorSelection[] sels = GetSelections();
|
||||
foreach (EditorSelection sel in sels)
|
||||
{
|
||||
if (sel.Content != null)
|
||||
{
|
||||
sb.Append(sel.Content.ToString());
|
||||
}
|
||||
}
|
||||
Clipboard.Default.SetText(sb.ToString());
|
||||
}
|
||||
/// <summary>
|
||||
/// Causes the editor to delete the currently-selected item.
|
||||
/// Pastes the content from the system clipboard into a new selection, overwriting any selected content.
|
||||
/// </summary>
|
||||
public abstract void Delete();
|
||||
public void Paste()
|
||||
{
|
||||
Selections.Clear();
|
||||
|
||||
string clipboardText = Clipboard.Default.GetText();
|
||||
Selections.Add(CreateSelection(clipboardText));
|
||||
}
|
||||
public void Delete()
|
||||
{
|
||||
foreach (EditorSelection sel in Selections)
|
||||
{
|
||||
sel.Content = null;
|
||||
}
|
||||
}
|
||||
|
||||
#region IEditorImplementation Members
|
||||
public virtual string Title { get { return String.Empty; } }
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
//
|
||||
// EditorSelection.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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;
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
public abstract class EditorSelection
|
||||
{
|
||||
public class EditorSelectionCollection
|
||||
: System.Collections.ObjectModel.Collection<EditorSelection>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract object Content { get; set; }
|
||||
}
|
||||
}
|
||||
@ -57,17 +57,20 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
e.Data = sb.ToString();
|
||||
}
|
||||
|
||||
public override void Copy()
|
||||
protected override EditorSelection CreateSelectionInternal(object content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override void Paste()
|
||||
public override void UpdateSelections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override void Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Selections.Clear();
|
||||
for (int i = 0; i < tv.SelectedRows.Count; i++)
|
||||
{
|
||||
TreeModelRow row = tv.SelectedRows[i];
|
||||
|
||||
FileSystemSelection sel = new FileSystemSelection(row.GetExtraData<IFileSystemObject>("item"));
|
||||
Selections.Add(sel);
|
||||
}
|
||||
}
|
||||
|
||||
private static EditorReference _er = null;
|
||||
@ -90,6 +93,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], "Folder"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], "")
|
||||
});
|
||||
r.SetExtraData<IFileSystemObject>("item", f);
|
||||
|
||||
foreach (Folder f2 in f.Folders)
|
||||
{
|
||||
@ -118,7 +122,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], ""),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], "")
|
||||
});
|
||||
|
||||
r.SetExtraData<IFileSystemObject>("item", f);
|
||||
|
||||
if (parent == null)
|
||||
{
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
//
|
||||
// FileSystemEditor.cs - cross-platform (UWT) file system editor for Universal Editor
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019
|
||||
//
|
||||
// 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 UniversalEditor.ObjectModels.FileSystem;
|
||||
using UniversalEditor.UserInterface;
|
||||
|
||||
namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
internal class FileSystemSelection : EditorSelection
|
||||
{
|
||||
public IFileSystemObject Item { get; set; } = null;
|
||||
public override object Content { get => Item; set => Item = (value is IFileSystemObject ? (value as IFileSystemObject) : null); }
|
||||
|
||||
public FileSystemSelection(IFileSystemObject item)
|
||||
{
|
||||
Item = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,16 +41,13 @@ namespace UniversalEditor.Editors.PropertyList
|
||||
return _er;
|
||||
}
|
||||
|
||||
public override void Copy()
|
||||
protected override EditorSelection CreateSelectionInternal(object content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Paste()
|
||||
public override void UpdateSelections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void OnObjectModelChanged(EventArgs e)
|
||||
|
||||
@ -29,25 +29,29 @@ using UniversalWidgetToolkit.Layouts;
|
||||
|
||||
namespace UniversalEditor.Editors.Text.Plain
|
||||
{
|
||||
public class PlainTextEditor : Editor
|
||||
public class PlainTextEditor : TextEditor
|
||||
{
|
||||
public override void Copy()
|
||||
protected override EditorSelection CreateSelectionInternal(object content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (content is string)
|
||||
{
|
||||
txt.SelectedText = (string)content;
|
||||
return new TextEditorSelection(this, (string)content);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Delete()
|
||||
public override void UpdateSelections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Selections.Clear();
|
||||
Selections.Add(new TextEditorSelection(this, txt.SelectedText, txt.SelectionStart, txt.SelectionLength));
|
||||
}
|
||||
|
||||
public override void Paste()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private TextBox txt = null;
|
||||
|
||||
internal override void ClearSelectedText()
|
||||
{
|
||||
txt.SelectedText = null;
|
||||
}
|
||||
|
||||
private static EditorReference _er = null;
|
||||
public override EditorReference MakeReference ()
|
||||
{
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
//
|
||||
// TextEditor.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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.UserInterface;
|
||||
|
||||
namespace UniversalEditor.Editors.Text
|
||||
{
|
||||
public abstract class TextEditor : Editor
|
||||
{
|
||||
internal abstract void ClearSelectedText();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
//
|
||||
// TextEditorSelection.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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.UserInterface;
|
||||
|
||||
namespace UniversalEditor.Editors.Text
|
||||
{
|
||||
public class TextEditorSelection : EditorSelection
|
||||
{
|
||||
public int Start { get; set; } = -1;
|
||||
public int Length { get; set; } = -1;
|
||||
|
||||
private string mvarContent = null;
|
||||
public override object Content
|
||||
{
|
||||
get => mvarContent;
|
||||
set
|
||||
{
|
||||
mvarContent = (value is string ? (string)value : null);
|
||||
if (mvarContent == null)
|
||||
{
|
||||
Length = 0;
|
||||
_parent.ClearSelectedText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TextEditor _parent = null;
|
||||
internal TextEditorSelection(TextEditor parent, string text)
|
||||
{
|
||||
_parent = parent;
|
||||
mvarContent = text;
|
||||
}
|
||||
internal TextEditorSelection(TextEditor parent, string text, int start, int length)
|
||||
{
|
||||
_parent = parent;
|
||||
mvarContent = text;
|
||||
Start = start;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,11 +281,9 @@ namespace UniversalEditor.UserInterface
|
||||
#region Edit
|
||||
Application.AttachCommandEventHandler("EditCut", delegate(object sender, EventArgs e)
|
||||
{
|
||||
Command cmdCopy = Application.Commands["EditCopy"];
|
||||
Command cmdDelete = Application.Commands["EditDelete"];
|
||||
|
||||
cmdCopy.Execute ();
|
||||
cmdDelete.Execute ();
|
||||
Editor editor = LastWindow.GetCurrentEditor();
|
||||
if (editor == null) return;
|
||||
editor.Cut();
|
||||
});
|
||||
Application.AttachCommandEventHandler("EditCopy", delegate(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@ -114,6 +114,10 @@
|
||||
<Compile Include="Controls\UniversalEditorFileBrowserControl.cs" />
|
||||
<Compile Include="Controls\GenericBrowserButton.cs" />
|
||||
<Compile Include="Dialogs\AboutDialog.cs" />
|
||||
<Compile Include="EditorSelection.cs" />
|
||||
<Compile Include="Editors\Text\TextEditorSelection.cs" />
|
||||
<Compile Include="Editors\FileSystem\FileSystemSelection.cs" />
|
||||
<Compile Include="Editors\Text\TextEditor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user