Skip to content

Commit

Permalink
feat: Local and global file search
Browse files Browse the repository at this point in the history
  • Loading branch information
aiguoli committed Jan 14, 2024
1 parent 2c700de commit ace1b70
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SimpleList is a OneDrive files index application developed using WinUI3.

Unzip and then double click

# Sttings
# Settings

Modify `SimpleList/appsettings.json` to customize the configuration.

Expand All @@ -34,7 +34,7 @@ Modify `SimpleList/appsettings.json` to customize the configuration.
- [x] i18n
- [x] Tools page

# Screenshots
# Screenshots(may not be the latest version)

![HomePage](./ScreenShots/HomePage.png)
![CloudPage](./ScreenShots/CloudPage.png)
Expand Down
4 changes: 2 additions & 2 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OneDrive

解压后双击打开

# Sttings
# 配置

修改`SimpleList/appsettings.json`可以自定义ClientID等配置。

Expand Down Expand Up @@ -38,7 +38,7 @@ OneDrive

WinForms,WPF太老了,Avalonia坑太多了用不明白,HTML+CSS+JS的框架又太大,Iced和Slint生态不知道怎样,不敢上手,遂选用WinUI3,发现写起来很爽,文档也比较完整。第一次写桌面端和WinUI3,权当练手项目了。

# 截图
# 截图(可能不是最新版本)

![HomePage](./ScreenShots/HomePage.png)
![CloudPage](./ScreenShots/CloudPage.png)
Expand Down
11 changes: 8 additions & 3 deletions SimpleList/Pages/DrivePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@
<KeyboardAccelerator Modifiers="Menu" Key="Right" />
</BreadcrumbBar.KeyboardAccelerators>
</BreadcrumbBar>
<Button x:Name="RefreshButton" Command="{Binding RefreshCommand}" RelativePanel.AlignRightWithPanel="True">
<FontIcon Glyph="&#xE72C;" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Button>
<StackPanel Orientation="Horizontal" RelativePanel.AlignRightWithPanel="True">
<Button Margin="0 0 5 0" Click="ShowSearchDialogAsync">
<FontIcon Glyph="&#xE721;" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Button>
<Button x:Name="RefreshButton" Command="{Binding RefreshCommand}">
<FontIcon Glyph="&#xE72C;" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Button>
</StackPanel>
</RelativePanel>
<ContentControl Grid.Row="2"
x:Name="CloudControl"
Expand Down
10 changes: 10 additions & 0 deletions SimpleList/Pages/DrivePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,15 @@ private async void BackToLastFolder(KeyboardAccelerator sender, KeyboardAccelera
items.RemoveAt(items.Count - 1);
await (DataContext as DriveViewModel).GetFiles(items.Last().ItemId);
}

private async void ShowSearchDialogAsync(object sender, RoutedEventArgs e)
{
SearchView dialog = new()
{
XamlRoot = XamlRoot,
DataContext = new SearchViewModel(DataContext as DriveViewModel)
};
await dialog.ShowAsync();
}
}
}
5 changes: 0 additions & 5 deletions SimpleList/Services/OneDrive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,5 @@ public static void SaveTokenCache()
public string ClientId;
// used for identify account for now
public string HomeAccountId;
public enum SearchType
{
Part,
Global,
}
}
}
6 changes: 5 additions & 1 deletion SimpleList/SimpleList.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<AssemblyName>SimpleList</AssemblyName>
<Authors>Thawne</Authors>
<PackageProjectUrl>https://github.com/aiguoli/SimpleList</PackageProjectUrl>
<AssemblyVersion>1.11.4</AssemblyVersion>
<AssemblyVersion>1.12.0</AssemblyVersion>
<ApplicationIcon>Assets\favicon.ico</ApplicationIcon>
<PackageIcon>128.png</PackageIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -65,6 +65,7 @@
<None Remove="Views\Preview\MediaPreviewView.xaml" />
<None Remove="Views\PropertyView.xaml" />
<None Remove="Views\RenameFileView.xaml" />
<None Remove="Views\SearchView.xaml" />
<None Remove="Views\ShareFileView.xaml" />
<None Remove="Views\Tools\CreateLink.xaml" />
<None Remove="Views\Tools\LinkDetails.xaml" />
Expand Down Expand Up @@ -121,6 +122,9 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<Page Update="Views\SearchView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\Preview\MediaPreviewView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
15 changes: 15 additions & 0 deletions SimpleList/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@
<data name="RootFileName" xml:space="preserve">
<value>Home</value>
</data>
<data name="SearchView.Title" xml:space="preserve">
<value>Search File</value>
</data>
<data name="SearchView_FileName.Header" xml:space="preserve">
<value>FileName</value>
</data>
<data name="SearchView_Mode.Header" xml:space="preserve">
<value>SearchMode</value>
</data>
<data name="SearchView_Mode_Global.Content" xml:space="preserve">
<value>Global</value>
</data>
<data name="SearchView_Mode_Local.Content" xml:space="preserve">
<value>Local</value>
</data>
<data name="SettingPage_AboutTitle.Text" xml:space="preserve">
<value>About</value>
</data>
Expand Down
18 changes: 15 additions & 3 deletions SimpleList/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@
<data name="RootFileName" xml:space="preserve">
<value>根目录</value>
</data>
<data name="SearchView.Title" xml:space="preserve">
<value>搜索文件</value>
</data>
<data name="SearchView_FileName.Header" xml:space="preserve">
<value>文件名</value>
</data>
<data name="SearchView_Mode.Header" xml:space="preserve">
<value>搜索模式</value>
</data>
<data name="SearchView_Mode_Global.Content" xml:space="preserve">
<value>全局</value>
</data>
<data name="SearchView_Mode_Local.Content" xml:space="preserve">
<value>当前目录</value>
</data>
<data name="SettingPage_AboutTitle.Text" xml:space="preserve">
<value>关于</value>
</data>
Expand Down Expand Up @@ -261,9 +276,6 @@
<data name="ShareCommunityPage_Flyout_Refresh.Text" xml:space="preserve">
<value>刷新</value>
</data>
<data name="String1" xml:space="preserve">
<value />
</data>
<data name="TaskManagerPage_Pivot_Download.Header" xml:space="preserve">
<value>下载</value>
</data>
Expand Down
28 changes: 28 additions & 0 deletions SimpleList/ViewModels/DriveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SimpleList.Models;
using SimpleList.Services;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleList.ViewModels
Expand Down Expand Up @@ -58,6 +59,33 @@ public async Task OpenFolder(FileViewModel file)
await GetFiles(file.Id);
}

