Skip to content
Merged

Fixes #528

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 130 additions & 76 deletions editor/Assets/AssetBrowserView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,26 @@
<!-- Header -->
<Border DockPanel.Dock="Top">
<Grid ColumnDefinitions="*, Auto, Auto">
<TextBlock Text="Folders"
FontWeight="SemiBold"
VerticalAlignment="Center" Classes="compact-text" />
<Button Command="{Binding ToggleTagsViewCommand}"
ToolTip.Tip="Switch between folders and tags"
HorizontalAlignment="Left"
Background="Transparent"
Padding="4,2"
CornerRadius="4" Classes="compact-control">
<StackPanel Orientation="Horizontal"
Spacing="4">
<TextBlock Text="{Binding SidebarTitle}"
FontWeight="SemiBold"
VerticalAlignment="Center" Classes="compact-text" />
<LucideIcon Kind="ArrowLeftRight"
Size="12"
StrokeWidth="2.5"
Foreground="{StaticResource TextMuted}" />
</StackPanel>
</Button>
<Button Grid.Column="1"
Command="{Binding ExpandAllCommand}"
IsVisible="{Binding ShowFoldersView}"
ToolTip.Tip="Expand All"
Background="{StaticResource Bg4}"
Padding="4"
Expand All @@ -156,6 +171,7 @@
</Button>
<Button Grid.Column="2"
Command="{Binding CollapseAllCommand}"
IsVisible="{Binding ShowFoldersView}"
ToolTip.Tip="Collapse All"
Background="{StaticResource Bg4}"
Padding="4"
Expand All @@ -167,80 +183,118 @@
</Grid>
</Border>
<!-- Tree -->
<ScrollViewer Margin="-6"
Padding="6"
HorizontalScrollBarVisibility="Disabled">
<TreeView Classes="folder-tree" ItemsSource="{Binding Folders}"
DragDrop.AllowDrop="True"
DragDrop.DragOver="OnFolderTargetDragOver"
DragDrop.Drop="OnFolderTargetDrop"
SelectedItem="{Binding SelectedFolder, Mode=TwoWay}"
SelectionMode="Single"
Margin="0,4,0,0"
Background="Transparent">
<TreeView.Styles>
<Style Selector="TreeViewItem">
<Setter Property="IsExpanded"
Value="{ReflectionBinding IsExpanded, Mode=TwoWay}" />
<Setter Property="CornerRadius"
Value="6" />
</Style>
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate x:DataType="vm:AssetFolder"
ItemsSource="{Binding SubFolders}">
<Panel>
<TreeView Classes="folder-tree" ItemsSource="{Binding Folders}"
IsVisible="{Binding ShowFoldersView}"
DragDrop.AllowDrop="True"
DragDrop.DragOver="OnFolderTargetDragOver"
DragDrop.Drop="OnFolderTargetDrop"
SelectedItem="{Binding SelectedFolder, Mode=TwoWay}"
SelectionMode="Single"
Margin="-6,0,-6,0"
Padding="6,4,6,6"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Background="Transparent">
<TreeView.Styles>
<Style Selector="TreeViewItem">
<Setter Property="IsExpanded"
Value="{ReflectionBinding IsExpanded, Mode=TwoWay}" />
<Setter Property="CornerRadius"
Value="6" />
</Style>
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate x:DataType="vm:AssetFolder"
ItemsSource="{Binding SubFolders}">
<TextBlock Text="{Binding Name}"
TextTrimming="CharacterEllipsis" Classes="compact-text">
<TextBlock.ContextMenu>
<ContextMenu x:DataType="vm:AssetFolder">
<MenuItem Command="{Binding Owner.RenameCommand}"
CommandParameter="{Binding}"
InputGesture="F2"
IsEnabled="{Binding CanModify}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="Pencil"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="Rename" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding Owner.CreateFolderCommand}"
CommandParameter="{Binding}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="FolderPlus"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="New Folder" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<Separator />
<MenuItem Command="{Binding Owner.DeleteCommand}"
CommandParameter="{Binding}"
InputGesture="Delete"
IsEnabled="{Binding CanModify}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="Shredder"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="Delete" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</TreeDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<ListBox ItemsSource="{Binding Tags}"
SelectedItem="{Binding SelectedTag, Mode=TwoWay}"
IsVisible="{Binding ShowTagsView}"
Margin="-6,0,-6,0"
Padding="6,4,6,6"
Background="Transparent"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Padding"
Value="4,2" />
<Setter Property="CornerRadius"
Value="6" />
<Setter Property="MinHeight"
Value="0" />
</Style>
</ListBox.Styles>
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:AssetTag">
<StackPanel Orientation="Horizontal"
Spacing="6">
<Border Background="{Binding Brush}"
Width="8"
Height="8"
CornerRadius="100"
VerticalAlignment="Center" />
<TextBlock Text="{Binding Name}"
TextTrimming="CharacterEllipsis" Classes="compact-text">
<TextBlock.ContextMenu>
<ContextMenu x:DataType="vm:AssetFolder">
<MenuItem Command="{Binding Owner.RenameCommand}"
CommandParameter="{Binding}"
InputGesture="F2"
IsEnabled="{Binding CanModify}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="Pencil"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="Rename" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding Owner.CreateFolderCommand}"
CommandParameter="{Binding}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="FolderPlus"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="New Folder" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<Separator />
<MenuItem Command="{Binding Owner.DeleteCommand}"
CommandParameter="{Binding}"
InputGesture="Delete"
IsEnabled="{Binding CanModify}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal"
Spacing="8">
<LucideIcon Kind="Shredder"
StrokeWidth="2.5"
Size="16" />
<TextBlock Text="Delete" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</TreeDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</ScrollViewer>
TextTrimming="CharacterEllipsis"
VerticalAlignment="Center" Classes="compact-text" />
<TextBlock Text="{Binding AssetCountText}"
Foreground="{StaticResource TextMuted}"
FontSize="11"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Panel>
</DockPanel>
</Border>

