Skip to content

Commit

Permalink
Merge pull request #46 from xiaomi7732/dev/saars/small-touches
Browse files Browse the repository at this point in the history
Dev/saars/small touches
  • Loading branch information
xiaomi7732 authored Jan 29, 2022
2 parents a74913b + 551341d commit 799bd92
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 15 deletions.
50 changes: 50 additions & 0 deletions CodeNameK/src/CodeNameK.ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -98,6 +100,8 @@ public MainViewModel(
IsSyncEnabled = _userPreferenceService.UserPreference.EnableSync;
EnableSyncCommand = new AsyncRelayCommand(EnableSyncAsync, p => !IsSyncEnabled, exceptionCallback: _errorRevealerFactory.CreateInstance($"Unhandled Exception Invoking {nameof(EnableSyncCommand)}").Reveal);
DisableSyncCommand = new AsyncRelayCommand(DisableSyncAsync, p => IsSyncEnabled, exceptionCallback: _errorRevealerFactory.CreateInstance($"Unhandled Exception Invoking {nameof(DisableSyncCommand)}").Reveal);
ShowDataFolderPathCommand = new RelayCommand(ShowDataFolderPath);
OpenUriCommand = new RelayCommand(OpenUri);

SelectedDateRangeOption = DateRangeOptions.First();
_selectedDateRangeOption = SelectedDateRangeOption;
Expand Down Expand Up @@ -225,10 +229,23 @@ public string DataFolderPath
{
_dataFolderPath = value;
RaisePropertyChanged();
RaisePropertyChanged(nameof(DataFolderShortName));
}
}
}

public string? DataFolderShortName
{
get
{
if (string.IsNullOrEmpty(DataFolderPath))
{
return null;
}
return Path.GetFileName(DataFolderPath);
}
}

private DataPoint? _hoverPoint;
public DataPointViewModel SelectedDataPoint { get; }

Expand Down Expand Up @@ -646,6 +663,39 @@ private async Task DisableSyncAsync(object? parameter)
await _userPreferenceService.DisableSyncAsync(default).ConfigureAwait(false);
}

public ICommand ShowDataFolderPathCommand { get; }
private void ShowDataFolderPath()
{
string path = DataFolderPath;
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
{
try
{
Process.Start("explorer.exe", DataFolderPath);
}
catch (Exception ex)
{
_errorRevealerFactory.CreateInstance().Reveal(ex);
}
}
}

public ICommand OpenUriCommand { get; }
public void OpenUri(object? uri)
{
if (uri is string uriString)
{
if (Uri.TryCreate(uriString, UriKind.Absolute, out Uri targetUri))
{
Process.Start(new ProcessStartInfo()
{
FileName = targetUri.AbsoluteUri,
UseShellExecute = true,
});
}
}
}

private async Task RequestInitialSync()
{
if (_initialSyncRequested)
Expand Down
5 changes: 5 additions & 0 deletions CodeNameK/src/CodeNameK.ViewModels/RelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public event EventHandler? CanExecuteChanged
remove { CommandManager.RequerySuggested -= value; }
}

public RelayCommand(Action execute)
{
_execute = (value) => execute();
}

