private void ListBoxResultsMouseDoubleClick(object sender, MouseEventArgs e) { var selectedItem = this.listBoxResults.SelectedItem; if(selectedItem == null) { this.buttonAddFolder.Enabled = false; return; } var entry = selectedItem as NotebookEntry; this.buttonAddFolder.Enabled = true; this.buttonAddPage.Enabled = true; if(entry.IsDirectory) { this.loadDirectory(entry.NextPathOrFile); this.currentNotebookFolder = entry.NextPathOrFile; this.currentNotebookFolder = this.currentNotebookFolder.Last() == Path.DirectorySeparatorChar ? this.currentNotebookFolder : this.currentNotebookFolder + Path.DirectorySeparatorChar; this.currentDocument = null; return; } if(entry.IsPage) { this.currentNotebookFolder = string.Join(string.Empty + Path.DirectorySeparatorChar, entry.Path.Split(Path.DirectorySeparatorChar).Reverse().Skip(1).Reverse()); this.currentNotebookFolder = this.currentNotebookFolder.Last() == Path.DirectorySeparatorChar ? this.currentNotebookFolder : this.currentNotebookFolder + Path.DirectorySeparatorChar; this.currentDocument = entry; Process.Start("wordpad.exe", string.Format(@"""{0}""", entry.Path)); } }
private void TextBoxSearchTextChanged(object sender, EventArgs e) { if(this.textBoxSearch.Text.Trim().Length == 0) { this.loadDirectory(this.notebookFolder); return; } this.buttonAddFolder.Enabled = false; this.buttonAddPage.Enabled = false; this.currentDocument = null; this.currentNotebookFolder = string.Empty; var result = new List<NotebookEntry>(); var dirs = Directory.EnumerateDirectories(this.notebookFolder, "*.*", SearchOption.AllDirectories).Where(n => n.ToLower().Contains(this.textBoxSearch.Text.ToLower())); var files = Directory.EnumerateFiles(this.notebookFolder, "*.rtf", SearchOption.AllDirectories).Where(n => n.ToLower().Contains(this.textBoxSearch.Text.ToLower())); foreach(var dir in dirs) { result.Add(new NotebookEntry(this.notebookFolder, dir)); } foreach(var file in files) { result.Add(new NotebookEntry(this.notebookFolder, file)); } result.Sort(); this.listBoxResults.Items.Clear(); this.listBoxResults.Items.AddRange(result.ToArray()); }