Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New options for search #112

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/SmartCommander/Assets/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/SmartCommander/Assets/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,22 @@
<data name="MenuSearch" xml:space="preserve">
<value>_Rechercher</value>
</data>
<data name="SearchTopDirectoryOnly" xml:space="preserve">
<value>Rechercher dans le répertoire supérieur uniquement</value>
</data>
<data name="SearchFileContent" xml:space="preserve">
<value>Rechercher dans le contenu du fichier</value>
</data>
<data name="Header" xml:space="preserve">
<value>En-tête</value>
</data>
<data name="Operation" xml:space="preserve">
<value>Opération</value>
</data>
<data name="Language" xml:space="preserve">
<value>Langue</value>
</data>
<data name="Plugins" xml:space="preserve">
<value>Plugins</value>
</data>
</root>
18 changes: 18 additions & 0 deletions src/SmartCommander/Assets/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,22 @@
<data name="MenuSearch" xml:space="preserve">
<value>_Search</value>
</data>
<data name="SearchTopDirectoryOnly" xml:space="preserve">
<value>Search in top directory only</value>
</data>
<data name="SearchFileContent" xml:space="preserve">
<value>Search in file content</value>
</data>
<data name="Header" xml:space="preserve">
<value>Header</value>
</data>
<data name="Operation" xml:space="preserve">
<value>Operation</value>
</data>
<data name="Language" xml:space="preserve">
<value>Language</value>
</data>
<data name="Plugins" xml:space="preserve">
<value>Plugins</value>
</data>
</root>
52 changes: 35 additions & 17 deletions src/SmartCommander/Assets/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,46 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="mimetype" type="xsd:string"/>
<xsd:attribute ref="xml:space"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="alias" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
<xsd:attribute ref="xml:space"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:choice>
Expand Down Expand Up @@ -324,4 +324,22 @@
<data name="MenuSearch" xml:space="preserve">
<value>_Поиск</value>
</data>
<data name="SearchTopDirectoryOnly" xml:space="preserve">
<value>Искать только в основной папке</value>
</data>
<data name="SearchFileContent" xml:space="preserve">
<value>Искать в содержимом файлов</value>
</data>
<data name="Header" xml:space="preserve">
<value>Заголовок</value>
</data>
<data name="Operation" xml:space="preserve">
<value>Операция</value>
</data>
<data name="Language" xml:space="preserve">
<value>Язык</value>
</data>
<data name="Plugins" xml:space="preserve">
<value>Плагины</value>
</data>
</root>
18 changes: 18 additions & 0 deletions src/SmartCommander/Assets/Resources.sr-Cyrl-RS.resx
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,22 @@
<data name="MenuSearch" xml:space="preserve">
<value>_Тражи</value>
</data>
<data name="SearchTopDirectoryOnly" xml:space="preserve">
<value>Тражи само у горњем директоријуму</value>
</data>
<data name="SearchFileContent" xml:space="preserve">
<value>Тражи садржај датотеке</value>
</data>
<data name="Header" xml:space="preserve">
<value>Заглавље</value>
</data>
<data name="Operation" xml:space="preserve">
<value>Операција</value>
</data>
<data name="Language" xml:space="preserve">
<value>Језик</value>
</data>
<data name="Plugins" xml:space="preserve">
<value>Допуне</value>
</data>
</root>
18 changes: 18 additions & 0 deletions src/SmartCommander/Assets/Resources.sr-Latn-ME.resx
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,22 @@
<data name="MenuSearch" xml:space="preserve">
<value>_Traži</value>
</data>
<data name="SearchTopDirectoryOnly" xml:space="preserve">
<value>Traži samo u gornjem direktorijumu</value>
</data>
<data name="SearchFileContent" xml:space="preserve">
<value>Traži sadržaj datoteke</value>
</data>
<data name="Header" xml:space="preserve">
<value>Zaglavlje</value>
</data>
<data name="Operation" xml:space="preserve">
<value>Operacija</value>
</data>
<data name="Language" xml:space="preserve">
<value>Jezik</value>
</data>
<data name="Plugins" xml:space="preserve">
<value>Dopune</value>
</data>
</root>
55 changes: 42 additions & 13 deletions src/SmartCommander/ViewModels/FileSearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public string CurrentFolder

public string StatusFolder { get; set; } = "";

public bool TopDirectoryOnly { get; set; }

public bool SearchContent { get; set; }

public string SearchText { get; set; } = "";

public string FileMask
{
get => _fileMask;
Expand Down Expand Up @@ -55,25 +61,48 @@ public FileSearchViewModel(string folder = "")
}

