示例#1
0
        void CompletionList_OnInsert(ScintillaControl sender, int position, string text, char trigger, ICompletionListItem item)
        {
            if (trigger == '(' || trigger == '.') return;
            if (!(item is MemberItem)) return; // Generate Event
              //      if (item is EventItem) return;
             currentData = (DataEvent)currentNotifyEvent;
             Hashtable table = currentData.Data as Hashtable;
             if (table==null) return;

            ASResult res = (table)["context"] as ASResult;

            if (res == null) return;

            MemberModel member = res.Member;
            int posAdd = 0;

                    if (member != null)
                    {
                        if ((member.Flags & FlagType.Function) == 0) { return; }

                            int pos = sender.CurrentPos;
                            int insertPos = pos;
                            if (((member.Flags & FlagType.Constructor) > 0))
                            {

                                if (!thereIsNewWord(sender))
                                {
                                    sender.GotoPos(pos);
                                    return;
                                }
                            }

                          //  sender.ReplaceSel
                                bool hasParameters = false;

                                char lastChar=' ';
                                posAdd = SearchNextNewLineWithoutChar(sender, position, text, ref lastChar);

                                if (lastChar == '(')
                                {
                                    return;
                                }

                            // Search if is a parameter of a function
                                if (lastChar == ',' || lastChar == ')')
                                {
                                    if (IsFunctionParameter(sender, position - 1))
                                    {
                                        return;
                                    };
                                }

                                sender.BeginUndoAction();

                                if (posAdd > 0)
                                {
                                    sender.InsertText(pos, "();");
                                    posAdd = 1;

                                }
                                else
                                    sender.InsertText(pos, "()");

                                pos++;

                                if (!(trigger == '[' || trigger == '"'))
                                {
                                    if (member.Parameters != null)
                                    {
                                        if (member.Parameters.Count == 0)
                                        {
                                            pos += 1 + posAdd;

                                        }
                                        else
                                        {
                                            hasParameters = true;
                                        }

                                    }
                                    else
                                    {
                                        pos += 1 + posAdd;
                                    }

                                }

                                sender.GotoPos(pos);

                                if (hasParameters)
                                {
                                    if (abbreviations != null &&  member.Parameters[0].Value == null && member.Parameters[0].Name != "...rest")
                                    {

                                       // string str = res.Member.ToString();
                                        TextParameters tp = new TextParameters(res.Member);

                                        if (member.Name.EndsWith("EventListener"))
                                        {
                                            if (text.EndsWith("Event"))
                                            {
                                                sender.GotoPos(insertPos+2);
                                                sender.DeleteBack();
                                                sender.DeleteBack();
                                                sender.EndUndoAction();
                                                return;
                                            }
                                            abbreviations.CreateParameters(member.Parameters, true,tp);

                                        }
                                        else
                                            abbreviations.CreateParameters(member.Parameters, false,tp);

                                        sender.EndUndoAction();
                                        return;
                                    }

                                    ASComplete.HandleFunctionCompletion(sender, true);
                                }

                                sender.EndUndoAction();

                    }
                    else if (res.Type != null)
                    {

                        int pos2 = sender.CurrentPos;

                        bool hasParameters = false;
                        MemberModel mlConstructor = null;

                        if (!thereIsNewWord(sender)) { sender.GotoPos(pos2); return; }

                            char lastChar=' ';
                            posAdd = SearchNextNewLineWithoutChar(sender, pos2, "",ref lastChar);

                            if (lastChar == '(') { sender.GotoPos(pos2); return; }

                            if (res.Type.Members.Count > 0)
                            {

                                foreach (MemberModel ml in res.Type.Members)
                                {
                                    if ((ml.Flags & FlagType.Constructor)>0)
                                    {
                                        if (ml.Parameters!=null && ml.Parameters.Count > 0)
                                        {
                                            mlConstructor = ml;
                                            hasParameters = true;
                                        }
                                        break;
                                    }
                                }

                            }

                            if(posAdd>0)
                                sender.InsertText(pos2, "();");
                            else
                            sender.InsertText(pos2, "()");

                            if (trigger == '[' || trigger == '"' || hasParameters)
                              pos2++;
                            else
                            pos2 += 2 + posAdd;

                        sender.GotoPos(pos2);
                        if (hasParameters)
                        {
                            sender.BeginUndoAction();
                            if (abbreviations != null && mlConstructor.Parameters[0].Value == null && mlConstructor.Parameters[0].Name != "...rest")
                            {
                                TextParameters tp = new TextParameters(mlConstructor);

                               abbreviations.CreateParameters(mlConstructor.Parameters, false, tp);
                            }
                            else
                                ASComplete.HandleFunctionCompletion(sender, true);
                            sender.EndUndoAction();
                        }

                    }
        }
 void IDisposable.Dispose()
 {
     textParameters = null;
     textParameter = null;
     NextWord = null;
 }
