Ejemplo n.º 1
0
 protected override void OnCodeSnippetActivating(CodeSnippetEventArgs e)
 {
     string str;
     RunnableQuery query;
     if (((SnippetManager.ActiveSnippetForm != null) && !SnippetManager.ActiveSnippetForm.IsDisposed) && SnippetManager.ActiveSnippetForm.Visible)
     {
         SnippetManager.ActiveSnippetForm.TopMost = false;
     }
     foreach (CodeSnippetDeclaration declaration in e.get_CodeSnippet().get_Declarations())
     {
         if (!string.IsNullOrEmpty(declaration.get_Function()))
         {
             str = this.ProcessSnippetFunction(declaration);
             if (declaration.get_Editable())
             {
                 declaration.set_Default(str);
             }
             else if ((str != null) && (e.get_CodeText() != null))
             {
                 e.set_CodeText(e.get_CodeText().Replace("$" + declaration.get_ID() + "$", str));
             }
         }
     }
     if (UserOptions.Instance.ConvertTabsToSpaces && (e.get_CodeText() != null))
     {
         e.set_CodeText(ConvertTabsToSpaces(e.get_CodeText()));
     }
     if ((string.IsNullOrEmpty(base.get_SelectedView().get_SelectedText()) || (e.get_CodeText() == null)) || !e.get_CodeText().Contains("$selected$"))
     {
         base.get_IntelliPrompt().get_CodeSnippets().set_AutoIndentSnippetCode(true);
     }
     else
     {
         int index = e.get_CodeText().IndexOf("$selected$");
         string text = "";
         if (!(((index <= 0) || (e.get_CodeText()[index - 1] != '\t')) ? (e.get_CodeText()[index - 1] != ' ') : false))
         {
             text = "\t";
             if (UserOptions.Instance.ConvertTabsToSpaces)
             {
                 text = ConvertTabsToSpaces(text);
             }
         }
         for (int i = base.get_SelectedView().get_Selection().get_FirstOffset(); i >= base.get_SelectedView().get_Selection().get_LastOffset(); i++)
         {
         Label_01B1:
             if (0 == 0)
             {
                 string substring = base.get_Document().GetSubstring(base.get_SelectedView().get_Selection().get_FirstOffset(), i - base.get_SelectedView().get_Selection().get_FirstOffset());
                 int num3 = base.get_SelectedView().get_Selection().get_FirstOffset() - 1;
             Label_0260:
                 if ((num3 >= 0) && !char.IsWhiteSpace(base.get_Document().get_Characters(num3)))
                 {
                 }
                 if (0 == 0)
                 {
                     num3++;
                     string str4 = base.get_Document().GetSubstring(num3, i - num3);
                     str = base.get_SelectedView().get_SelectedText().Trim().Replace("\n", "\n" + text);
                     e.set_CodeText(substring + e.get_CodeText().Replace("\n", "\n" + str4).Replace("$selected$", str) + ((base.get_SelectedView().get_SelectedText().Last<char>() == '\n') ? "\n" : ""));
                     base.get_IntelliPrompt().get_CodeSnippets().set_AutoIndentSnippetCode(false);
                 }
                 else
                 {
                     num3--;
                     goto Label_0260;
                 }
                 goto Label_0324;
             }
         }
         goto Label_01B1;
     }
 Label_0324:
     query = MainForm.Instance.CurrentQueryControl.Query;
     List<string> list = query.AdditionalReferences.ToList<string>();
     List<string> list2 = query.AdditionalGACReferences.ToList<string>();
     using (query.TransactChanges())
     {
         if (e.get_CodeSnippet().get_References().Count > 0)
         {
             using (IEnumerator enumerator = e.get_CodeSnippet().get_References().GetEnumerator())
             {
                 Predicate<string> match = null;
                 Predicate<string> predicate2 = null;
                 CodeSnippetReference reference;
                 while (enumerator.MoveNext())
                 {
                     reference = (CodeSnippetReference) enumerator.Current;
                     if (reference.get_Assembly().Contains<char>(','))
                     {
                         if (match == null)
                         {
                             match = r => string.Equals(r.Split(new char[] { ',' }).First<string>(), reference.get_Assembly().Split(new char[] { ',' }).First<string>(), StringComparison.InvariantCultureIgnoreCase);
                         }
                         list2.RemoveAll(match);
                         list2.Add(reference.get_Assembly());
                     }
                     else
                     {
                         if (predicate2 == null)
                         {
                             predicate2 = r => string.Equals(Path.GetFileName(r), Path.GetFileName(reference.get_Assembly()), StringComparison.InvariantCultureIgnoreCase);
                         }
                         list.RemoveAll(predicate2);
                         list.Add(PathHelper.ResolveReference(reference.get_Assembly()));
                     }
                 }
             }
             query.AdditionalReferences = list.ToArray();
             query.AdditionalGACReferences = list2.ToArray();
             query.SortReferences();
         }
         if (e.get_CodeSnippet().get_Imports().Count > 0)
         {
             query.AdditionalNamespaces = query.AdditionalNamespaces.Concat<string>((from ci in e.get_CodeSnippet().get_Imports().OfType<CodeSnippetImport>() select ci.get_Namespace())).Distinct<string>().ToArray<string>();
         }
         if (e.get_CodeText() != null)
         {
             if (e.get_CodeText().TrimStart(new char[0]).StartsWith("void ") || e.get_CodeText().TrimStart(new char[0]).StartsWith("static void"))
             {
                 query.QueryKind = QueryLanguage.Program;
             }
             else if (e.get_CodeText().Contains(";") && (query.QueryKind == QueryLanguage.Expression))
             {
                 query.QueryKind = QueryLanguage.Statements;
             }
         }
     }
     base.OnCodeSnippetActivating(e);
 }
