Ejemplo n.º 1
0
        public IWorkItem GetParameterFromSelectedSuggestion(IWorkItem selectedSuggestion)
        {
            if (selectedSuggestion is StringWorkItem)
            {
                StringWorkItem selectedStringWorkItem = (StringWorkItem)selectedSuggestion;
                if (selectedStringWorkItem.GetValueAsText() == "[Current date and time in sortable format]")
                {
                    selectedSuggestion = new StringWorkItem(CraftSynth.BuildingBlocks.Common.DateAndTime.GetCurrentDateAndTimeInSortableFormat());;
                }
                else if (selectedStringWorkItem.GetValueAsText() == "[Current date and time in sortable format for file system]")
                {
                    selectedSuggestion = new StringWorkItem(CraftSynth.BuildingBlocks.Common.DateAndTime.GetCurrentDateAndTimeInSortableFormatForFileSystem());;
                }
                else
                if (selectedStringWorkItem.GetValueAsText() == "[Current date in sortable format]")
                {
                    selectedSuggestion = new StringWorkItem(CraftSynth.BuildingBlocks.Common.DateAndTime.GetCurrentDateInSortableFormat());;
                }
                else if (selectedStringWorkItem.GetValueAsText() == "[Current date in sortable format for file system]")
                {
                    selectedSuggestion = new StringWorkItem(CraftSynth.BuildingBlocks.Common.DateAndTime.GetCurrentDateInSortableFormatForFileSystem());;
                }
                else if (selectedStringWorkItem.GetValueAsText() == "[Guid]")
                {
                    selectedSuggestion = new StringWorkItem(Guid.NewGuid().ToString());
                }
            }

            return(selectedSuggestion);
        }
Ejemplo n.º 2
0
        public Dictionary <string, IWorkItem> GetSuggestions()
        {
            Dictionary <string, IWorkItem> suggestions = new Dictionary <string, IWorkItem>();

            StringWorkItem currentDateInSortableFormat = new StringWorkItem("[Current date in sortable format]");

            currentDateInSortableFormat.provider = this;
            suggestions.Add("[Current date in sortable format]", currentDateInSortableFormat);

            StringWorkItem currentDateAndTimeInSortableFormat = new StringWorkItem("[Current date and time in sortable format]");

            currentDateAndTimeInSortableFormat.provider = this;
            suggestions.Add("[Current date and time in sortable format]", currentDateAndTimeInSortableFormat);

            StringWorkItem currentDateInSortableFormatForFileSystem = new StringWorkItem("[Current date in sortable format for file system]");

            currentDateInSortableFormatForFileSystem.provider = this;
            suggestions.Add("[Current date in sortable format for file system]", currentDateInSortableFormatForFileSystem);

            StringWorkItem currentDateAndTimeInSortableFormatForFileSystem = new StringWorkItem("[Current date and time in sortable format for file system]");

            currentDateAndTimeInSortableFormatForFileSystem.provider = this;
            suggestions.Add("[Current date and time in sortable format for file system]", currentDateAndTimeInSortableFormatForFileSystem);


            StringWorkItem guid = new StringWorkItem("[Guid]");

            guid.provider = this;
            suggestions.Add("[Guid]", guid);


            return(suggestions);
        }
Ejemplo n.º 3
0
        public Dictionary <string, IWorkItem> GetSuggestions()
        {
            Dictionary <string, IWorkItem> suggestions = new Dictionary <string, IWorkItem>();

            StringWorkItem bookmarkBrowser = new StringWorkItem("[Browse Bookmarks]");

            bookmarkBrowser.provider = this;
            suggestions.Add("[Browse Bookmarks]", bookmarkBrowser);

            return(suggestions);
        }
Ejemplo n.º 4
0
        public Dictionary <string, IWorkItem> GetSuggestions()
        {
            Dictionary <string, IWorkItem> suggestions = new Dictionary <string, IWorkItem>();

            if (CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName() == DataFormats.Text ||
                CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName() == DataFormats.UnicodeText ||
                CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName() == DataFormats.StringFormat ||
                CraftSynth.BuildingBlocks.IO.Clipboard.GetClipboardFormatName() == DataFormats.OemText)
            {
                StringWorkItem item = new StringWorkItem(CraftSynth.BuildingBlocks.IO.Clipboard.GetTextFromClipboard());                //new StringWorkItem(CraftSynth.Win32Clipboard.ClipboardProxy.GrabClipboardDataStripped(false, null).AsUnicodeText);
                item.provider = this;
                suggestions.Add("[Clipboard Text]", item);
            }

            return(suggestions);
        }
Ejemplo n.º 5
0
        public static IWorkItem GetLastWorkItem()
        {
            IWorkItem lastWorkItem = new StringWorkItem("No work items in history");

            int i = history.Count - 1;

            while (i >= 0)
            {
                if (history[i].parametersOnExecute.Count > 0)
                {
                    string lastParameterOnExecuteValueAsText = history[i].parametersOnExecute[history[i].parametersOnExecute.Count - 1].GetValueAsText();
                    if (lastParameterOnExecuteValueAsText != "last")
                    {
                        lastWorkItem = history[i].parametersOnExecute[history[i].parametersOnExecute.Count - 1];
                        break;
                    }
                }
                i--;
            }

            return(lastWorkItem);
        }
Ejemplo n.º 6
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();
        }