Ejemplo n.º 1
0
 void TotalMatch(NameTextPair selectedEntry)
 {
     totalMatch = selectedEntry;
     if (SelectEntry(selectedEntry))
     {
         EnableSelectButton();
     }
 }
Ejemplo n.º 2
0
 bool SelectEntry(NameTextPair entry)
 {
     return(entry.IsDirectory ? SelectDirs(selectOptions) : SelectFiles(selectOptions));
 }
Ejemplo n.º 3
0
 void TotalUnmatch()
 {
     DisableSelectButton();
     totalMatch = null;
 }
Ejemplo n.º 4
0
            void PathChanged(TextChangedEventArgs args)
            {
                string oldPath    = Path.Combine(currentDirectory, currentFileName);
                string newDirPath = null;

                if (!IsValidPath(args.Text))
                {
                    PathChangeFailed(oldPath);
                    return;
                }

                try {
                    string newPath = args.Text;
                    newDirPath = newPath == "" ? "" : Path.GetDirectoryName(newPath);

                    if (newDirPath == null)
                    {
                        PathChangeFailed(oldPath);
                        return;
                    }
                }
                catch (ArgumentException) {
                    PathChangeFailed(oldPath);
                    return;
                }
                catch (PathTooLongException) {
                    PathChangeFailed(oldPath);
                    return;
                }

                //If directory changed, show the contents of the new directory
                if (newDirPath != currentDirectory)
                {
                    //Load the new directory contents
                    if (!LoadDirectory(newDirPath))
                    {
                        //The new directory could not be loaded, revert change
                        PathChangeFailed(oldPath);
                        return;
                    }
                }

                //Path may not represent the current directory, but some files in it
                // Later, after we know the fileName, we check it and set it again if needed
                CurrentDirDeselected();

                string fileName = null;

                try {
                    fileName = Path.GetFileName(args.Text);
                }
                catch (ArgumentException)
                {
                    //Hide all items, no item matches invalid fileName
                    foreach (var entry in cDirEntries)
                    {
                        entry.Text.Visible = false;
                    }
                    return;
                }

                //At this point we are certain that both dirPath and fileName are correct, set them as current
                currentDirectory = newDirPath;
                currentFileName  = fileName;

                //If empty filename, path points to the directory itself
                if (fileName == "")
                {
                    TotalUnmatch();
                    CurrentDirSelected();

                    foreach (var entry in cDirEntries)
                    {
                        entry.Text.Visible = true;
                    }
                    return;
                }

                //Path points to some files in the directory
                int          matches   = 0;
                NameTextPair lastMatch = null;

                foreach (var entry in cDirEntries)
                {
                    //Show only the matching files
                    bool match = entry.Name.StartsWith(fileName);
                    entry.Text.Visible = match;
                    if (match)
                    {
                        matches++;
                        lastMatch = entry;
                    }
                }

                //If only one file matches, enable selecting
                if (matches == 1)
                {
                    TotalMatch(lastMatch);
                }
                else
                {
                    TotalUnmatch();
                }
            }