Skip to content

Commit

Permalink
Merge branch 'main' into features/addons-enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky authored Jan 26, 2024
2 parents f166440 + fe884e0 commit 30c708e
Show file tree
Hide file tree
Showing 18 changed files with 429 additions and 32 deletions.
3 changes: 3 additions & 0 deletions SkEditor/API/ISkEditorAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SkEditor.Utilities;
using SkEditor.Views;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SkEditor.API;
Expand Down Expand Up @@ -42,6 +43,8 @@ public interface ISkEditorAPI
public bool IsAddonEnabled(string addonName);

public void SaveData();

public List<TextEditor> GetOpenedEditors();


#region Events
Expand Down
1 change: 1 addition & 0 deletions SkEditor/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<sty:FluentAvaloniaTheme />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="/Views/FileTypes/Images/AdvancedImageBox.axaml"/>
<StyleInclude Source="/Styles/ButtonStyles.axaml"></StyleInclude>
</Application.Styles>

<Application.Resources>
Expand Down
26 changes: 3 additions & 23 deletions SkEditor/Controls/SideBarControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,11 @@
</Style>
</UserControl.Styles>

<Grid ColumnDefinitions="auto,auto" RowDefinitions="*">
<Grid Name="GridPanels" ColumnDefinitions="auto,auto" RowDefinitions="*">
<Border Grid.Column="0" Width="36" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7">
<StackPanel Spacing="10" HorizontalAlignment="Center">
<Button Name="ProjectsButton" Height="36" Width="36" Classes="barButton">
<Button.Content>
<ui:SymbolIcon Symbol="Folder" FontSize="24" Foreground="#bfffffff" />
</Button.Content>
</Button>
<StackPanel Name="Buttons" Spacing="10" HorizontalAlignment="Center">

</StackPanel>
</Border>

<Border Name="ExtendedSideBar" Grid.Column="1" Width="0" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7" Margin="10,0,0,0">
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Width" Duration="0:0:0.05" Easing="QuadraticEaseIn"/>
</Transitions>
</Border.Transitions>

<Grid RowDefinitions="auto,auto,*">
<TextBlock Grid.Row="0" Text="Explorer" FontWeight="DemiBold" Margin="20,10,20,10"/>
<Separator Grid.Row="1" Margin="0,0,0,10"/>
<TreeView Grid.Row="2" Name="FileTreeView">

</TreeView>
</Grid>
</Border>
</Grid>
</UserControl>
85 changes: 78 additions & 7 deletions SkEditor/Controls/SideBarControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,94 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Media;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using SkEditor.Controls.Sidebar;
using SkEditor.Utilities;

namespace SkEditor.Controls;
public partial class SideBarControl : UserControl
{
private static readonly List<SidebarPanel> Panels = new();

public readonly ExplorerSidebarPanel.ExplorerPanel ProjectPanel = new();

public static void RegisterPanel(SidebarPanel panel)
{
Panels.Add(panel);
}

private SidebarPanel? _currentPanel;
public SideBarControl()
{
InitializeComponent();

RegisterPanel(ProjectPanel);
}

AssignCommands();
public void LoadPanels()
{
foreach (SidebarPanel panel in Panels)
{
var btn = CreatePanelButton(panel);
var content = panel.Content;
content.Width = 0;

btn.Command = new RelayCommand(() =>
{
if (_currentPanel == panel)
{
_currentPanel.Content.Width = 0; // Close current panel
_currentPanel.OnClose();
_currentPanel = null;
return;
}
if (panel.IsDisabled)
return;
if (_currentPanel != null)
{
_currentPanel.OnClose();
_currentPanel.Content.Width = 0; // Close current panel
_currentPanel = null;
}
_currentPanel = panel;
_currentPanel.Content.Width = 250;
_currentPanel.OnOpen();
});

GridPanels.Children.Add(content);
Grid.SetColumn(content, 1);

Buttons.Children.Add(btn);
}
}

private void AssignCommands()
private Button CreatePanelButton(SidebarPanel panel)
{
ProjectsButton.Command = new RelayCommand(() =>
var icon = panel.Icon;
if (icon is SymbolIconSource symbolIcon) symbolIcon.FontSize = 24;
IconSourceElement iconElement = new()
{
IconSource = icon,
Width = 24,
Height = 24,
Foreground = new SolidColorBrush(Color.Parse("#bfffffff")),
};

Button button = new()
{
ScrollViewer.SetHorizontalScrollBarVisibility(FileTreeView, Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled);
ScrollViewer.SetVerticalScrollBarVisibility(FileTreeView, Avalonia.Controls.Primitives.ScrollBarVisibility.Auto);
ExtendedSideBar.Width = ExtendedSideBar.Width == 0 ? 250 : 0;
});
Height = 36,
Width = 36,
Classes = { "barButton" },
Content = iconElement,
IsEnabled = !panel.IsDisabled,
};

return button;
}
}
37 changes: 37 additions & 0 deletions SkEditor/Controls/Sidebar/ExplorerSidebarPanel.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<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:ui="using:FluentAvalonia.UI.Controls"
x:Class="SkEditor.Controls.Sidebar.ExplorerSidebarPanel">