示例#3
0
        /// <summary>
        /// Place the cursor a the end of the next word
        /// </summary>
        public void MoveNextWord()
        {
            if (isList>-1)
            {

                CompletionList.OnInsert -= new InsertedTextHandler(CompletionList_OnInsert);
                if (CompletionList.Active)
                    CompletionList.Hide();
                isList = -1;
            }

            if (UITools.CallTip.CallTipActive)
                UITools.CallTip.Hide();

            curIndWord++;

            if (curIndWord >= Words.Count ) curIndWord = 0;

             WordRegionBase wr =  Words[curIndWord];

               if (wr.type == WordRegion.kind.place || wr.type== WordRegionBase.kind.VarLink)
               {
                   sciMonitor.SetSel(wr.startWord, wr.endWord);

                   return;
               }
               else if (wr.type == WordRegionBase.kind.Parameter)
               {
                   sciMonitor.SetSel(wr.startWord, wr.endWord);

                   ((WordRegionParameter)wr).ShowTips(sciMonitor);

               }
               else if (wr.type == WordRegionBase.kind.customList)
               {
                   sciMonitor.SetSel(wr.startWord, wr.endWord);
                   WordCustomList wc = (WordCustomList)wr;
                   List<PluginCore.ICompletionListItem> lcomp = new List<PluginCore.ICompletionListItem>();
                   List<string> ls = null;
                   if (_dictCustomList.ContainsKey(wc.indList))
                   {

                       ls = _dictCustomList[wc.indList];

                       if (ls.Count == 0)
                       {
                           UITools.CallTip.CallTipShow(ASContext.CurSciControl,ASContext.CurSciControl.CurrentPos, "This List is empty!!");
                           return;
                       }
                       else
                       {
                           foreach (string item in ls)
                           {
                               lcomp.Add(new CompletionListItem(item, ManagerResources.EmptyBitmap));
                           }
                       }
                   }
                   else
                   {
                       UITools.CallTip.CallTipShow(ASContext.CurSciControl, ASContext.CurSciControl.CurrentPos, "No list at current index!!");
                       return;
                   }

                   CompletionList.OnInsert += new InsertedTextHandler(CompletionList_OnInsert);
                   CompletionList.Show(lcomp, false);

                   isList = curIndWord;

               }
               else if (wr.type == WordRegion.kind.showCompType || wr.type == WordRegionBase.kind.VarLinkAndComp)
               {
                   sciMonitor.SetSel(wr.startWord, wr.endWord);

                   if (ASContext.HasContext && ASContext.Context.IsFileValid)
                   {
                       int pos = wr.startWord - 1;
                       char c = (char)sciMonitor.CharAt(pos);

                       if (c == ' ')
                           c = '.';

                    //   CompletionList.OnChar(sciMonitor, (int)c);
                      UITools.Manager.SendChar(sciMonitor, c);
                      if (!CompletionList.Active) return;

                       CompletionList.OnInsert += new InsertedTextHandler(CompletionList_OnInsert);
                       isList = curIndWord;

                   }

               }
               else if (wr.type == WordRegion.kind.temporary )
               {
                   //if (wr.type == WordRegionBase.kind.Import)
                   //{

                   //    MoveNextWord();
                   //    // eliminate import word
                   //    Words.Remove(declarationWord);
                   //    firstWord = declarationWord.NextWord;
                   //    declarationWord.NextWord = null;
                   //    declarationWord = null;

                   //    return;
                   //}

                   sciMonitor.GotoPos(wr.endWord - 1);

               }
               else if (wr.type == WordRegion.kind.cursor)
               {
                   sciMonitor.GotoPos(wr.endWord);
                   //isCursorWord = true;
               }
               else if (wr.type == WordRegionBase.kind.createParameters)
               {
                   sciMonitor.GotoPos(wr.startWord);
                   ASCompletion.Completion.ASResult result = null;

                   // sciMonitor.GotoPos(wr.startWord);

                  int pos = sciMonitor.CurrentPos;
                  int pos2 = pos;

                  char c =(char) sciMonitor.CharAt(--pos);

                   while(char.IsWhiteSpace(c))
                   {
                       c = (char)sciMonitor.CharAt(--pos);
                   }

                   if (c != '(') return;

                   char c2 = (char)sciMonitor.CharAt(pos2);

                   while (char.IsWhiteSpace(c2))
                   {
                       c2 = (char)sciMonitor.CharAt(++pos2);
                   }

                   if (c2 != ')') return;

                  if(PathExplorer.IsWorking)
                  {
                      Abbreviations.WaitFinishPathExplorer();
                  }

                   c = (char)sciMonitor.CharAt(--pos);

                  while (char.IsWhiteSpace(c))
                  {
                      c = (char)sciMonitor.CharAt(--pos);
                  }
                  pos++;

                   //sciMonitor.WordLeft();
                   //string str = sciMonitor.GetWordFromPosition(pos);
                   //string str1 = sciMonitor.GetLine(sciMonitor.LineFromPosition(wr.startWord));
                     result = ASCompletion.Completion.ASComplete.GetExpressionType(sciMonitor, pos);

                   if (result.Member != null)
                   {

                       if ( result.Member.Parameters!=null &&  result.Member.Parameters.Count > 0)
                       {
                           if (result.Member.Parameters[0].Value == null &&  result.Member.Parameters[0].Type!=null && result.Member.Parameters[0].Name != "...rest")
                           {

                               TextParameters tp = new TextParameters(result.Member);

                               CreateParameters(result.Member.Parameters, tp);
                               return;
                           }
                           else
                           {
                               sciMonitor.GotoPos(wr.endWord);
                               ASCompletion.Completion.ASComplete.HandleFunctionCompletion(sciMonitor, true);
                           }
                       }
                       else
                       {
                           sciMonitor.GotoPos(wr.endWord);
                       }
                   }
                   else if (result.Type != null)
                   {
                       if (result.Type.Members.Count > 0)
                       {

                           foreach (MemberModel ml in result.Type.Members)
                           {
                               if ((ml.Flags & FlagType.Constructor) > 0)
                               {
                                   if (ml.Parameters != null && ml.Parameters.Count > 0)
                                   {
                                       if (ml.Parameters[0].Value == null && ml.Parameters[0].Name != "...rest")
                                       {
                                           TextParameters tp = new TextParameters(ml);

                                           CreateParameters(ml.Parameters, tp);

                                       }
                                       else
                                       {
                                           sciMonitor.GotoPos(wr.endWord);
                                           ASCompletion.Completion.ASComplete.HandleFunctionCompletion(sciMonitor, true);
                                       }

                                   }

                                   break;
                               }
                           }
                       }
                       else
                       {
                           sciMonitor.GotoPos(wr.endWord);
                       }

                   }
                   else
                   {
                       sciMonitor.GotoPos(wr.endWord);
                   }

               }
               else if (wr.type == WordRegion.kind.browser)
               {
                   sciMonitor.SetSel(wr.startWord, wr.endWord);
                   System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();

                   //  isOpenDialog = true;
                   of.ShowDialog();
                   //isOpenDialog = false;
                   if (of.FileName.Length!=0)
                   {

                       int ind = of.FileName.IndexOf(ASContext.Context.CurrentModel.BasePath);

                       if (ind == -1)
                       {
                           // is extern to project
                           sciMonitor.ReplaceSel("\"" + of.FileName + "\"");
                       }
                       else
                       {

                           string relPath = ProjectManager.Projects.ProjectPaths.GetRelativePath(
                               System.IO.Path.GetDirectoryName(ASContext.Context.CurrentFile), of.FileName).Replace('\\', '/');

                           sciMonitor.ReplaceSel("\"" + relPath + "\"");
                       }

                       if (curIndWord != Words.Count - 1)
                           MoveNextWord();
                   }

               }
        }
