internal bool ExpandTemplateOnTab()
        {
            string word = GetWordBeforeCaret();

            if (word != null)
            {
                CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(FileName);
                if (templateGroup != null)
                {
                    foreach (CodeTemplate template in templateGroup.Templates)
                    {
                        if (template.Shortcut == word)
                        {
                            if (word.Length > 0)
                            {
                                int newCaretOffset = DeleteWordBeforeCaret();
                                //// set new position in text area
                                ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
                            }

                            InsertTemplate(template);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            preSelection = "";

            CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(fileName);

            if (templateGroup == null)
            {
                return(null);
            }
            bool automaticInsert = this.AutomaticInsert || DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.AutoInsertTemplates;
            List <ICompletionData> completionData = new List <ICompletionData>();

            foreach (CodeTemplate template in templateGroup.Templates)
            {
                completionData.Add(new TemplateCompletionData(template, automaticInsert));
            }

            return(completionData.ToArray());
        }
Exemplo n.º 3
0
        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            preSelection = "";

            imageList.Images.Add(IconService.GetBitmap("Icons.16x16.TextFileIcon"));
            CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(fileName);

            if (templateGroup == null)
            {
                return(null);
            }
            ArrayList completionData = new ArrayList();

            foreach (CodeTemplate template in templateGroup.Templates)
            {
                completionData.Add(new TemplateCompletionData(template));
            }

            return((ICompletionData[])completionData.ToArray(typeof(ICompletionData)));
        }
Exemplo n.º 4
0
        bool HandleKeyPress(char ch)
        {
            if (inHandleKeyPress)
            {
                return(false);
            }
            inHandleKeyPress = true;
            try {
                if (codeCompletionWindow != null && !codeCompletionWindow.IsDisposed)
                {
                    if (codeCompletionWindow.ProcessKeyEvent(ch))
                    {
                        return(true);
                    }
                    if (codeCompletionWindow != null && !codeCompletionWindow.IsDisposed)
                    {
                        // code-completion window is still opened but did not want to handle
                        // the keypress -> don't try to restart code-completion
                        return(false);
                    }
                }

                if (CodeCompletionOptions.EnableCodeCompletion)
                {
                    foreach (ICodeCompletionBinding ccBinding in CodeCompletionBindings)
                    {
                        if (ccBinding.HandleKeyPress(this, ch))
                        {
                            return(false);
                        }
                    }
                }
                if (ch == ' ')
                {
                    string word = GetWordBeforeCaret();
                    if (word != null)
                    {
                        CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(FileName);
                        if (templateGroup != null)
                        {
                            foreach (CodeTemplate template in templateGroup.Templates)
                            {
                                if (template.Shortcut == word)
                                {
                                    if (word.Length > 0)
                                    {
                                        int newCaretOffset = DeleteWordBeforeCaret();
                                        //// set new position in text area
                                        ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
                                    }

                                    InsertTemplate(template);
                                    return(true);
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                LogException(ex);
            } finally {
                inHandleKeyPress = false;
            }
            return(false);
        }