Browse Source

Первый рабочий комит. Реализовано отображение найденных файлов в виде дерева. Добавлены следующие методы: fillChildNode, handleSearchBtn_click. Немного рефакторинга.

release
Никита 6 years ago
parent
commit
731403c665
  1. 47
      fileFinder/Form1.cs
  2. 60
      fileFinder/MainForm.Designer.cs
  3. 99
      fileFinder/MainForm.cs
  4. 0
      fileFinder/MainForm.resx
  5. 10
      fileFinder/fileFinder.csproj

47
fileFinder/Form1.cs

@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace fileFinder
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void dirSelectBtn_Click(object sender, EventArgs e)
{
using (var dialog = new FolderBrowserDialog())
{
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK && !String.IsNullOrWhiteSpace(dialog.SelectedPath))
{
curDirTextBox.Text = dialog.SelectedPath;
hintHided = true;
}
}
}
bool hintHided = false;
private void curDirTextBox_Enter(object sender, EventArgs e)
{
if (!hintHided)
{
hintHided = true;
curDirTextBox.Text = "";
}
}
}
}

60
fileFinder/Form1.Designer.cs → fileFinder/MainForm.Designer.cs

@ -28,18 +28,12 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("Node 1");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("Узел3");
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("Узел4");
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("Root node", new System.Windows.Forms.TreeNode[] {
treeNode1,
treeNode2,
treeNode3});
this.resultViewer = new System.Windows.Forms.TreeView(); this.resultViewer = new System.Windows.Forms.TreeView();
this.dirSelectBtn = new System.Windows.Forms.Button(); this.dirSelectBtn = new System.Windows.Forms.Button();
this.curDirTextBox = new System.Windows.Forms.TextBox(); this.curDirTextBox = new System.Windows.Forms.TextBox();
this.splitContainer = new System.Windows.Forms.SplitContainer(); this.splitContainer = new System.Windows.Forms.SplitContainer();
this.handleSearch = new System.Windows.Forms.Button(); this.handleSearchBtn = new System.Windows.Forms.Button();
this.innerQueryTextBox = new System.Windows.Forms.TextBox();
this.queryTextBox = new System.Windows.Forms.TextBox(); this.queryTextBox = new System.Windows.Forms.TextBox();
this.bottomPanel = new System.Windows.Forms.Panel(); this.bottomPanel = new System.Windows.Forms.Panel();
this.infoLabel = new System.Windows.Forms.Label(); this.infoLabel = new System.Windows.Forms.Label();
@ -55,17 +49,7 @@
this.resultViewer.Dock = System.Windows.Forms.DockStyle.Top; this.resultViewer.Dock = System.Windows.Forms.DockStyle.Top;
this.resultViewer.Location = new System.Drawing.Point(0, 0); this.resultViewer.Location = new System.Drawing.Point(0, 0);
this.resultViewer.Name = "resultViewer"; this.resultViewer.Name = "resultViewer";
treeNode1.Name = "Node 1"; this.resultViewer.Size = new System.Drawing.Size(800, 342);
treeNode1.Text = "Node 1";
treeNode2.Name = "Узел3";
treeNode2.Text = "Узел3";
treeNode3.Name = "Узел4";
treeNode3.Text = "Узел4";
treeNode4.Name = "Root";
treeNode4.Text = "Root node";
this.resultViewer.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode4});
this.resultViewer.Size = new System.Drawing.Size(800, 358);
this.resultViewer.TabIndex = 3; this.resultViewer.TabIndex = 3;
// //
// dirSelectBtn // dirSelectBtn
@ -84,7 +68,7 @@
this.curDirTextBox.Name = "curDirTextBox"; this.curDirTextBox.Name = "curDirTextBox";
this.curDirTextBox.Size = new System.Drawing.Size(650, 20); this.curDirTextBox.Size = new System.Drawing.Size(650, 20);
this.curDirTextBox.TabIndex = 1; this.curDirTextBox.TabIndex = 1;
this.curDirTextBox.Text = "Choose or enter folder location"; this.curDirTextBox.Text = "C:\\Users\\itsmy_000\\Desktop\\a\\";
this.curDirTextBox.Enter += new System.EventHandler(this.curDirTextBox_Enter); this.curDirTextBox.Enter += new System.EventHandler(this.curDirTextBox_Enter);
// //
// splitContainer // splitContainer
@ -96,27 +80,37 @@
// //
// splitContainer.Panel1 // splitContainer.Panel1
// //
this.splitContainer.Panel1.Controls.Add(this.handleSearch); this.splitContainer.Panel1.Controls.Add(this.handleSearchBtn);
this.splitContainer.Panel1.Controls.Add(this.dirSelectBtn); this.splitContainer.Panel1.Controls.Add(this.dirSelectBtn);
this.splitContainer.Panel1.Controls.Add(this.innerQueryTextBox);
this.splitContainer.Panel1.Controls.Add(this.queryTextBox); this.splitContainer.Panel1.Controls.Add(this.queryTextBox);
this.splitContainer.Panel1.Controls.Add(this.curDirTextBox); this.splitContainer.Panel1.Controls.Add(this.curDirTextBox);
// //
// splitContainer.Panel2 // splitContainer.Panel2
// //
this.splitContainer.Panel2.Controls.Add(this.bottomPanel);
this.splitContainer.Panel2.Controls.Add(this.resultViewer); this.splitContainer.Panel2.Controls.Add(this.resultViewer);
this.splitContainer.Panel2.Controls.Add(this.bottomPanel);
this.splitContainer.Size = new System.Drawing.Size(800, 450); this.splitContainer.Size = new System.Drawing.Size(800, 450);
this.splitContainer.SplitterDistance = 66; this.splitContainer.SplitterDistance = 88;
this.splitContainer.TabIndex = 4; this.splitContainer.TabIndex = 4;
// //
// handleSearch // handleSearchBtn
//
this.handleSearchBtn.Location = new System.Drawing.Point(667, 38);
this.handleSearchBtn.Name = "handleSearchBtn";
this.handleSearchBtn.Size = new System.Drawing.Size(120, 21);
this.handleSearchBtn.TabIndex = 2;
this.handleSearchBtn.Text = "Start/Pause";
this.handleSearchBtn.UseVisualStyleBackColor = true;
this.handleSearchBtn.Click += new System.EventHandler(this.handleSearchBtn_Click);
//
// innerQueryTextBox
// //
this.handleSearch.Location = new System.Drawing.Point(667, 38); this.innerQueryTextBox.Location = new System.Drawing.Point(11, 65);
this.handleSearch.Name = "handleSearch"; this.innerQueryTextBox.Name = "innerQueryTextBox";
this.handleSearch.Size = new System.Drawing.Size(120, 21); this.innerQueryTextBox.Size = new System.Drawing.Size(776, 20);
this.handleSearch.TabIndex = 2; this.innerQueryTextBox.TabIndex = 1;
this.handleSearch.Text = "Start/Pause"; this.innerQueryTextBox.Tag = "";
this.handleSearch.UseVisualStyleBackColor = true;
// //
// queryTextBox // queryTextBox
// //
@ -125,13 +119,14 @@
this.queryTextBox.Size = new System.Drawing.Size(650, 20); this.queryTextBox.Size = new System.Drawing.Size(650, 20);
this.queryTextBox.TabIndex = 1; this.queryTextBox.TabIndex = 1;
this.queryTextBox.Tag = ""; this.queryTextBox.Tag = "";
this.queryTextBox.Text = "*.txt";
// //
// bottomPanel // bottomPanel
// //
this.bottomPanel.AutoSize = true; this.bottomPanel.AutoSize = true;
this.bottomPanel.Controls.Add(this.infoLabel); this.bottomPanel.Controls.Add(this.infoLabel);
this.bottomPanel.Dock = System.Windows.Forms.DockStyle.Bottom; this.bottomPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bottomPanel.Location = new System.Drawing.Point(0, 367); this.bottomPanel.Location = new System.Drawing.Point(0, 345);
this.bottomPanel.Name = "bottomPanel"; this.bottomPanel.Name = "bottomPanel";
this.bottomPanel.Size = new System.Drawing.Size(800, 13); this.bottomPanel.Size = new System.Drawing.Size(800, 13);
this.bottomPanel.TabIndex = 4; this.bottomPanel.TabIndex = 4;
@ -173,10 +168,11 @@
private System.Windows.Forms.Button dirSelectBtn; private System.Windows.Forms.Button dirSelectBtn;
private System.Windows.Forms.TextBox curDirTextBox; private System.Windows.Forms.TextBox curDirTextBox;
private System.Windows.Forms.SplitContainer splitContainer; private System.Windows.Forms.SplitContainer splitContainer;
private System.Windows.Forms.Button handleSearch; private System.Windows.Forms.Button handleSearchBtn;
private System.Windows.Forms.Panel bottomPanel; private System.Windows.Forms.Panel bottomPanel;
private System.Windows.Forms.Label infoLabel; private System.Windows.Forms.Label infoLabel;
private System.Windows.Forms.TextBox queryTextBox; private System.Windows.Forms.TextBox queryTextBox;
private System.Windows.Forms.TextBox innerQueryTextBox;
} }
} }