public async Task<bool> SearchAsync(string folderPath, string searchPattern, CancellationToken cancellationToken)
{
{
try
{
cancellationToken.ThrowIfCancellationRequested();

_statusFolder = folderPath;
List<string> findedFolderAndFiles = new List<string>();
var findedFolderAndFiles = new List<string>();

var dirs = Directory.GetDirectories(folderPath, searchPattern, SearchOption.TopDirectoryOnly);
findedFolderAndFiles.AddRange(dirs);
string[] files = Directory.GetFiles(folderPath, searchPattern);
findedFolderAndFiles.AddRange(files);
SearchResults.AddRange(findedFolderAndFiles);

string[] subDirectories = Directory.GetDirectories(folderPath);
foreach (var subDir in subDirectories)
if (SearchContent)
{
var files = Directory.GetFiles(folderPath, "*", SearchOption.TopDirectoryOnly);
foreach(var file in files)
{
cancellationToken.ThrowIfCancellationRequested();
foreach (string line in File.ReadLines(file))
{
if (line.Contains(searchPattern))
{
SearchResults.Add(file);
break;
}
}
}

}
else
{
var dirs = Directory.GetDirectories(folderPath, searchPattern, SearchOption.TopDirectoryOnly);
findedFolderAndFiles.AddRange(dirs);
var files = Directory.GetFiles(folderPath, searchPattern);
findedFolderAndFiles.AddRange(files);
SearchResults.AddRange(findedFolderAndFiles);
}

if (!TopDirectoryOnly)
{
cancellationToken.ThrowIfCancellationRequested();
await SearchAsync(subDir, searchPattern, cancellationToken);
var subDirectories = Directory.GetDirectories(folderPath);
foreach (var subDir in subDirectories)
{
cancellationToken.ThrowIfCancellationRequested();
await SearchAsync(subDir, searchPattern, cancellationToken);
}
}
}
catch (OperationCanceledException e)
Expand Down Expand Up @@ -101,7 +130,7 @@ private async Task StartSearch()
SearchResults.Clear();
_cancellationTokenSource = new CancellationTokenSource();
_timer = new Timer(OnTimerTick, null, 0, 500);
await Task.Run(() => SearchAsync(CurrentFolder, FileMask, _cancellationTokenSource.Token));
await Task.Run(() => SearchAsync(CurrentFolder, SearchContent ? SearchText : FileMask, _cancellationTokenSource.Token));

_statusFolder = "";
IsSearching = false;
Expand Down
23 changes: 15 additions & 8 deletions src/SmartCommander/Views/FileSearchWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
Title="{x:Static assets:Resources.FilesSearch}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid Grid.Row="0">
Expand All @@ -26,15 +26,22 @@
</Grid.RowDefinitions>

<StackPanel Margin="5">
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0" Text="{x:Static assets:Resources.FileName}"/>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding FileMask, Mode=TwoWay}"/>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0" Text="{x:Static assets:Resources.CurrentFolder}"/>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding CurrentFolder, Mode=TwoWay}"/>
<TextBlock Text="{x:Static assets:Resources.FileName}"/>
<TextBox IsEnabled="{Binding ElementName=contentCheckBox, Path=!IsChecked}" Text="{Binding FileMask, Mode=TwoWay}"/>
<CheckBox Name="contentCheckBox" IsChecked="{Binding SearchContent, Mode=TwoWay}"
Content="{x:Static assets:Resources.SearchFileContent}"></CheckBox>
<TextBox IsEnabled="{Binding ElementName=contentCheckBox, Path=IsChecked}" Text="{Binding SearchText, Mode=TwoWay}" />
<TextBlock Text="{x:Static assets:Resources.CurrentFolder}"/>
<TextBox Text="{Binding CurrentFolder, Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding TopDirectoryOnly, Mode=TwoWay}"
Content="{x:Static assets:Resources.SearchTopDirectoryOnly}"></CheckBox>
</StackPanel>

<StackPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Orientation="Vertical" VerticalAlignment="Center">
<Button Content="{x:Static assets:Resources.StartSearch}" Command="{Binding StartSearchCommand}" IsEnabled="{Binding !IsSearching}"/>
<Button Content="{x:Static assets:Resources.Cancel}" Command="{Binding CancelSearchCommand}" IsEnabled="{Binding IsSearching}"/>
<Button Content="{x:Static assets:Resources.StartSearch}" Margin="5"
Command="{Binding StartSearchCommand}" IsEnabled="{Binding !IsSearching}"/>
<Button Content="{x:Static assets:Resources.Cancel}" Margin="5"
Command="{Binding CancelSearchCommand}" IsEnabled="{Binding IsSearching}"/>
</StackPanel>
</Grid>

Expand Down
Loading
Loading