FileItem now have an "Open With" menu.
TabHost can select next button to closed tab.
This commit is contained in:
@@ -5,13 +5,17 @@ using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using Progrart.Core;
|
||||
using Progrart.Core.ProjectSystem;
|
||||
using Progrart.Core.Settings;
|
||||
using Progrart.Icons;
|
||||
using Progrart.Pages;
|
||||
using Progrart.Views;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart;
|
||||
|
||||
@@ -30,14 +34,27 @@ public partial class App : Application
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public async Task LoadProject(IStorageFile item)
|
||||
{
|
||||
|
||||
using var stream = await (item).OpenReadAsync();
|
||||
using var reader = new StreamReader(stream);
|
||||
var txt = await reader.ReadToEndAsync();
|
||||
App.LoadedProject = JsonConvert.DeserializeObject<Project>(txt);
|
||||
}
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
IconProvider.Register(new DefaultIconProvider());
|
||||
EditorProvider.Register("text", "Default Text Editor", typeof(EditorPage));
|
||||
EditorProvider.Register("image", "Default Image Viewer", typeof(ImageViewPage));
|
||||
EditorProvider.Register("progrart", "Default Progrart Editor", typeof(ProgrartEditorPage));
|
||||
EditorProvider.Register("project", "Progrart Project Editor", typeof(ProjectEditor));
|
||||
EditorProvider.Register("console", "Console", typeof(Pages.Console));
|
||||
EditorProvider.Register("text", new EditorFileHandler<EditorPage>("Default Text Editor"));
|
||||
EditorProvider.Register("image", new EditorFileHandler<ImageViewPage>("Default Image Viewer"));
|
||||
EditorProvider.Register("progrart", new EditorFileHandler<ProgrartEditorPage>("Default Progrart Editor"));
|
||||
EditorProvider.Register("as_project", new FileHandler("Load Project",async (item) =>
|
||||
{
|
||||
await LoadProject(item);
|
||||
ProjectLoadHandler?.Invoke();
|
||||
}));
|
||||
EditorProvider.Register("project_editor", new EditorFileHandler<ProjectEditor>("Progrart Project Editor"));
|
||||
EditorProvider.Register("console", new EditorFileHandler<Pages.Console>("Console"));
|
||||
EditorProvider.BindFileType("cs", "text");
|
||||
EditorProvider.BindFileType("c", "text");
|
||||
EditorProvider.BindFileType("cpp", "text");
|
||||
@@ -49,11 +66,14 @@ public partial class App : Application
|
||||
EditorProvider.BindFileType("json", "text");
|
||||
EditorProvider.BindFileType("sh", "text");
|
||||
EditorProvider.BindFileType("progrart", "progrart");
|
||||
EditorProvider.BindFileType("progrart", "text");
|
||||
EditorProvider.BindFileType("bashrc", "text");
|
||||
EditorProvider.BindFileType("png", "image");
|
||||
EditorProvider.BindFileType("bmp", "image");
|
||||
EditorProvider.BindFileType("jpg", "image");
|
||||
EditorProvider.BindFileType("progrart-project", "project");
|
||||
EditorProvider.BindFileType("progrart-project", "as_project");
|
||||
EditorProvider.BindFileType("progrart-project", "project_editor");
|
||||
EditorProvider.BindFileType("progrart-project", "text");
|
||||
EditorProvider.BindFileType("wd", "console");
|
||||
if (!OperatingSystem.IsBrowser())
|
||||
{
|
||||
|
||||
@@ -10,11 +10,37 @@
|
||||
FontFamily="{StaticResource SarasaMonoSlabCLFont}">
|
||||
<avaloniaedit:TextEditor.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="_Copy" Click="Copy_Click"/>
|
||||
<MenuItem Header="Cut (_X)" Click="Cut_Click"/>
|
||||
<MenuItem Header="Paste (_V)" Click="Paste_Click"/>
|
||||
<MenuItem Header="Cop_y" Click="Copy_Click">
|
||||
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 8 3.799999 C 7.44 3.799999 6.966666 3.993334 6.58 4.379999 C 6.193333 4.766666 6 5.24 6 5.799999 L 6 15.799999 C 6 16.360001 6.193333 16.833332 6.58 17.219999 C 6.966666 17.606667 7.44 17.799999 8 17.799999 L 14 17.799999 C 14.559999 17.799999 15.033333 17.606667 15.42 17.219999 C 15.806666 16.833332 16 16.360001 16 15.799999 L 16 5.799999 C 16 5.24 15.806666 4.766666 15.42 4.379999 C 15.033333 3.993334 14.559999 3.799999 14 3.799999 Z M 7 5.799999 C 7 5.533333 7.1 5.299999 7.3 5.1 C 7.5 4.9 7.733333 4.799999 8 4.799999 L 14 4.799999 C 14.266666 4.799999 14.5 4.9 14.7 5.1 C 14.9 5.299999 14.999999 5.533333 15 5.799999 L 15 15.799999 C 14.999999 16.066666 14.9 16.299999 14.7 16.5 C 14.5 16.700001 14.266666 16.799999 14 16.799999 L 8 16.799999 C 7.733333 16.799999 7.5 16.700001 7.3 16.5 C 7.1 16.299999 7 16.066666 7 15.799999 Z M 4 7.799999 C 4 7.453333 4.086667 7.12 4.26 6.799999 C 4.433333 6.48 4.68 6.240001 5 6.08 L 5 16.279999 C 5 16.973333 5.246666 17.566666 5.74 18.059999 C 6.233333 18.553333 6.813333 18.799999 7.48 18.799999 L 13.719999 18.799999 C 13.559999 19.119999 13.32 19.366667 13 19.539999 C 12.679998 19.713333 12.346665 19.799999 12 19.799999 L 7.52 19.799999 C 6.533333 19.799999 5.7 19.459999 5.02 18.779999 C 4.34 18.099998 4 17.266666 4 16.279999 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Cu_t" Click="Cut_Click">
|
||||
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 14.88 4.959999 L 11.8 9.719999 L 10.88 8.36 L 13.639999 4.16 C 13.746666 3.973333 13.899999 3.860001 14.099999 3.82 C 14.299999 3.780001 14.486666 3.813334 14.66 3.92 C 14.833332 4.026667 14.939999 4.18 14.98 4.379999 C 15.019999 4.58 14.986666 4.773335 14.88 4.959999 Z M 12.48 13.559999 C 13.253332 13.24 14.026666 13.213333 14.799999 13.48 C 15.573333 13.746667 16.166666 14.24 16.58 14.959999 C 16.993332 15.679999 17.113333 16.439999 16.940001 17.24 C 16.766666 18.039999 16.346666 18.686666 15.679999 19.18 C 15.013332 19.673332 14.266666 19.879999 13.44 19.799999 C 12.613333 19.719999 11.919999 19.373333 11.36 18.759998 C 10.799999 18.146666 10.513332 17.426666 10.5 16.599998 C 10.486666 15.773333 10.746666 15.053333 11.28 14.44 L 10 12.48 L 8.72 14.44 C 9.253332 15.053333 9.513332 15.773333 9.5 16.599998 C 9.486666 17.426666 9.199999 18.146666 8.639999 18.759998 C 8.079999 19.373333 7.386666 19.719999 6.56 19.799999 C 5.733333 19.879999 4.986666 19.673332 4.32 19.18 C 3.653333 18.686666 3.233333 18.039999 3.06 17.24 C 2.886667 16.439999 3.006667 15.679999 3.42 14.959999 C 3.833333 14.24 4.426666 13.746667 5.2 13.48 C 5.973332 13.213333 6.746666 13.24 7.52 13.559999 L 9.12 11.08 L 5.12 4.959999 C 5.013333 4.773335 4.98 4.58 5.02 4.379999 C 5.059999 4.18 5.166666 4.026667 5.34 3.92 C 5.513333 3.813334 5.7 3.780001 5.9 3.82 C 6.099999 3.860001 6.266666 3.959999 6.4 4.119999 Z M 12.679999 15.16 C 12.306665 15.453333 12.086666 15.84 12.02 16.32 C 11.953333 16.799999 12.059999 17.233334 12.34 17.619999 C 12.619999 18.006666 12.999998 18.233334 13.48 18.299999 C 13.959999 18.366667 14.393333 18.253332 14.78 17.959999 C 15.166666 17.666666 15.393332 17.286667 15.46 16.82 C 15.526666 16.353333 15.419998 15.926666 15.139999 15.539999 C 14.859999 15.153334 14.48 14.92 14 14.839999 C 13.52 14.759999 13.093332 14.866666 12.719999 15.16 Z M 6.24 14.799999 C 5.76 14.799999 5.346666 14.973332 5 15.32 C 4.653333 15.666666 4.486667 16.08 4.5 16.559999 C 4.513333 17.039999 4.686666 17.453333 5.02 17.799999 C 5.353333 18.146666 5.76 18.313332 6.24 18.299999 C 6.72 18.286667 7.133333 18.113333 7.48 17.779999 C 7.826666 17.446667 8 17.039999 8 16.559999 C 8 16.08 7.826666 15.666666 7.48 15.32 C 7.133333 14.973332 6.72 14.799999 6.24 14.799999 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Paste" Click="Paste_Click">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 4.52 5.799999 L 6.08 5.799999 C 6.186666 6.093334 6.373333 6.333334 6.64 6.52 C 6.906667 6.706667 7.186666 6.8 7.48 6.799999 L 10.52 6.799999 C 10.813334 6.8 11.093333 6.706667 11.36 6.52 C 11.626666 6.333334 11.813333 6.093334 11.92 5.799999 L 13.52 5.799999 C 13.653332 5.799999 13.766665 5.846666 13.86 5.94 C 13.953333 6.033334 14 6.146667 14 6.28 L 14 7.28 C 14 7.44 14.046666 7.566667 14.139999 7.66 C 14.233333 7.753333 14.353333 7.799999 14.5 7.799999 C 14.646666 7.799999 14.766666 7.753333 14.86 7.66 C 14.953333 7.566667 14.999999 7.453333 15 7.32 L 15 6.28 C 14.999999 5.880001 14.853333 5.533335 14.559999 5.24 C 14.266666 4.946667 13.906666 4.799999 13.48 4.799999 L 11.92 4.799999 C 11.813333 4.506666 11.626666 4.266666 11.36 4.08 C 11.093333 3.893333 10.799999 3.799999 10.48 3.799999 L 7.52 3.799999 C 7.2 3.799999 6.906667 3.893333 6.64 4.08 C 6.373333 4.266666 6.186666 4.506666 6.08 4.799999 L 4.52 4.799999 C 4.093333 4.799999 3.733333 4.946667 3.44 5.24 C 3.146667 5.533335 3 5.893334 3 6.32 L 3 18.279999 C 3 18.706665 3.146667 19.066666 3.44 19.359999 C 3.733333 19.653332 4.093333 19.799999 4.52 19.799999 L 7.52 19.799999 C 7.653333 19.799999 7.766666 19.753332 7.86 19.66 C 7.953333 19.566666 8 19.446667 8 19.299999 C 8 19.153332 7.953333 19.033333 7.86 18.939999 C 7.766666 18.846666 7.653333 18.799999 7.52 18.799999 L 4.52 18.799999 C 4.36 18.799999 4.233333 18.753332 4.14 18.66 C 4.046667 18.566666 4 18.439999 4 18.279999 L 4 6.28 C 4 6.146667 4.046667 6.033334 4.14 5.94 C 4.233333 5.846666 4.36 5.799999 4.52 5.799999 Z M 7.52 5.799999 C 7.36 5.799999 7.233333 5.753334 7.14 5.66 C 7.046667 5.566668 7 5.446667 7 5.299999 C 7 5.153334 7.046667 5.033333 7.14 4.940001 C 7.233333 4.846666 7.346666 4.799999 7.48 4.799999 L 10.52 4.799999 C 10.653332 4.799999 10.766665 4.846666 10.86 4.940001 C 10.953333 5.033333 11 5.153334 11 5.299999 C 11 5.446667 10.953333 5.566668 10.86 5.66 C 10.766665 5.753334 10.653332 5.799999 10.52 5.799999 Z M 10.52 8.799999 C 10.093333 8.799999 9.733334 8.946667 9.44 9.24 C 9.146666 9.533334 9 9.893333 9 10.32 L 9 18.279999 C 9 18.706665 9.146666 19.066666 9.44 19.359999 C 9.733334 19.653332 10.093333 19.799999 10.52 19.799999 L 15.52 19.799999 C 15.919998 19.799999 16.266665 19.653332 16.559999 19.359999 C 16.853333 19.066666 17 18.706665 17 18.279999 L 17 10.28 C 17 9.88 16.853333 9.533334 16.559999 9.24 C 16.266665 8.946667 15.906665 8.799999 15.48 8.799999 Z M 10 10.28 C 10 10.146667 10.046666 10.033333 10.139999 9.94 C 10.233333 9.846666 10.346666 9.799999 10.48 9.799999 L 15.52 9.799999 C 15.653332 9.799999 15.766665 9.846666 15.86 9.94 C 15.953333 10.033333 16 10.146667 16 10.28 L 16 18.279999 C 16 18.439999 15.953333 18.566666 15.86 18.66 C 15.766665 18.753332 15.653332 18.799999 15.52 18.799999 L 10.52 18.799999 C 10.359999 18.799999 10.233333 18.753332 10.139999 18.66 C 10.046666 18.566666 10 18.439999 10 18.279999 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator/>
|
||||
<MenuItem Header="_Find" Click="Find_Click"/>
|
||||
<MenuItem Header="_Find" Click="Find_Click">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 12.719999 15.24 C 11.866666 15.986666 10.886666 16.466667 9.78 16.68 C 8.673333 16.893333 7.58 16.826666 6.5 16.48 C 5.42 16.133333 4.493333 15.539999 3.72 14.699999 C 2.946666 13.86 2.433333 12.893333 2.18 11.799999 C 1.926667 10.706667 1.946667 9.62 2.24 8.54 C 2.533333 7.46 3.086666 6.513333 3.9 5.699999 C 4.713333 4.886665 5.66 4.333332 6.74 4.039999 C 7.82 3.746666 8.906666 3.726667 10 3.98 C 11.093332 4.233334 12.059999 4.746666 12.9 5.52 C 13.74 6.293334 14.333333 7.22 14.679999 8.299999 C 15.026666 9.379999 15.093332 10.473333 14.88 11.58 C 14.666666 12.686666 14.186666 13.666666 13.44 14.52 L 16.84 17.959999 C 16.946667 18.039999 17 18.146666 17 18.279999 C 17 18.413332 16.959999 18.526667 16.879999 18.619999 C 16.799999 18.713333 16.693333 18.766666 16.559999 18.779999 C 16.426664 18.793333 16.306664 18.773333 16.199999 18.719999 Z M 12.04 14.52 C 12.653333 14.013332 13.133333 13.386666 13.48 12.639999 C 13.826666 11.893333 14 11.106667 14 10.28 C 14 9 13.599999 7.860001 12.799999 6.86 C 11.999999 5.859999 10.966666 5.219999 9.7 4.940001 C 8.433332 4.66 7.219999 4.799999 6.06 5.359999 C 4.9 5.92 4.046666 6.786667 3.5 7.959999 C 2.953333 9.133333 2.833333 10.346666 3.14 11.599999 C 3.446666 12.853333 4.113333 13.873333 5.14 14.66 C 6.166666 15.446666 7.32 15.826666 8.599999 15.799999 C 9.879999 15.773333 11.026666 15.346666 12.04 14.52 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</avaloniaedit:TextEditor.ContextMenu>
|
||||
</avaloniaedit:TextEditor>
|
||||
|
||||
@@ -68,11 +68,19 @@ public partial class BaseEditor : UserControl
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (extension_name == ".progrart") extension_name = ".js";
|
||||
if (extension_name == ".progrart-project") extension_name = ".json";
|
||||
try
|
||||
{
|
||||
_textMateInstallation?.SetGrammar(
|
||||
_registryOptions?.GetScopeByLanguageId(
|
||||
_registryOptions.GetLanguageByExtension(extension_name).Id
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,21 @@
|
||||
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="_Open" Name="OpenFileMenuItem"/>
|
||||
<MenuItem Header="_Open" Name="OpenFileMenuItem">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 6.24 6.28 C 5.76 6.280001 5.346666 6.453334 5 6.799999 C 4.653333 7.146667 4.48 7.559999 4.48 8.04 L 4.48 15.559999 C 4.506666 16.039999 4.686666 16.446667 5.02 16.779999 C 5.353333 17.113333 5.76 17.279999 6.24 17.279999 L 13.759999 17.279999 C 14.24 17.279999 14.653333 17.113333 15 16.779999 C 15.346665 16.446667 15.519999 16.039999 15.52 15.559999 L 15.52 13.559999 C 15.519999 13.346666 15.586665 13.166666 15.719999 13.02 C 15.853333 12.873333 16.026667 12.799999 16.24 12.799999 C 16.453333 12.799999 16.633331 12.873333 16.779999 13.02 C 16.926666 13.166666 17 13.346666 17 13.559999 L 17 15.559999 C 17 16.439999 16.68 17.199999 16.039999 17.84 C 15.399999 18.48 14.639999 18.799999 13.759999 18.799999 L 6.24 18.799999 C 5.36 18.799999 4.6 18.48 3.96 17.84 C 3.32 17.199999 3 16.439999 3 15.559999 L 3 8.04 C 3 7.16 3.32 6.400001 3.96 5.76 C 4.6 5.119999 5.36 4.799999 6.24 4.799999 L 8.24 4.799999 C 8.453333 4.799999 8.633333 4.873333 8.78 5.02 C 8.926666 5.166668 9 5.346666 9 5.559999 C 9 5.773333 8.926666 5.953333 8.78 6.099999 C 8.633333 6.246667 8.453333 6.320001 8.24 6.32 L 6.24 6.32 Z M 10.52 5.559999 C 10.519999 5.346666 10.586666 5.166668 10.719999 5.02 C 10.853333 4.873333 11.026667 4.799999 11.24 4.799999 L 16.24 4.799999 C 16.453333 4.799999 16.633331 4.873333 16.779999 5.02 C 16.926666 5.166668 17 5.346666 17 5.559999 L 17 10.559999 C 17 10.773333 16.926666 10.953333 16.779999 11.099999 C 16.633331 11.246667 16.453333 11.313334 16.24 11.299999 C 16.026667 11.286667 15.853333 11.213333 15.719999 11.08 C 15.586665 10.946667 15.506665 10.773333 15.48 10.559999 L 15.48 7.36 L 11.8 11.08 C 11.586666 11.293333 11.333333 11.366667 11.04 11.299999 C 10.746666 11.233334 10.566666 11.053333 10.5 10.759999 C 10.433332 10.466666 10.506666 10.226666 10.719999 10.04 L 14.44 6.28 L 11.24 6.28 C 11.026667 6.280001 10.853333 6.213334 10.719999 6.08 C 10.586666 5.946667 10.506666 5.773333 10.48 5.559999 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Open _With..." Name="OpenWithMenu">
|
||||
<MenuItem.Icon>
|
||||
<Viewbox Height="11">
|
||||
<PathIcon Data="F1 M 8 6.28 C 8 6.146667 8.046666 6.033334 8.139999 5.94 C 8.233333 5.846666 8.346666 5.799999 8.48 5.799999 L 17.52 5.799999 C 17.653332 5.799999 17.766666 5.846666 17.859999 5.94 C 17.953331 6.033334 18 6.153334 18 6.299999 C 18 6.446667 17.953331 6.566668 17.859999 6.66 C 17.766666 6.753334 17.653332 6.8 17.52 6.799999 L 8.52 6.799999 C 8.36 6.8 8.233333 6.753334 8.139999 6.66 C 8.046666 6.566668 8 6.453334 8 6.32 Z M 8 12.28 C 8 12.146667 8.046666 12.033334 8.139999 11.94 C 8.233333 11.846666 8.346666 11.799999 8.48 11.799999 L 17.52 11.799999 C 17.653332 11.799999 17.766666 11.846666 17.859999 11.94 C 17.953331 12.033334 18 12.153334 18 12.299999 C 18 12.446667 17.953331 12.566667 17.859999 12.66 C 17.766666 12.753333 17.653332 12.799999 17.52 12.799999 L 8.52 12.799999 C 8.36 12.799999 8.233333 12.753333 8.139999 12.66 C 8.046666 12.566667 8 12.453333 8 12.32 Z M 8 18.279999 C 8 18.146666 8.046666 18.033333 8.139999 17.939999 C 8.233333 17.846666 8.346666 17.799999 8.48 17.799999 L 17.52 17.799999 C 17.653332 17.799999 17.766666 17.846666 17.859999 17.939999 C 17.953331 18.033333 18 18.153332 18 18.299999 C 18 18.446667 17.953331 18.566666 17.859999 18.66 C 17.766666 18.753332 17.653332 18.799999 17.52 18.799999 L 8.52 18.799999 C 8.36 18.799999 8.233333 18.753332 8.139999 18.66 C 8.046666 18.566666 8 18.439999 8 18.279999 Z M 2 17.279999 C 2 16.879999 2.146667 16.533333 2.44 16.24 C 2.733333 15.946667 3.08 15.799999 3.48 15.799999 L 4.52 15.799999 C 4.92 15.799999 5.266666 15.946667 5.56 16.24 C 5.853333 16.533333 6 16.879999 6 17.279999 L 6 18.279999 C 6 18.706665 5.853333 19.066666 5.56 19.359999 C 5.266666 19.653332 4.92 19.799999 4.52 19.799999 L 3.52 19.799999 C 3.093333 19.799999 2.733333 19.653332 2.44 19.359999 C 2.146667 19.066666 2 18.706665 2 18.279999 Z M 2 11.28 C 2 10.879999 2.146667 10.533333 2.44 10.24 C 2.733333 9.946667 3.08 9.799999 3.48 9.799999 L 4.52 9.799999 C 4.92 9.799999 5.266666 9.946667 5.56 10.24 C 5.853333 10.533333 6 10.893333 6 11.32 L 6 12.28 C 6 12.706667 5.853333 13.066667 5.56 13.36 C 5.266666 13.653333 4.92 13.799999 4.52 13.799999 L 3.52 13.799999 C 3.093333 13.799999 2.733333 13.653333 2.44 13.36 C 2.146667 13.066667 2 12.706667 2 12.28 Z M 2 5.279999 C 2 4.880001 2.146667 4.533333 2.44 4.24 C 2.733333 3.946667 3.08 3.799999 3.48 3.799999 L 4.52 3.799999 C 4.92 3.799999 5.266666 3.946667 5.56 4.24 C 5.853333 4.533333 6 4.893333 6 5.32 L 6 6.28 C 6 6.706667 5.853333 7.066667 5.56 7.36 C 5.266666 7.653333 4.92 7.799999 4.52 7.799999 L 3.52 7.799999 C 3.093333 7.799999 2.733333 7.653333 2.44 7.36 C 2.146667 7.066667 2 6.706667 2 6.28 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Viewbox>
|
||||
</MenuItem.Icon>
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem Header="_New" Name="NewFiles">
|
||||
<MenuItem Header="_Progrart Image" Name="CreateProgrartItem"/>
|
||||
<MenuItem Header="_Folder" Name="CreateFolderItem"/>
|
||||
|
||||
@@ -32,6 +32,7 @@ public partial class FileItem : UserControl
|
||||
FolderIcon.IsVisible = true;
|
||||
GenericFileIcon.IsVisible = false;
|
||||
IconContainer.IsVisible = false;
|
||||
OpenWithMenu.IsVisible = false;
|
||||
}
|
||||
else if (storageItem is IStorageFile file)
|
||||
{
|
||||
@@ -48,17 +49,27 @@ public partial class FileItem : UserControl
|
||||
GenericFileIcon.IsVisible = false;
|
||||
IconContainer.Children.Add(icon);
|
||||
}
|
||||
foreach (var item in EditorProvider.GetHandlerCollection(extension))
|
||||
{
|
||||
MenuItem mItem = new() { Header = item.Name };
|
||||
mItem.Click += async (a, b) =>
|
||||
{
|
||||
if (item.OpenAction is not null)
|
||||
await item.OpenAction(file);
|
||||
};
|
||||
OpenWithMenu.Items.Add(mItem);
|
||||
}
|
||||
}
|
||||
IconContainer.IsVisible = true;
|
||||
}
|
||||
NameBlock.Text = storageItem.Name;
|
||||
MainButton.DoubleTapped += async (_, _) =>
|
||||
{
|
||||
OpenItem();
|
||||
await OpenItem();
|
||||
};
|
||||
OpenFileMenuItem.Click += async (a, b) =>
|
||||
{
|
||||
OpenItem();
|
||||
await OpenItem();
|
||||
};
|
||||
CreateFolderItem.Click += async (a, b) =>
|
||||
{
|
||||
@@ -133,7 +144,7 @@ public partial class FileItem : UserControl
|
||||
await DialogHost.Show(content);
|
||||
};
|
||||
}
|
||||
void OpenItem()
|
||||
public async Task OpenItem()
|
||||
{
|
||||
|
||||
if (currentItem is IStorageFolder folder)
|
||||
@@ -146,7 +157,7 @@ public partial class FileItem : UserControl
|
||||
else
|
||||
{
|
||||
isOpen = true;
|
||||
Task.Run(async () =>
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await LoadAll(folder);
|
||||
});
|
||||
@@ -161,23 +172,25 @@ public partial class FileItem : UserControl
|
||||
EditorProvider.SelectTabPage(btn);
|
||||
}
|
||||
else
|
||||
if (EditorProvider.TryGetEditor(extension, out var page))
|
||||
if (EditorProvider.TryGetHandler(extension, out var page))
|
||||
{
|
||||
if (page is ITabPage editor)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (page is IEditorPage editor_page)
|
||||
{
|
||||
editor_page.LoadDocument(file);
|
||||
}
|
||||
EditorProvider.OpenEditor(editor);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Trace.WriteLine(e);
|
||||
}
|
||||
}
|
||||
if (page.OpenAction is not null)
|
||||
await page.OpenAction(file);
|
||||
//if (page is ITabPage editor)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// if (page is IEditorPage editor_page)
|
||||
// {
|
||||
// editor_page.LoadDocument(file);
|
||||
// }
|
||||
// EditorProvider.OpenEditor(editor);
|
||||
// }
|
||||
// catch (System.Exception e)
|
||||
// {
|
||||
// Trace.WriteLine(e);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ public partial class TabButton : UserControl
|
||||
Host.RemoveButton(this);
|
||||
};
|
||||
}
|
||||
public bool IsVisibleInHost()
|
||||
{
|
||||
if (page is Control pageControl)
|
||||
return pageControl.IsVisible;
|
||||
return false;
|
||||
}
|
||||
public void SetSelectState(bool v)
|
||||
{
|
||||
if (page is Control pageControl)
|
||||
|
||||
@@ -63,10 +63,47 @@ public partial class TabHost : UserControl
|
||||
itemBtn.SetSelectState(item == button);
|
||||
}
|
||||
}
|
||||
public void SelectButton(int index)
|
||||
{
|
||||
for (int i = 0; i < TabContainer.Children.Count; i++)
|
||||
{
|
||||
Control? item = TabContainer.Children[i];
|
||||
if (item is TabButton itemBtn)
|
||||
itemBtn.SetSelectState(i == index);
|
||||
}
|
||||
}
|
||||
private int GetOpenIndex()
|
||||
{
|
||||
for (int i = 0; i < TabContainer.Children.Count; i++)
|
||||
{
|
||||
Control item = TabContainer.Children[i];
|
||||
if (item is TabButton itemBtn)
|
||||
{
|
||||
if (itemBtn.IsVisibleInHost()) return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public void RemoveButton(TabButton button)
|
||||
{
|
||||
var index = TabContainer.Children.IndexOf(button);
|
||||
int v = GetOpenIndex();
|
||||
TabContainer.Children.Remove(button);
|
||||
if (button.page is Control pageControl)
|
||||
PageContainer.Children.Remove(pageControl);
|
||||
|
||||
if (index == v)
|
||||
{
|
||||
if (index - 1 > 0)
|
||||
SelectButton(index - 1);
|
||||
else
|
||||
{
|
||||
SelectButton(1);
|
||||
}
|
||||
}
|
||||
if (v == -1)
|
||||
{
|
||||
SelectButton(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Progrart/Core/FileHandler.cs
Normal file
36
Progrart/Core/FileHandler.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Avalonia.Platform.Storage;
|
||||
using Progrart.Controls.TabSystem;
|
||||
using Progrart.Pages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Progrart.Core
|
||||
{
|
||||
public class FileHandler
|
||||
{
|
||||
public string Name = "";
|
||||
public Func<IStorageFile,Task>? OpenAction = null;
|
||||
|
||||
public FileHandler(string name, Func<IStorageFile, Task>? openAction)
|
||||
{
|
||||
Name = name;
|
||||
OpenAction = openAction;
|
||||
}
|
||||
}
|
||||
public class EditorFileHandler<T> : FileHandler where T : IEditorPage, ITabPage
|
||||
{
|
||||
public EditorFileHandler(string name) : base(name, async (item) =>
|
||||
{
|
||||
if (item is IStorageFile file)
|
||||
{
|
||||
var page = (T)Activator.CreateInstance(typeof(T))!;
|
||||
page.LoadDocument(file);
|
||||
EditorProvider.OpenEditor(page);
|
||||
}
|
||||
})
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -13,22 +14,28 @@ namespace Progrart.Pages
|
||||
{
|
||||
static public class EditorProvider
|
||||
{
|
||||
static Dictionary<string, string> Names = new();
|
||||
static Dictionary<string, string> ExtensionMapping = new();
|
||||
static Dictionary<string, Type> EditorTypes = new();
|
||||
static Dictionary<string, FileHandler> handlers = new();
|
||||
static Dictionary<string, List<string>> ExtensionMapping = new();
|
||||
//static Dictionary<string, Type> EditorTypes = new();
|
||||
static TabHost? currentHost = null;
|
||||
public static void setHost(TabHost host)
|
||||
{
|
||||
currentHost = host;
|
||||
}
|
||||
public static void Register(string id, string name, Type t)
|
||||
public static void Register(string id, FileHandler handler)
|
||||
{
|
||||
Names[id] = name;
|
||||
EditorTypes[id] = t;
|
||||
handlers[id] = handler;
|
||||
}
|
||||
public static void BindFileType(string type, string id)
|
||||
{
|
||||
ExtensionMapping[type] = id;
|
||||
if (ExtensionMapping.TryGetValue(type, out var list))
|
||||
{
|
||||
list.Add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtensionMapping[type] = [id];
|
||||
}
|
||||
}
|
||||
public static TabButton? IsOpen(IStorageFile file)
|
||||
{
|
||||
@@ -42,24 +49,33 @@ namespace Progrart.Pages
|
||||
{
|
||||
currentHost?.AddPage(page);
|
||||
}
|
||||
public static bool TryGetEditor(string extension, [MaybeNullWhen(false)] out Control editorPage)
|
||||
|
||||
public static bool TryGetHandler(string extension, [MaybeNullWhen(false)] out FileHandler handler)
|
||||
{
|
||||
if (ExtensionMapping.TryGetValue(extension.ToLower(), out var id))
|
||||
{
|
||||
|
||||
if (EditorTypes.TryGetValue(id, out var editorType))
|
||||
if (handlers.TryGetValue(id.First(), out var editorType))
|
||||
{
|
||||
var obj = Activator.CreateInstance(editorType);
|
||||
if (obj is Control control)
|
||||
{
|
||||
editorPage = control;
|
||||
handler = editorType;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
editorPage = null;
|
||||
handler = null;
|
||||
return false;
|
||||
}
|
||||
public static List<FileHandler> GetHandlerCollection(string extension)
|
||||
{
|
||||
List<FileHandler> handlersList = new();
|
||||
if (ExtensionMapping.TryGetValue(extension.ToLower(), out var id))
|
||||
{
|
||||
foreach (var item in id)
|
||||
{
|
||||
handlersList.Add(handlers[item]);
|
||||
}
|
||||
}
|
||||
return handlersList;
|
||||
}
|
||||
}
|
||||
public interface IEditorPage
|
||||
{
|
||||
|
||||
@@ -109,7 +109,8 @@ public partial class MainView : UserControl
|
||||
FileContainer.Children.Clear();
|
||||
var folder = folders[0];
|
||||
App.CurrentOpenFolder = folder;
|
||||
FileContainer.Children.Add(new FileItem(folder));
|
||||
FileItem item1 = new(folder);
|
||||
FileContainer.Children.Add(item1);
|
||||
await foreach (var item in folder.GetItemsAsync())
|
||||
{
|
||||
if (item.Name.ToLower().EndsWith(".progrart-project", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -122,6 +123,7 @@ public partial class MainView : UserControl
|
||||
break;
|
||||
}
|
||||
}
|
||||
await item1.OpenItem();
|
||||
}
|
||||
};
|
||||
FileExplorerCloseButton.Click += (_, _) =>
|
||||
|
||||
Reference in New Issue
Block a user