Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
fileiconservice + dynamic folder loading
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Mar 10, 2024
1 parent 335e0f5 commit b03c21a
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 124 deletions.
43 changes: 0 additions & 43 deletions src/OneWare.Essentials/Converters/FileExtensionIconConverter.cs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/OneWare.Essentials/Converters/SharedConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public static readonly IValueConverter
public static readonly IValueConverter UiExtensionToControlConverter = new UiExtensionToControlConverter();
public static readonly IValueConverter ComparisonConverter = new ComparisonConverter();
public static readonly IValueConverter EnumToStringConverter = new EnumToStringConverter();
public static readonly IValueConverter FileExtensionIconConverter = new FileExtensionIconConverter();
public static readonly IValueConverter FileExtensionIconConverterObservable = new FileExtensionIconConverterObservable();
public static readonly IValueConverter FileOpacityConverter = new FileOpacityConverter();
public static readonly IValueConverter NoComparisonConverter = new NoComparisonConverter();
public static readonly IValueConverter ObjectNotTypeConverter = new ObjectNotTypeConverter();
Expand Down
13 changes: 2 additions & 11 deletions src/OneWare.Essentials/Helpers/ProjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,12 @@ public static void ImportEntries(string source, IProjectFolder destination)

private static IEnumerable<(string path, FileAttributes attributes)> GetFileMatches(string source, Func<string,bool>? valid = null)
{
var entries = Directory.EnumerateFileSystemEntries(source);

var entries = Directory.EnumerateFileSystemEntries(source, "**", SearchOption.AllDirectories);
foreach (var path in entries)
{
var attr = File.GetAttributes(path);

if (attr.HasFlag(FileAttributes.Directory))
{
var subDirMatches = GetFileMatches(path,valid);
foreach (var subMatch in subDirMatches)
{
yield return subMatch;
}
}

var match = valid?.Invoke(path) ?? true;
if (match) yield return (path, attr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Essentials/Models/ErrorListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public int CompareTo(ErrorListItem? other)
if(other == null) return -1;
if (Type < other.Type) return -1;
if(Type > other.Type) return 1;
var stringComp = string.Compare(File.Header, other.File.Header, StringComparison.OrdinalIgnoreCase);
var stringComp = string.Compare(File.Name, other.File.Name, StringComparison.OrdinalIgnoreCase);
if (stringComp < 0) return -1;
if (StartLine < other.StartLine) return -1;
if (Equals(other)) return 0;
Expand Down
10 changes: 6 additions & 4 deletions src/OneWare.Essentials/Models/ExternalFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using CommunityToolkit.Mvvm.ComponentModel;
using DynamicData.Binding;
using OneWare.Essentials.Converters;
using OneWare.Essentials.Services;
using Prism.Ioc;

namespace OneWare.Essentials.Models;

public class ExternalFile : ObservableObject, IFile
{
public string Extension => Path.GetExtension(FullPath);
public string FullPath { get; set; }
public string Header => Path.GetFileName(FullPath);
public string Name => Path.GetFileName(FullPath);
public bool LoadingFailed { get; set; }
public DateTime LastSaveTime { get; set; }

Expand All @@ -31,10 +33,10 @@ public ExternalFile(string fullPath)
this.WhenValueChanged(x => x.FullPath).Subscribe(x =>
{
fileSubscription?.Dispose();
var observable = SharedConverters.FileExtensionIconConverterObservable.Convert(Extension, typeof(IImage), null, CultureInfo.CurrentCulture) as IObservable<object?>;
fileSubscription = observable?.Subscribe(x =>
var observable = ContainerLocator.Container.Resolve<IFileIconService>().GetFileIcon(Extension);
fileSubscription = observable?.Subscribe(icon =>
{
Icon = x as IImage;
Icon = icon;
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Essentials/Models/IHasPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public interface IHasPath
{
public string FullPath { get; }
public string Header { get; }
public string Name { get; }
public bool LoadingFailed { get; set; }
}
20 changes: 6 additions & 14 deletions src/OneWare.Essentials/Models/IProjectEntry.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using Avalonia.Media;

namespace OneWare.Essentials.Models;

public interface IProjectEntry : IHasPath, ICanHaveIcon
/// <summary>
/// Can be a file or a folder
/// </summary>
public interface IProjectEntry : IProjectExplorerNode, IHasPath
{
public new string Header { get; set; }

public ObservableCollection<IProjectEntry> Items { get; }
public ReadOnlyObservableCollection<IProjectEntry> Entities { get; }

public string RelativePath { get; }

public ObservableCollection<IImage> IconOverlays { get; }

public bool IsExpanded { get; set; }

public IBrush Background { get; set; }

public FontWeight FontWeight { get; set; }

public float TextOpacity { get; }

public IProjectRoot Root { get; }

Expand Down
27 changes: 27 additions & 0 deletions src/OneWare.Essentials/Models/IProjectExplorerNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using Avalonia.Media;

namespace OneWare.Essentials.Models;

/// <summary>
/// Node displayed in the project explorer
/// </summary>
public interface IProjectExplorerNode : ICanHaveIcon, INotifyPropertyChanged
{
public string Header { get; }

public IProjectExplorerNode? Parent { get; }

public ObservableCollection<IProjectExplorerNode> Children { get; }

public ObservableCollection<IImage> IconOverlays { get; }

public bool IsExpanded { get; set; }

public IBrush Background { get; set; }

public FontWeight FontWeight { get; set; }

public float TextOpacity { get; }
}
1 change: 1 addition & 0 deletions src/OneWare.Essentials/Models/IProjectRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface IProjectRoot : IProjectFolder
public bool IsActive { get; set; }
public bool IsPathIncluded(string relativePath);
public void IncludePath(string path);
public void OnExternalEntryAdded(string path, FileAttributes attributes);
}
2 changes: 1 addition & 1 deletion src/OneWare.Essentials/OneWare.Essentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Import Project="..\..\build\props\Asmichi.ChildProcess.props"/>

<PropertyGroup>
<Version>0.3.1</Version>
<Version>0.4.0</Version>
<Authors>Hendrik Mennen</Authors>
<Company>One Ware</Company>
<Description>Essentials Needed for One Ware Plugin Development</Description>
Expand Down
10 changes: 10 additions & 0 deletions src/OneWare.Essentials/Services/IFileIconService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Avalonia.Media;

namespace OneWare.Essentials.Services;

public interface IFileIconService
{
public void RegisterFileIcon(IObservable<IImage> icon, params string[] extensions);
public void RegisterFileIcon(string resourceName, params string[] extensions);
public IObservable<IImage> GetFileIcon(string extension);
}
10 changes: 5 additions & 5 deletions src/OneWare.Essentials/Services/IProjectExplorerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace OneWare.Essentials.Services;

public interface IProjectExplorerService : IDockable, INotifyPropertyChanged
{
public ObservableCollection<IProjectEntry> Items { get; }
public ObservableCollection<IProjectEntry> SelectedItems { get; }
public ObservableCollection<IProjectRoot> Projects { get; }
public ObservableCollection<IProjectExplorerNode> SelectedItems { get; }
public IProjectRoot? ActiveProject { get; set; }
public event EventHandler<IFile>? FileRemoved;
public event EventHandler<IProjectRoot>? ProjectRemoved;
public void Insert(IProjectEntry entry);
public void Insert(IProjectRoot project);
public Task RemoveAsync(params IProjectEntry[] entries);
public Task DeleteAsync(params IProjectEntry[] entries);
public IProjectEntry? Search(string path, bool recursive = true);
Expand All @@ -23,11 +23,11 @@ public interface IProjectExplorerService : IDockable, INotifyPropertyChanged
public IFile GetTemporaryFile(string path);
public void RemoveTemporaryFile(IFile file);
public Task<IProjectEntry> RenameAsync(IProjectEntry entry, string newName);
public void ExpandToRoot(IProjectEntry entry);
public void ExpandToRoot(IProjectExplorerNode node);
public Task ImportFolderDialogAsync(IProjectFolder? destination = null);
public Task<IProjectEntry> ReloadAsync(IProjectEntry entry);
public Task SaveProjectAsync(IProjectRoot project);
public Task SaveLastProjectsFileAsync();
public Task OpenLastProjectsFileAsync();
public void RegisterConstructContextMenu(Func<IList<IProjectEntry>, IEnumerable<MenuItemViewModel>?> construct);
public void RegisterConstructContextMenu(Func<IList<IProjectExplorerNode>, IEnumerable<MenuItemViewModel>?> construct);
}
4 changes: 2 additions & 2 deletions src/OneWare.Essentials/ViewModels/ExtendedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public bool IsDirty
protected set => SetProperty(ref _isDirty, value);
}

public virtual string CloseWarningMessage => $"Do you want to save changes to the file {CurrentFile?.Header}?";
public virtual string CloseWarningMessage => $"Do you want to save changes to the file {CurrentFile?.Name}?";

protected ExtendedDocument(string fullPath, IProjectExplorerService projectExplorerService, IDockService dockService, IWindowService windowService)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public virtual void InitializeContent()
if (CurrentFile?.FullPath != FullPath)
{
CurrentFile = _projectExplorerService.Search(FullPath) as IFile ?? _projectExplorerService.GetTemporaryFile(FullPath);
Title = CurrentFile is ExternalFile ? $"[{CurrentFile.Header}]" : CurrentFile.Header;
Title = CurrentFile is ExternalFile ? $"[{CurrentFile.Name}]" : CurrentFile.Name;
}
_dockService.OpenFiles.TryAdd(CurrentFile, this);
UpdateCurrentFile(oldCurrentFile);
Expand Down

0 comments on commit b03c21a

Please sign in to comment.