From 731403c66566be5cad659df494322dcc8b550e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Mon, 1 Oct 2018 21:06:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=B8?= =?UTF-8?q?=D1=82.=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20=D0=B2=D0=B8=D0=B4=D0=B5=20=D0=B4=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B:=20fillChildNode,?= =?UTF-8?q?=20handleSearchBtn=5Fclick.=20=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fileFinder/Form1.cs | 47 --------- ...Form1.Designer.cs => MainForm.Designer.cs} | 60 ++++++----- fileFinder/MainForm.cs | 99 +++++++++++++++++++ fileFinder/{Form1.resx => MainForm.resx} | 0 fileFinder/fileFinder.csproj | 10 +- 5 files changed, 132 insertions(+), 84 deletions(-) delete mode 100644 fileFinder/Form1.cs rename fileFinder/{Form1.Designer.cs => MainForm.Designer.cs} (81%) create mode 100644 fileFinder/MainForm.cs rename fileFinder/{Form1.resx => MainForm.resx} (100%) diff --git a/fileFinder/Form1.cs b/fileFinder/Form1.cs deleted file mode 100644 index 0bafe76..0000000 --- a/fileFinder/Form1.cs +++ /dev/null @@ -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 = ""; - } - } - - - - - } -} diff --git a/fileFinder/Form1.Designer.cs b/fileFinder/MainForm.Designer.cs similarity index 81% rename from fileFinder/Form1.Designer.cs rename to fileFinder/MainForm.Designer.cs index 8ffdad9..f7f2103 100644 --- a/fileFinder/Form1.Designer.cs +++ b/fileFinder/MainForm.Designer.cs @@ -28,18 +28,12 @@ /// 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.dirSelectBtn = new System.Windows.Forms.Button(); this.curDirTextBox = new System.Windows.Forms.TextBox(); 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.bottomPanel = new System.Windows.Forms.Panel(); this.infoLabel = new System.Windows.Forms.Label(); @@ -55,17 +49,7 @@ this.resultViewer.Dock = System.Windows.Forms.DockStyle.Top; this.resultViewer.Location = new System.Drawing.Point(0, 0); this.resultViewer.Name = "resultViewer"; - treeNode1.Name = "Node 1"; - 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.Size = new System.Drawing.Size(800, 342); this.resultViewer.TabIndex = 3; // // dirSelectBtn @@ -84,7 +68,7 @@ this.curDirTextBox.Name = "curDirTextBox"; this.curDirTextBox.Size = new System.Drawing.Size(650, 20); 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); // // splitContainer @@ -96,27 +80,37 @@ // // 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.innerQueryTextBox); this.splitContainer.Panel1.Controls.Add(this.queryTextBox); this.splitContainer.Panel1.Controls.Add(this.curDirTextBox); // // splitContainer.Panel2 // - this.splitContainer.Panel2.Controls.Add(this.bottomPanel); 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.SplitterDistance = 66; + this.splitContainer.SplitterDistance = 88; 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.handleSearch.Name = "handleSearch"; - this.handleSearch.Size = new System.Drawing.Size(120, 21); - this.handleSearch.TabIndex = 2; - this.handleSearch.Text = "Start/Pause"; - this.handleSearch.UseVisualStyleBackColor = true; + this.innerQueryTextBox.Location = new System.Drawing.Point(11, 65); + this.innerQueryTextBox.Name = "innerQueryTextBox"; + this.innerQueryTextBox.Size = new System.Drawing.Size(776, 20); + this.innerQueryTextBox.TabIndex = 1; + this.innerQueryTextBox.Tag = ""; // // queryTextBox // @@ -125,13 +119,14 @@ this.queryTextBox.Size = new System.Drawing.Size(650, 20); this.queryTextBox.TabIndex = 1; this.queryTextBox.Tag = ""; + this.queryTextBox.Text = "*.txt"; // // bottomPanel // this.bottomPanel.AutoSize = true; this.bottomPanel.Controls.Add(this.infoLabel); 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.Size = new System.Drawing.Size(800, 13); this.bottomPanel.TabIndex = 4; @@ -173,10 +168,11 @@ private System.Windows.Forms.Button dirSelectBtn; private System.Windows.Forms.TextBox curDirTextBox; 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.Label infoLabel; private System.Windows.Forms.TextBox queryTextBox; + private System.Windows.Forms.TextBox innerQueryTextBox; } } diff --git a/fileFinder/MainForm.cs b/fileFinder/MainForm.cs new file mode 100644 index 0000000..99153b2 --- /dev/null +++ b/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 foundFiles = new List(); + TreeNode itemsNode = new TreeNode(); + + try + { + foundFiles = Directory.GetFiles(curDirTextBox.Text, queryTextBox.Text, SearchOption.AllDirectories).ToList(); + } 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); + } + + + } +} diff --git a/fileFinder/Form1.resx b/fileFinder/MainForm.resx similarity index 100% rename from fileFinder/Form1.resx rename to fileFinder/MainForm.resx diff --git a/fileFinder/fileFinder.csproj b/fileFinder/fileFinder.csproj index 00a202e..91c32c1 100644 --- a/fileFinder/fileFinder.csproj +++ b/fileFinder/fileFinder.csproj @@ -45,16 +45,16 @@ - + Form - - Form1.cs + + MainForm.cs - - Form1.cs + + MainForm.cs ResXFileCodeGenerator