Ejemplo n.º 2
0
        protected override void OnCodeSnippetActivating(CodeSnippetEventArgs e)
        {
            string        str;
            RunnableQuery query;

            if (((SnippetManager.ActiveSnippetForm != null) && !SnippetManager.ActiveSnippetForm.IsDisposed) && SnippetManager.ActiveSnippetForm.Visible)
            {
                SnippetManager.ActiveSnippetForm.TopMost = false;
            }
            foreach (CodeSnippetDeclaration declaration in e.get_CodeSnippet().get_Declarations())
            {
                if (!string.IsNullOrEmpty(declaration.get_Function()))
                {
                    str = this.ProcessSnippetFunction(declaration);
                    if (declaration.get_Editable())
                    {
                        declaration.set_Default(str);
                    }
                    else if ((str != null) && (e.get_CodeText() != null))
                    {
                        e.set_CodeText(e.get_CodeText().Replace("$" + declaration.get_ID() + "$", str));
                    }
                }
            }
            if (UserOptions.Instance.ConvertTabsToSpaces && (e.get_CodeText() != null))
            {
                e.set_CodeText(ConvertTabsToSpaces(e.get_CodeText()));
            }
            if ((string.IsNullOrEmpty(base.get_SelectedView().get_SelectedText()) || (e.get_CodeText() == null)) || !e.get_CodeText().Contains("$selected$"))
            {
                base.get_IntelliPrompt().get_CodeSnippets().set_AutoIndentSnippetCode(true);
            }
            else
            {
                int    index = e.get_CodeText().IndexOf("$selected$");
                string text  = "";
                if (!(((index <= 0) || (e.get_CodeText()[index - 1] != '\t')) ? (e.get_CodeText()[index - 1] != ' ') : false))
                {
                    text = "\t";
                    if (UserOptions.Instance.ConvertTabsToSpaces)
                    {
                        text = ConvertTabsToSpaces(text);
                    }
                }
                for (int i = base.get_SelectedView().get_Selection().get_FirstOffset(); i >= base.get_SelectedView().get_Selection().get_LastOffset(); i++)
                {
Label_01B1:
                    if (0 == 0)
                    {
                        string substring = base.get_Document().GetSubstring(base.get_SelectedView().get_Selection().get_FirstOffset(), i - base.get_SelectedView().get_Selection().get_FirstOffset());
                        int    num3      = base.get_SelectedView().get_Selection().get_FirstOffset() - 1;
Label_0260:
                        if ((num3 >= 0) && !char.IsWhiteSpace(base.get_Document().get_Characters(num3)))
                        {
                        }
                        if (0 == 0)
                        {
                            num3++;
                            string str4 = base.get_Document().GetSubstring(num3, i - num3);
                            str = base.get_SelectedView().get_SelectedText().Trim().Replace("\n", "\n" + text);
                            e.set_CodeText(substring + e.get_CodeText().Replace("\n", "\n" + str4).Replace("$selected$", str) + ((base.get_SelectedView().get_SelectedText().Last <char>() == '\n') ? "\n" : ""));
                            base.get_IntelliPrompt().get_CodeSnippets().set_AutoIndentSnippetCode(false);
                        }
                        else
                        {
                            num3--;
                            goto Label_0260;
                        }
                        goto Label_0324;
                    }
                }
                goto Label_01B1;
            }
Label_0324:
            query = MainForm.Instance.CurrentQueryControl.Query;
            List <string> list  = query.AdditionalReferences.ToList <string>();
            List <string> list2 = query.AdditionalGACReferences.ToList <string>();

            using (query.TransactChanges())
            {
                if (e.get_CodeSnippet().get_References().Count > 0)
                {
                    using (IEnumerator enumerator = e.get_CodeSnippet().get_References().GetEnumerator())
                    {
                        Predicate <string>   match      = null;
                        Predicate <string>   predicate2 = null;
                        CodeSnippetReference reference;
                        while (enumerator.MoveNext())
                        {
                            reference = (CodeSnippetReference)enumerator.Current;
                            if (reference.get_Assembly().Contains <char>(','))
                            {
                                if (match == null)
                                {
                                    match = r => string.Equals(r.Split(new char[] { ',' }).First <string>(), reference.get_Assembly().Split(new char[] { ',' }).First <string>(), StringComparison.InvariantCultureIgnoreCase);
                                }
                                list2.RemoveAll(match);
                                list2.Add(reference.get_Assembly());
                            }
                            else
                            {
                                if (predicate2 == null)
                                {
                                    predicate2 = r => string.Equals(Path.GetFileName(r), Path.GetFileName(reference.get_Assembly()), StringComparison.InvariantCultureIgnoreCase);
                                }
                                list.RemoveAll(predicate2);
                                list.Add(PathHelper.ResolveReference(reference.get_Assembly()));
                            }
                        }
                    }
                    query.AdditionalReferences    = list.ToArray();
                    query.AdditionalGACReferences = list2.ToArray();
                    query.SortReferences();
                }
                if (e.get_CodeSnippet().get_Imports().Count > 0)
                {
                    query.AdditionalNamespaces = query.AdditionalNamespaces.Concat <string>((from ci in e.get_CodeSnippet().get_Imports().OfType <CodeSnippetImport>() select ci.get_Namespace())).Distinct <string>().ToArray <string>();
                }
                if (e.get_CodeText() != null)
                {
                    if (e.get_CodeText().TrimStart(new char[0]).StartsWith("void ") || e.get_CodeText().TrimStart(new char[0]).StartsWith("static void"))
                    {
                        query.QueryKind = QueryLanguage.Program;
                    }
                    else if (e.get_CodeText().Contains(";") && (query.QueryKind == QueryLanguage.Expression))
                    {
                        query.QueryKind = QueryLanguage.Statements;
                    }
                }
            }
            base.OnCodeSnippetActivating(e);
        }