Ejemplo n.º 1
0
        private void ComputeCurrentArrayVariable(CommandConsoleWindow window)
        {
            if (currentArrayIDEdited < 0 || currentArrayIDEdited >= CurrentArrayTextEntered.Count)
            {
                return;
            }

            //TODO refactor this condition mess

            CurrentArrayTextEntered[CurrentArrayIDEdited] = CurrentTextEntered;

            object outputObj = null;

            if (!Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage &&
                !CurrentTextEntered.IsNullOrEmpty())
            {
                currentInterpreter.TryParse(CurrentTextEntered, out outputObj);
            }

            if ((!CurrentTextEntered.IsNullOrEmpty() || CurrentAutoCompleteID != -1) &&
                IsAutoCompleteSuggestions && outputObj == null &&
                (Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage || CurrentAutoCompleteID != -1))
            {
                if (CurrentAutoCompleteID == -1)
                {
                    CurrentAutoCompleteID = 0;
                }

                CurrentArrayValuesParsed[CurrentArrayIDEdited] =
                    (CurrentAutoComplete.GetValue(CurrentAutoCompleteID));
                CurrentArrayTextEntered[CurrentArrayIDEdited] =
                    CurrentAutoComplete.GetStringValue(CurrentAutoCompleteID);
                CurrentAutoComplete.InitializeAutoComplete();
            }
            else
            {
                CurrentArrayValuesParsed[CurrentArrayIDEdited] = outputObj;
            }

            CurrentAutoCompleteID = -1;

            CurrentAutoComplete?.InitializeAutoComplete();

            window.SelectedIndex       = -1;
            window.SearchTerms         = "";
            window.PreviousSearchTerms = "";

            window.Repaint();
            window.Focus();
        }
Ejemplo n.º 2
0
        public void NotifyNextVariable(CommandConsoleWindow window)
        {
            if (IsArray)
            {
                if (!CurrentTextEntered.IsNullOrEmpty() || CurrentAutoCompleteID != -1)
                {
                    AddNewArraySlotIfNeeded();

                    JumpToArrayID(window, currentArrayIDEdited + 1);
                    return;
                }
            }

            if (CurrentParameterID != -1)
            {
                ComputeCurrentParameterValue(window);
            }

            if (HasNextVariable)
            {
                CurrentParameterID++;
            }
            else
            {
                window.TryExecuteCurrentParametricCommand();
                return;
            }



            PrepareParameterEdition();

            window.SelectedIndex = CurrentAutoCompleteID;

            window.TabFrames = 10;
            window.Repaint();
        }