public RelayCommand(Action<object?> execute, Func<object?, bool>? canExecute = null)
{
_execute = execute;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CodeNameK/src/CodeNameK.WPF/Assets/ArrowsUp64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CodeNameK/src/CodeNameK.WPF/Assets/Idea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CodeNameK/src/CodeNameK.WPF/Assets/icon128.ico
Binary file not shown.
File renamed without changes
12 changes: 8 additions & 4 deletions CodeNameK/src/CodeNameK.WPF/CodeNameK.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRunEmitSymbols>true</PublishReadyToRunEmitSymbols>
<ApplicationIcon>Assets\icon128.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DEBUG'">
<OutputType>Exe</OutputType>
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
</PropertyGroup>
<ItemGroup>
<Resource Include="Assets\icon128.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeNameK.ViewModels\CodeNameK.ViewModels.csproj" />
<!-- <ProjectReference Include="..\..\..\..\fork-WpfToolkit\WpfToolkit\WPF.Themes\DotNetProjects.WPF.Themes.csproj" /> -->
<!-- <ProjectReference Include="..\..\..\..\fork-livechart-2\src\skiasharp\LiveChartsCore.SkiaSharp.WPF\LiveChartsCore.SkiaSharpView.WPF.csproj" /> -->

</ItemGroup>
Expand All @@ -38,8 +41,9 @@
<None Include="appsettings.debug.jsonc" CopyToOutputDirectory="PreserveNewest" Condition="'$(Configuration)'=='Debug'" />
</ItemGroup>
<ItemGroup>
<None Remove="icon128.png" />
<Resource Include="icon128.png" />
<Resource Include="Assets\ArrowsDown64.png" />
<Resource Include="Assets\ArrowsUp64.png" />
<Resource Include="Assets\Idea.png" />
<Resource Include="Assets\icon128.png" />
</ItemGroup>

</Project>
32 changes: 21 additions & 11 deletions CodeNameK/src/CodeNameK.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CodeNameK.WPF"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" TextElement.Foreground="{DynamicResource MaterialDesignBody}" Background="{DynamicResource MaterialDesignPaper}" TextElement.FontWeight="Normal" TextElement.FontSize="14" mc:Ignorable="d"
Title="NumberIt" Height="800" Width="1024" Icon="/icon128.png">
Title="NumberIt" Height="800" Width="1024" Icon="/Assets/icon128.png">
<Window.Resources>
<DataTemplate x:Key="categoryItemTemplate">
<TextBlock Text="{Binding Id}" ToolTip="{Binding Id}" />
Expand All @@ -16,11 +16,19 @@
<MenuItem Header="_Sync" Command="{Binding SyncCommand}" />
<MenuItem Header="_Cancel Sign In" Command="{Binding CancelSignInCommand}" />
<Separator />
<MenuItem Header="_Exit" Command="{Binding ExitCommand}" />
<MenuItem Header="E_xit" Command="{Binding ExitCommand}" />
</MenuItem>
<MenuItem Header="_Options">
<MenuItem Header="_Enable Sync" Command="{Binding EnableSyncCommand}" Visibility="{Binding IsSyncEnabled, Converter={StaticResource InverseBoolToVisConverter}}" />
<MenuItem Header="_Disable Sync" Command="{Binding DisableSyncCommand}" Visibility="{Binding IsSyncEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" />
<MenuItem Header="Enable _Sync" Command="{Binding EnableSyncCommand}" Visibility="{Binding IsSyncEnabled, Converter={StaticResource InverseBoolToVisConverter}}" />
<MenuItem Header="Disable _Sync" Command="{Binding DisableSyncCommand}" Visibility="{Binding IsSyncEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" />
</MenuItem>
<MenuItem Header="Abou_t">
<MenuItem Header="_GitHub" Command="{Binding OpenUriCommand}" CommandParameter="https://github.com/xiaomi7732/CodeWithSaar/tree/main/CodeNameK" />
<MenuItem Header="_YouTube" Command="{Binding OpenUriCommand}" CommandParameter="https://www.youtube.com/c/CodewithSaar" />
<MenuItem Header="Twitter (@_CodeWithSaar)" Command="{Binding OpenUriCommand}" CommandParameter="https://twitter.com/codewithsaar" />
<MenuItem Header="Twitter (@_SaarShen)" Command="{Binding OpenUriCommand}" CommandParameter="https://twitter.com/saarshen" />
<MenuItem Header="_Buy me a coffee" Command="{Binding OpenUriCommand}" CommandParameter="https://www.buymeacoffee.com/codewithsaar" />
<MenuItem Header="_Discord" Command="{Binding OpenUriCommand}" CommandParameter="https://discord.com/invite/H8ZqDgczQb" />
</MenuItem>
</Menu>
<!--Status bar-->
Expand All @@ -29,7 +37,9 @@
<TextBlock Text="Data Folder: " />
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="{Binding DataFolderPath}" />
<Hyperlink NavigateUri="{Binding DataFolderPath}" Command="{Binding ShowDataFolderPathCommand}">
<TextBlock Text="{Binding DataFolderShortName}" ToolTip="Click to open data folder." />
</Hyperlink>
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="Sync Status:" />
Expand All @@ -50,13 +60,13 @@
<TextBlock Text="{Binding UpSyncStateText}" />
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="U:" />
<Image Source="/Assets/ArrowsUp64.png" Stretch="Fill" Width="16" Height="16" ToolTip="Uploading Count" />
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="{Binding UpSyncQueueLength}" />
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="D:" />
<Image Source="/Assets/ArrowsDown64.png" Stretch="Fill" Width="16" Height="16" ToolTip="Downloading Count" />
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="{Binding DownSyncQueueLength}" />
Expand Down Expand Up @@ -145,16 +155,16 @@
<Button Grid.Column="2" ToolTip="Use mouse scroller to zoom in. Click here to reset zoom." Command="{Binding ResetZoomCommand}"
Style="{StaticResource MaterialDesignFlatButton}">_Reset Zoom</Button>
<TextBlock Grid.Column="3" Margin="0 0 8 0" VerticalAlignment="Center">
<Bold>> Tips</Bold>
<Image Source="/Assets/Idea.png" Width="20" Stretch="Uniform" />
<TextBlock.ToolTip>
<StackPanel Orientation="Vertical">
<TextBlock>
<Bold>Mouse wheel</Bold>
to zoom in/out.
to zoom in/out. (5 more points)
</TextBlock>
<TextBlock>
<Bold>Click down + move</Bold>
to move the chart.
<Bold>Click down + ◀️/▶️</Bold>
to move the chart when zoomed in.
</TextBlock>
<TextBlock>
<Bold>Ctrl+Click</Bold>
Expand Down

0 comments on commit 799bd92

Please sign in to comment.