Exemplo n.º 1
0
        private void lstViewIndex_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstViewIndex.SelectedIndices.Count > 0)
            {
                var itemSelected = lstViewIndex.SelectedItems[0];

                // get object back from listview
                TextFile txtFile = (TextFile)itemSelected.Tag;

                rchTxtBoxFileDescription.Text = File.ReadAllText(txtFile.Path);
                lblTxtFileView.Text           = $"'{txtFile.Name}' Text View";
                var index = 0;
                while (index < rchTxtBoxFileDescription.Text.LastIndexOf(word))
                {
                    // Searches the word in the RichTextBox
                    rchTxtBoxFileDescription.Find(word, index, rchTxtBoxFileDescription.TextLength, RichTextBoxFinds.None);
                    // Selection color
                    rchTxtBoxFileDescription.SelectionBackColor = Color.Yellow;
                    // after a match is found the index is increased
                    index = rchTxtBoxFileDescription.Text.IndexOf(word, index) + 1;
                }
            }
        }
Exemplo n.º 2
0
        private void btnAddFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                // set FileSystemWatcher path to root of this folder   Failed attempt
                //fileSystemWatcher.Path = Path.GetPathRoot(fbd.SelectedPath);
                //MessageBox.Show(fileSystemWatcher.Path);

                var selectedFolder = fbd.SelectedPath;
                var exists         = false;

                // check if folder exists in listbox
                foreach (Folder item in lstBoxFolders.Items)
                {
                    if (item.Path == selectedFolder)
                    {
                        exists = true;
                    }
                }

                if (exists == true)
                {
                    MessageBox.Show("Folder already in showcase!");
                }
                else
                {
                    // instantiate folder object
                    var folder = new Folder();
                    folder.Name      = Path.GetFileName(selectedFolder);
                    folder.Path      = selectedFolder;
                    folder.TextFiles = new List <TextFile>();

                    lstBoxFolders.Items.Add(folder);

                    // txt files in selected folder to add to collection
                    var files = Directory.GetFiles(folder.Path, "*.txt");

                    if (files.Length != 0) // contains txt file
                    {
                        foreach (var txtFilePath in files)
                        {
                            var txtFile = new TextFile
                            {
                                Name   = Path.GetFileName(txtFilePath),
                                Path   = txtFilePath,
                                Folder = folder.Name
                            };
                            // add to folder
                            folder.TextFiles.Add(txtFile);
                            // add to collection
                            collectedTxtFiles.Add(txtFile);

                            MessageBox.Show($"'{txtFile.Name}' Added to collection");
                        }
                    }
                    else
                    {
                        MessageBox.Show($"'{Path.GetFileName(selectedFolder)}' does not contain any txt file");
                    }
                }
            }
        }