Ejemplo n.º 3
0
        private void ComputeCurrentParameterValue(CommandConsoleWindow window)
        {
            if (CurrentParameterID == -1)
            {
                return;
            }

            LastParameterCompleted = CurrentParameterID;

            if (!IsArray)
            {
                TextEntered[CurrentParameterID] = CurrentTextEntered;

                object parsedObject = null;


                if (!CurrentParameterInfo.PreventDefaultValueUsage &&
                    CurrentTextEntered.IsNullOrEmpty())
                {
                    parsedObject = CurrentParameterInfo.DefaultValue;
                    if (CurrentAutoComplete != null)
                    {
                        if (CurrentAutoCompleteID == -1 || CurrentAutoCompleteID >= CurrentAutoComplete.Count)
                        {
                            for (int i = 0; i < CurrentAutoComplete.Count; i++)
                            {
                                if (CurrentAutoComplete.GetValue(i) != null &&
                                    CurrentAutoComplete.GetValue(i).ToString() == parsedObject.ToString())
                                {
                                    CurrentAutoCompleteID = i;
                                    break;
                                }
                            }
                        }
                        if (CurrentAutoCompleteID != -1 && CurrentAutoCompleteID < CurrentAutoComplete.Count)
                        {
                            parsedObject = CurrentAutoComplete.GetValue(CurrentAutoCompleteID);
                        }
                    }
                }
                else
                {
                    if (!Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage &&
                        CurrentAutoCompleteID == -1)
                    {
                        currentInterpreter.TryParse(CurrentTextEntered, out parsedObject);
                    }

                    if (IsAutoCompleteSuggestions &&
                        parsedObject == null &&
                        (Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage ||
                         CurrentAutoCompleteID != -1))
                    {
                        if (CurrentAutoCompleteID == -1)
                        {
                            CurrentAutoCompleteID = 0;
                        }

                        if (CurrentAutoComplete != null)
                        {
                            if (CurrentAutoComplete.Count <= CurrentAutoCompleteID)
                            {
                                CurrentAutoComplete.GenerateAndSortAutoComplete(CurrentTextEntered);
                            }

                            parsedObject = CurrentAutoComplete.GetValue(CurrentAutoCompleteID);
                            TextEntered[CurrentParameterID] =
                                CurrentAutoComplete.GetStringValue(CurrentAutoCompleteID);
                        }
                        else
                        {
                            parsedObject = CurrentParameterInfo.DefaultValue;
                        }
                    }
                }



                if (parsedObject == null)
                {
                    valuesParsed[CurrentParameterID] = TextEntered[CurrentParameterID]
                                                       .IsNullOrEmpty() && !CurrentParameterInfo.PreventDefaultValueUsage
                        ? Info.CommandParameterInfo[CurrentParameterID].DefaultValue
                        : null;
                }
                else
                {
                    valuesParsed[CurrentParameterID] = parsedObject;
                }
            }
            else
            {
                ComputeCurrentArrayVariable(window);
                if (CurrentArrayValuesParsed != null && CurrentArrayValuesParsed.Count > 0)
                {
                    if (!CurrentArrayValuesParsed.Contains(null))
                    {
                        Type elemType = CurrentParameterInfo.ParameterType.GetElementType();
                        if (elemType != null)
                        {
                            var obj = Array.CreateInstance(elemType,
                                                           CurrentArrayValuesParsed.Count);
                            for (int i = 0; i < CurrentArrayValuesParsed.Count; i++)
                            {
                                obj.SetValue(CurrentArrayValuesParsed[i], i);
                            }
                            valuesParsed[CurrentParameterID] = obj;
                        }
                        else
                        {
                            valuesParsed[CurrentParameterID] = null;
                        }
                    }
                    else
                    {
                        valuesParsed[CurrentParameterID] = null;
                    }
                    arrayValuesParsed[CurrentParameterID] = CurrentArrayValuesParsed;
                }
                else if (!CurrentParameterInfo.PreventDefaultValueUsage &&
                         CurrentParameterInfo.DefaultValue != null)
                {
                    valuesParsed[CurrentParameterID] = CurrentParameterInfo.DefaultValue;
                    Array ar = (Array)
                               CurrentParameterInfo.DefaultValue;

                    if (ar != null)
                    {
                        List <object> list = new List <object>();

                        foreach (object o in ar)
                        {
                            list.Add(o);
                        }

                        arrayValuesParsed[CurrentParameterID] = list;
                    }
                }
                else
                {
                    valuesParsed[CurrentParameterID]      = null;
                    arrayValuesParsed[CurrentParameterID] = CurrentArrayValuesParsed;
                }
            }
        }
Ejemplo n.º 4
0
        private void PrepareParameterEdition()
        {
            CommandParameterInfo paramInfo = Info.CommandParameterInfo[CurrentParameterID];

            currentInterpreter = CommandParameterInterpreter.
                                 GetInterpreter(paramInfo.ParameterType);
            CurrentTextEntered = TextEntered[CurrentParameterID];

            CurrentAutoComplete = paramInfo.HasAutoComplete
                ? paramInfo.AutoComplete
                : AutoCompleteManager.GetDefaultAutoComplete(IsArray ?
                                                             paramInfo.ParameterType.GetElementType() :
                                                             paramInfo.ParameterType);

            CurrentAutoComplete?.InitializeAutoComplete();

            CurrentAutoCompleteID = -1;

            if (!CurrentParameterInfo.PreventDefaultValueUsage && CurrentParameterInfo.HadDefaultValue && CurrentAutoComplete != null)
            {
                if (CurrentAutoComplete.Count == 0)
                {
                    CurrentAutoComplete.GenerateAndSortAutoComplete("");
                }

                for (int i = 0; i < CurrentAutoComplete.Count; i++)
                {
                    if (CurrentAutoComplete.GetValue(i).Equals(CurrentParameterInfo.DefaultValue))
                    //   if (CurrentAutoComplete.GetValue(i).ToString() == CurrentParameterInfo.DefaultValue.ToString())
                    {
                        CurrentAutoCompleteID = i;
                        break;
                    }
                }
            }

            if (IsArray)
            {
                CurrentArrayTextEntered  = arrayTextEntered[CurrentParameterID];
                CurrentArrayValuesParsed = arrayValuesParsed[CurrentParameterID];
                currentArrayIDEdited     = CurrentArrayTextEntered.Count - 1;
                if (CurrentArrayIDEdited >= 0)
                {
                    CurrentTextEntered = CurrentArrayTextEntered[CurrentArrayIDEdited];
                }
            }
            else
            {
                CurrentTextEntered = TextEntered[CurrentParameterID];
            }

            if (!CurrentTextEntered.IsNullOrEmpty())
            {
                RegenerateAutoComplete();
            }
            else
            {
                CurrentAutoComplete?.InitializeAutoComplete();
            }

            CommandConsoleWindow.CurrentPanel.SearchTerms         = CurrentTextEntered;
            CommandConsoleWindow.CurrentPanel.PreviousSearchTerms = CurrentTextEntered;
        }