Advertisement
Roland-2

SnipTree

Nov 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.26 KB | None | 0 0
  1.  Dim NodesThatMatch As New List(Of TreeNode)
  2.  
  3.     Private Function SearchTheTreeView(ByVal TV As TreeView, ByVal TextToFind As String) As TreeNode
  4.         '  Empty previous
  5.         NodesThatMatch.Clear()
  6.  
  7.         ' Keep calling RecursiveSearch
  8.         For Each TN As TreeNode In TV.Nodes
  9.             If TN.Text = TextToFind Then
  10.                 NodesThatMatch.Add(TN)
  11.             End If
  12.  
  13.             RecursiveSearch(TN, TextToFind)
  14.         Next
  15.  
  16.         If NodesThatMatch.Count > 0 Then
  17.             Return NodesThatMatch(0)
  18.         Else
  19.             Return Nothing
  20.         End If
  21.  
  22.     End Function
  23.  
  24.  
  25.     Private Sub RecursiveSearch(ByVal treeNode As TreeNode, ByVal TextToFind As String)
  26.  
  27.         ' Keep calling the test recursively.
  28.         For Each TN As TreeNode In treeNode.Nodes
  29.             If TN.Text = TextToFind Then
  30.                 NodesThatMatch.Add(TN)
  31.             End If
  32.  
  33.             RecursiveSearch(TN, TextToFind)
  34.         Next
  35.     End Sub
  36.  
  37.  
  38.  
  39.  
  40.  
  41.     Dim GoPlaceHolder As String = ""
  42.  
  43.  
  44.  
  45.     Private Sub btnexpand_Click(sender As Object, e As EventArgs) Handles btnexpand.Click
  46.  
  47.         If btnexpand.Text = CStr("CollapseAll") Then
  48.             btnexpand.Text = "ExpandAll"
  49.         Else
  50.             btnexpand.Text = CStr("CollapseAll")
  51.         End If
  52.         If btnexpand.Text = "CollapseAll" Then explorer_tree.ExpandAll()
  53.         If btnexpand.Text = "ExpandAll" Then explorer_tree.CollapseAll()
  54.     End Sub
  55.  
  56.  
  57.  
  58.     Private Sub btnsavetxt_Click(sender As Object, e As EventArgs) Handles btnsavetxt.Click
  59.         My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\snippettree_data\home\" + Txtenterpath.Text, hometxt.Text, False)
  60.     End Sub
  61.  
  62.  
  63.  
  64.     Private Sub btnnewfolder_Click(sender As Object, e As EventArgs) Handles btnnewfolder.Click
  65.         Dim di As DirectoryInfo
  66.         Dim plus As String = Txtenterpath.Text
  67.  
  68.         If plus.Length > 1 Then
  69.             di = New DirectoryInfo(home + "\" + plus)
  70.         Else
  71.             di = New DirectoryInfo(home)
  72.         End If
  73.  
  74.  
  75.         Dim sd As DirectoryInfo = di.CreateSubdirectory(Txtfoldername.Text)
  76.  
  77.         If Not Me.explorer_tree.SelectedNode Is Nothing Then
  78.             Me.explorer_tree.SelectedNode.Collapse()
  79.             Me.explorer_tree.SelectedNode.Expand()
  80.         Else
  81.  
  82.             Dim Pname As String = sd.ToString
  83.  
  84.             Dim names() As String = Pname.Split("\")
  85.             Dim count As Integer = names.Count - 1
  86.             For z As Integer = 0 To count
  87.                 btngo.PerformClick()
  88.  
  89.                 explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names(z))
  90.  
  91.  
  92.  
  93.             Next
  94.         End If
  95.     End Sub
  96.  
  97.  
  98.  
  99.  
  100.     Private Sub btnBinfolder_Click(sender As Object, e As EventArgs) Handles btnbinfolder.Click
  101.         Dim snode2 As TreeNode = Me.explorer_tree.SelectedNode
  102.         Dim vCurrentPath As String = GetFullPathForTreeNode(snode2)
  103.         Dim Extension As String = Path.GetExtension(vCurrentPath)
  104.  
  105.         If Not Extension = ".txt" Or Extension = ".snippet" Then
  106.             My.Computer.FileSystem.DeleteDirectory(Application.StartupPath + "\snippettree_data\home\" + Txtenterpath.Text, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
  107.         End If
  108.  
  109.         Dim parentf As String = dirictoryparentname1(vCurrentPath)
  110.  
  111.         Txtenterpath.Text = parentf
  112.  
  113.         explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, parentf)
  114.  
  115.  
  116.         If Not Me.explorer_tree.SelectedNode Is Nothing Then
  117.             Me.explorer_tree.SelectedNode.Collapse()
  118.             Me.explorer_tree.SelectedNode.Expand()
  119.         Else
  120.  
  121.             Dim Pname As String = parentf
  122.  
  123.             Dim names() As String = Pname.Split("\")
  124.             Dim count As Integer = names.Count - 1
  125.             For z As Integer = 0 To count
  126.                 If GoPlaceHolder.Length > 0 Then
  127.                     gohome(home + "\" + GoPlaceHolder)
  128.                 Else
  129.                     gohome(home)
  130.                 End If
  131.  
  132.  
  133.                 explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names(z))
  134.  
  135.  
  136.  
  137.             Next
  138.         End If
  139.  
  140.     End Sub
  141.  
  142.     Private Sub btnnewfile_Click(sender As Object, e As EventArgs) Handles btnnewfile.Click
  143.  
  144.  
  145.  
  146.         Dim str As String = Txtenterpath.Text
  147.         If str.Contains(".txt") = False Then
  148.  
  149.             ' Suedo Code You Have A Parent
  150.             If Txtenterpath.Text.Length > 0 Then
  151.  
  152.  
  153.                 Dim chosentxtname As String = txtfilename.Text
  154.                 Dim path As String = ""
  155.  
  156.  
  157.  
  158.                 path = home & "\" & Txtenterpath.Text & "\" & chosentxtname & ".txt"
  159.  
  160.  
  161.  
  162.                 Dim sw As StreamWriter = File.CreateText(path) ' Create a file to write to.
  163.                 sw.WriteLine("Hello")
  164.                 sw.Flush()
  165.                 sw.Close()
  166.  
  167.                 ' Suedo Code Refresh The Home Loction NOW UPDATE Select Files
  168.                 If GoPlaceHolder.Length > 0 Then
  169.                     gohome(home + "\" + GoPlaceHolder)
  170.  
  171.                     Dim fullname As String = Txtenterpath.Text & "\" & chosentxtname & ".txt"
  172.                     Dim names2() As String = fullname.Split("\")
  173.                     Dim count As Integer = names2.Count - 1
  174.  
  175.  
  176.                     Dim fullnameGOPlaceHolder As String = GoPlaceHolder
  177.                     Dim namesGo() As String = fullnameGOPlaceHolder.Split("\")
  178.                     Dim countGo As Integer = namesGo.Count - 1
  179.  
  180.  
  181.  
  182.                     For z As Integer = 0 To count
  183.  
  184.  
  185.                         If z > countGo Then
  186.                             If Not z = count Then
  187.                                 explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names2(z))
  188.                                 Me.explorer_tree.SelectedNode.Expand()
  189.                             Else
  190.                                 explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names2(z))
  191.                             End If
  192.  
  193.                         End If
  194.  
  195.                     Next
  196.  
  197.  
  198.                 Else
  199.                     gohome(home)
  200.  
  201.                     Dim fullname As String = Txtenterpath.Text & "\" & chosentxtname & ".txt"
  202.                     Dim names2() As String = fullname.Split("\")
  203.                     Dim count As Integer = names2.Count - 1
  204.  
  205.                     For z As Integer = 0 To count
  206.  
  207.  
  208.                         If Not z = count Then
  209.                             explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names2(z))
  210.                             Me.explorer_tree.SelectedNode.Expand()
  211.                         Else
  212.                             explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, names2(z))
  213.                         End If
  214.  
  215.  
  216.  
  217.                     Next
  218.  
  219.  
  220.  
  221.                 End If
  222.             Else
  223.                 Dim chosentxtname As String = txtfilename.Text
  224.                 Dim path As String = ""
  225.  
  226.                 path = home & "\" & chosentxtname & ".txt"
  227.  
  228.  
  229.  
  230.                 Dim sw As StreamWriter = File.CreateText(path) ' Create a file to write to.
  231.                 sw.WriteLine("Hello")
  232.                 sw.Flush()
  233.                 sw.Close()
  234.                 gohome(home)
  235.                 explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, chosentxtname & ".txt")
  236.  
  237.  
  238.             End If
  239.  
  240.  
  241.         Else
  242.             MsgBox("Can Not Create On Txt File")
  243.         End If
  244.  
  245.  
  246.     End Sub
  247.  
  248.     Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles BtnBack.Click
  249.  
  250.         If Not Me.explorer_tree.SelectedNode Is Nothing Then
  251.  
  252.             Dim snode2 As TreeNode = Me.explorer_tree.SelectedNode
  253.             Dim vCurrentPath As String = GetFullPathForTreeNode(snode2)
  254.  
  255.             Dim newCurrentDirectory As DirectoryInfo = New DirectoryInfo(vCurrentPath)
  256.  
  257.             Dim HoldString As String = newCurrentDirectory.Parent.FullName
  258.  
  259.             Dim name1 As String = dirictoryname1(HoldString)
  260.  
  261.  
  262.  
  263.  
  264.             explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, name1)
  265.  
  266.         Else
  267.             MsgBox("Selected ?..")
  268.         End If
  269.  
  270.     End Sub
  271.  
  272.  
  273.  
  274.  
  275.     Private Sub Btnfiledel_Click_1(sender As Object, e As EventArgs) Handles Btnfiledel.Click
  276.  
  277.         Dim snode2 As TreeNode = Me.explorer_tree.SelectedNode
  278.         Dim vCurrentPath As String = GetFullPathForTreeNode(snode2)
  279.         Dim parentf As String = dirictoryparentname1(vCurrentPath)
  280.  
  281.         Dim placeholder As String = Txtenterpath.Text
  282.  
  283.         explorer_tree.SelectedNode = SearchTheTreeView(explorer_tree, parentf)
  284.  
  285.         My.Computer.FileSystem.DeleteFile(home + "\" + placeholder, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
  286.  
  287.         If Not Me.explorer_tree.SelectedNode Is Nothing Then
  288.  
  289.             Me.explorer_tree.SelectedNode.Collapse()
  290.             Me.explorer_tree.SelectedNode.Expand()
  291.  
  292.         Else
  293.  
  294.             Txtenterpath.Text = GoPlaceHolder
  295.             hometxt.Clear()
  296.             Dim vCurrentFolder As String = Application.StartupPath + "\snippettree_data\home\" + GoPlaceHolder
  297.             Dim Extension As String = Path.GetExtension(Txtenterpath.Text)
  298.             explorer_tree.BeginUpdate()
  299.             explorer_tree.Nodes.Clear()
  300.             FillExplorerTree(vCurrentFolder, Nothing)
  301.             explorer_tree.EndUpdate()
  302.  
  303.         End If
  304.  
  305.  
  306.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement