コード例 #1
0
 void ProcessListBoxDoubleClick(string entry)
 {
     string line = MainForm.InputBox.Text;
     int offset = MainForm.InputBox.SelectionStart;
     CommandArguments arguments;
     CommandArgument activeArgument;
     try
     {
         arguments = new CommandArguments(line);
         activeArgument = arguments.FindMatchingResult(offset);
         PerformInputBoxReplacement(line, entry, activeArgument);
     }
     catch (ArgumentException)
     {
         Beep();
         return;
     }
 }
コード例 #2
0
        void Tab()
        {
            lock (this)
            {
                CloseAutoCompletionForm();

                int offset = MainForm.InputBox.SelectionStart;
                string line = MainForm.InputBox.Text;
                CommandArguments arguments;
                try
                {
                    arguments = new CommandArguments(line);
                }
                catch (ArgumentException)
                {
                    //there was a missing quote - this could possibly be handed by automatically attaching another quote at the end
                    Beep();
                    return;
                }
                CommandArgument activeArgument;
                try
                {
                    activeArgument = arguments.FindMatchingResult(offset);
                }
                catch (ArgumentException)
                {
                    //the cursor of the user was not within the boundaries of any argument within the line
                    Beep();
                    return;
                }
                string argumentString = activeArgument.Argument;

                //fix for weird tabbing behaviour on Windows for strings like "c:"
                if (IsWindows && argumentString.Length == 2 && Char.IsLetter(argumentString[0]) && argumentString[1] == ':')
                    argumentString += Path.DirectorySeparatorChar;

                HashSet<string> autoCompletionStrings = new HashSet<string>();
                if (System.Object.ReferenceEquals(activeArgument, arguments.Command))
                {
                    //the user is performing the tab within the first unit of the input - that is the command unit
                    foreach (string i in PathNames)
                        autoCompletionStrings.Add(i);
                }
                else
                {
                    //the user is performing the tab within the boundaries of one of the argument units and not the command unit
                    List<string> currentDirectory = LoadDirectoryContentsForAPathToAFile(argumentString);
                    foreach (string i in currentDirectory)
                        autoCompletionStrings.Add(i);
                }

                if (Nil.File.GetFileType(argumentString) == Nil.File.FileType.Directory)
                {
                    //the current argument the user is tabbing in refers to a directory
                    List<string> directoryContent = LoadDirectoryContent(argumentString);
                    foreach (string i in directoryContent)
                        autoCompletionStrings.Add(i);
                }
                else
                {
                    //the tabbed argument either refers to a file or is simply incomplete and refers to neither a file nor a directory
                    //just add the directory it currently refers to then
                    List<string> directoryContent = LoadDirectoryContentsForAPathToAFile(argumentString);
                    foreach (string i in directoryContent)
                        autoCompletionStrings.Add(i);
                }

                //filter out the strings which do not match the tabbed argument
                List<string> filteredAutoCompletionStrings = new List<string>();
                foreach (string target in autoCompletionStrings)
                {
                    if
                    (
                        target.Length >= argumentString.Length &&
                        CaseInsensitiveStringComparison(argumentString, target.Substring(0, argumentString.Length))
                    )
                        filteredAutoCompletionStrings.Add(target);
                }

                if (filteredAutoCompletionStrings.Count == 0)
                {
                    //no matches could be found
                    Beep();
                    return;
                }

                if (filteredAutoCompletionStrings.Count > 1)
                    ShowAutoCompletionForm(filteredAutoCompletionStrings);

                string longestCommonSubstring = GetLongestCommonSubstring(filteredAutoCompletionStrings, argumentString.Length);
                if (longestCommonSubstring == argumentString)
                {
                    //no better match could be found, play a beep
                    Beep();
                    return;
                }

                PerformInputBoxReplacement(line, longestCommonSubstring, activeArgument);
            }
        }