Implemented loads of expected functionality for FileSystemEditor - needs a lot of improvement though
This commit is contained in:
parent
ec639a7d20
commit
1772394d28
@ -0,0 +1,62 @@
|
||||
<UniversalEditor Version="5.0">
|
||||
<Editors>
|
||||
<Editor TypeName="UniversalEditor.Editors.FileSystem.FileSystemEditor">
|
||||
<Commands>
|
||||
<Command ID="FileSystemContextMenu_View" />
|
||||
<Command ID="FileSystemContextMenu_Add" />
|
||||
<Command ID="FileSystemContextMenu_New" />
|
||||
|
||||
<Command ID="FileSystemContextMenu_Open" />
|
||||
<Command ID="FileSystemContextMenu_OpenNewTab" />
|
||||
<Command ID="FileSystemContextMenu_OpenNewWindow" />
|
||||
<Command ID="FileSystemContextMenu_SendTo" />
|
||||
|
||||
<Command ID="FileSystemContextMenu_MoveTo" />
|
||||
<Command ID="FileSystemContextMenu_CopyTo" />
|
||||
|
||||
<Command ID="FileSystemContextMenu_CreateShortcut" />
|
||||
<Command ID="FileSystemContextMenu_Rename" />
|
||||
</Commands>
|
||||
<Menus>
|
||||
<Menu ID="UniversalEditor.Editors.FileSystem.FileSystemEditor.ContextMenuUnselected">
|
||||
<Items>
|
||||
<CommandReference CommandID="FileSystemContextMenu_View" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="ViewArrangeIconsBy" />
|
||||
<CommandReference CommandID="ViewRefresh" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="EditPaste" />
|
||||
<CommandReference CommandID="FileSystemContextMenu_PasteShortcut" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileSystemContextMenu_Add" />
|
||||
<CommandReference CommandID="FileSystemContextMenu_New" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileProperties" />
|
||||
</Items>
|
||||
</Menu>
|
||||
<Menu ID="UniversalEditor.Editors.FileSystem.FileSystemEditor.ContextMenuSelected">
|
||||
<Items>
|
||||
<CommandReference CommandID="FileSystemContextMenu_Open" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileSystemContextMenu_OpenNewTab" />
|
||||
<CommandReference CommandID="FileSystemContextMenu_OpenNewWindow" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileSystemContextMenu_SendTo" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="EditCut" />
|
||||
<CommandReference CommandID="EditCopy" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileSystemContextMenu_MoveTo" />
|
||||
<CommandReference CommandID="FileSystemContextMenu_CopyTo" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileSystemContextMenu_CreateShortcut" />
|
||||
<CommandReference CommandID="EditDelete" />
|
||||
<CommandReference CommandID="FileSystemContextMenu_Rename" />
|
||||
<Separator />
|
||||
<CommandReference CommandID="FileProperties" />
|
||||
</Items>
|
||||
</Menu>
|
||||
</Menus>
|
||||
</Editor>
|
||||
</Editors>
|
||||
</UniversalEditor>
|
||||
@ -641,6 +641,7 @@
|
||||
<Content Include="Extensions\FileSystem\Associations\Apogee\DLT.uexml" />
|
||||
<Content Include="Extensions\GraphicDesigner\Associations\Picture\PCX.uexml" />
|
||||
<Content Include="Extensions\GraphicDesigner\Associations\Picture\PSD.uexml" />
|
||||
<Content Include="Editors\UniversalEditor.Editors.FileSystem.FileSystemEditor\Commands.uexml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Configuration\Application.upl" />
|
||||
@ -656,6 +657,7 @@
|
||||
<Folder Include="Extensions\FileSystem\Associations\NewWorldComputing\" />
|
||||
<Folder Include="Extensions\FileSystem\Associations\Apogee\" />
|
||||
<Folder Include="Accessors\" />
|
||||
<Folder Include="Editors\UniversalEditor.Editors.FileSystem.FileSystemEditor\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Extensions\SoftwareDeveloper\Templates\Project\Software Development\Arduino\Images\Blink.xcf" />
|
||||
|
||||
@ -186,5 +186,19 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public IFileSystemObject[] GetContents()
|
||||
{
|
||||
List<IFileSystemObject> fsos = new List<IFileSystemObject>();
|
||||
foreach (Folder folder in Folders)
|
||||
{
|
||||
fsos.Add(folder);
|
||||
}
|
||||
foreach (File file in Files)
|
||||
{
|
||||
fsos.Add(file);
|
||||
}
|
||||
return fsos.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
//
|
||||
// FilePropertiesDialog.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 System.ComponentModel;
|
||||
using MBS.Framework.UserInterface;
|
||||
using MBS.Framework.UserInterface.Controls;
|
||||
using MBS.Framework.UserInterface.Layouts;
|
||||
using UniversalEditor.ObjectModels.FileSystem;
|
||||
|
||||
namespace UniversalEditor.Editors.FileSystem.Dialogs
|
||||
{
|
||||
public class FilePropertiesDialog : Dialog
|
||||
{
|
||||
private TextBox txtFileName = null;
|
||||
private TextBox txtFileType = null;
|
||||
private TextBox txtFileSize = null;
|
||||
private TextBox txtFileDate = null;
|
||||
|
||||
public static DialogResult ShowDialog(IFileSystemObject fso)
|
||||
{
|
||||
FilePropertiesDialog dlg = new FilePropertiesDialog();
|
||||
dlg.Text = String.Format("{0} Properties", fso.Name);
|
||||
dlg.txtFileName.Text = fso.Name;
|
||||
|
||||
if (fso is Folder)
|
||||
{
|
||||
Folder f = fso as Folder;
|
||||
dlg.txtFileType.Text = "Folder";
|
||||
dlg.txtFileSize.Text = String.Format("{0} files, {1} folders", f.Files.Count, f.Folders.Count);
|
||||
}
|
||||
else if (fso is File)
|
||||
{
|
||||
File f = fso as File;
|
||||
dlg.txtFileType.Text = System.IO.Path.GetExtension(f.Name) + " File";
|
||||
dlg.txtFileSize.Text = UniversalEditor.UserInterface.Common.FileInfo.FormatSize(f.Size);
|
||||
}
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fso.Name = dlg.txtFileName.Text;
|
||||
return DialogResult.OK;
|
||||
}
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
|
||||
public FilePropertiesDialog()
|
||||
{
|
||||
Layout = new BoxLayout(Orientation.Vertical);
|
||||
Size = new MBS.Framework.Drawing.Dimension2D(400, 600);
|
||||
|
||||
TabContainer tbs = new TabContainer();
|
||||
|
||||
TabPage tabGeneral = new TabPage();
|
||||
tabGeneral.Text = "General";
|
||||
tabGeneral.Layout = new GridLayout();
|
||||
|
||||
tabGeneral.Controls.Add(new Label("_Name"), new GridLayout.Constraints(0, 0));
|
||||
txtFileName = new TextBox();
|
||||
tabGeneral.Controls.Add(txtFileName, new GridLayout.Constraints(0, 1, 1, 2, ExpandMode.Horizontal));
|
||||
|
||||
tabGeneral.Controls.Add(new Label("_Size"), new GridLayout.Constraints(1, 0));
|
||||
txtFileSize = new TextBox();
|
||||
txtFileSize.Editable = false;
|
||||
tabGeneral.Controls.Add(txtFileSize, new GridLayout.Constraints(1, 1, 1, 2, ExpandMode.Horizontal));
|
||||
|
||||
tabGeneral.Controls.Add(new Label("_Type"), new GridLayout.Constraints(2, 0));
|
||||
txtFileType = new TextBox();
|
||||
txtFileType.Editable = false;
|
||||
tabGeneral.Controls.Add(txtFileType, new GridLayout.Constraints(2, 1, 1, 2, ExpandMode.Horizontal));
|
||||
|
||||
Button cmdChangeType = new Button("C_hange...");
|
||||
tabGeneral.Controls.Add(cmdChangeType, new GridLayout.Constraints(2, 2, 1, 1));
|
||||
|
||||
tabGeneral.Controls.Add(new Label("_Date modified"), new GridLayout.Constraints(3, 0));
|
||||
txtFileDate = new TextBox();
|
||||
tabGeneral.Controls.Add(txtFileDate, new GridLayout.Constraints(3, 1, 1, 2, ExpandMode.Horizontal));
|
||||
|
||||
tbs.TabPages.Add(tabGeneral);
|
||||
|
||||
Controls.Add(tbs, new BoxLayout.Constraints(true, true));
|
||||
|
||||
Buttons.Add(new Button(ButtonStockType.OK, DialogResult.OK));
|
||||
Buttons.Add(new Button(ButtonStockType.Cancel, DialogResult.Cancel));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@
|
||||
using System;
|
||||
using MBS.Framework.UserInterface;
|
||||
using MBS.Framework.UserInterface.Controls;
|
||||
using MBS.Framework.UserInterface.Dialogs;
|
||||
using MBS.Framework.UserInterface.Input.Mouse;
|
||||
using MBS.Framework.UserInterface.Layouts;
|
||||
|
||||
@ -34,8 +35,13 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
private Menu contextMenuUnselected = new Menu();
|
||||
private Menu contextMenuSelected = new Menu();
|
||||
|
||||
private CommandMenuItem contextMenuUnselectedPaste = null;
|
||||
private CommandMenuItem contextMenuUnselectedPasteShortcut = new CommandMenuItem("Paste _shortcut");
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
contextMenuUnselectedPaste = new CommandMenuItem("_Paste", null, contextMenuUnselectedPaste_Click);
|
||||
|
||||
this.Layout = new BoxLayout(Orientation.Vertical);
|
||||
|
||||
this.tmTreeView = new DefaultTreeModel(new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) });
|
||||
@ -45,6 +51,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
this.tv.SelectionMode = SelectionMode.Multiple;
|
||||
this.tv.Model = this.tmTreeView;
|
||||
|
||||
// these need to somehow be loaded from xml
|
||||
contextMenuUnselected.Items.AddRange(new MenuItem[]
|
||||
{
|
||||
new CommandMenuItem("_View", new MenuItem[]
|
||||
@ -67,14 +74,24 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
new CommandMenuItem("_Auto arrange"),
|
||||
new CommandMenuItem("A_lign to grid")
|
||||
}),
|
||||
new CommandMenuItem("_Refresh"),
|
||||
new CommandMenuItem("R_efresh"),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("_Paste"),
|
||||
new CommandMenuItem("Paste _shortcut"),
|
||||
contextMenuUnselectedPaste,
|
||||
contextMenuUnselectedPasteShortcut,
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("A_dd", new MenuItem[]
|
||||
{
|
||||
new CommandMenuItem("Ne_w Item", null, delegate(object sender, EventArgs e) { MessageDialog.ShowDialog("TODO: Implement a way to open a new document editor for an embedded file", "Not Implemented", MessageDialogButtons.OK, MessageDialogIcon.Warning); }),
|
||||
new CommandMenuItem("E_xisting Item...", null, FileAddExistingItem_Click),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("New Fol_der", null, FileNewFolder_Click),
|
||||
new CommandMenuItem("Existin_g Folder...", null, FileAddItemsFromFolder_Click),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("_Files from Folder...", null, FileAddExistingFolder_Click)
|
||||
}),
|
||||
new CommandMenuItem("Ne_w", new MenuItem[]
|
||||
{
|
||||
new CommandMenuItem("_Folder"),
|
||||
new CommandMenuItem("_Folder", null, FileNewFolder_Click),
|
||||
new CommandMenuItem("_Shortcut"),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("Briefcase"),
|
||||
@ -85,7 +102,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
new CommandMenuItem("Compressed (zipped) folder")
|
||||
}),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("P_roperties")
|
||||
new CommandMenuItem("P_roperties", null, ContextMenuProperties_Click)
|
||||
});
|
||||
|
||||
contextMenuSelected.Items.AddRange(new MenuItem[]
|
||||
@ -104,10 +121,10 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
new CommandMenuItem("Copy to...", null, ContextMenuCopyTo_Click),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("Create _shortcut"),
|
||||
new CommandMenuItem("_Delete"),
|
||||
new CommandMenuItem("Rena_me"),
|
||||
new CommandMenuItem("_Delete", null, ContextMenuDelete_Click),
|
||||
new CommandMenuItem("Rena_me", null, ContextMenuRename_Click),
|
||||
new SeparatorMenuItem(),
|
||||
new CommandMenuItem("P_roperties")
|
||||
new CommandMenuItem("P_roperties", null, ContextMenuProperties_Click)
|
||||
});
|
||||
|
||||
this.tv.BeforeContextMenu += tv_BeforeContextMenu;
|
||||
|
||||
@ -28,6 +28,7 @@ using MBS.Framework.UserInterface.Dialogs;
|
||||
using MBS.Framework.UserInterface.DragDrop;
|
||||
using MBS.Framework.UserInterface.Input.Keyboard;
|
||||
using MBS.Framework.UserInterface.Input.Mouse;
|
||||
using UniversalEditor.Editors.FileSystem.Dialogs;
|
||||
|
||||
namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
@ -42,7 +43,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
while (tv.SelectedRows.Count > 0)
|
||||
{
|
||||
if (tv.SelectedRows[0].GetExtraData<IFileSystemObject>("item") == sel.Item)
|
||||
if (tv.SelectedRows[0].GetExtraData<IFileSystemObject>("item") == sel.Items[0])
|
||||
{
|
||||
tmTreeView.Rows.Remove(tv.SelectedRows[0]);
|
||||
break;
|
||||
@ -62,6 +63,20 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
this.tv.DragDropDataRequest += tv_DragDropDataRequest;
|
||||
}
|
||||
|
||||
private void ContextMenuDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
// forward to EditDelete - this will be unnecessary once we implement these menu item definitions as XML
|
||||
if (Application.Commands["EditDelete"] != null)
|
||||
Application.Commands["EditDelete"].Execute();
|
||||
}
|
||||
|
||||
private void contextMenuUnselectedPaste_Click(object sender, EventArgs e)
|
||||
{
|
||||
// forward to EditPaste - this will be unnecessary once we implement these menu item definitions as XML
|
||||
if (Application.Commands["EditPaste"] != null)
|
||||
Application.Commands["EditPaste"].Execute();
|
||||
}
|
||||
|
||||
private void tv_DragDropDataRequest(object sender, DragDropDataRequestEventArgs e)
|
||||
{
|
||||
if (tv.SelectedRows.Count == 0) return;
|
||||
@ -80,10 +95,249 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
e.Data = list.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prompts the user to select an existing file to add to the currently-loaded <see cref="FileSystemObjectModel"/>.
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender.</param>
|
||||
/// <param name="e">E.</param>
|
||||
private void FileAddExistingItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel;
|
||||
if (fsom == null)
|
||||
return;
|
||||
|
||||
FileDialog fd = new FileDialog();
|
||||
fd.Mode = FileDialogMode.Open;
|
||||
fd.MultiSelect = true;
|
||||
if (fd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
foreach (string fileName in fd.SelectedFileNames)
|
||||
{
|
||||
string fileTitle = System.IO.Path.GetFileName(fileName);
|
||||
byte[] data = System.IO.File.ReadAllBytes(fileName);
|
||||
|
||||
UIAddExistingFile(fsom, fileTitle, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Folder UIAddEmptyFolder(IFileSystemContainer fsom, string fileTitle)
|
||||
{
|
||||
Folder f = fsom.Folders.Add(fileTitle);
|
||||
TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmTreeView.Columns[0], f.Name),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[1], String.Format("{0} files, {1} folders", f.Files.Count, f.Folders.Count)),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], "Folder"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], DateTime.Now.ToString())
|
||||
});
|
||||
row.SetExtraData<IFileSystemObject>("item", f);
|
||||
|
||||
tmTreeView.Rows.Add(row);
|
||||
return f;
|
||||
}
|
||||
private File UIAddExistingFile(IFileSystemContainer fsom, string fileTitle, byte[] data)
|
||||
{
|
||||
File f = fsom.AddFile(fileTitle, data);
|
||||
TreeModelRow row = UIGetTreeModelRowForFileSystemObject(f);
|
||||
row.SetExtraData<IFileSystemObject>("item", f);
|
||||
tmTreeView.Rows.Add(row);
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new folder in the current directory of the currently-loaded <see cref="FileSystemObjectModel"/>.
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender.</param>
|
||||
/// <param name="e">E.</param>
|
||||
private void FileNewFolder_Click(object sender, EventArgs e)
|
||||
{
|
||||
FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel;
|
||||
if (fsom == null)
|
||||
return;
|
||||
|
||||
int iNewFolderCt = 0;
|
||||
foreach (Folder ef in fsom.Folders)
|
||||
{
|
||||
if (ef.Name.Equals("New folder") || ef.Name.StartsWith("New folder "))
|
||||
{
|
||||
iNewFolderCt++;
|
||||
}
|
||||
}
|
||||
|
||||
UIAddEmptyFolder(fsom, String.Format("New folder{0}", ((iNewFolderCt > 0) ? " (" + (iNewFolderCt + 1).ToString() + ")" : String.Empty)));
|
||||
}
|
||||
|
||||
private void FileAddItemsFromFolder_Click(object sender, EventArgs e)
|
||||
{
|
||||
FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel;
|
||||
if (fsom == null)
|
||||
return;
|
||||
|
||||
FileDialog fd = new FileDialog();
|
||||
fd.Mode = FileDialogMode.SelectFolder;
|
||||
if (fd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Folder f = FolderFromPath(fd.SelectedFileNames[fd.SelectedFileNames.Count - 1]);
|
||||
RecursiveAddFolder(f);
|
||||
}
|
||||
}
|
||||
private void FileAddExistingFolder_Click(object sender, EventArgs e)
|
||||
{
|
||||
FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel;
|
||||
if (fsom == null)
|
||||
return;
|
||||
|
||||
FileDialog fd = new FileDialog();
|
||||
fd.Mode = FileDialogMode.SelectFolder;
|
||||
if (fd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Folder f = FolderFromPath(fd.SelectedFileNames[fd.SelectedFileNames.Count - 1]);
|
||||
IFileSystemObject[] files = f.GetContents();
|
||||
foreach (IFileSystemObject fso in files)
|
||||
{
|
||||
if (fso is File)
|
||||
{
|
||||
RecursiveAddFile(fso as File);
|
||||
}
|
||||
else if (fso is Folder)
|
||||
{
|
||||
RecursiveAddFolder(fso as Folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override EditorSelection CreateSelectionInternal(object content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
FileSystemObjectModel fsom = (ObjectModel as FileSystemObjectModel);
|
||||
if (fsom == null) return null;
|
||||
|
||||
if (content is string)
|
||||
{
|
||||
string str = (string)content;
|
||||
|
||||
// FIXME: assuming nautilus, for now, PLEASE FIX THIS
|
||||
string[] parts = str.Split(new char[] { '\n' });
|
||||
if (parts[0] == "x-special/nautilus-clipboard")
|
||||
{
|
||||
if (parts[1] == "cut" || parts[1] == "copy")
|
||||
{
|
||||
List<IFileSystemObject> fileList = new List<IFileSystemObject>();
|
||||
for (int ip = 2; ip < parts.Length - 1; ip++)
|
||||
{
|
||||
string url = parts[ip];
|
||||
Uri uri = new Uri(url);
|
||||
|
||||
string filepath = uri.LocalPath;
|
||||
|
||||
IFileSystemObject fso = FileSystemObjectFromPath(filepath);
|
||||
if (fso == null)
|
||||
continue;
|
||||
|
||||
TreeModelRow row = UIGetTreeModelRowForFileSystemObject(fso);
|
||||
tmTreeView.Rows.Add(row);
|
||||
|
||||
fileList.Add(fso);
|
||||
}
|
||||
return new FileSystemSelection(this, fileList.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns a new <see cref="TreeModelRow" /> containing details about the specified <see cref="IFileSystemObject" />.
|
||||
/// </summary>
|
||||
/// <returns>The et tree model row for file system object.</returns>
|
||||
/// <param name="fso">Fso.</param>
|
||||
private TreeModelRow UIGetTreeModelRowForFileSystemObject(IFileSystemObject fso, bool recurse = true)
|
||||
{
|
||||
TreeModelRow r = null;
|
||||
if (fso is Folder)
|
||||
{
|
||||
Folder f = (fso as Folder);
|
||||
r = new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmTreeView.Columns[0], f.Name),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[1], (f.Folders.Count + f.Files.Count).ToString() + " items"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], "Folder"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], "")
|
||||
});
|
||||
|
||||
if (recurse)
|
||||
{
|
||||
foreach (Folder folder in f.Folders)
|
||||
{
|
||||
TreeModelRow r2 = UIGetTreeModelRowForFileSystemObject(folder);
|
||||
r.Rows.Add(r2);
|
||||
}
|
||||
foreach (File file in f.Files)
|
||||
{
|
||||
TreeModelRow r2 = UIGetTreeModelRowForFileSystemObject(file);
|
||||
r.Rows.Add(r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fso is File)
|
||||
{
|
||||
File f = (fso as File);
|
||||
r = new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmTreeView.Columns[0], f.Name),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[1], UserInterface.Common.FileInfo.FormatSize(f.Size)),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], "File"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], DateTime.Now.ToString())
|
||||
});
|
||||
}
|
||||
r.SetExtraData<IFileSystemObject>("item", fso);
|
||||
return r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Folder" /> or a <see cref="File" /> from the specified path to a folder or a file.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="IFileSystemObject" />.</returns>
|
||||
/// <param name="filepath">The path in the actual file system that contains the object to load.</param>
|
||||
private IFileSystemObject FileSystemObjectFromPath(string filepath)
|
||||
{
|
||||
if (System.IO.Directory.Exists(filepath))
|
||||
{
|
||||
return FolderFromPath(filepath);
|
||||
}
|
||||
else if (System.IO.File.Exists(filepath))
|
||||
{
|
||||
return FileFromPath(filepath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private File FileFromPath(string filepath)
|
||||
{
|
||||
File file = new File();
|
||||
file.Name = System.IO.Path.GetFileName(filepath);
|
||||
file.SetData(System.IO.File.ReadAllBytes(filepath));
|
||||
return file;
|
||||
}
|
||||
private Folder FolderFromPath(string filepath)
|
||||
{
|
||||
Folder f = new Folder();
|
||||
f.Name = System.IO.Path.GetFileName(filepath);
|
||||
|
||||
string[] folders = System.IO.Directory.GetDirectories(filepath);
|
||||
foreach (string folder in folders)
|
||||
{
|
||||
f.Folders.Add(FolderFromPath(folder));
|
||||
}
|
||||
string[] files = System.IO.Directory.GetFiles(filepath);
|
||||
foreach (string file in files)
|
||||
{
|
||||
f.Files.Add(FileFromPath(file));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public override void UpdateSelections()
|
||||
{
|
||||
Selections.Clear();
|
||||
@ -109,15 +363,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
|
||||
private void RecursiveAddFolder(Folder f, TreeModelRow parent = null)
|
||||
{
|
||||
TreeModelRow r = new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmTreeView.Columns[0], f.Name),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[1], (f.Folders.Count + f.Files.Count).ToString() + " items"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], "Folder"),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], "")
|
||||
});
|
||||
r.SetExtraData<IFileSystemObject>("item", f);
|
||||
|
||||
TreeModelRow r = UIGetTreeModelRowForFileSystemObject(f, false);
|
||||
foreach (Folder f2 in f.Folders)
|
||||
{
|
||||
RecursiveAddFolder(f2, r);
|
||||
@ -138,13 +384,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
}
|
||||
private void RecursiveAddFile(File f, TreeModelRow parent = null)
|
||||
{
|
||||
TreeModelRow r = new TreeModelRow(new TreeModelRowColumn[]
|
||||
{
|
||||
new TreeModelRowColumn(tmTreeView.Columns[0], f.Name),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[1], UniversalEditor.UserInterface.Common.FileInfo.FormatSize(f.Size)),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[2], ""),
|
||||
new TreeModelRowColumn(tmTreeView.Columns[3], "")
|
||||
});
|
||||
TreeModelRow r = UIGetTreeModelRowForFileSystemObject(f);
|
||||
r.SetExtraData<IFileSystemObject>("item", f);
|
||||
|
||||
if (parent == null)
|
||||
@ -174,7 +414,29 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
}
|
||||
}
|
||||
|
||||
void ContextMenuCopyTo_Click(object sender, EventArgs e)
|
||||
private void ContextMenuProperties_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (tv.SelectedRows.Count == 1 && tv.LastHitTest.Row != null)
|
||||
{
|
||||
TreeModelRow row = tv.SelectedRows[0];
|
||||
IFileSystemObject fso = row.GetExtraData<IFileSystemObject>("item");
|
||||
|
||||
if (FilePropertiesDialog.ShowDialog(fso) == DialogResult.OK)
|
||||
{
|
||||
row.RowColumns[0].Value = fso.Name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prompts the user to choose a filename, and then extracts the selected file in the current <see cref="FileSystemObjectModel" /> to a file on disk with the chosen filename.
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender.</param>
|
||||
/// <param name="e">E.</param>
|
||||
private void ContextMenuCopyTo_Click(object sender, EventArgs e)
|
||||
{
|
||||
// extract files
|
||||
if (tv.SelectedRows.Count == 1)
|
||||
@ -186,8 +448,59 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
FileDialog fd = new FileDialog();
|
||||
fd.Mode = FileDialogMode.SelectFolder;
|
||||
fd.MultiSelect = false;
|
||||
foreach (TreeModelRow row in tv.SelectedRows)
|
||||
|
||||
if (fd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string fileName = fd.SelectedFileNames[0];
|
||||
|
||||
if (!System.IO.Directory.Exists(fileName))
|
||||
System.IO.Directory.CreateDirectory(fileName);
|
||||
|
||||
foreach (TreeModelRow row in tv.SelectedRows)
|
||||
{
|
||||
IFileSystemObject fso = row.GetExtraData<IFileSystemObject>("item");
|
||||
ExtractFileSystemObject(fso, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ContextMenuRename_Click(object sender, EventArgs e)
|
||||
{
|
||||
// gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column, GtkCellRenderer* cell);
|
||||
// tv.SelectedRows[0].RowColumns[0].BeginEdit();
|
||||
}
|
||||
|
||||
private void ExtractFileSystemObject(IFileSystemObject fso, string fileName)
|
||||
{
|
||||
if (String.IsNullOrEmpty(fso.Name))
|
||||
{
|
||||
Console.Error.WriteLine("ERROR! FileSystemEditor::ExtractFileSystemObject - we have to work around some weirdo bug in ZIP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fso is File)
|
||||
{
|
||||
File f = (fso as File);
|
||||
|
||||
string filePath = System.IO.Path.Combine(new string[] { fileName, System.IO.Path.GetFileName(f.Name) });
|
||||
System.IO.File.WriteAllBytes(filePath, f.GetData());
|
||||
}
|
||||
else if (fso is Folder)
|
||||
{
|
||||
Folder f = (fso as Folder);
|
||||
|
||||
string filePath = System.IO.Path.Combine(new string[] { fileName, f.Name });
|
||||
if (!System.IO.Directory.Exists(filePath))
|
||||
System.IO.Directory.CreateDirectory(filePath);
|
||||
|
||||
foreach (File file in f.Files)
|
||||
{
|
||||
ExtractFileSystemObject(file, filePath);
|
||||
}
|
||||
foreach (Folder file in f.Folders)
|
||||
{
|
||||
ExtractFileSystemObject(file, filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,8 +536,7 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
fd.MultiSelect = false;
|
||||
if (fd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(fd.SelectedFileNames[fd.SelectedFileNames.Count - 1]);
|
||||
// TODO: implement this
|
||||
ExtractFileSystemObject(f, fd.SelectedFileNames[fd.SelectedFileNames.Count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,6 +552,9 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
row = info.Row;
|
||||
}
|
||||
|
||||
contextMenuUnselectedPaste.Enabled = Clipboard.Default.ContainsFileList;
|
||||
contextMenuUnselectedPasteShortcut.Enabled = Clipboard.Default.ContainsFileList;
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
tv.ContextMenu = contextMenuSelected;
|
||||
|
||||
@ -25,16 +25,16 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
{
|
||||
internal class FileSystemSelection : EditorSelection
|
||||
{
|
||||
public IFileSystemObject Item { get; set; } = null;
|
||||
public IFileSystemObject[] Items { get; set; } = null;
|
||||
public override object Content
|
||||
{
|
||||
get => Item;
|
||||
get => Items;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
_parent.ClearSelectionContent(this);
|
||||
|
||||
Item = (value is IFileSystemObject ? (value as IFileSystemObject) : null);
|
||||
Items = (value is IFileSystemObject[] ? (value as IFileSystemObject[]) : null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,12 @@ namespace UniversalEditor.Editors.FileSystem
|
||||
internal FileSystemSelection(FileSystemEditor parent, IFileSystemObject item)
|
||||
{
|
||||
_parent = parent;
|
||||
Item = item;
|
||||
Items = new IFileSystemObject[] { item };
|
||||
}
|
||||
internal FileSystemSelection(FileSystemEditor parent, IFileSystemObject[] items)
|
||||
{
|
||||
_parent = parent;
|
||||
Items = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -370,23 +370,31 @@ namespace UniversalEditor.UserInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorReference[] editors = Common.Reflection.GetAvailableEditors(doc.ObjectModel.MakeReference());
|
||||
Console.WriteLine("found {0} editors for object model {1}", editors.Length.ToString(), doc.ObjectModel.ToString());
|
||||
if (editors.Length > 0)
|
||||
|
||||
if (doc.ObjectModel != null)
|
||||
{
|
||||
// no need to open and load file, it's already been done
|
||||
Editor editor = editors[0].Create();
|
||||
EditorPage page = new EditorPage();
|
||||
page.Controls.Add(editor, new BoxLayout.Constraints(true, true));
|
||||
EditorReference[] editors = Common.Reflection.GetAvailableEditors(doc.ObjectModel.MakeReference());
|
||||
Console.WriteLine("found {0} editors for object model {1}", editors.Length.ToString(), doc.ObjectModel.ToString());
|
||||
if (editors.Length > 0)
|
||||
{
|
||||
// no need to open and load file, it's already been done
|
||||
Editor editor = editors[0].Create();
|
||||
EditorPage page = new EditorPage();
|
||||
page.Controls.Add(editor, new BoxLayout.Constraints(true, true));
|
||||
|
||||
InitDocTab(doc.Title, page);
|
||||
InitDocTab(doc.Title, page);
|
||||
|
||||
editor.ObjectModel = doc.ObjectModel;
|
||||
editor.ObjectModel = doc.ObjectModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine("Editor not found for object model " + doc.ObjectModel.MakeReference().Title + " ; using default editor");
|
||||
OpenDefaultEditor(doc.Accessor.GetFileName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine("Editor not found for object model " + doc.ObjectModel.MakeReference().Title + " ; using default editor");
|
||||
Console.Error.WriteLine("ObjectModel not specified for accessor " + doc.Accessor.ToString() + " ; using default editor");
|
||||
OpenDefaultEditor(doc.Accessor.GetFileName());
|
||||
}
|
||||
}
|
||||
@ -416,7 +424,7 @@ namespace UniversalEditor.UserInterface
|
||||
if (System.IO.File.Exists(filename))
|
||||
{
|
||||
System.IO.FileInfo fi = new System.IO.FileInfo(filename);
|
||||
if (fi.Length < Math.Pow(1024, 2))
|
||||
if (fi.Length < Math.Pow(1024, 4))
|
||||
{
|
||||
byte[] content = System.IO.File.ReadAllBytes(filename);
|
||||
om1.Data = content;
|
||||
|
||||
@ -51,6 +51,7 @@ namespace UniversalEditor.UserInterface
|
||||
string path = System.IO.Path.Combine(new string[]
|
||||
{
|
||||
System.IO.Path.GetTempPath(),
|
||||
"universal-editor",
|
||||
pathName
|
||||
});
|
||||
|
||||
@ -106,6 +107,12 @@ namespace UniversalEditor.UserInterface
|
||||
{
|
||||
System.IO.Directory.Delete(mvarTemporaryFilePath, true);
|
||||
}
|
||||
|
||||
string uetmppath = System.IO.Path.Combine(new string[] { System.IO.Path.GetTempPath(), "universal-editor" });
|
||||
if (System.IO.Directory.Exists(uetmppath) && System.IO.Directory.GetFileSystemEntries(uetmppath).Length == 0)
|
||||
{
|
||||
System.IO.Directory.Delete(uetmppath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +121,7 @@
|
||||
<Compile Include="Editors\Binary\BinaryEditor.cs" />
|
||||
<Compile Include="Editors\Binary\FieldDefinitionPropertiesDialog.cs" />
|
||||
<Compile Include="Editors\Binary\FieldDefinition.cs" />
|
||||
<Compile Include="Editors\FileSystem\Dialogs\FilePropertiesDialog.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
@ -172,6 +173,7 @@
|
||||
<Folder Include="Editors\PropertyList\" />
|
||||
<Folder Include="Controls\" />
|
||||
<Folder Include="Editors\Binary\" />
|
||||
<Folder Include="Editors\FileSystem\Dialogs\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user