Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Nov 27, 2020
1 parent aa5bbbf commit c653550
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 39 deletions.
10 changes: 0 additions & 10 deletions src/AssemblyInfo.cs

This file was deleted.

30 changes: 14 additions & 16 deletions src/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@ public static List<Item> GetItems(string searchText)
Everything_Query(true);
uint count = Everything_GetNumResults();

if (count > 100)
count = 100;
if (count > 1000)
count = 1000;

for (uint i = 0; i < count; i++)
{
try {
Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity);
string path = sb.ToString();
Everything_GetResultSize(i, out var size);
Everything_GetResultDateModified(i, out var fileTime);

items.Add(new Item() {
Directory = Path.GetDirectoryName(path),
Name = Path.GetFileName(path),
Size = size,
Date = DateTime.FromFileTime(fileTime)
});
} catch {}
Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity);
string path = sb.ToString();
Everything_GetResultSize(i, out var size);
Everything_GetResultDateModified(i, out var fileTime);

items.Add(new Item() {
Directory = Path.GetDirectoryName(path),
Name = Path.GetFileName(path),
Size = size,
Date = DateTime.FromFileTime(fileTime)
});
}
return items;
}
Expand All @@ -60,7 +58,7 @@ public static List<Item> GetItems(string searchText)
[DllImport("Everything.dll")]
static extern void Everything_SetSort(UInt32 dwSortType);

[DllImport("Everything.dll", CharSet = CharSet.Unicode)]
[DllImport("Everything.dll")]
static extern bool Everything_Query(bool bWait);

[DllImport("Everything.dll", CharSet = CharSet.Unicode)]
Expand Down
21 changes: 21 additions & 0 deletions src/TypeAssistant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

using System;
using System.Threading;

public class TypeAssistant
{
public event Action<string> Idled;
string Text;
Timer WaitingTimer;

public TypeAssistant()
{
WaitingTimer = new Timer(p => Idled(Text));
}

public void TextChanged(string text)
{
Text = text;
WaitingTimer.Change(500, Timeout.Infinite);
}
}
3 changes: 1 addition & 2 deletions src/View.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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:local="clr-namespace:EverythingFrontend"
xmlns:glob="clr-namespace:System.Globalization;assembly=mscorlib"
Style="{StaticResource {x:Type Window}}"
mc:Ignorable="d"
Expand All @@ -25,7 +24,7 @@
Margin="20"
Padding="2"
FontSize="14"
Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" >
</TextBox>

<DataGrid AutoGenerateColumns="False"
Expand Down
38 changes: 27 additions & 11 deletions src/ViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@

using System;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;

namespace EverythingFrontend
{
class ViewModel : ViewModelBase
{
public ObservableCollection<Item> Items { get; } = new ObservableCollection<Item>();
TypeAssistant TypeAssistant;

public ViewModel()
{
TypeAssistant = new TypeAssistant();
TypeAssistant.Idled += TypeAssistant_Idled;
Task.Run(() => Update(""));
}

private List<Item> ItemsValue;

public List<Item> Items {
get => ItemsValue;
set {
ItemsValue = value;
OnPropertyChanged();
}
}

string SearchTextValue;

public string SearchText {
get => SearchTextValue;
set {
SearchTextValue = value;
Update();
TypeAssistant.TextChanged(value);
}
}

void Update()
{
Items.Clear();
void TypeAssistant_Idled(string text) => Update(text);

foreach (var item in Model.GetItems(SearchText))
Items.Add(item);
void Update(string text)
{
List<Item> items = Model.GetItems(text);
Application.Current.Dispatcher.Invoke(() => Items = items);
}
}
}

0 comments on commit c653550

Please sign in to comment.