Esempio n. 1
0
        /// <summary>
        /// Generates completion options for a report. This should also work for the property presenter.
        /// </summary>
        /// <param name="code">Source code.</param>
        /// <param name="offset">Offset of the cursor/caret in the source code.</param>
        /// <param name="controlSpace">True iff this intellisense request was generated by the user pressing control + space.</param>
        /// <returns>True if any completion options are found. False otherwise.</returns>
        public bool GenerateGridCompletions(string cellContents, int offset, IModel model, bool properties, bool methods, bool events, bool controlSpace = false)
        {
            // TODO : Perhaps there should be a separate intellisense class for grid completions?
            string contentsToCursor = cellContents.Substring(0, offset);

            // Remove any potential trailing period.
            contentsToCursor = contentsToCursor.TrimEnd('.');

            // Ignore everything before the most recent comma.
            string objectName = contentsToCursor.Substring(contentsToCursor.LastIndexOf(',') + 1);

            // Set the trigger word for later use.
            triggerWord = controlSpace ? GetTriggerWord(objectName) : string.Empty;

            // Ignore everything before most recent model name in square brackets.
            // I'm assuming that model/node names cannot start with a number.
            string modelNamePattern = @"\[([A-Za-z]+[A-Za-z0-9]*)\]";
            var    matches          = System.Text.RegularExpressions.Regex.Matches(objectName, modelNamePattern);

            if (matches.Count > 0)
            {
                int modelNameIndex = objectName.LastIndexOf(matches[matches.Count - 1].Value);
                if (modelNameIndex >= 0)
                {
                    objectName = objectName.Substring(modelNameIndex);
                }
            }

            List <NeedContextItemsArgs.ContextItem> results = NeedContextItemsArgs.ExamineModelForContextItemsV2(model as Model, objectName, properties, methods, events);

            view.Populate(results);
            return(results.Any());
        }
Esempio n. 2
0
 /// <summary>
 /// User has pressed a '.'.
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
 {
     if (this.ContextItemsNeeded != null)
     {
         this.ContextItemsNeeded.Invoke(this, e);
     }
 }
