Skip to content

Commit 5f9775d

Browse files
committed
add searchable extensions textbox, fix folder history saving
1 parent 1b6f3f1 commit 5f9775d

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

FindInFiles/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<setting name="windowHeight" serializeAs="String">
1717
<value>420</value>
1818
</setting>
19+
<setting name="extensionList" serializeAs="String">
20+
<value>*.txt|*.shader|*.cs|*.log|*.js|*.cginc|*.rtf</value>
21+
</setting>
1922
</FindInFiles.Properties.Settings>
2023
</userSettings>
2124
</configuration>

FindInFiles/MainWindow.xaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:local="clr-namespace:FindInFiles"
77
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="FindInFiles.MainWindow"
88
mc:Ignorable="d"
9-
Title="FindInFiles" Height="392.388" Width="781.747" Icon="findinfiles.ico"
9+
Title="FindInFiles" Height="462.843" Width="781.747" Icon="findinfiles.ico"
1010
Closed="OnExit"
1111
>
1212
<Grid Margin="1,0,-1,0">
@@ -17,9 +17,12 @@
1717
<Button x:Name="btnBrowse" Content="..." HorizontalAlignment="Left" Margin="686,28,0,0" VerticalAlignment="Top" Width="75" Click="btnBrowse_Click" Height="22"/>
1818
<DataGrid x:Name="gridResults" HorizontalAlignment="Left" Height="294" Margin="11,58,0,0" VerticalAlignment="Top" Width="754" MouseDoubleClick="gridResults_MouseDoubleClick" IsReadOnly="True" IsTabStop="True" TabIndex="2"/>
1919
<ComboBox x:Name="cmbSearch" HorizontalAlignment="Left" Margin="10,28,0,0" VerticalAlignment="Top" Width="227" KeyDown="OnKeyDownSearch" IsEditable="True" DropDownClosed="cmbSearch_DropDownClosed" IsSynchronizedWithCurrentItem="True" IsTabStop="True" TabIndex="0" Loaded="cmbSearch_Loaded" />
20-
<ComboBox x:Name="cmbFolder" HorizontalAlignment="Left" Margin="356,28,0,0" VerticalAlignment="Top" KeyDown="OnKeyDownFolder" Width="325" IsEditable="True" IsTabStop="True" TabIndex="1"/>
21-
<Label Content="Search String" HorizontalAlignment="Left" Margin="6,8,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30"/>
22-
<Label Content="Folder" HorizontalAlignment="Left" Margin="351,8,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30"/>
20+
<ComboBox x:Name="cmbFolder" HorizontalAlignment="Left" Margin="356,28,0,0" VerticalAlignment="Top" KeyDown="OnKeyDownFolder" Width="325" IsEditable="True" IsTabStop="True" TabIndex="1" />
21+
<Label Content="Search String" HorizontalAlignment="Left" Margin="6,6,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30" FontWeight="Bold"/>
22+
<Label Content="Folder" HorizontalAlignment="Left" Margin="351,6,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30" FontWeight="Bold"/>
23+
<Label Content="Settings" HorizontalAlignment="Left" Margin="11,363,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30" FontWeight="Bold"/>
24+
<TextBox x:Name="txtExtensions" KeyUp="txtExtensions_KeyUp" LostFocus="OnLostFocusExtensions" HorizontalAlignment="Left" Height="23" Margin="84,399,0,0" TextWrapping="Wrap" Text="*.txt|*.shader|*.cs|*.log|*.js|*.cginc|*.rtf" VerticalAlignment="Top" Width="361"/>
25+
<Label Content="Extensions:" HorizontalAlignment="Left" Margin="11,395,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.026,0.308" Height="30"/>
2326

2427
</Grid>
2528
</Window>

