Skip to content

Commit

Permalink
Add Resize windows, work in progress. Update languages. Fix file dupl…
Browse files Browse the repository at this point in the history
…ication loading. Refactor code.
  • Loading branch information
Ruben2776 committed Oct 22, 2024
1 parent 89ccce2 commit 6ba5bb5
Show file tree
Hide file tree
Showing 37 changed files with 722 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
Height="28"
LineHeight="28"
Padding="30,0,0,0"
Text="{CompiledBinding Resize,
Text="{CompiledBinding ResizeImage,
Mode=OneWay}"
TextAlignment="Center"
x:Name="TitleText" />
Expand All @@ -93,8 +93,6 @@
<views:SingleImageResizeView
Background="{DynamicResource NoisyTexture}"
Focusable="True"
Margin="0"
Padding="10,2,5,10"
PointerPressed="MoveWindow" />
</StackPanel>
</Border>
Expand Down
26 changes: 16 additions & 10 deletions src/PicView.Avalonia/Navigation/ImageIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class ImageIterator : IDisposable
private PreLoader PreLoader { get; } = new();

private static FileSystemWatcher? _watcher;
private static bool _isRunning;
public bool IsRunning { get; private set; }
private readonly MainViewModel? _vm;

#endregion
Expand Down Expand Up @@ -100,13 +100,13 @@ private async Task OnFileAdded(FileSystemEventArgs e)
}

var retries = 0;
while (_isRunning && retries < 10)
while (IsRunning && retries < 10)
{
await Task.Delay(200);
retries++;
}

_isRunning = true;
IsRunning = true;

var newList = await Task.FromResult(_vm.PlatformService.GetFiles(fileInfo));
if (newList.Count == 0)
Expand All @@ -126,7 +126,7 @@ private async Task OnFileAdded(FileSystemEventArgs e)

ImagePaths = newList;

_isRunning = false;
IsRunning = false;

var index = ImagePaths.IndexOf(e.FullPath);
if (index < 0)
Expand Down Expand Up @@ -192,12 +192,12 @@ private async Task OnFileDeleted(FileSystemEventArgs e)
return;
}

if (_isRunning)
if (IsRunning)
{
return;
}

_isRunning = true;
IsRunning = true;
var index = ImagePaths.IndexOf(e.FullPath);
if (index < 0)
{
Expand Down Expand Up @@ -268,7 +268,7 @@ private async Task OnFileDeleted(FileSystemEventArgs e)


FileHistoryNavigation.Remove(e.FullPath);
_isRunning = false;
IsRunning = false;

SetTitleHelper.SetTitle(_vm);
if (cleared)
Expand All @@ -289,12 +289,12 @@ private async Task OnFileRenamed(RenamedEventArgs e)
return;
}

if (_isRunning)
if (IsRunning)
{
return;
}

_isRunning = true;
IsRunning = true;

var oldIndex = ImagePaths.IndexOf(e.OldFullPath);
var sameFile = CurrentIndex == oldIndex;
Expand Down Expand Up @@ -336,7 +336,7 @@ private async Task OnFileRenamed(RenamedEventArgs e)

SetTitleHelper.SetTitle(_vm);

_isRunning = false;
IsRunning = false;
FileHistoryNavigation.Rename(e.OldFullPath, e.FullPath);
GalleryFunctions.RemoveGalleryItem(oldIndex, _vm);
await GalleryFunctions.AddGalleryItem(index, fileInfo, _vm);
Expand Down Expand Up @@ -416,6 +416,12 @@ public async Task ReloadFileList()
InitiateFileSystemWatcher(InitialFileInfo);
}

public async Task QuickReload()
{
RemoveCurrentItemFromPreLoader();
await IterateToIndex(CurrentIndex).ConfigureAwait(false);
}