[RelayCommand]
public async Task SearchFile(string fileName)
{
IsLoading = Visibility.Visible;
var files = await Provider.SearchGlobalItems(fileName);
Files.Clear();
Images.Clear();
files.Value.ForEach(file =>
{
FileViewModel newFile = new(this, file);
Files.Add(newFile);
if (file.Image != null)
Images.Add(newFile);
});
IsLoading = Visibility.Collapsed;
}

public void FilterByName(string name)
{
var filesToRemove = Files.Where(file => !file.Name.Contains(name)).ToList();
foreach (var file in filesToRemove)
{
Files.Remove(file);
Images.Remove(file);
}
}

private string _parentItemId = "Root";
[ObservableProperty] private Visibility _isLoading = Visibility.Collapsed;
[ObservableProperty] private string _storageInfo;
Expand Down
38 changes: 38 additions & 0 deletions SimpleList/ViewModels/SearchViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Threading.Tasks;

namespace SimpleList.ViewModels
{
public partial class SearchViewModel : ObservableObject
{
public SearchViewModel(DriveViewModel drive)
{
_drive = drive;
}

[RelayCommand]
private async Task Search()
{
if (string.IsNullOrEmpty(FileName))
return;
if (Mode == SearchMode.Local)
{
_drive.FilterByName(FileName);
} else
{
await _drive.SearchFile(FileName);
}
}

public enum SearchMode
{
Local,
Global,
}

private readonly DriveViewModel _drive;
[ObservableProperty] private string _fileName;
[ObservableProperty] private SearchMode _mode;
}
}
18 changes: 1 addition & 17 deletions SimpleList/Views/RenameFileView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace SimpleList.Views
{
public sealed partial class RenameFileView : ContentDialog
{
public RenameFileView()
{
this.InitializeComponent();
InitializeComponent();
}
}
}
24 changes: 24 additions & 0 deletions SimpleList/Views/SearchView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentDialog
x:Class="SimpleList.Views.SearchView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:SimpleList.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Uid="SearchView"
d:DataContext="{x:Bind vm:SearchViewModel}"
PrimaryButtonText="OK"
CloseButtonText="Cancel"
DefaultButton="Primary"
PrimaryButtonCommand="{Binding SearchCommand}">

<StackPanel>
<ComboBox x:Uid="SearchView_Mode" SelectedIndex="{Binding Mode, Mode=TwoWay}" Loaded="LoadDefaultValue">
<ComboBoxItem Content="Local" />
<ComboBoxItem Content="Global" />
</ComboBox>
<TextBox x:Uid="SearchView_FileName" Text="{Binding FileName, Mode=TwoWay}" />
</StackPanel>
</ContentDialog>
20 changes: 20 additions & 0 deletions SimpleList/Views/SearchView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.UI.Xaml.Controls;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace SimpleList.Views
{
public sealed partial class SearchView : ContentDialog
{
public SearchView()
{
InitializeComponent();
}

private void LoadDefaultValue(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
(sender as ComboBox).SelectedIndex = 0;
}
}
}

0 comments on commit ace1b70

Please sign in to comment.