FindInFiles/MainWindow.xaml.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace FindInFiles
1919
/// </summary>
2020
public partial class MainWindow : Window
2121
{
22-
string[] fileExtensions = new[] { "*.txt", "*.shader", "*.cs", "*.log", "*.js", "*.cging" , "*.rtf" };
22+
string[] fileExtensions;
2323
const int previewSnippetLength = 32;
2424
const int maxRecentItems = 32;
2525
bool isSearching = false;
@@ -45,6 +45,10 @@ void Start()
4545
this.Width = Properties.Settings.Default.windowWidth;
4646
this.Height = Properties.Settings.Default.windowHeight;
4747

48+
// get extensions
49+
txtExtensions.Text = Properties.Settings.Default.extensionList;
50+
RefreshExtensionsList();
51+
4852
// restore search history
4953
cmbSearch.ItemsSource = Properties.Settings.Default.recentSearches;
5054
cmbFolder.ItemsSource = Properties.Settings.Default.recentFolders;
@@ -79,6 +83,7 @@ void OnWindowClose(object sender, CancelEventArgs e)
7983
{
8084
Properties.Settings.Default.windowWidth = (int)this.Width;
8185
Properties.Settings.Default.windowHeight = (int)this.Height;
86+
Properties.Settings.Default.extensionList = txtExtensions.Text;
8287
Properties.Settings.Default.Save();
8388
}
8489

@@ -95,13 +100,14 @@ void AddSearchHistory(string searchString)
95100
Properties.Settings.Default.recentSearches = new StringCollection();
96101
}
97102

98-
// remove old items
103+
// remove old items if too many
99104
if (Properties.Settings.Default.recentSearches.Count > maxRecentItems)
100105
{
106+
Console.WriteLine("too many items, removing " + Properties.Settings.Default.recentSearches[0]);
101107
Properties.Settings.Default.recentSearches.RemoveAt(0);
102108
}
103109

104-
// skip if duplicate
110+
// skip if duplicate already in list
105111
if (Properties.Settings.Default.recentSearches.Contains(searchString) == false)
106112
{
107113
Properties.Settings.Default.recentSearches.Add(searchString);
@@ -212,6 +218,7 @@ void Search(string searchString, string sourceFolder)
212218
int searchLen = searchString.Length;
213219
if (searchLen < 2) return;
214220
AddSearchHistory(cmbSearch.Text);
221+
AddFolderHistory(cmbFolder.Text);
215222

216223
// validate folder
217224
if (Directory.Exists(sourceFolder) == false) return;
@@ -243,7 +250,6 @@ void SearchLoop(System.Object a)
243250
{
244251
if (isSearching == false)
245252
{
246-
Console.WriteLine("exit");
247253
break;
248254
}
249255
// brute-search, measure later..
@@ -298,6 +304,34 @@ private void OnExit(object sender, EventArgs e)
298304
isSearching = false;
299305
}
300306

307+
private void RefreshExtensionsList()
308+
{
309+
var newExtensions = txtExtensions.Text.Split('|');
310+
if (newExtensions != null && newExtensions.Length > 0)
311+
{
312+
fileExtensions = newExtensions;
313+
}
314+
else // use default list if nothing else
315+
{
316+
fileExtensions = new[] { "*.txt", "*.shader", "*.cs", "*.log", "*.js", "*.cginc", "*.rtf" };
317+
}
318+
}
319+
320+
private void OnLostFocusExtensions(object sender, EventArgs e)
321+
{
322+
RefreshExtensionsList();
323+
}
324+
325+
// enter pressed in extensions textbox
326+
private void txtExtensions_KeyUp(object sender, KeyEventArgs e)
327+
{
328+
if (e.Key == Key.Enter)
329+
{
330+
RefreshExtensionsList();
331+
cmbSearch.Focus();
332+
}
333+
}
334+
301335
} // class
302336
} // namespace
303337

FindInFiles/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FindInFiles/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<Setting Name="recentFolders" Type="System.Collections.Specialized.StringCollection" Scope="User">
1515
<Value Profile="(Default)" />
1616
</Setting>
17+
<Setting Name="extensionList" Type="System.String" Scope="User">
18+
<Value Profile="(Default)">*.txt|*.shader|*.cs|*.log|*.js|*.cginc|*.rtf</Value>
19+
</Setting>
1720
</Settings>
1821
</SettingsFile>

0 commit comments

Comments
 (0)