Esempio n. 3
0
        private void OnKeyPress(object sender, KeyPressEventArgs args)
        {
            bool controlSpace      = (args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask && args.Event.Key == Gdk.Key.space;
            bool controlShiftSpace = controlSpace && (args.Event.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask;
            bool isPeriod          = args.Event.Key == Gdk.Key.period;

            if (isPeriod || controlSpace || controlShiftSpace)
            {
                if (IntellisenseItemsNeeded != null)
                {
                    int x, y;
                    textentry1.GdkWindow.GetOrigin(out x, out y);
                    System.Drawing.Point coordinates = new System.Drawing.Point(x, y + textentry1.SizeRequest().Height);
                    NeedContextItemsArgs e           = new NeedContextItemsArgs()
                    {
                        Coordinates       = coordinates,
                        Code              = textentry1.Text,
                        ControlSpace      = controlSpace,
                        ControlShiftSpace = controlShiftSpace,
                        Offset            = Offset,
                        ColNo             = this.textentry1.CursorPosition
                    };
                    lastText = textentry1.Text;
                    IntellisenseItemsNeeded.Invoke(this, e);
                }
            }
            else if ((args.Event.Key & Gdk.Key.Return) == Gdk.Key.Return)
            {
                OnSelectionChanged(this, EventArgs.Empty);
            }
        }
 /// <summary>
 /// Called when the view is asking for completion items.
 /// Shows the intellisense popup.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event data.</param>
 private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
 {
     if (intellisense.GenerateGridCompletions(e.Code, e.Offset, tableModel as IModel, true, false, false, false, false))
     {
         intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Intellisense lookup.
        /// </summary>
        void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName == "")
            {
                e.ObjectName = ".";
            }
            try
            {
                Experiment experiment = Factor.Parent.Parent as Experiment;
                if (experiment != null && experiment.BaseSimulation != null)
                {
                    object o = experiment.BaseSimulation.Get(e.ObjectName);

                    if (o != null)
                    {
                        foreach (IVariable Property in Apsim.FieldsAndProperties(o, BindingFlags.Instance | BindingFlags.Public))
                        {
                            e.Items.Add(Property.Name);
                        }
                        e.Items.Sort();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 6
0
 /// <summary>
 /// The view is asking for items for its intellisense.
 /// </summary>
 /// <param name="sender">Editor that the user is typing in.</param>
 /// <param name="e">Event Arguments.</param>
 /// <param name="properties">Whether or not property suggestions should be generated.</param>
 /// <param name="methods">Whether or not method suggestions should be generated.</param>
 /// <param name="events">Whether or not event suggestions should be generated.</param>
 private void GetCompletionOptions(object sender, NeedContextItemsArgs e, bool properties, bool methods, bool events)
 {
     try
     {
         string currentLine = GetLine(e.Code, e.LineNo - 1);
         if (intellisense.GenerateGridCompletions(currentLine, e.ColNo, report, properties, methods, events, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.Item1, e.Coordinates.Item2);
         }
         intellisense.ItemSelected += (o, args) =>
         {
             if (args.ItemSelected == string.Empty)
             {
                 (sender as IEditorView).InsertAtCaret(args.ItemSelected);
             }
             else
             {
                 (sender as IEditorView).InsertCompletionOption(args.ItemSelected, args.TriggerWord);
             }
         };
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 7
0
 private void OnKeyPress(object sender, KeyPressEventArgs args)
 {
     if ((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask && args.Event.Key == Gdk.Key.space)
     {
         /*
          * Point p = textEditor.TextArea.LocationToPoint(textEditor.Caret.Location);
          * p.Y += (int)textEditor.LineHeight;
          * // Need to convert to screen coordinates....
          * int x, y, frameX, frameY;
          * MasterView.MainWindow.GetOrigin(out frameX, out frameY);
          * textEditor.TextArea.TranslateCoordinates(_mainWidget.Toplevel, p.X, p.Y, out x, out y);
          */
         if (IntellisenseItemsNeeded != null)
         {
             int x, y;
             textentry1.GdkWindow.GetOrigin(out x, out y);
             Tuple <int, int>     coordinates = new Tuple <int, int>(x, y + textentry1.SizeRequest().Height);
             NeedContextItemsArgs e           = new NeedContextItemsArgs()
             {
                 Coordinates = coordinates,
                 Code        = textentry1.Text,
                 Offset      = Offset
             };
             lastText = textentry1.Text;
             IntellisenseItemsNeeded.Invoke(this, e);
         }
     }
     else if ((args.Event.Key & Gdk.Key.Return) == Gdk.Key.Return)
     {
         OnSelectionChanged(this, EventArgs.Empty);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// The view is asking for event names.
        /// </summary>
        void OnNeedEventNames(object Sender, NeedContextItemsArgs e)
        {
            object o = Apsim.Get(Report, e.ObjectName);

            if (o != null)
            {
                e.AllItems.AddRange(NeedContextItemsArgs.ExamineObjectForContextItems(o, false, false, true));
            }
        }
Esempio n. 9
0
        [GLib.ConnectBefore] // Otherwise this is handled internally, and we won't see it
        private void OnKeyPress(object sender, KeyPressEventArgs e)
        {
            char keyChar      = (char)Gdk.Keyval.ToUnicode(e.Event.KeyValue);
            bool controlSpace = IsControlSpace(e.Event);

            if (e.Event.Key == Gdk.Key.F3)
            {
                if (string.IsNullOrEmpty(_findForm.LookFor))
                {
                    _findForm.ShowFor(textEditor, false);
                }
                else
                {
                    _findForm.FindNext(true, (e.Event.State & Gdk.ModifierType.ShiftMask) == 0, string.Format("Search text «{0}» not found.", _findForm.LookFor));
                }
                e.RetVal = true;
            }
            else if (IntelliSenseChars.Contains(keyChar.ToString()) || controlSpace)
            {
                // If user one of the IntelliSenseChars, then display contextlist.
                string textBeforePeriod = GetWordBeforePosition(textEditor.Caret.Offset) + keyChar;

                // If the user entered a period, we need to take that into account when generating intellisense options.
                // To do this, we insert a period manually and stop the Gtk signal from propagating further.
                e.RetVal = true;
                if (keyChar == '.')
                {
                    textEditor.InsertAtCaret(keyChar.ToString());

                    // Process all events in the main loop, so that the period is inserted into the text editor.
                    while (GLib.MainContext.Iteration())
                    {
                        ;
                    }
                }
                NeedContextItemsArgs args = new NeedContextItemsArgs
                {
                    Coordinates  = GetPositionOfCursor(),
                    Code         = textEditor.Text,
                    Offset       = this.Offset,
                    ControlSpace = controlSpace,
                    LineNo       = textEditor.Caret.Line,
                    ColNo        = textEditor.Caret.Column - 1
                };

                ContextItemsNeeded?.Invoke(this, args);
            }
            else if (e.Event.Key == Gdk.Key.Key_0 && (e.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
            {
                textEditor.Options.ZoomReset();
                e.RetVal = true;
            }
            else
            {
                e.RetVal = false;
            }
        }
Esempio n. 10
0
 /// <summary>
 /// The view is asking for variable names for its intellisense.
 /// </summary>
 /// <param name="sender">Sending object</param>
 /// <param name="e">Context item arguments</param>
 public void OnNeedVariableNames(object sender, NeedContextItemsArgs e)
 {
     try
     {
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// The view is asking for items for the intellisense.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void OnIntellisenseNeeded(object sender, NeedContextItemsArgs args)
 {
     try
     {
         //fixme if (intellisense.GenerateSeriesCompletions(args.Code, args.Offset, view.TableList.SelectedValue, dataStore.Reader))
         intellisense.Show(args.Coordinates.X, args.Coordinates.Y);
     }
     catch (Exception err)
     {
         presenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// The view is asking for variable names.
        /// </summary>
        void OnNeedVariableNames(object Sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName == "")
            {
                e.ObjectName = ".";
            }
            object o = Apsim.Get(Report, e.ObjectName);

            if (o != null)
            {
                e.AllItems.AddRange(NeedContextItemsArgs.ExamineObjectForContextItems(o, true, true, true));
            }
        }
Esempio n. 13
0
 private void GetContextItems(object o, NeedContextItemsArgs e)
 {
     try
     {
         if (intellisense.GenerateGridCompletions(e.Code, e.Offset, model, true, false, false, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.Item1, e.Coordinates.Item2);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 14
0
 /// <summary>
 /// The view is asking for items for the intellisense.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void OnIntellisenseNeeded(object sender, NeedContextItemsArgs args)
 {
     try
     {
         if (intellisense.GenerateSeriesCompletions(args.Code, args.Offset, view.TableList.SelectedValue, dataStore))
         {
             intellisense.Show(args.Coordinates.Item1, args.Coordinates.Item2);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 15
0
 /// <summary>
 /// The view is asking for variable names for its intellisense.
 /// </summary>
 /// <param name="sender">Sending object</param>
 /// <param name="e">Context item arguments</param>
 public void OnNeedVariableNames(object sender, NeedContextItemsArgs e)
 {
     try
     {
         if (intellisense.GenerateScriptCompletions(e.Code, e.Offset, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.Item1, e.Coordinates.Item2);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Invoked when the user is asking for items for the intellisense.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void OnIntellisenseItemsNeeded(object sender, NeedContextItemsArgs args)
 {
     try
     {
         if (intellisense.GenerateSeriesCompletions(args.Code, args.Offset, seriesView.DataSource.SelectedValue, storage.Reader))
         {
             intellisense.Show(args.Coordinates.X, args.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Invoked when the view is asking for completion options.
 /// Generates and displays these completion options.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Evenet arguments.</param>
 private void OnIntellisenseItemsNeeded(object sender, NeedContextItemsArgs args)
 {
     try
     {
         if (intellisense.GenerateGridCompletions(args.Code, args.Offset, (tableModel as IModel).Children[0], true, false, false, args.ControlSpace))
         {
             intellisense.Show(args.Coordinates.X, args.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         presenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Gets a list of all events which are published by models in
        /// the current simulations tree.
        /// </summary>
        /// <param name="model"></param>
        public List <NeedContextItemsArgs.ContextItem> GetEvents(IModel model)
        {
            var events = new List <NeedContextItemsArgs.ContextItem>();

            List <IModel> allModels = Apsim.ChildrenRecursively(Apsim.Parent(model, typeof(Simulations)));

            foreach (var publisher in Events.Publisher.FindAll(allModels))
            {
                string description = NeedContextItemsArgs.GetDescription(publisher.EventInfo);
                Type   eventType   = publisher.EventInfo.EventHandlerType;
                events.Add(NeedContextItemsArgs.ContextItem.NewEvent(publisher.Name, description, eventType));
            }

            return(events);
        }
Esempio n. 19
0
        /// <summary>
        /// Gets a list of all events which are published by models in
        /// the current simulations tree.
        /// </summary>
        /// <param name="model"></param>
        public List <NeedContextItemsArgs.ContextItem> GetEvents(IModel model)
        {
            var events = new List <NeedContextItemsArgs.ContextItem>();

            IEnumerable <IModel> allModels = model.FindAncestor <Simulations>().FindAllDescendants();

            foreach (var publisher in Events.Publisher.FindAll(allModels))
            {
                string description = NeedContextItemsArgs.GetDescription(publisher.EventInfo);
                Type   eventType   = publisher.EventInfo.EventHandlerType;
                events.Add(NeedContextItemsArgs.ContextItem.NewEvent(publisher.Name, description, eventType));
            }

            return(events);
        }
Esempio n. 20
0
 /// <summary>
 /// The view is asking for items for its intellisense.
 /// </summary>
 /// <param name="sender">Editor that the user is typing in.</param>
 /// <param name="e">Event Arguments.</param>
 /// <param name="properties">Whether or not property suggestions should be generated.</param>
 /// <param name="methods">Whether or not method suggestions should be generated.</param>
 /// <param name="events">Whether or not event suggestions should be generated.</param>
 private void GetCompletionOptions(object sender, NeedContextItemsArgs e, bool properties, bool methods, bool events)
 {
     try
     {
         string currentLine = GetLine(e.Code, e.LineNo - 1);
         currentEditor = sender;
         if (!e.ControlShiftSpace && intellisense.GenerateGridCompletions(currentLine, e.ColNo, report, properties, methods, events, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 21
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Context item arguments</param>
        public void OnNeedVariableNames(object sender, NeedContextItemsArgs e)
        {
            CSharpParser parser     = new CSharpParser();
            SyntaxTree   syntaxTree = parser.Parse(this.managerView.Editor.Text); // Manager.Code);

            syntaxTree.Freeze();

            IEnumerable <FieldDeclaration> fields = syntaxTree.Descendants.OfType <FieldDeclaration>();

            e.ObjectName = e.ObjectName.Trim(" \t".ToCharArray());
            string typeName = string.Empty;

            // Determine the field name to find. User may have typed
            // Soil.SoilWater. In this case the field to look for is Soil
            string fieldName = e.ObjectName;
            int    posPeriod = e.ObjectName.IndexOf('.');

            if (posPeriod != -1)
            {
                fieldName = e.ObjectName.Substring(0, posPeriod);
            }

            // Look for the field name.
            foreach (FieldDeclaration field in fields)
            {
                foreach (VariableInitializer var in field.Variables)
                {
                    if (fieldName == var.Name)
                    {
                        typeName = field.ReturnType.ToString();
                    }
                }
            }

            // find the properties and methods
            if (typeName != string.Empty)
            {
                Type atype = ReflectionUtilities.GetTypeFromUnqualifiedName(typeName);
                if (posPeriod != -1)
                {
                    string childName = e.ObjectName.Substring(posPeriod + 1);
                    atype = this.FindType(atype, childName);
                }

                e.AllItems.AddRange(NeedContextItemsArgs.ExamineTypeForContextItems(atype, true, true, false));
            }
        }
Esempio n. 22
0
 private void GetContextItems(object o, NeedContextItemsArgs e)
 {
     try
     {
         if (e.ControlShiftSpace)
         {
             intellisense.ShowMethodCompletion(model, e.Code, e.Offset, new Point(e.Coordinates.X, e.Coordinates.Y));
         }
         else if (intellisense.GenerateGridCompletions(e.Code, e.Offset, model, true, false, false, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         presenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 23
0
 /// <summary>User has pressed a '.' in the commands window - supply context items.</summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
 {
     try
     {
         if (e.ControlShiftSpace)
         {
             intellisense.ShowMethodCompletion(cultivar, e.Code, e.Offset, new Point(e.Coordinates.X, e.Coordinates.Y));
         }
         else if (intellisense.GenerateGridCompletions(e.Code, e.Offset, cultivar, true, false, false, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 24
0
 /// <summary>
 /// The view is asking for variable names for its intellisense.
 /// </summary>
 /// <param name="sender">Sending object</param>
 /// <param name="e">Context item arguments</param>
 public void OnNeedVariableNames(object sender, NeedContextItemsArgs e)
 {
     try
     {
         if (e.ControlShiftSpace)
         {
             intellisense.ShowScriptMethodCompletion(manager, e.Code, e.Offset, new Point(e.Coordinates.X, e.Coordinates.Y));
         }
         else if (intellisense.GenerateScriptCompletions(e.Code, e.Offset, e.ControlSpace))
         {
             intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 25
0
 /// <summary>
 /// The view is asking for items for its intellisense.
 /// </summary>
 /// <param name="sender">Editor that the user is typing in.</param>
 /// <param name="e">Event Arguments.</param>
 /// <param name="rules">Controls whether rules (events) will be shown in intellisense</param>
 private void GetCompletionOptions(object sender, NeedContextItemsArgs e, bool rules)
 {
     try
     {
         string currentLine = GetLine(e.Code, e.LineNo - 1);
         currentEditor = sender as IEditorView;
         if (!e.ControlShiftSpace &&
             (rules ?
              intellisense.GenerateGridCompletions(currentLine, e.ColNo, model, true, false, false, false, e.ControlSpace) :
              intellisense.GenerateGridCompletions(currentLine, e.ColNo, model, false, true, false, true, e.ControlSpace)))
         {
             intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
         }
     }
     catch (Exception err)
     {
         presenter.MainPresenter.ShowError(err);
     }
 }
Esempio n. 26
0
        /// <summary>User has pressed a '.' in the commands window - supply context items.</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName == string.Empty)
            {
                e.ObjectName = ".";
            }

            object o = Apsim.Get(this.cultivar, e.ObjectName);

            if (o != null)
            {
                foreach (IVariable property in Apsim.FieldsAndProperties(o, BindingFlags.Instance | BindingFlags.Public))
                {
                    e.Items.Add(property.Name);
                }

                e.Items.Sort();
            }
        }
Esempio n. 27
0
        /// <summary>User has pressed a '.' in the commands window - supply context items.</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName == string.Empty)
            {
                e.ObjectName = ".";
            }

            object o = Apsim.Get(this.cultivar, e.ObjectName);

            if (o != null)
            {
                foreach (IVariable property in Apsim.FieldsAndProperties(o, BindingFlags.Instance | BindingFlags.Public))
                {
                    e.Items.Add(property.Name);
                }

                e.Items.Sort();
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Editor needs context items.
        /// </summary>
        private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (Operations.Parent is Factor)
            {
            }
            else
            {
                object o = Apsim.Get(Operations, e.ObjectName);

                if (o == null)
                {
                    o = Apsim.Find(Operations, e.ObjectName);
                }

                if (o != null)
                {
                    e.AllItems.AddRange(NeedContextItemsArgs.ExamineObjectForContextItems(o, true, true, false));
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Intellisense lookup.
        /// </summary>
        /// <param name="sender">The menu item</param>
        /// <param name="e">Event arguments</param>
        private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName == string.Empty)
            {
                e.ObjectName = ".";
            }

            try
            {
                string currentLine = GetLine(e.Code, e.LineNo - 1);
                if (e.ControlShiftSpace)
                {
                    intellisense.ShowMethodCompletion(factor, e.Code, e.Offset, new Point(e.Coordinates.X, e.Coordinates.Y));
                }
                else if (intellisense.GenerateGridCompletions(currentLine, e.ColNo, factor, true, false, false, false, e.ControlSpace))
                {
                    intellisense.Show(e.Coordinates.X, e.Coordinates.Y);
                }
            }
            catch (Exception err)
            {
                presenter.MainPresenter.ShowError(err);
            }
        }
Esempio n. 30
0
 /// <summary>The view is asking for event names.</summary>
 /// <param name="sender">The sending object</param>
 /// <param name="e">The argument values</param>
 private void OnNeedEventNames(object sender, NeedContextItemsArgs e)
 {
     GetCompletionOptions(sender, e, false, false, true);
 }
Esempio n. 31
0
        /// <summary>
        /// Invoked when the view wants context items.
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        public void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
        {
            if (e.ObjectName.Trim() == "Simulation")
            {
                e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "All" });

                foreach (string simulationName in this.dataStore.SimulationNames)
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = simulationName });
            }
            else if (e.ObjectName.Trim() == "Test")
            {
                string tableName = this.view.TableName;
                if (tableName != null)
                {
                    DataTable data = this.dataStore.GetData("*", tableName);
                    if (data != null)
                    {
                        foreach (string columnName in DataTableUtilities.GetColumnNames(data))
                            e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = columnName });
                    }
                }
            }
            else
            {
                string simulationName = this.GetWordFromLine(this.view.Editor.CurrentLineNumber, "Simulation:", false);
                string testName = this.GetWordFromLine(this.view.Editor.CurrentLineNumber, "Test:", false);
                if (simulationName != null && testName != null)
                {
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "=" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "<" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = ">" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "AllPositive" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "between" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "mean=" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "tolerance=" });
                    e.AllItems.Add(new NeedContextItemsArgs.ContextItem() { Name = "CompareToInput=" });
                }
            }
        }
Esempio n. 32
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Context item arguments</param>
        public void OnNeedVariableNames(object sender, NeedContextItemsArgs e)
        {
            CSharpParser parser = new CSharpParser();
            SyntaxTree syntaxTree = parser.Parse(this.managerView.Editor.Text); // Manager.Code);
            syntaxTree.Freeze();

            IEnumerable<FieldDeclaration> fields = syntaxTree.Descendants.OfType<FieldDeclaration>();

            e.ObjectName = e.ObjectName.Trim(" \t".ToCharArray());
            string typeName = string.Empty;

            // Determine the field name to find. User may have typed
            // Soil.SoilWater. In this case the field to look for is Soil
            string fieldName = e.ObjectName;
            int posPeriod = e.ObjectName.IndexOf('.');
            if (posPeriod != -1)
                fieldName = e.ObjectName.Substring(0, posPeriod);

            // Look for the field name.
            foreach (FieldDeclaration field in fields)
            {
                foreach (VariableInitializer var in field.Variables)
                {
                    if (fieldName == var.Name)
                    {
                        typeName = field.ReturnType.ToString();
                    }
                }
            }

            // find the properties and methods
            if (typeName != string.Empty)
            {
                Type atype = ReflectionUtilities.GetTypeFromUnqualifiedName(typeName);
                if (posPeriod != -1)
                {
                    string childName = e.ObjectName.Substring(posPeriod + 1);
                    atype = this.FindType(atype, childName);
                }

                e.AllItems.AddRange(NeedContextItemsArgs.ExamineTypeForContextItems(atype, true, true, false));
            }
        }
Esempio n. 33
0
 /// <summary>User has pressed a '.' in the commands window - supply context items.</summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
 {
     e.AllItems.AddRange(NeedContextItemsArgs.ExamineModelForNames(this.cultivar, e.ObjectName, true, true, false));
 }
Esempio n. 34
0
 /// <summary>The view is asking for variable names.</summary>
 void OnNeedVariableNames(object Sender, NeedContextItemsArgs e)
 {
     e.AllItems.AddRange(NeedContextItemsArgs.ExamineModelForNames(report, e.ObjectName, true, true, false));
 }
Esempio n. 35
0
        /// <summary>
        /// Shows completion information for a method call.
        /// </summary>
        /// <param name="relativeTo">Model to be used as a reference when searching for completion data.</param>
        /// <param name="code">Code for which we want to generate completion data.</param>
        /// <param name="offset">Offset of the cursor/caret in the code.</param>
        public void ShowMethodCompletion(IModel relativeTo, string code, int offset, Point location)
        {
            string contentsToCursor = code.Substring(0, offset).TrimEnd('.');

            // Ignore everything before the most recent comma.
            contentsToCursor = contentsToCursor.Substring(contentsToCursor.LastIndexOf(',') + 1);

            string currentLine = contentsToCursor.Split(Environment.NewLine.ToCharArray()).Last().Trim();

            // Set the trigger word for later use.
            triggerWord = GetTriggerWord(currentLine);

            // Ignore everything before most recent model name in square brackets.
            // I'm assuming that model/node names cannot start with a number.
            string modelNamePattern = @"\[([A-Za-z]+[A-Za-z0-9]*)\]";
            string objectName       = currentLine;
            var    matches          = System.Text.RegularExpressions.Regex.Matches(code, modelNamePattern);

            if (matches.Count > 0)
            {
                int modelNameIndex = currentLine.LastIndexOf(matches[matches.Count - 1].Value);
                if (modelNameIndex >= 0)
                {
                    currentLine = currentLine.Substring(modelNameIndex);
                    int lastPeriod = currentLine.LastIndexOf('.');
                    objectName = lastPeriod >= 0 ? currentLine.Substring(0, lastPeriod) : currentLine;
                }
            }
            string     methodName = triggerWord.TrimEnd('(');
            MethodInfo method     = NeedContextItemsArgs.GetMethodInfo(relativeTo as Model, methodName, objectName);

            if (method == null)
            {
                return;
            }
            MethodCompletion completion = new MethodCompletion();

            List <string> parameterStrings       = new List <string>();
            StringBuilder parameterDocumentation = new StringBuilder();

            foreach (ParameterInfo parameter in method.GetParameters())
            {
                string parameterString = string.Format("{0} {1}", parameter.ParameterType.Name, parameter.Name);
                if (parameter.DefaultValue != DBNull.Value)
                {
                    parameterString += string.Format(" = {0}", parameter.DefaultValue.ToString());
                }
                parameterStrings.Add(parameterString);
                parameterDocumentation.AppendLine(string.Format("{0}: {1}", parameter.Name, NeedContextItemsArgs.GetDescription(method, parameter.Name)));
            }
            string parameters = parameterStrings.Aggregate((a, b) => string.Format("{0}, {1}", a, b));

            completion.Signature = string.Format("{0} {1}({2})", method.ReturnType.Name, method.Name, parameters);
            completion.Summary   = NeedContextItemsArgs.GetDescription(method);
            completion.ParameterDocumentation = parameterDocumentation.ToString().Trim(Environment.NewLine.ToCharArray());

            methodCompletionView.Completions = new List <MethodCompletion>()
            {
                completion
            };
            methodCompletionView.Location = location;
            methodCompletionView.Visible  = true;
        }
Esempio n. 36
0
 /// <summary>
 /// User has pressed a '.'.
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void OnContextItemsNeeded(object sender, NeedContextItemsArgs e)
 {
     if (this.ContextItemsNeeded != null)
     {
         this.ContextItemsNeeded.Invoke(this, e);
     }
 }