-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from one-ware/libraries
Add Library Explorer
- Loading branch information
Showing
15 changed files
with
441 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using CommunityToolkit.Mvvm.Input; | ||
using OneWare.Essentials.Enums; | ||
using OneWare.Essentials.Services; | ||
using OneWare.Essentials.ViewModels; | ||
using OneWare.LibraryExplorer.ViewModels; | ||
using OneWare.ProjectExplorer.ViewModels; | ||
using Prism.Ioc; | ||
using Prism.Modularity; | ||
|
||
namespace OneWare.LibraryExplorer; | ||
|
||
public class LibraryExplorerModule : IModule | ||
{ | ||
public void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
containerRegistry.RegisterSingleton<LibraryExplorerViewModel>(); | ||
} | ||
|
||
public void OnInitialized(IContainerProvider containerProvider) | ||
{ | ||
var dockService = containerProvider.Resolve<IDockService>(); | ||
var windowService = containerProvider.Resolve<IWindowService>(); | ||
|
||
dockService.RegisterLayoutExtension<LibraryExplorerViewModel>(DockShowLocation.Left); | ||
|
||
windowService.RegisterMenuItem("MainWindow_MainMenu/View/Tool Windows", | ||
new MenuItemViewModel("Library Explorer") | ||
{ | ||
Header = "Library Explorer", | ||
Command = | ||
new RelayCommand(() => dockService.Show(containerProvider.Resolve<LibraryExplorerViewModel>())), | ||
IconObservable = Application.Current!.GetResourceObservable(LibraryExplorerViewModel.IconKey) | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/OneWare.LibraryExplorer/OneWare.LibraryExplorer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\build\props\Base.props"/> | ||
<Import Project="..\..\build\props\OneWare.Module.props"/> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\OneWare.Essentials\OneWare.Essentials.csproj"/> | ||
<ProjectReference Include="..\OneWare.FolderProjectSystem\OneWare.FolderProjectSystem.csproj" /> | ||
<ProjectReference Include="..\OneWare.ProjectExplorer\OneWare.ProjectExplorer.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Views\LibraryExplorerView.axaml.cs"> | ||
<DependentUpon>ProjectExplorerView.axaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
</Project> |
133 changes: 133 additions & 0 deletions
133
src/OneWare.LibraryExplorer/ViewModels/LibraryExplorerViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Dock.Model.Core; | ||
using OneWare.Essentials.Helpers; | ||
using OneWare.Essentials.Models; | ||
using OneWare.Essentials.Services; | ||
using OneWare.Essentials.ViewModels; | ||
using OneWare.FolderProjectSystem; | ||
using OneWare.ProjectExplorer.Services; | ||
using OneWare.ProjectExplorer.ViewModels; | ||
using Prism.Ioc; | ||
|
||
namespace OneWare.LibraryExplorer.ViewModels; | ||
|
||
public class LibraryExplorerViewModel : ProjectViewModelBase | ||
{ | ||
public const string IconKey = "BoxIcons.RegularLibrary"; | ||
|
||
private string _libraryFolderPath; | ||
|
||
private readonly IFileWatchService _fileWatchService; | ||
private readonly IDockService _dockService; | ||
private readonly IProjectExplorerService _projectExplorerService; | ||
|
||
public LibraryExplorerViewModel(IPaths paths, IFileWatchService fileWatchService, IDockService dockService, IProjectExplorerService projectExplorerService) : base(IconKey) | ||
{ | ||
Id = "LibraryExplorer"; | ||
Title = "Library Explorer"; | ||
|
||
_fileWatchService = fileWatchService; | ||
_dockService = dockService; | ||
_projectExplorerService = projectExplorerService; | ||
|
||
_libraryFolderPath = Path.Combine(paths.PackagesDirectory, "Libraries"); | ||
|
||
_ = LoadAsync(); | ||
} | ||
|
||
public override void Insert(IProjectRoot project) | ||
{ | ||
base.Insert(project); | ||
_fileWatchService.Register(project); | ||
} | ||
|
||
public void DoubleTab(IProjectEntry entry) | ||
{ | ||
if (entry is IProjectFile file) | ||
_ = PreviewFileAsync(file); | ||
else | ||
entry.IsExpanded = !entry.IsExpanded; | ||
} | ||
|
||
public async Task LoadAsync() | ||
{ | ||
var manager = ContainerLocator.Container.Resolve<FolderProjectManager>(); | ||
|
||
Directory.CreateDirectory(_libraryFolderPath); | ||
var directories = Directory.EnumerateDirectories(_libraryFolderPath); | ||
|
||
Projects.Clear(); | ||
|
||
foreach (var dir in directories) | ||
{ | ||
var root = await manager.LoadProjectAsync(dir); | ||
Insert(root!); | ||
} | ||
} | ||
|
||
public void ConstructContextMenu(TopLevel topLevel) | ||
{ | ||
var menuItems = new List<MenuItemViewModel>(); | ||
|
||
if (SelectedItems is [{ } item]) | ||
{ | ||
switch (item) | ||
{ | ||
case IProjectFile file: | ||
menuItems.Add(new MenuItemViewModel("Open") | ||
{ | ||
Header = "Open", | ||
Command = new AsyncRelayCommand(() => PreviewFileAsync(file)) | ||
}); | ||
break; | ||
} | ||
} | ||
if (SelectedItems.Count > 0) | ||
{ | ||
menuItems.Add(new MenuItemViewModel("Copy to Project") | ||
{ | ||
Header = "Copy to Active Project", | ||
Command = new AsyncRelayCommand(() => CopyLibraryAsync(SelectedItems.Cast<IProjectEntry>() | ||
.ToArray()), () => _projectExplorerService.ActiveProject != null) | ||
}); | ||
} | ||
else | ||
{ | ||
menuItems.Add(new MenuItemViewModel("Refresh") | ||
{ | ||
Header = "Refresh", | ||
Command = new RelayCommand(() => PlatformHelper.OpenExplorerPath(_libraryFolderPath)) | ||
}); | ||
menuItems.Add(new MenuItemViewModel("Open Library Folder") | ||
{ | ||
Header = "Open Library Folder", | ||
Command = new RelayCommand(() => PlatformHelper.OpenExplorerPath(_libraryFolderPath)) | ||
}); | ||
} | ||
|
||
TreeViewContextMenu = menuItems; | ||
} | ||
|
||
private async Task PreviewFileAsync(IProjectFile file) | ||
{ | ||
var extendedDocument = await _dockService.OpenFileAsync(file); | ||
if (extendedDocument != null) | ||
{ | ||
extendedDocument.IsReadOnly = true; | ||
extendedDocument.Title = "PREVIEW: " + extendedDocument.CurrentFile?.Name; | ||
} | ||
} | ||
|
||
private async Task CopyLibraryAsync(params IProjectEntry[] entries) | ||
{ | ||
var proj = _projectExplorerService.ActiveProject; | ||
|
||
if(proj == null) return; | ||
|
||
var libFolder = proj.AddFolder("lib"); | ||
|
||
await _projectExplorerService.ImportAsync(libFolder, true, true, entries.Select(x => x.FullPath).ToArray()); | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/OneWare.LibraryExplorer/Views/LibraryExplorerView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="clr-namespace:OneWare.Essentials.Controls;assembly=OneWare.Essentials" | ||
xmlns:models="clr-namespace:OneWare.Essentials.Models;assembly=OneWare.Essentials" | ||
xmlns:behaviors="clr-namespace:OneWare.Essentials.Behaviors;assembly=OneWare.Essentials" | ||
xmlns:behaviors1="clr-namespace:OneWare.ProjectExplorer.Behaviors" | ||
xmlns:viewModels="clr-namespace:OneWare.LibraryExplorer.ViewModels" | ||
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="450" | ||
x:Class="OneWare.LibraryExplorer.Views.LibraryExplorerView" | ||
Background="{DynamicResource ThemeControlLowBrush}" | ||
BorderBrush="{DynamicResource ThemeBorderLowBrush}" | ||
x:CompileBindings="True" x:DataType="viewModels:LibraryExplorerViewModel" | ||
Name="ProjectExplorerViewView" | ||
Foreground="{DynamicResource ThemeForegroundColor}" | ||
BorderThickness="0"> | ||
|
||
<UserControl.Styles> | ||
|
||
<Style Selector="TextBox"> | ||
<Setter Property="Padding" Value="0" /> | ||
<Setter Property="Margin" Value="0" /> | ||
<Setter Property="BorderThickness" Value="0" /> | ||
<Setter Property="Background" Value="Transparent" /> | ||
<Setter Property="TextWrapping" Value="NoWrap" /> | ||
</Style> | ||
|
||
</UserControl.Styles> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<Border Grid.ColumnSpan="2" BorderBrush="{DynamicResource ThemeBorderLowBrush}" BorderThickness="0 1 0 1"> | ||
<controls:SearchBox Background="{DynamicResource ThemeBackgroundBrush}" | ||
SearchText="{Binding SearchString, Mode=TwoWay}" VerticalAlignment="Center" | ||
VerticalContentAlignment="Center" x:Name="SearchBox" Height="24" /> | ||
</Border> | ||
<TreeView AutoScrollToSelectedItem="True" | ||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionMode="Multiple" | ||
SelectedItems="{Binding SelectedItems, Mode=TwoWay}" Grid.Row="1" Name="ProjectTree" | ||
ItemsSource="{Binding Projects}"> | ||
<TreeView.ContextMenu> | ||
<ContextMenu Classes="BindMenu" x:Name="TreeViewContextMenu" | ||
ItemsSource="{Binding TreeViewContextMenu}" /> | ||
</TreeView.ContextMenu> | ||
<TreeView.Styles> | ||
<Style Selector="TreeViewItem" x:DataType="models:IProjectExplorerNode"> | ||
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" /> | ||
<Setter Property="Background" Value="{Binding Background}" /> | ||
</Style> | ||
</TreeView.Styles> | ||
<TreeView.DataTemplates> | ||
<TreeDataTemplate DataType="models:IProjectExplorerNode" ItemsSource="{Binding Children}"> | ||
<DockPanel> | ||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right"> | ||
<ItemsControl ItemsSource="{Binding RightIcons}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" Spacing="3" /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Image Source="{Binding }" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</StackPanel> | ||
|
||
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" Spacing="4" Background="Transparent"> | ||
<Interaction.Behaviors> | ||
<behaviors:CommandOnDoubleTapBehavior | ||
Command="{Binding $parent[TreeView].((viewModels:LibraryExplorerViewModel)DataContext).DoubleTab, FallbackValue={x:Null}}" | ||
CommandParameter="{Binding}" /> | ||
</Interaction.Behaviors> | ||
|
||
<Grid VerticalAlignment="Center"> | ||
<Image Height="16" Width="16" | ||
Source="{Binding Icon}" /> | ||
<ItemsControl ItemsSource="{Binding IconOverlays}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<Panel /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Image Source="{Binding }" Height="16" Width="16" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</Grid> | ||
|
||
<!-- | ||
<Grid DockPanel.Dock="Right" Width="11"> | ||
<TextBlock HorizontalAlignment="Center" | ||
ToolTip.Tip="{Binding GitChangeStatus, Converter={StaticResource EnumToStringConverter}}" | ||
Text="{Binding GitChangeStatus, Converter={StaticResource ChangeStatusCharConverter}}" | ||
FontWeight="Bold" | ||
Foreground="{Binding GitChangeStatus, Converter={StaticResource ChangeStatusBrushConverter}}" /> | ||
</Grid>--> | ||
|
||
<controls:RenamingTextBox FontWeight="{Binding FontWeight}" ToolTip.Tip="{Binding Header}" | ||
VerticalAlignment="Center" | ||
IsEnabled="False" x:Name="RenamingTextBox" | ||
Text="{Binding Header, Mode=OneWay}" | ||
RenameAction="{Binding (models:IProjectEntry).RequestRename}" | ||
Opacity="{Binding TextOpacity}" /> | ||
</StackPanel> | ||
</DockPanel> | ||
</TreeDataTemplate> | ||
</TreeView.DataTemplates> | ||
</TreeView> | ||
</Grid> | ||
|
||
|
||
</UserControl> |
Oops, something went wrong.