public void OnCommand(EnsoCommand command, String postfix)
        {
            Match m = boundsParser.Match(postfix);

            int from = 0;
            String s_from = m.Groups[1].Value;

            try
            {
                if (!"".Equals(s_from.Trim()))
                    from = Convert.ToInt32(s_from);
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR));
            }

            int to = int.MaxValue;
            String s_to = m.Groups[2].Value;

            try
            {
                if (!"".Equals(s_to.Trim()))
                    to = Convert.ToInt32(s_to);
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR));
            }

            int result = random.Next(from, to);

            service.InsertUnicodeAtCursor(result.ToString(), command);
        }
 public LingvoExtension()
 {
     translateCommand = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
         COMMAND_DESC, COMMAND_HELP, EnsoPostfixType.Arbitrary);
     quitCommand = new EnsoCommand(QUIT_NAME, null, QUIT_DESC,
         QUIT_DESC, EnsoPostfixType.None);
 }
Esempio n. 3
0
 private static void PrepareHelp(EnsoCommand command)
 {
     if (string.IsNullOrEmpty(command.Help))
     {
         command.Help = command.Description.Replace("&", "_").Replace(@"/", "_").Replace(@"\", "_").Replace(@"#", "_").Replace(@"<", "_").Replace(@">", "_");
     }
     if (string.IsNullOrEmpty(command.Help))
     {
         command.Help = "No help specified.";
     }
 }
        public void OnCommand(EnsoCommand command, string postfix)
        {
            Guid guid = Guid.NewGuid();
            String result;

            if (POSTFIX_NUMERIC.Equals(postfix))
                result = guid.ToString("N").ToUpper();
            else
                result = POSTFIX_LOWER.Equals(postfix)
                                ? guid.ToString()
                                : guid.ToString().ToUpper();

            service.InsertUnicodeAtCursor(result, command);
        }
Esempio n. 5
0
 private static void OnClose(EnsoCommand c, string postfix, IntPtr fw)
 {
     Program.extensionPlus.OnCommand(c, postfix, fw);
 }
 public RandomExtension()
 {
     command = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
         COMMAND_DESC, COMMAND_DESC, EnsoPostfixType.Arbitrary);
 }