示例#4
0
        public void CreateParameters(List<ASCompletion.Model.MemberModel> parameters, TextParameters textParameters)
        {
            WordRegionBase previous = null;
            WordRegionBase nextWord = null;
            StringBuilder sb = new StringBuilder(10);
            int actpos = ASContext.CurSciControl.CurrentPos;
            int varpos = actpos;
            int index =0;
            WordRegionBase wrCurrent = null;
            if (!isMonitoring)
            {
                Words = new List<WordRegionBase>();
                curIndWord = index;

            }
            else
            {
               // if (curIndWord == Words.Count) curIndWord--;
                if (highlightWord != null)
                    highlightWord.Stop();

                 wrCurrent = firstWord;
                int position = sciMonitor.CurrentPos;

                TestInRegion(position);

                // La parola nella quale viene inserito/rimosso il carattere
                while (wrCurrent != null)
                {

                    if (position <= wrCurrent.endWord)
                    {
                        if ((wrCurrent.startWord <= position))
                        {

                            break;
                        }

                    }

                    previous = wrCurrent;
                    wrCurrent = wrCurrent.NextWord;

                }

                nextWord = wrCurrent.NextWord;

                sciMonitor.TextInserted -= new TextInsertedHandler(sciMonitor_TextInserted);
                index = curIndWord;
                Words.RemoveAt(curIndWord);

            }

            int startToolTip = textParameters.text.IndexOf("(") +1;
            textParameters.posParameters = actpos - startToolTip + 1;
              //  int indexToolTip = 0;

            WordRegionParameter wordParamater=null;
            WordRegionBase realPrevious = null;
            foreach (ASCompletion.Model.MemberModel mm in parameters)
            {
                if (mm.Value != null || mm.Name == "...rest") break;

                wordParamater = new WordRegionParameter();
                wordParamater.startWord = varpos;
                wordParamater.endWord = varpos + mm.Name.Length;
                wordParamater.type = WordRegionBase.kind.Parameter;
                wordParamater.textParameters = textParameters;
                wordParamater.startToolTip = startToolTip;
                //es              ( X              :    number)

                int typeLength = (mm.Type != null) ? mm.Type.Length : 0;

                wordParamater.endToolTip = startToolTip + mm.Name.Length + 1 + typeLength;
                // (, )
                startToolTip = wordParamater.endToolTip + 2;
                //indexToolTip++;

                //wr.indexToolTip = indexToolTip;
                sb.Append(mm.Name);
                sb.Append(", ");
                varpos = actpos + sb.Length;

                if (textParameters.comments != null)
                {

                    Match mParam = Regex.Match(textParameters.comments, "@param\\s+" + Regex.Escape(mm.Name) + "[ \t:]+(?<desc>[^\r\n]*)");

                    if (mParam.Success)
                    {
                        wordParamater.textParameter = "\n[B]" + mm.Name + ":[/B] " + mParam.Groups["desc"].Value.Trim();
                    }

                }

                Words.Insert(index, wordParamater);
                index++;
                if (previous == null)
                {
                    previous = wordParamater;
                }
                else
                {
                    previous.NextWord = wordParamater;
                    realPrevious = previous;
                    previous = wordParamater;
                }

            }

            sb.Remove(sb.Length - 2, 2);

            ASContext.CurSciControl.InsertText(actpos, sb.ToString());

            if (Words.Count > 1)
            {
                numCursors = 2;

                // last word
                if (nextWord == null)
                {
                    index--;
                   // WordRegionBase wb = Words[index];
                   // LastWordRegionParameter lw = (LastWordRegionParameter)wb.getLastWord();
                    WordRegionBase lw = wordParamater.getLastWord();
                   // Words[index - 1].NextWord = lw;
                    if (realPrevious != null)
                    {
                        realPrevious.NextWord = lw;
                    }

                    Words[index] = lw;
                    lastWord = lw;
                }
                else
                {
                    previous.NextWord = nextWord;
                }

                firstWord = Words[0];

                if (!isMonitoring)
                {
                    curIndWord = -1;
                    TryActivateMonitor();

                    if (highlightWord != null)
                        highlightWord.Start();

                    return;
                }
            }
            else
            {
                if(!isMonitoring)
                ASContext.CurSciControl.SetSel(previous.startWord, previous.endWord);
                numCursors = 1;
            }

            if (isMonitoring)
            {
                if (highlightWord != null)
                    highlightWord.Start();

                if (nextWord != null)
                {
                    nextWord.addCharactersNextWord(sb.Length);
                    wrCurrent.Disable();

                }
                sciMonitor.TextInserted += new TextInsertedHandler(sciMonitor_TextInserted);
                curIndWord--;
                MoveNextWord();

            }
        }
示例#5
0
        public void CreateParameters(List<MemberModel> list, bool isEventListener, TextParameters textParameters)
        {
            ScintillaControl sci = ASContext.CurSciControl;

            if (!dictionaryCreateWords.TryGetValue(sci.Handle, out currentCreateWords))
            {

                currentCreateWords = CreateNewWords();
                currentSci = sci;

            }

            currentCreateWords.CreateParameters(list, textParameters);

            if (isEventListener)
            {
               // ScintillaControl sci = ASContext.CurSciControl;
                sci.ReplaceSel("");
                PluginCore.Controls.UITools.CallTip.Hide();
                ASComplete.HandleFunctionCompletion(sci, true);
                currentCreateWords.ActivateList();

            }
        }