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;
     }
 }
        void AttemptProcessExecution(CommandArguments arguments)
        {
            try
            {
                ProcessIOActive = false;

                //check for executable programs matching that name
                Process = new Process();

                ProcessStartInfo info = Process.StartInfo;
                info.UseShellExecute = false;
                info.RedirectStandardInput = true;
                info.RedirectStandardOutput = true;
                info.RedirectStandardError = true;
                info.FileName = arguments.Command.Argument;
                info.Arguments = arguments.GetQuotedArguments();
                info.WindowStyle = ProcessWindowStyle.Hidden;
                info.CreateNoWindow = true;

                Process.Start();

                StandardOutputReader = new AsynchronousReader(this, HandleStandardOutputRead, Process.StandardOutput);
                StandardErrorReader = new AsynchronousReader(this, HandleStandardErrorRead, Process.StandardError);

                new Thread(ProcessTerminationCheckThread).Start();

                ProcessIOActive = true;
            }
            catch (System.ComponentModel.Win32Exception exception)
            {
                Process = null;
                ProcessIOActive = false;
                PrintError(exception.Message);
                PromptAndSelect();
            }
        }
        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);
            }
        }
Exemplo n.º 4
0
        public void Execute(string line)
        {
            line = line.Trim();
            if (line.Length == 0)
                return;
            CommandArguments arguments;

            try
            {
                arguments = new CommandArguments(line);
                //visualiseArguments(arguments);
            }
            catch (ArgumentException exception)
            {
                PrintError(exception.Message);
                PromptAndSelect();
                return;
            }

            Execute(arguments);
        }
Exemplo n.º 5
0
 void VisualiseArguments(CommandArguments arguments)
 {
     PrintLine("Command: \"" + arguments.Command + "\"");
     string output = "Arguments:";
     for (int i = 0; i < arguments.Arguments.Length; i++)
     {
         string argument = arguments.Arguments[i].Argument;
         output += " " + (i + 1).ToString() + ". \"" + argument + "\"";
     }
     PrintLine(output);
 }
Exemplo n.º 6
0
        public void Execute(CommandArguments arguments)
        {
            string command = arguments.Command.Argument;

            if (CommandHandlerDictionary.ContainsKey(command))
            {
                CommandHandler handler = CommandHandlerDictionary[command];
                if (handler.ArgumentCount != -1 && arguments.Arguments.Length != handler.ArgumentCount)
                {
                    PrintError("Invalid argument count.");
                    PrintLine(handler.Usage());
                }
                else
                    handler.Function(arguments.GetArgumentString());
                PromptAndSelect();
            }
            else
            {
                if (ProgramConfiguration.Aliases.ContainsKey(command))
                {
                    string aliasLine = ProgramConfiguration.Aliases[command] + " " + arguments.GetQuotedArguments();
                    Execute(aliasLine);
                }
                else
                {
                    if (PerformChangeDirectoryCheck(arguments.Command.Argument))
                        return;

                    AttemptProcessExecution(arguments);
                    return;
                }
            }
        }