<UserControl.Styles>
<Style Selector="Button.barButton">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
<Style Selector="Separator">
<Setter Property="Margin" Value="0,1"/>
</Style>
<Style Selector="TreeViewItem">
<Setter Property="FontWeight" Value="Regular"/>
</Style>
</UserControl.Styles>

<Border Name="ExtendedSideBar" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7" Margin="10,0,0,0">
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Width" Duration="0:0:0.05" Easing="QuadraticEaseIn"/>
</Transitions>
</Border.Transitions>

<Grid RowDefinitions="auto,auto,*">
<TextBlock Grid.Row="0" Text="Explorer" FontWeight="DemiBold" Margin="20,10,20,10"/>
<Separator Grid.Row="1" Margin="0,0,0,10"/>
<TreeView Grid.Row="2" Name="FileTreeView">

</TreeView>
</Grid>
</Border>
</UserControl>
24 changes: 24 additions & 0 deletions SkEditor/Controls/Sidebar/ExplorerSidebarPanel.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using FluentAvalonia.UI.Controls;
using SkEditor.Utilities;

namespace SkEditor.Controls.Sidebar;

public partial class ExplorerSidebarPanel : UserControl
{
public ExplorerSidebarPanel()
{
InitializeComponent();
}

public class ExplorerPanel : SidebarPanel
{
public override UserControl Content => Panel;
public override IconSource Icon => new SymbolIconSource() { Symbol = Symbol.Folder };
public override bool IsDisabled => false;

public readonly ExplorerSidebarPanel Panel = new ();
}
}
4 changes: 4 additions & 0 deletions SkEditor/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<system:String x:Key="SettingsGeneralTitle">General</system:String>
<system:String x:Key="SettingsGeneralLanguage">Language</system:String>
<system:String x:Key="SettingsGeneralWrapping">Wrapping</system:String>
<system:String x:Key="SettingsGeneralTabType">Indentation Type</system:String>
<system:String x:Key="SettingsGeneralTabTypeDescription">Choose between tabs and spaces, and set the size of the tab.</system:String>
<system:String x:Key="SettingsGeneralTabTypeTabs">Tabs</system:String>
<system:String x:Key="SettingsGeneralTabTypeSpaces">Spaces</system:String>
<system:String x:Key="SettingsGeneralAutoIndent">Auto-indent</system:String>
<system:String x:Key="SettingsGeneralAutoIndentDescription">Automatically inserts a tab in a new line if the previous line ends with a colon.</system:String>
<system:String x:Key="SettingsGeneralAutoPairing">Auto-pairing</system:String>
Expand Down
8 changes: 8 additions & 0 deletions SkEditor/SkEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ public void SaveData()
GetAppConfig().Save();
}

public List<TextEditor> GetOpenedEditors()
{
return GetTabView().TabItems
.OfType<TabViewItem>()
.Select(x => x.Content as TextEditor)
.Where(editor => editor != null)
.ToList();
}


#region Events
Expand Down
2 changes: 2 additions & 0 deletions SkEditor/SkEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
</Compile>
<Compile Update="Views\FileTypes\Images\ImageViewer.axaml.cs">
<DependentUpon>ImageViewer.axaml</DependentUpon>
<Compile Update="Controls\Sidebar\CodeParser\ParserSidebarPanel.axaml.cs">
<DependentUpon>ParserSidebarPanel.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
Expand Down
Loading

0 comments on commit 30c708e

Please sign in to comment.