Esempio n. 7
0
        public void OnCommand(EnsoCommand ensoCommand, string postfix, IntPtr foregroundWindowForGrab)
        {
            Logging.AddDebugLog("OnCommand:" + ensoCommand.Name + " postfix:" + postfix + "------------------------------------------------------------------------------------------------");
            try
            {
                //SelectionListener.Listener.Current.IfOpenedPause();

                MergedCommand mergedCommand = this.mergedCommands[ensoCommand.Name];

                //if none of potentially chosen commands use selection skip expensive operations:
                //  this.service.GetFileSelection() and/or this.service.GetUnicodeSelection();
                bool skipGetUnicodeSelection = true;
                bool skipGetFileSelection    = true;
                foreach (var sourceCommand in mergedCommand.sourceCommands)
                {
                    if (sourceCommand.canUseTextSelectionForParameter)
                    {
                        skipGetUnicodeSelection = false;
                    }

                    if (sourceCommand.canUseFileSelectionForParameter)
                    {
                        skipGetFileSelection = false;
                    }

                    if (!skipGetUnicodeSelection && !skipGetFileSelection)
                    {
                        break;
                    }
                }
                Logging.AddDebugLog("OnCommand: skipGetUnicodeSelection=" + skipGetUnicodeSelection + " skipGetFilesSelection=" + skipGetFileSelection);

                //do we need file selection?
                if ((ensoCommand.Name == "topen" || ensoCommand.Name == "rtopen" || ensoCommand.Name == "empty"))
                {
                    try
                    {
                        if (CraftSynth.BuildingBlocks.WindowsNT.Misc.GetForegroundWindowCaption().Contains("Total Commander"))
                        {
                            skipGetFileSelection = true;
                        }
                    }
                    catch
                    {
                    }
                }

                //read selection
                ClipboardData selectedData = null;
                if (!skipGetUnicodeSelection || !skipGetFileSelection)
                {
                    selectedData = HandlerForSelection.Get(foregroundWindowForGrab);
                }
                Logging.AddDebugLog("OnCommand: first 100 chars of HandlerForSelection.Get=" + (selectedData == null?"null":selectedData.AsUnicodeText).FirstXChars(100, "..."));

                //Get text selection if needed
                string selectedText = null;
                if (!skipGetUnicodeSelection && selectedData != null)
                {
                    selectedText = selectedData.AsUnicodeText;
                }
                Logging.AddDebugLog("OnCommand: first 100 chars of selectedText=" + (selectedText ?? "null").FirstXChars(100, "..."));

                //Get file selection if needed
                string[] fileSelectionArray = null;
                if (!skipGetFileSelection &&
                    !skipGetUnicodeSelection && string.IsNullOrEmpty(selectedText) && selectedData != null)
                {
                    var ffl = selectedData.AsFileFolderList;
                    if (ffl == null)
                    {
                        fileSelectionArray = null;
                    }
                    else
                    {
                        fileSelectionArray = ffl.ToArray();
                    }
                    ;     //ex: this.service.GetFileSelection();
                }
                else
                {
                    fileSelectionArray = new string[] { };
                }
                Logging.AddDebugLog("OnCommand: first 100 chars of fileSelectionArray=" + (fileSelectionArray == null? "null": Syntax.FileSelectionArrayToString(fileSelectionArray)).FirstXChars(100, "..."));

                if (fileSelectionArray != null && fileSelectionArray.Length > 0 && string.IsNullOrEmpty(selectedText))
                {
                    selectedText = Syntax.FileSelectionArrayToString(fileSelectionArray);
                }

                Command bestCandidateForUsedCommand = null;
                bool    bestCandidateForUsedCommandRequiresParameterInput = false;
                foreach (Command sourceCommand in mergedCommand.sourceCommands)
                {
                    Logging.AddDebugLog("OnCommand: Syntax.ExtractParameterValues...");
                    int           parameterCountInSyntax      = 0;
                    List <string> parametersFromInlineCommand = Syntax.ExtractParameterValues(sourceCommand.Postfix, postfix, (GetSelectionForCommand(selectedText, sourceCommand)), mergedCommand.sourceCommands.Count == 1, out parameterCountInSyntax);

                    Logging.AddDebugLog("OnCommand: parametersFromInlineCommand=" + (parametersFromInlineCommand == null?"null":parametersFromInlineCommand.ToCSV()));
                    if (parametersFromInlineCommand == null)
                    {
                        continue;
                    }

                    //replace jockers - should be refactored
                    Logging.AddDebugLog("OnCommand: replace jockers...");
                    int i = parametersFromInlineCommand.Count - 1;
                    while (i >= 0)
                    {
                        if (parametersFromInlineCommand[i] == Syntax.lastMessageInPostfix)
                        {
                            parametersFromInlineCommand[i] = MessagesHandler.GetLastFromHistory().Text;
                        }
                        else if (parametersFromInlineCommand[i] == Syntax.selectionInPostfix1 || parametersFromInlineCommand[i] == Syntax.selectionInPostfix2)
                        {
                            parametersFromInlineCommand.RemoveAt(i);
                        }
                        i--;
                    }
                    Logging.AddDebugLog("OnCommand: Determine best candidate...");

                    if ((GetSelectionForCommand(selectedText, sourceCommand) == string.Empty && parametersFromInlineCommand.Count == parameterCountInSyntax) ||
                        (parameterCountInSyntax == 0 && sourceCommand.Postfix == " ") ||
                        (GetSelectionForCommand(selectedText, sourceCommand) != string.Empty && parametersFromInlineCommand.Count == parameterCountInSyntax && GetSelectionForCommand(selectedText, sourceCommand).CompareTo(parametersFromInlineCommand[parametersFromInlineCommand.Count - 1]) == 0))
                    {
                        bestCandidateForUsedCommand = sourceCommand.GetClone();
                        bestCandidateForUsedCommand.parametersOnExecute   = StringWorkItem.CreateInstances(parametersFromInlineCommand);
                        bestCandidateForUsedCommandRequiresParameterInput = false;
                        Logging.AddDebugLog("OnCommand: bc=a");
                        break;
                    }
                    else if (GetSelectionForCommand(selectedText, sourceCommand) != string.Empty && parametersFromInlineCommand.Count == parameterCountInSyntax && GetSelectionForCommand(selectedText, sourceCommand).CompareTo(parametersFromInlineCommand[parametersFromInlineCommand.Count - 1]) != 0)
                    {
                        bestCandidateForUsedCommand = sourceCommand.GetClone();
                        bestCandidateForUsedCommand.parametersOnExecute   = StringWorkItem.CreateInstances(parametersFromInlineCommand);
                        bestCandidateForUsedCommandRequiresParameterInput = false;
                        Logging.AddDebugLog("OnCommand: bc=b");
                    }
                    else if (parametersFromInlineCommand.Count == (parameterCountInSyntax - 1))
                    {
                        bestCandidateForUsedCommand = sourceCommand.GetClone();
                        bestCandidateForUsedCommand.parametersOnExecute   = StringWorkItem.CreateInstances(parametersFromInlineCommand);
                        bestCandidateForUsedCommandRequiresParameterInput = true;
                        Logging.AddDebugLog("OnCommand: bc=c");
                    }
                }



                if (bestCandidateForUsedCommand == null)
                {
                    Logging.AddDebugLog("OnCommand: postfix Invalid!");
                    MessagesHandler.Display("Postfix invalid!", ensoCommand.Name + " " + ensoCommand.Postfix);
                }
                else
                {
                    Logging.AddDebugLog("OnCommand: bestCandidateForUsedCommand=" + bestCandidateForUsedCommand.Name);
                    Logging.AddDebugLog("OnCommand: replace 'last' parameter with last used parameter/WorkItem");
                    //replace 'last' parameter with last used parameter/WorkItem
                    int j = 0;
                    while (j < bestCandidateForUsedCommand.parametersOnExecute.Count)
                    {
                        Logging.AddDebugLog("OnCommand: first 100 chars of paramsOnExecute[" + j + "]=" + (bestCandidateForUsedCommand.parametersOnExecute[j].GetValueAsText().FirstXChars(100, "...")));
                        if (bestCandidateForUsedCommand.parametersOnExecute[j].GetValueAsText() == Syntax.lastParameterInPostfix)
                        {
                            bestCandidateForUsedCommand.parametersOnExecute[j] = WorkItemsProviders.CommandsHistory.CommandsHistory.GetLastWorkItem();
                            Logging.AddDebugLog("OnCommand: first 100 chars of paramsOnExecute[" + j + "]=" + bestCandidateForUsedCommand.parametersOnExecute[j].GetValueAsText().FirstXChars(100, "..."));
                        }

                        j++;
                    }

                    if (bestCandidateForUsedCommand.parameterInputArguments.acceptOnlySuggested && !bestCandidateForUsedCommandRequiresParameterInput && bestCandidateForUsedCommand.parametersOnExecute.Count > 0)
                    {//user entered all parameters and command uses cloased parameter group
                        Logging.AddDebugLog("OnCommand: user entered all parameters and command uses cloased parameter group");
                        Dictionary <string, IWorkItem> suggestions = GetAvailableSuggestions(bestCandidateForUsedCommand);
                        IWorkItem selectedSuggestion = null;
                        if (suggestions.TryGetValue(bestCandidateForUsedCommand.parametersOnExecute[bestCandidateForUsedCommand.parametersOnExecute.Count - 1].GetCaption(), out selectedSuggestion))
                        {//user-entered parameter does not exist in group - add it to list
                            Logging.AddDebugLog("OnCommand: user-entered parameter does not exist in group - add it to list");
                            IWorkItem postProcessedSuggestion = PostProcessSelectedSuggestion(selectedSuggestion);
                            if (postProcessedSuggestion == null)
                            {//user probably canceled command - abort command
                                Logging.AddDebugLog("OnCommand: user probably canceled command - abort command");
                                return;
                            }
                            bestCandidateForUsedCommand.parametersOnExecute[bestCandidateForUsedCommand.parametersOnExecute.Count - 1] = postProcessedSuggestion;
                        }
                        else
                        {//user-entered parameter does not exist in group - plan input parameter box
                            Logging.AddDebugLog("OnCommand: user-entered parameter does not exist in group - plan input parameter box");
                            if (bestCandidateForUsedCommand.parameterInputArguments.acceptOnlySuggested)
                            {
                                bestCandidateForUsedCommand.parameterInputArguments.predefinedValue = string.Empty;
                            }
                            else
                            {
                                bestCandidateForUsedCommand.parameterInputArguments.predefinedValue = bestCandidateForUsedCommand.parametersOnExecute[bestCandidateForUsedCommand.parametersOnExecute.Count - 1].GetCaption();
                            }
                            bestCandidateForUsedCommand.parametersOnExecute.RemoveAt(bestCandidateForUsedCommand.parametersOnExecute.Count - 1);
                            bestCandidateForUsedCommandRequiresParameterInput = true;
                        }
                    }

                    if (!bestCandidateForUsedCommandRequiresParameterInput)
                    {
                        Logging.AddDebugLog("OnCommand: bestCandidateForUsedCommandRequiresParameterInput==false");
                        Logging.AddDebugLog("OnCommand: ExecuteCommandCandidate...");
                        ExecuteCommandCandidate(bestCandidateForUsedCommand);
                    }
                    else
                    {
                        Logging.AddDebugLog("OnCommand: ProcessingBeforeParameterInput...");
                        bool cancel = false;
                        bestCandidateForUsedCommand.provider.ProcessingBeforeParameterInput(bestCandidateForUsedCommand, ref cancel);
                        Logging.AddDebugLog("OnCommand: ProcessingBeforeParameterInput done. cancel=" + cancel);
                        if (cancel)
                        {
                            return;
                        }

                        Logging.AddDebugLog("OnCommand: GetAvailableSuggestions...");
                        Dictionary <string, IWorkItem> suggestions = GetAvailableSuggestions(bestCandidateForUsedCommand);

                        //prepare parameters to suggestions
                        bestCandidateForUsedCommand.parameterInputArguments.suggestions = new List <string>();
                        foreach (var suggestion in suggestions)
                        {
                            bestCandidateForUsedCommand.parameterInputArguments.suggestions.Add(suggestion.Key);
                        }

                        //execute dropbox
                        Logging.AddDebugLog("OnCommand: execute dropbox...");
                        try
                        {
                            PostParameterInputArguments contextData = new PostParameterInputArguments();
                            contextData.suggestions = suggestions;
                            contextData.bestCandidateForUsedCommand = bestCandidateForUsedCommand;
                            contextData.bestCandidateForUsedCommandRequiresParameterInput = bestCandidateForUsedCommandRequiresParameterInput;

                            ParameterInput.Display(bestCandidateForUsedCommand.parameterInputArguments, ParameterInput_OnClose, contextData, Screen.FromPoint(Cursor.Position));
                        }
                        catch (Exception exception)
                        {
                            MessagesHandler.Display("Error", exception.Message);
                            Logging.AddErrorLog("Parameter input failed: " + exception.Message + ((exception.InnerException != null) ? ":" + exception.InnerException.Message : ""));
                            Common.Logging.AddExceptionLog(exception);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logging.AddErrorLog("Command execution failed: " + exception.Message + ((exception.InnerException != null) ? ":" + exception.InnerException.Message : ""));
                Logging.AddExceptionLog(exception);
                throw exception;
            }
            //SelectionListener.Listener.Current.IfOpenedContinue();
        }
        public void OnCommand(EnsoCommand command, string postfix)
        {
            Action action = commandActions[command.Name];

            if (action != null)
                new Thread(new ThreadStart(action)).Start();
        }
 public void OnCommand(EnsoCommand command, string postfix)
 {
     CommandDesc desc = commandActions[command.Name];
     new Thread(() => desc.action(postfix, service)).Start();
 }
        public void OnCommand(EnsoCommand command, String postfix)
        {
            Action<String, IEnsoService> action = commandActions[command.Name];

            if (action != null)
                new Thread(() => action(postfix, service)).Start();
        }
Esempio n. 11
0
 public GUIDExtension()
 {
     command = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
         COMMAND_DESC, COMMAND_DESC, EnsoPostfixType.Bounded);
 }
        void IEnsoService.UnregisterCommand(EnsoCommand command)
        {
            if (disposed)
                throw new ObjectDisposedException(GetType().Name);

            if (command == null)
                throw new ArgumentNullException("command");

            IDictionary<EnsoCommand, EnsoExtensionProxy> commands = this.commands;
            if (commands == null)
                throw new ObjectDisposedException(GetType().Name);

            lock (this)
            {
                EnsoExtensionProxy extensionProxy;
                if (!commands.TryGetValue(command, out extensionProxy))
                    throw new EnsoException("Command not registered.");

                try
                {
                    ensoProxy.UnregisterCommand(GetUrlForUri(extensionProxy.Uri), command.ToString());
                }
                catch (Exception e)
                {
                    throw new EnsoException("UnregisterCommand failed", e);
                }

                commands.Remove(command);
                extensionProxy.Commands.Remove(command.ToString());

                if (extensionProxy.Commands.Count == 0)
                    extensions.Remove(extensionProxy.Uri);
            }
        }
        void IEnsoService.SetUnicodeSelection(string text, EnsoCommand fromCommand)
        {
            if (disposed)
                throw new ObjectDisposedException(GetType().Name);

            if (text == null)
                throw new ArgumentNullException("text");

            if (fromCommand == null)
                throw new ArgumentNullException("fromCommand");

            try
            {
                ensoProxy.SetUnicodeSelection(text, fromCommand.ToString());
            }
            catch (Exception e)
            {
                throw new EnsoException("SetUnicodeSelection failed", e);
            }
        }
        void IEnsoService.SetCommandValidPostfixes(EnsoCommand command, string[] postfixes)
        {
            if (disposed)
                throw new ObjectDisposedException(GetType().Name);

            if (command == null)
                throw new ArgumentNullException("command");

            if (postfixes == null)
                throw new ArgumentNullException("postfixes");

            IDictionary<EnsoCommand, EnsoExtensionProxy> commands = this.commands;
            if (commands == null)
                throw new ObjectDisposedException(GetType().Name);

            EnsoExtensionProxy extensionProxy;
            if (!commands.TryGetValue(command, out extensionProxy))
                throw new EnsoException("Command not registered.");

            try
            {
                ensoProxy.SetCommandValidPostfixes(GetUrlForUri(extensionProxy.Uri), command.ToString(), postfixes);
            }
            catch (Exception e)
            {
                throw new EnsoException("SetCommandValidPostfixes failed", e);
            }
        }
        void IEnsoService.RegisterCommand(IEnsoExtension extension, string uri, EnsoCommand command)
        {
            if (disposed)
                throw new ObjectDisposedException(GetType().Name);

            if (extension == null)
                throw new ArgumentNullException("extension");

            if (command == null)
                throw new ArgumentNullException("command");

            IDictionary<string, EnsoExtensionProxy> extensions = this.extensions;
            IDictionary<EnsoCommand, EnsoExtensionProxy> commands = this.commands;
            if (extensions == null || commands == null)
                throw new ObjectDisposedException(GetType().Name);

            lock (this)
            {
                EnsoExtensionProxy extensionProxy;
                if (!extensions.TryGetValue(uri, out extensionProxy))
                {
                    extensionProxy = new EnsoExtensionProxy(extension, uri);
                    RemotingServices.Marshal(extensionProxy, uri, typeof(EnsoExtensionProxy));
                    extensions.Add(uri, extensionProxy);
                }
                else if (extensionProxy.Extension != extension)
                    throw new EnsoException("Invalid uri.");

                try
                {
                    ensoProxy.RegisterCommand(GetUrlForUri(uri), command.ToString(),
                        command.Description, command.Help, postfixTypes[(int)command.PostfixType]);
                }
                catch (Exception e)
                {
                    throw new EnsoException("RegisterCommand failed", e);
                }

                commands.Add(command, extensionProxy);
                extensionProxy.Commands.Add(command.ToString(), command);
            }
        }