Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buttons for collapse and expand with icons #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions ModMyFactoryGUI/Controls/Icons/CollapseAllIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
Copyright (C) 2020-2021 Mathis Rech

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.
-->

<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ModMyFactoryGUI.Controls.Icons.CollapseAllIcon">

<Grid Width="24" Height="24">
<Path Fill="{DynamicResource IconBaseBrush1}" Data="M4,2A2,2 0 0,0 2,4V14H4V4H14V2H4M8,6A2,2 0 0,0 6,8V18H8V8H18V6H8M20,12V20H12V12H20M20,10H12A2,2 0 0,0 10,12V20A2,2 0 0,0 12,22H20A2,2 0 0,0 22,20V12A2,2 0 0,0 20,10M19,17H13V15H19V17Z" />
</Grid>
</UserControl>
25 changes: 25 additions & 0 deletions ModMyFactoryGUI/Controls/Icons/CollapseAllIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2020-2021 Mathis Rech
//
// 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.

using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace ModMyFactoryGUI.Controls.Icons
{
internal class CollapseAllIcon : UserControl
{
public CollapseAllIcon()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
17 changes: 17 additions & 0 deletions ModMyFactoryGUI/Controls/Icons/ExpandAllIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
Copyright (C) 2020-2021 Mathis Rech

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.
-->

<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ModMyFactoryGUI.Controls.Icons.ExpandAllIcon">

<Grid Width="24" Height="24">
<Path Fill="{DynamicResource IconBaseBrush1}" Data="M4,2A2,2 0 0,0 2,4V14H4V4H14V2H4M8,6A2,2 0 0,0 6,8V18H8V8H18V6H8M20,12V20H12V12H20M20,10H12A2,2 0 0,0 10,12V20A2,2 0 0,0 12,22H20A2,2 0 0,0 22,20V12A2,2 0 0,0 20,10M19,17H17V19H15V17H13V15H15V13H17V15H19V17Z" />
</Grid>
</UserControl>
25 changes: 25 additions & 0 deletions ModMyFactoryGUI/Controls/Icons/ExpandAllIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2020-2021 Mathis Rech
//
// 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.

using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace ModMyFactoryGUI.Controls.Icons
{
internal class ExpandAllIcon : UserControl
{
public ExpandAllIcon()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
7 changes: 7 additions & 0 deletions ModMyFactoryGUI/ViewModels/ModpackViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public bool IsRenaming
}
}

public bool IsExpanded
{
get => _isExpanded;
set => this.RaiseAndSetIfChanged(ref _isExpanded, value);
}

// Store information for fuzzy search
public bool MatchesSearch { get; private set; } = true;

Expand Down Expand Up @@ -118,6 +124,7 @@ public void ApplyFuzzyFilter(in string filter)
#region IDisposable Support

private bool _disposed = false;
private bool _isExpanded = false;

private void Dispose(bool disposing)
{
Expand Down
16 changes: 14 additions & 2 deletions ModMyFactoryGUI/Views/ManagerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ the Free Software Foundation, either version 3 of the License, or
<Border Grid.Column="2" Grid.Row="0" Margin="0,4,4,4" Background="{DynamicResource ThemeAccentBrush2}">
<DockPanel Margin="4,2">
<CheckBox DockPanel.Dock="Left" VerticalAlignment="Center" IsChecked="{Binding AllModpacksEnabled, Mode=TwoWay}" />
<TextBlock Margin="6,0,2,0" VerticalAlignment="Center" Classes="h2" FontWeight="SemiBold" Text="{l:LocalizedResource ModpacksHeader}" />
<Button Click="ExpandAllModpacks_OnClick" DockPanel.Dock="Right" >
<StackPanel Orientation="Horizontal">
<icons:ExpandAllIcon HorizontalAlignment="Center" />
<TextBlock Margin="4" Text="{l:LocalizedResource ExpandAll}" TextAlignment="Center" />
</StackPanel>
</Button>
<Button DockPanel.Dock="Right" Margin="4,0" Click="CollapseAllModpacks_OnClick" >
<StackPanel Orientation="Horizontal">
<icons:CollapseAllIcon HorizontalAlignment="Center" />
<TextBlock Margin="4" Text="{l:LocalizedResource CollapseAll}" TextAlignment="Center" />
</StackPanel>
</Button>
<TextBlock Margin="6,0,2,0" DockPanel.Dock="Left" VerticalAlignment="Center" Classes="h2" FontWeight="SemiBold" Text="{l:LocalizedResource ModpacksHeader}" />
</DockPanel>
</Border>

Expand All @@ -125,7 +137,7 @@ the Free Software Foundation, either version 3 of the License, or
PreviewPointerMoved="PointerMovedHandler" DragOver="DragOverHandler" Drop="DropHandler">
<controls:DragDropListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:ModpackViewModel}">
<Expander Background="Transparent">
<Expander Background="Transparent" IsExpanded="{Binding IsExpanded}">

<Expander.Header>
<Grid ColumnDefinitions="Auto,Auto,Auto,Auto,*">
Expand Down
25 changes: 25 additions & 0 deletions ModMyFactoryGUI/Views/ManagerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.LogicalTree;

namespace ModMyFactoryGUI.Views
{
Expand Down Expand Up @@ -240,5 +241,29 @@ public void ScrollModpackIntoView(ModpackViewModel vm)
var listBox = this.FindControl<ListBox>("ModpackList");
listBox.ScrollIntoView(vm);
}

private void ExpandAllModpacks_OnClick(object? sender, RoutedEventArgs e)
{
var listBox = this.FindControl<ListBox>("ModpackList");
foreach (var modpack in listBox.Items)
{
if (modpack is ModpackViewModel modpackVm)
{
modpackVm.IsExpanded = true;
}
}
}

private void CollapseAllModpacks_OnClick(object? sender, RoutedEventArgs e)
{
var listBox = this.FindControl<ListBox>("ModpackList");
foreach (var modpack in listBox.Items)
{
if (modpack is ModpackViewModel modpackVm)
{
modpackVm.IsExpanded = false;
}
}
}
}
}
8 changes: 8 additions & 0 deletions ModMyFactoryGUI/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@
"type": "string",
"value": "Alt+F4"
},
"CollapseAll": {
"type": "string",
"value": "Collapse all"
},
"ExpandAll": {
"type": "string",
"value": "Expand all"
},

// Edit menu
"EditMenuItem": {
Expand Down