PageRenderTime 48ms CodeModel.GetById 10ms app.highlight 34ms RepoModel.GetById 2ms app.codeStats 0ms

/src/AddIns/Misc/PackageManagement/Packages/ICSharpCode.TextEditor.Sample/Content/TextEditorSample/TextEditorForm.cs.pp

https://github.com/ajadex/SharpDevelop
Puppet | 152 lines | 131 code | 21 blank | 0 comment | 15 complexity | 2e4eee912729d391ab84267487a8f312 MD5 | raw file
  1
  2using System;
  3using System.Drawing;
  4using System.Windows.Forms;
  5using ICSharpCode.TextEditor;
  6using ICSharpCode.TextEditor.Document;
  7using ICSharpCode.TextEditor.Gui.CompletionWindow;
  8
  9namespace $rootnamespace$.TextEditorSample
 10{
 11	public partial class TextEditorForm : Form
 12	{
 13		string currentFileName;
 14		TextArea textArea;
 15		CodeCompletionWindow completionWindow;
 16		
 17		public TextEditorForm()
 18		{
 19			//
 20			// The InitializeComponent() call is required for Windows Forms designer support.
 21			//
 22			InitializeComponent();
 23			Init();
 24		}
 25		
 26		void Init()
 27		{
 28			propertyGridComboBox.SelectedIndex = 1;
 29			textArea = textEditorControl.ActiveTextAreaControl.TextArea;
 30			textArea.KeyEventHandler += ProcessKey;
 31			
 32			PopulateHighlightingComboBox();
 33			
 34			highlightingToolStripComboBox.Text = "C#";
 35		}
 36
 37		bool ProcessKey(char ch)
 38		{
 39			if (ch == '.') {
 40				ShowCompletionWindow();
 41			}
 42			return false;
 43		}
 44		
 45		void ShowCompletionWindow()
 46		{
 47			CompletionDataProvider completionDataProvider = new CompletionDataProvider();
 48			completionWindow = CodeCompletionWindow.ShowCompletionWindow(this, textEditorControl, String.Empty, completionDataProvider, '.');
 49			if (completionWindow != null) {
 50				completionWindow.Closed += CompletionWindowClosed;
 51			}
 52		}
 53		
 54		void CompletionWindowClosed(object source, EventArgs e)
 55		{
 56			if (completionWindow != null) {
 57				completionWindow.Closed -= CompletionWindowClosed;
 58				completionWindow.Dispose();
 59				completionWindow = null;
 60			}
 61		}
 62		
 63		void PopulateHighlightingComboBox()
 64		{
 65			foreach (string highlighting in HighlightingManager.Manager.HighlightingDefinitions.Keys) {
 66				highlightingToolStripComboBox.Items.Add(highlighting);
 67			}
 68			highlightingToolStripComboBox.Sorted = true;
 69		}
 70		
 71		void ExitToolStripMenuItemClick(object sender, EventArgs e)
 72		{
 73			Close();
 74		}
 75		
 76		void PropertyGridComboBoxSelectedIndexChanged(object sender, EventArgs e)
 77		{
 78			switch (propertyGridComboBox.SelectedIndex) {
 79				case 0:
 80					propertyGrid.SelectedObject = textEditorControl.TextEditorProperties;
 81					break;
 82				case 1:
 83					propertyGrid.SelectedObject = textEditorControl;
 84					break;
 85			}
 86		}
 87		
 88		void OpenToolStripMenuItemClick(object sender, EventArgs e)
 89		{
 90			using (OpenFileDialog openFileDialog = new OpenFileDialog()) {
 91				openFileDialog.CheckFileExists = true;
 92				if (openFileDialog.ShowDialog() == DialogResult.OK) {
 93					currentFileName = openFileDialog.FileName;
 94					textEditorControl.LoadFile(currentFileName);
 95					highlightingToolStripComboBox.Text = textEditorControl.Document.HighlightingStrategy.Name;
 96				}
 97			}
 98		}
 99		
100		void SaveToolStripMenuItemClick(object sender, EventArgs e)
101		{
102			if (currentFileName == null) {
103				using (SaveFileDialog saveFileDialog = new SaveFileDialog()) {
104					if (saveFileDialog.ShowDialog() == DialogResult.OK) {
105						currentFileName = saveFileDialog.FileName;
106					} else {
107						return;
108					}
109				}
110			}
111			textEditorControl.SaveFile(currentFileName);
112		}
113		
114		void CutToolStripMenuItemClick(object sender, EventArgs e)
115		{
116			textArea.ClipboardHandler.Cut(sender, e);
117		}
118		
119		void UndoToolStripMenuItemClick(object sender, EventArgs e)
120		{
121			textEditorControl.Undo();
122		}
123		
124		void RedoToolStripMenuItemClick(object sender, EventArgs e)
125		{
126			textEditorControl.Redo();
127		}
128		
129		void CopyToolStripMenuItemClick(object sender, EventArgs e)
130		{
131			textArea.AutoClearSelection = false;
132			textArea.ClipboardHandler.Copy(sender, e);
133		}
134		
135		void PasteToolStripMenuItemClick(object sender, EventArgs e)
136		{
137			textArea.ClipboardHandler.Paste(sender, e);
138		}
139		
140		void DeleteToolStripMenuItemClick(object sender, EventArgs e)
141		{
142			textArea.ClipboardHandler.Delete(sender, e);
143		}
144		
145		void HighlightingToolStripComboBoxSelectedIndexChanged(object sender, EventArgs e)
146		{
147			string highlighter = highlightingToolStripComboBox.Text;
148			textEditorControl.SetHighlighting(highlighter);
149			textEditorControl.Refresh();
150		}
151	}
152}