Expand Down
11 changes: 8 additions & 3 deletions editor/Assets/AssetBrowserView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ private void OnSelectTemplateKey(object? sender, SelectTemplateEventArgs e) {
private void OnCardPointerPressed(object? sender, PointerPressedEventArgs e) {
var point = e.GetCurrentPoint(this);
if (point.Properties.IsRightButtonPressed) {
if (GetCardItem(e.Source) is AssetFile rightClickedFile)
PrepareFileContextMenu(e.Source, rightClickedFile);
if (GetCardItem(e.Source) is { } rightClicked) {
if (!Vm.SelectedItems.Contains(rightClicked)) Vm.SelectItem(rightClicked, KeyModifiers.None);
if (rightClicked is AssetFile rightClickedFile) PrepareFileContextMenu(e.Source, rightClickedFile);
e.Handled = true;
}

return;
}

Expand Down Expand Up @@ -382,7 +386,8 @@ private async void Import_OnClick(object? sender, RoutedEventArgs e) {
if (!Vm.CanWriteToSelectedFolder) return;
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return;
var importWindow = new ImportWindow();
var destination = Vm.SelectedFolder is { } folder ? ProjectContext.ToVirtual(folder.Filepath) : null;
var importWindow = new ImportWindow(destination);
await importWindow.ShowDialog(owner);
}

Expand Down
26 changes: 25 additions & 1 deletion editor/Assets/AssetBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using editor.Git;
using editor.Workspace;
using Lucide.Avalonia;
using editor.Components.Elements;

namespace editor.Assets;

Expand Down Expand Up @@ -220,6 +221,29 @@ public bool? FilterAll {
}

public ObservableCollection<AssetTagFilter> TagFilters { get; } = [];
private bool m_showTagsView;
private AssetTag? m_selectedTag;
public ObservableCollection<AssetTag> Tags => AssetBrowserSettings.Tags;
public bool ShowTagsView => m_showTagsView;
public bool ShowFoldersView => !m_showTagsView;
public string SidebarTitle => m_showTagsView ? "Tags" : "Folders";
public IRelayCommand ToggleTagsViewCommand => new RelayCommand(() => {
m_showTagsView = !m_showTagsView;
if (!m_showTagsView) SelectedTag = null;
Notify(nameof(ShowTagsView));
Notify(nameof(ShowFoldersView));
Notify(nameof(SidebarTitle));
});

public AssetTag? SelectedTag {
get => m_selectedTag;
set {
if (m_selectedTag == value) return;
m_selectedTag = value;
Notify();
SearchText = value is null ? "" : $"Tag=\"{value.Name}\"";
}
}

public bool HasTags => AssetBrowserSettings.Tags.Count > 0;

Expand Down Expand Up @@ -1155,7 +1179,7 @@ private void RefreshCurrentItems() {
.Where(f => search.Type is null || f.Definition == search.Type)
.Where(f => search.Tags.Count == 0 || MatchesTagTerms(f, search.Tags))
.Where(f => string.IsNullOrEmpty(search.Text) ||
f.Name.Contains(search.Text, StringComparison.OrdinalIgnoreCase));
FuzzyMatcher.Matches(f.Name, search.Text));
items = SortFiles(files).Cast<object>();
} else if (m_selectedFolder is not null) {
var files = m_selectedFolder.Files.Where(f => IsTypeVisible(f.Definition) && isTagVisible(f));
Expand Down
20 changes: 20 additions & 0 deletions editor/Assets/AssetDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ public static async Task CheckArtworkChanges(Action<string> log) {
if (artwork.Hash == hash) continue;

log($"Artwork changed: {sourceVirtual}");
var (choice, _) = await ShowChoiceEx(new ModalConfig(
"Artwork changed",
$"{sourceVirtual} changed since it was imported. Reimport it?",
ModalButtons.OkNoCancel,
LucideIconKind.FileExclamationPoint,
Application.Current!.TryGetResource("Yellow", null, out var r) ? r as SolidColorBrush : null,
"Ok",
"Don't import",
"Skip",
LucideIconKind.RefreshCw,
LucideIconKind.X,
LucideIconKind.SkipForward));

// skip leaves the old hash so it asks again next time
if (choice is null) continue;
if (choice == false) {
AssetStore.SetArtworkHash(sourceVirtual, hash);
continue;
}

await Reimport(sourceVirtual, log);
reimported = true;
}
Expand Down
6 changes: 4 additions & 2 deletions editor/Assets/Importers/ImportWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace editor.Assets.Importers;

public partial class ImportWindow : Window {
public ImportWindow() {
public ImportWindow() : this(null) { }

public ImportWindow(string? destination) {
InitializeComponent();
DataContext = new ImportWindowViewModel();
DataContext = new ImportWindowViewModel(destination);
Loaded += (_, _) => ((ImportWindowViewModel)DataContext!).SetWindow(this);
}
}
Loading
Loading