public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false)
{
int next;
Expand Down
12 changes: 12 additions & 0 deletions src/PicView.Avalonia/Navigation/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ public static async Task LoadPicFromFile(string fileName, MainViewModel vm, File
{
if (fileInfo.DirectoryName == vm.ImageIterator.InitialFileInfo.DirectoryName)
{
// Need to wait for the file watching to add it to the list
var retries = 0;
while (vm.ImageIterator.IsRunning && retries < 10)
{
await Task.Delay(50).ConfigureAwait(false);
retries++;
if (retries > 10)
{
await ErrorHandling.ReloadAsync(vm);
return;
}
}
var index = vm.ImageIterator.ImagePaths.IndexOf(fileName);
if (index != -1)
{
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Avalonia/Navigation/Preloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized, false);
}

private void Dispose(bool disposing)
Expand Down
3 changes: 2 additions & 1 deletion src/PicView.Avalonia/PicViewTheme/Classes.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="2" />
<Setter Property="CaretBrush" Value="{DynamicResource MainTextColor}" />
<Setter Property="Margin" Value="5,0,0,0" />
<Setter Property="Padding" Value="5,9,0,7" />
<Setter Property="Width" Value="180" />
<Setter Property="CaretBrush" Value="{StaticResource SecondaryTextColor}" />
<Setter Property="SelectionForegroundBrush" Value="{StaticResource SecondaryTextColor}" />
</Style>
</Styles>
33 changes: 33 additions & 0 deletions src/PicView.Avalonia/PicViewTheme/Controls/Button.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,39 @@
<Setter Property="Background" Value="{DynamicResource AccentColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>

<Style Selector="^.accentHover:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style.Animations>
<Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
<KeyFrame>
<Setter Property="Foreground">
<SolidColorBrush Color="{StaticResource SecondaryTextColor}" />
</Setter>
<Setter Property="Background">
<SolidColorBrush Color="{DynamicResource AccentColor}" />
</Setter>
<Setter Property="BorderBrush">
<SolidColorBrush Color="{DynamicResource MainBorderColor}" />
</Setter>
</KeyFrame>
<KeyFrame Cue="1">
<Setter Property="Foreground">
<SolidColorBrush Color="#fff" />
</Setter>
<Setter Property="Background">
<SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
</Setter>
<Setter Property="BorderBrush">
<SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
</Setter>
</KeyFrame>
</Animation>
</Style.Animations>
<Setter Property="Foreground" Value="#fff" />
<Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
</Style>

<Style Selector="^.errorHover:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style.Animations>
<Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
Expand Down
3 changes: 2 additions & 1 deletion src/PicView.Avalonia/PicViewTheme/Controls/ComboBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
Focusable="False"
IsChecked="{TemplateBinding IsDropDownOpen,
Mode=TwoWay}"
Name="toggle">
Name="toggle"
Theme="{StaticResource NoneTemplate}">
<Panel>
<ContentControl
Content="{TemplateBinding SelectionBoxItem}"
Expand Down
8 changes: 8 additions & 0 deletions src/PicView.Avalonia/PicViewTheme/Controls/Menu.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@
<Setter Property="CornerRadius" Value="0,0,6,6" />
</Style>

<Style Selector="^.noCornerRadius:nth-child(1) /template/ Border#root">
<Setter Property="CornerRadius" Value="0" />
</Style>

<Style Selector="^.noCornerRadius:nth-last-child(1) /template/ Border#root">
<Setter Property="CornerRadius" Value="0" />
</Style>

<Style Selector="^:empty /template/ Path#rightArrow">
<Setter Property="IsVisible" Value="False" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^.noCornerRadius /template/ Border#LayoutRoot">
<Setter Property="CornerRadius" Value="0" />
</Style>
</ControlTheme>
</ResourceDictionary>
85 changes: 76 additions & 9 deletions src/PicView.Avalonia/PicViewTheme/Controls/RadioButton.axaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,89 @@
<ResourceDictionary
x:ClassModifier="internal"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:ClassModifier="internal">
<ControlTheme x:Key="{x:Type RadioButton}" TargetType="RadioButton">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme TargetType="RadioButton" x:Key="{x:Type RadioButton}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
<Setter Property="BorderThickness" Value="1" />

<Setter Property="Template">
<ControlTemplate>
<Grid Background="{TemplateBinding Background}" ColumnDefinitions="Auto,*">
<Border
Background="{DynamicResource TertiaryBackgroundColor}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
CornerRadius="6"
Height="18"
Name="border"
VerticalAlignment="Center"
Width="18" />
<Ellipse
Fill="#fff"
Grid.Column="0"
Height="10"
HorizontalAlignment="Center"
IsVisible="False"
Name="checkMark"
Stretch="Uniform"
VerticalAlignment="Center"
Width="10" />
<Border
Background="Transparent"
CornerRadius="6"
Grid.Column="0"
Height="10"
HorizontalAlignment="Center"
Name="indeterminateMark"
UseLayoutRounding="False"
VerticalAlignment="Center"
Width="10" />
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Column="1"
Margin="6,0,0,0"
Name="PART_ContentPresenter"
RecognizesAccessKey="True"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter>

<Style Selector="^:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
</Style>
<Style Selector="^:checked /template/ Border#border">
<Setter Property="Background" Value="{DynamicResource AccentColor}" />
</Style>

<Style Selector="^ /template/ Border#indeterminateMark">
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^:checked /template/ Ellipse#checkMark">
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^:indeterminate /template/ Border#indeterminateMark">
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^:disabled /template/ Border#border">
<Setter Property="Opacity" Value="{StaticResource ThemeDisabledOpacity}" />
</Style>
</ControlTheme>

<ControlTheme TargetType="RadioButton" x:Key="NoneTemplate">
<Setter Property="Template">
<ControlTemplate>
<Panel Background="{TemplateBinding Background}">

<ContentPresenter
Name="PART_ContentPresenter"
Margin="4,0,0,0"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
RecognizesAccessKey="True" />
Margin="4,0,0,0"
Name="PART_ContentPresenter"
RecognizesAccessKey="True"
VerticalAlignment="Center" />
</Panel>
</ControlTemplate>
</Setter>
Expand Down
Loading

0 comments on commit 6ba5bb5

Please sign in to comment.