Author: mkrueger
Date: 2008-01-23 07:53:27 -0500 (Wed, 23 Jan 2008)
New Revision: 93646
Added:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/EditActions.cs
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.mdp
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/gui.stetic
Log:
* gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs,
gtk-gui/gui.stetic, MonoDevelop.SourceEditor.mdp,
MonoDevelop.SourceEditor/ExtendibleTextEditor.cs,
MonoDevelop.SourceEditor/SourceEditorView.cs,
MonoDevelop.SourceEditor/EditActions.cs: Worked on code templates.
Modified: trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
2008-01-23 12:49:38 UTC (rev 93645)
+++ trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/ChangeLog
2008-01-23 12:53:27 UTC (rev 93646)
@@ -1,3 +1,19 @@
+2008-01-23 Mike Krüger <[EMAIL PROTECTED]>
+
+ * gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs,
+ gtk-gui/gui.stetic, MonoDevelop.SourceEditor.mdp,
+ MonoDevelop.SourceEditor/ExtendibleTextEditor.cs,
+ MonoDevelop.SourceEditor/SourceEditorView.cs,
+ MonoDevelop.SourceEditor/EditActions.cs: Worked on code templates.
+
+2008-01-23 Mike Krüger <[EMAIL PROTECTED]>
+
+ * gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs,
+ gtk-gui/gui.stetic, MonoDevelop.SourceEditor.mdp,
+ MonoDevelop.SourceEditor/ExtendibleTextEditor.cs,
+ MonoDevelop.SourceEditor/SourceEditorView.cs,
+ MonoDevelop.SourceEditor/EditActions.cs: Worked on code templates.
+
2008-01-22 Mike Krüger <[EMAIL PROTECTED]>
* gtk-gui/MonoDevelop.SourceEditor.OptionPanels.HighlightingPanel.cs,
Added:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/EditActions.cs
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/EditActions.cs
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/EditActions.cs
2008-01-23 12:53:27 UTC (rev 93646)
@@ -0,0 +1,47 @@
+// EditActions.cs
+//
+// Author:
+// Mike Krüger <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using Mono.TextEditor;
+
+namespace MonoDevelop.SourceEditor
+{
+ public class TabAction : InsertTab
+ {
+ ExtendibleTextEditor editor;
+
+ public TabAction (ExtendibleTextEditor editor)
+ {
+ this.editor = editor;
+ }
+
+ public override void Run (TextEditorData data)
+ {
+ if (!editor.DoInsertTemplate ())
+ base.Run (data);
+ }
+ }
+
+}
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtendibleTextEditor.cs
2008-01-23 12:53:27 UTC (rev 93646)
@@ -37,6 +37,7 @@
using MonoDevelop.Projects.Gui.Completion;
using MonoDevelop.Components.Commands;
using Mono.TextEditor.Highlighting;
+using MonoDevelop.Ide.CodeTemplates;
namespace MonoDevelop.SourceEditor
{
@@ -74,7 +75,7 @@
if (extension != null)
extension.TextChanged (args.Offset,
args.Offset + Math.Max (args.Count, args.Value != null ? args.Value.Length :
0));
};
-// keyBindings.Remove (GetKeyCode (Gdk.Key.Tab));
+ keyBindings [GetKeyCode (Gdk.Key.Tab)] = new TabAction
(this);
this.PopupMenu += delegate {
this.ShowPopup ();
};
@@ -91,11 +92,11 @@
protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
{
if (extension != null) {
- if (extension.KeyPress (evnt.Key, evnt.State))
+ if (extension.KeyPress (evnt.Key, evnt.State)) {
return true;
+ }
}
- bool result = base.OnKeyPressEvent (evnt);
- return result;
+ return base.OnKeyPressEvent (evnt);
}
double mx, my;
@@ -265,5 +266,84 @@
// base.OnPopulatePopup (menu);
// }
//
+
+#region Templates
+ int FindPrevWordStart (int offset)
+ {
+ while (--offset >= 0 && !Char.IsWhiteSpace
(Buffer.GetCharAt (offset)))
+ ;
+ return ++offset;
+ }
+
+ public string GetWordBeforeCaret ()
+ {
+ int offset = this.Caret.Offset;
+ int start = FindPrevWordStart (offset);
+ return Buffer.GetTextAt (start, offset - start);
+ }
+
+ public int DeleteWordBeforeCaret ()
+ {
+ int offset = this.Caret.Offset;
+ int start = FindPrevWordStart (offset);
+ Buffer.Remove (start, offset - start);
+ return start;
+ }
+
+ public string GetLeadingWhiteSpace (int line)
+ {
+ string lineText = Buffer.GetTextAt (Document.GetLine
(line));
+ int index = 0;
+ while (index < lineText.Length && Char.IsWhiteSpace
(lineText[index]))
+ index++;
+ return index > 0 ? lineText.Substring (0, index) : "";
+ }
+
+ public bool DoInsertTemplate ()
+ {
+ string word = GetWordBeforeCaret ();
+ System.Console.WriteLine("word before:" + word);
+ CodeTemplateGroup templateGroup =
CodeTemplateService.GetTemplateGroupPerFilename (this.view.ContentName);
+ if (String.IsNullOrEmpty (word) || templateGroup ==
null)
+ return false;
+
+ foreach (CodeTemplate template in
templateGroup.Templates) {
+ if (template.Shortcut == word) {
+ InsertTemplate (template);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void InsertTemplate (CodeTemplate template)
+ {
+ int offset = Caret.Offset;
+ string word = GetWordBeforeCaret ().Trim ();
+ if (word.Length > 0)
+ offset = DeleteWordBeforeCaret ();
+
+ string leadingWhiteSpace = GetLeadingWhiteSpace
(Caret.Line);
+
+ int finalCaretOffset = offset + template.Text.Length;
+ StringBuilder builder = new StringBuilder ();
+ for (int i = 0; i < template.Text.Length; ++i) {
+ switch (template.Text[i]) {
+ case '|':
+ finalCaretOffset = i + offset;
+ break;
+ default:
+ builder.Append (template.Text[i]);
+ break;
+ }
+ }
+
+// if (endLine > beginLine) {
+// IndentLines (beginLine+1, endLine,
leadingWhiteSpace);
+// }
+ Buffer.Insert (offset, builder);
+ Caret.Offset = finalCaretOffset;
+ }
+#endregion
}
}
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs
2008-01-23 12:53:27 UTC (rev 93646)
@@ -82,7 +82,7 @@
widget.TextEditor.Caret.PositionChanged += delegate {
FireCompletionContextChanged ();
};
-//
+
// GLib.Timeout.Add (1000, delegate {
// if (!widget.IsSplitted)
// widget.Split (true);
@@ -518,7 +518,7 @@
{
CodeCompletionContext result = new
CodeCompletionContext ();
result.TriggerOffset =
this.widget.TextEditor.Caret.Offset;
- result.TriggerLine = this.widget.TextEditor.Caret.Line
+ 1;
+ result.TriggerLine =
this.widget.TextEditor.Caret.Line + 1;
result.TriggerLineOffset =
this.widget.TextEditor.Document.Splitter.Get
(this.widget.TextEditor.Caret.Line).Offset;
Gdk.Point p =
this.widget.TextEditor.DocumentToVisualLocation
(this.widget.TextEditor.Caret.Location);
int tx, ty;
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.mdp
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.mdp
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.mdp
2008-01-23 12:53:27 UTC (rev 93646)
@@ -39,6 +39,7 @@
<File name="gtk-gui/MonoDevelop.SourceEditor.SourceEditorWidget.cs"
subtype="Code" buildaction="Compile" />
<File name="MonoDevelop.SourceEditor/SourceEditorOptions.cs"
subtype="Code" buildaction="Compile" />
<File name="AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
+ <File name="MonoDevelop.SourceEditor/EditActions.cs" subtype="Code"
buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="False" refto="Mono.TextEditor"
/>
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/MonoDevelop.SourceEditor.OptionPanels.GeneralOptionsPanel.cs
2008-01-23 12:53:27 UTC (rev 93646)
@@ -96,6 +96,7 @@
this.radiobutton1 = new
Gtk.RadioButton(Mono.Unix.Catalog.GetString("_Default monospace"));
this.radiobutton1.CanFocus = true;
this.radiobutton1.Name = "radiobutton1";
+ this.radiobutton1.Active = true;
this.radiobutton1.DrawIndicator = true;
this.radiobutton1.UseUnderline = true;
this.radiobutton1.Group = new GLib.SList(System.IntPtr.Zero);
Modified:
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/gui.stetic
===================================================================
---
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/gui.stetic
2008-01-23 12:49:38 UTC (rev 93645)
+++
trunk/monodevelop/main/src/addins/MonoDevelop.SourceEditor2/gtk-gui/gui.stetic
2008-01-23 12:53:27 UTC (rev 93646)
@@ -147,6 +147,7 @@
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Label" translatable="yes">_Default
monospace</property>
+ <property name="Active">True</property>
<property name="DrawIndicator">True</property>
<property name="HasLabel">True</property>
<property name="UseUnderline">True</property>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches