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);
        }
Ejemplo n.º 2
0
        void Init()
        {
            List <CodeTemplateGroup> groups = new List <CodeTemplateGroup>();

            CodeTemplateGroup group = new CodeTemplateGroup();

            group.TemplateGroupName = "Group Test 1";

            CodeTemplate tmp = new CodeTemplate();

            tmp.TemplateName = "Test";

            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("echo heeloo");

            tmp.TemplateCode = System.Convert.ToBase64String(plainTextBytes);
            List <CodeTemplate> temps = new List <CodeTemplate>();

            temps.Add(tmp);

            group.CodeTemplateList = temps;

            groups.Add(group);

            string xml = Utility.Serializer.XML.Serialize(groups);

            File.WriteAllText("CodeTemplates.XML", xml);
        }
Ejemplo n.º 3
0
        CodeTemplateGroup CreateNewTemplateGroup(string templateGroupName)
        {
            CodeTemplateGroup group = new CodeTemplateGroup();

            group.TemplateGroupName = templateGroupName;
            return(group);
        }
		public EditTemplateGroupDialog(CodeTemplateGroup codeTemplateGroup, string titlePrefix)
		{
			this.codeTemplateGroup = codeTemplateGroup;
			this.titlePrefix = titlePrefix;
			InitializeComponents();
			this.ShowAll();
		}
Ejemplo n.º 5
0
        private void Frm_OnAddTemplateGroup(string templateGroupName, object sender)
        {
            FormAddGroup frm = (FormAddGroup)sender;

            frm.Close();

            List <CodeTemplateGroup> groups = GetAllCodeTemplateGroups();
            CodeTemplateGroup        group  = null;

            if (frm.IsEdit)
            {
                CodeTemplateGroup curGroup = GetSelectedTemplateGroup();
                group = FindTemplateGroupByName(groups, curGroup.TemplateGroupName);
                if (group != null)
                {
                    group.TemplateGroupName = templateGroupName;
                }
            }
            else
            {
                group = CreateNewTemplateGroup(templateGroupName);
                groups.Add(group);
            }

            SaveCodeTemplateGroups(groups);
            MessageBox.Show("Saved");
            LoadCmbTemplateGroups();
            cmbTemplateGroup.SelectedIndex = cmbTemplateGroup.Items.Count - 1;
        }
Ejemplo n.º 6
0
 public EditTemplateGroupDialog(CodeTemplateGroup codeTemplateGroup, string titlePrefix)
 {
     this.codeTemplateGroup = codeTemplateGroup;
     this.titlePrefix       = titlePrefix;
     InitializeComponents();
     this.ShowAll();
 }
Ejemplo n.º 7
0
        void DisplaySelectedTemplateGroup()
        {
            CodeTemplateGroup group = GetSelectedTemplateGroup();

            if (group != null)
            {
                //this.dataGridView1.DataSource = new List<CodeTemplate>();
                //this.dataGridView1.DataSource = null;
                this.dataGridView1.DataSource = group.CodeTemplateList;
            }
        }
Ejemplo n.º 8
0
        private void btnDeleteGroup_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Are you sure ?", "Delete Confirmation", MessageBoxButtons.YesNo);

            if (res == DialogResult.Yes)
            {
                CodeTemplateGroup        group  = GetSelectedTemplateGroup();
                List <CodeTemplateGroup> groups = (List <CodeTemplateGroup>)cmbTemplateGroup.DataSource;
                groups.Remove(group);
                SaveCodeTemplateGroups(groups);
                LoadCmbTemplateGroups();
                cmbTemplateGroup.SelectedIndex = 0;
            }
        }
Ejemplo n.º 9
0
        ArrayList CopyCodeTemplateGroups(ArrayList groups)
        {
            ArrayList copiedGroups = new ArrayList();

            foreach (CodeTemplateGroup group in groups)
            {
                CodeTemplateGroup newGroup = new CodeTemplateGroup(String.Join(";", group.ExtensionStrings));
                foreach (CodeTemplate template in group.Templates)
                {
                    CodeTemplate newTemplate = new CodeTemplate(template.Shortcut, template.Description, template.Text);
                    newGroup.Templates.Add(newTemplate);
                }
                copiedGroups.Add(newGroup);
            }
            return(copiedGroups);
        }
Ejemplo n.º 10
0
        void UpdateCodeTemplate(CodeTemplate codeTemplate, string originalName)
        {
            CodeTemplateGroup   group = (CodeTemplateGroup)cmbTemplateGroup.SelectedItem;
            List <CodeTemplate> list  = group.CodeTemplateList;

            CodeTemplate tmp = null;

            foreach (CodeTemplate template in list)
            {
                if (template.TemplateName.ToLower().Contains(originalName.ToLower()))
                {
                    template.TemplateCode    = codeTemplate.TemplateCode;
                    template.DefaultFilename = codeTemplate.DefaultFilename;
                    template.TemplateName    = codeTemplate.TemplateName;
                    break;
                }
            }

            SaveCodeTemplateGroups((List <CodeTemplateGroup>)cmbTemplateGroup.DataSource);
        }
Ejemplo n.º 11
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());
        }
Ejemplo n.º 12
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)));
        }
Ejemplo n.º 13
0
 // handles the details of inserting a code template
 // returns true if it was inserted
 public bool InsertTemplate()
 {
     if (AutoInsertTemplates)
     {
         string word = GetWordBeforeCaret();
         if (word != null)
         {
             CodeTemplateGroup templateGroup = CodeTemplateService.GetTemplateGroupPerFilename(ParentEditor.DisplayBinding.ContentName);
             if (templateGroup != null)
             {
                 foreach (CodeTemplate template in templateGroup.Templates)
                 {
                     if (template.Shortcut == word)
                     {
                         InsertTemplate(template);
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 14
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);
        }