2
using System.Collections.Generic;
5
using System.Windows.Forms;
7
using TextEditorSWF.ExtensionModel;
10
[assembly: Addin ("SnippetsAddin","1.0", Namespace="TextEditor")]
11
[assembly: AddinDependency ("Core", "1.0")]
13
namespace SnippetsAddin
16
public class SnippetsExtension: EditorExtension
18
public override void Initialize ()
20
Program.MainWindow.Editor.KeyPress += new KeyPressEventHandler (EditorKeyPress);
23
void EditorKeyPress (object sender, KeyPressEventArgs e)
25
if (e.KeyChar != '\t')
27
RichTextBox editor = Program.MainWindow.Editor;
28
int p = editor.SelectionStart - 1;
29
string txt = editor.Text;
30
while (p >= 0 && char.IsLetterOrDigit (txt[p]))
33
string word = txt.Substring (p, editor.SelectionStart - p);
35
foreach (ISnippetProvider provider in AddinManager.GetExtensionObjects <ISnippetProvider>()) {
36
string fullText = provider.GetText (word);
37
if (fullText != null) {
39
int cursorPos = fullText.IndexOf ("<|>");
40
if (cursorPos != -1) {
41
fullText = fullText.Remove (cursorPos, 3);
42
nextp = p + cursorPos;
45
nextp = p + fullText.Length;
47
editor.Text = txt.Substring (0, p) + fullText + txt.Substring (editor.SelectionStart);
48
editor.SelectionStart = nextp;