99
fileFinder/MainForm.cs

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace fileFinder
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
try
{
ImageList iconList = new ImageList();
iconList.Images.Add(Image.FromFile("Folder.png")); // 0
iconList.Images.Add(Image.FromFile("OpenedFolder.png")); // 1
iconList.Images.Add(Image.FromFile("File.png")); // 2
iconList.Images.Add(Image.FromFile("Search.png")); // 3
resultViewer.ImageList = iconList;
resultViewer.ImageIndex = 3;
resultViewer.SelectedImageIndex = 3;
} catch { }
}
private void dirSelectBtn_Click(object sender, EventArgs e)
{
using (var dialog = new FolderBrowserDialog())
{
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK && !String.IsNullOrWhiteSpace(dialog.SelectedPath))
{
curDirTextBox.Text = dialog.SelectedPath;
hintHided = true;
}
}
}
bool hintHided = false;
private void curDirTextBox_Enter(object sender, EventArgs e)
{
if (!hintHided)
{
hintHided = true;
curDirTextBox.Text = "";
}
}
private void handleSearchBtn_Click(object sender, EventArgs e)
{
resultViewer.Nodes.Clear();
List<String> foundFiles = new List<String>();
TreeNode itemsNode = new TreeNode();
try
{
foundFiles = Directory.GetFiles(curDirTextBox.Text, queryTextBox.Text, SearchOption.AllDirectories).ToList<String>();
} catch { }
foreach (String item in foundFiles)
fillChildNode(itemsNode, item.Replace(curDirTextBox.Text, ""));
resultViewer.Nodes.Add(itemsNode);
}
public void fillChildNode (TreeNode node, String item)
{
int backSlashIndex = item.IndexOf("\\");
if (backSlashIndex > -1)
{
if (backSlashIndex == 0)
{
item = item.Remove(0, 1);
backSlashIndex = item.IndexOf("\\");
}
String currentNodeName = item.Substring(0, backSlashIndex);
int nodeIndex = node.Nodes.IndexOfKey(currentNodeName);
if (nodeIndex != -1)
fillChildNode(node.Nodes[nodeIndex], item.Remove(0, backSlashIndex + 1));
else
{
node.Nodes.Add(currentNodeName, currentNodeName, 0, 0);
nodeIndex = node.Nodes.IndexOfKey(currentNodeName);
fillChildNode(node.Nodes[nodeIndex], item.Remove(0, backSlashIndex + 1));
}
} else
node.Nodes.Add(item, item, 2, 2);
}
}
}

0
fileFinder/Form1.resx → fileFinder/MainForm.resx

10
fileFinder/fileFinder.csproj

@ -45,16 +45,16 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs"> <Compile Include="MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Form1.Designer.cs"> <Compile Include="MainForm.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="MainForm.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>

Loading…
Cancel
Save