Browse Source

Fixed forum-8340: error inserting code template in empty file

Translated ExceptionBox.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1457 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
7ea51e06df
  1. 38
      data/options/SharpDevelop-templates.xml
  2. BIN
      data/resources/StringResources.es-mx.resources
  3. BIN
      data/resources/StringResources.es.resources
  4. 2
      src/AddIns/Misc/RegExpTk/Project/Src/Dialogs/MainWindow.cs
  5. 21
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
  6. 7
      src/Main/Base/Project/Src/Internal/Templates/CodeTemplateGroup.cs
  7. 10
      src/Main/Base/Project/Src/Internal/Templates/CodeTemplateLoader.cs
  8. 1
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/TemplateCompletionDataProvider.cs
  9. 56
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs
  10. 176
      src/Main/StartUp/Project/Dialogs/ExceptionBox.cs
  11. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

38
data/options/SharpDevelop-templates.xml

@ -5,10 +5,10 @@ @@ -5,10 +5,10 @@
${Selection}
}</CodeTemplate>
<CodeTemplate template="forb" description="for block">for (|; ; ) {
${Selection}
${Selection}
}</CodeTemplate>
<CodeTemplate template="fors" description="for (no braces)">for (|; ; )
${Selection}</CodeTemplate>
${Selection}</CodeTemplate>
<CodeTemplate template="ifb" description="if statement">if (|) {
${Selection}
}</CodeTemplate>
@ -18,41 +18,41 @@ ${Selection}</CodeTemplate> @@ -18,41 +18,41 @@ ${Selection}</CodeTemplate>
}</CodeTemplate>
<CodeTemplate template="ifs" description="if statement (no braces)">if (|)
${Selection}</CodeTemplate>
${Selection}</CodeTemplate>
<CodeTemplate template="switchd" description="switch statement (with default)">switch (|) {
case:
break;
default:
${Selection}
break;
case:
break;
default:
${Selection}
break;
}</CodeTemplate>
<CodeTemplate template="switchs" description="switch statement">switch (|) {
case :
${Selection}
break;
case :
${Selection}
break;
}</CodeTemplate>
<CodeTemplate template="tryc" description="try / catch">try {
${Selection}|
${Selection}|
} catch (Exception) {
}</CodeTemplate>
<CodeTemplate template="trycf" description="try / catch / finally">try {
${Selection}|
${Selection}|
} catch (Exception) {
} finally {
}</CodeTemplate>
<CodeTemplate template="tryf" description="try / finally">try {
${Selection}|
${Selection}|
} finally {
}</CodeTemplate>
<CodeTemplate template="whileb" description="while">while (|) {
${Selection}
${Selection}
}</CodeTemplate>
<CodeTemplate template="whiles" description="while (no braces)">while (|)
${Selection}</CodeTemplate>
${Selection}</CodeTemplate>
<CodeTemplate template="scwl" description="System.Console.WriteLine">System.Console.WriteLine(${Selection}|);</CodeTemplate>
<CodeTemplate template="scw" description="System.Console.Write">System.Console.Write(${Selection}|);</CodeTemplate>
</CodeTemplateGroup>

BIN
data/resources/StringResources.es-mx.resources

Binary file not shown.

BIN
data/resources/StringResources.es.resources

Binary file not shown.

2
src/AddIns/Misc/RegExpTk/Project/Src/Dialogs/MainWindow.cs

@ -249,7 +249,7 @@ namespace Plugins.RegExpTk { @@ -249,7 +249,7 @@ namespace Plugins.RegExpTk {
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = "c:\\";
sfd.Filter = "${res:RegExpTk.MainDialog.Assemblies}";
sfd.Filter = ResourceService.GetString("RegExpTk.MainDialog.Assemblies");
sfd.DefaultExt = "dll";
sfd.CheckPathExists = true;

21
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs

@ -260,16 +260,19 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -260,16 +260,19 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
if (data != null) {
control.BeginUpdate();
if (endOffset - startOffset > 0) {
control.Document.Remove(startOffset, endOffset - startOffset);
}
if (dataProvider.InsertSpace) {
control.Document.Insert(startOffset++, " ");
try {
if (endOffset - startOffset > 0) {
control.Document.Remove(startOffset, endOffset - startOffset);
}
if (dataProvider.InsertSpace) {
control.Document.Insert(startOffset++, " ");
}
control.ActiveTextAreaControl.Caret.Position = control.Document.OffsetToPosition(startOffset);
result = data.InsertAction(control.ActiveTextAreaControl.TextArea, ch);
} finally {
control.EndUpdate();
}
control.ActiveTextAreaControl.Caret.Position = control.Document.OffsetToPosition(startOffset);
result = data.InsertAction(control.ActiveTextAreaControl.TextArea, ch);
control.EndUpdate();
}
Close();
return result;

7
src/Main/Base/Project/Src/Internal/Templates/CodeTemplateGroup.cs

@ -60,8 +60,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -60,8 +60,11 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
foreach (string ext in exts) {
extensions.Add(ext);
}
foreach (XmlElement childElement in el.ChildNodes) {
templates.Add(new CodeTemplate(childElement));
foreach (XmlNode childNode in el.ChildNodes) {
XmlElement childElement = childNode as XmlElement;
if (childElement != null) {
templates.Add(new CodeTemplate(childElement));
}
}
}

10
src/Main/Base/Project/Src/Internal/Templates/CodeTemplateLoader.cs

@ -59,6 +59,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -59,6 +59,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
XmlDocument doc = new XmlDocument();
try {
doc.PreserveWhitespace = true;
doc.Load(filename);
templateGroups = new ArrayList();
@ -67,10 +68,13 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates @@ -67,10 +68,13 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates
return false;
}
foreach (XmlElement el in doc.DocumentElement.ChildNodes) {
templateGroups.Add(new CodeTemplateGroup(el));
foreach (XmlNode n in doc.DocumentElement.ChildNodes) {
XmlElement el = n as XmlElement;
if (el != null) {
templateGroups.Add(new CodeTemplateGroup(el));
}
}
} catch (Exception) {
} catch (FileNotFoundException) {
return false;
}
return true;

1
src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/TemplateCompletionDataProvider.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -31,6 +31,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
{
preSelection = "";
imageList.Images.Add(IconService.GetBitmap("Icons.16x16.TextFileIcon"));
CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(fileName);

56
src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
@ -344,53 +345,36 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -344,53 +345,36 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
ActiveTextAreaControl.TextArea.Caret.Position = ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection[0].StartPosition;
base.ActiveTextAreaControl.TextArea.SelectionManager.RemoveSelectedText();
}
int newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
int finalCaretOffset = newCaretOffset;
int firstLine = Document.GetLineNumberForOffset(newCaretOffset);
// save old properties, these properties cause strange effects, when not
// be turned off (like insert curly braces or other formatting stuff)
bool save1 = TextEditorProperties.AutoInsertCurlyBracket;
IndentStyle save2 = TextEditorProperties.IndentStyle;
TextEditorProperties.AutoInsertCurlyBracket = false;
TextEditorProperties.IndentStyle = IndentStyle.Auto;
string templateText = StringParser.Parse(template.Text, new string[,] { { "Selection", selectedText } });
int finalCaretOffset = templateText.IndexOf('|');
if (finalCaretOffset >= 0) {
templateText = templateText.Remove(finalCaretOffset, 1);
} else {
finalCaretOffset = templateText.Length;
}
int caretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
BeginUpdate();
for (int i =0; i < templateText.Length; ++i) {
switch (templateText[i]) {
case '|':
finalCaretOffset = newCaretOffset;
break;
case '\r':
break;
case '\t':
// new Tab().Execute(ActiveTextAreaControl.TextArea);
break;
case '\n':
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
new Return().Execute(ActiveTextAreaControl.TextArea);
newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
break;
default:
ActiveTextAreaControl.TextArea.InsertChar(templateText[i]);
newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
break;
}
}
int lastLine = Document.GetLineNumberForOffset(newCaretOffset);
int beginLine = ActiveTextAreaControl.TextArea.Caret.Line;
Document.Insert(caretOffset, templateText);
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(caretOffset + finalCaretOffset);
int endLine = Document.OffsetToPosition(caretOffset + templateText.Length).Y;
IndentStyle save1 = TextEditorProperties.IndentStyle;
TextEditorProperties.IndentStyle = IndentStyle.Smart;
Console.WriteLine("Indent between {0} and {1}", beginLine, endLine);
Document.FormattingStrategy.IndentLines(ActiveTextAreaControl.TextArea, beginLine, endLine);
EndUpdate();
Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
Document.CommitUpdate();
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(finalCaretOffset);
TextEditorProperties.IndentStyle = IndentStyle.Smart;
Document.FormattingStrategy.IndentLines(ActiveTextAreaControl.TextArea, firstLine, lastLine);
// restore old property settings
TextEditorProperties.AutoInsertCurlyBracket = save1;
TextEditorProperties.IndentStyle = save2;
TextEditorProperties.IndentStyle = save1;
}
public void InitializeFormatter()

176
src/Main/StartUp/Project/Dialogs/ExceptionBox.cs

@ -44,6 +44,10 @@ namespace ICSharpCode.SharpDevelop @@ -44,6 +44,10 @@ namespace ICSharpCode.SharpDevelop
continueButton.Width = closeButton.Width;
}
try {
Translate(this);
} catch {}
exceptionTextBox.Text = getClipboardString();
try {
@ -52,6 +56,14 @@ namespace ICSharpCode.SharpDevelop @@ -52,6 +56,14 @@ namespace ICSharpCode.SharpDevelop
} catch {}
}
void Translate(Control ctl)
{
ctl.Text = StringParser.Parse(ctl.Text);
foreach (Control child in ctl.Controls) {
Translate(child);
}
}
string getClipboardString()
{
string str = "";
@ -159,125 +171,123 @@ namespace ICSharpCode.SharpDevelop @@ -159,125 +171,123 @@ namespace ICSharpCode.SharpDevelop
void CloseButtonClick(object sender, EventArgs e)
{
if (MessageBox.Show("Do you really want to quit SharpDevelop?", "SharpDevelop", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
if (MessageBox.Show(StringParser.Parse("${res:ICSharpCode.SharpDevelop.ExceptionBox.QuitWarning}"), "SharpDevelop", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
Application.Exit();
}
}
void InitializeComponent() {
void InitializeComponent()
{
this.closeButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label = new System.Windows.Forms.Label();
this.continueButton = new System.Windows.Forms.Button();
this.reportButton = new System.Windows.Forms.Button();
this.copyErrorCheckBox = new System.Windows.Forms.CheckBox();
this.exceptionTextBox = new System.Windows.Forms.TextBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
//
// ExceptionBox
//
this.ClientSize = new System.Drawing.Size(688, 453);
closeButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// closeButton
//
closeButton.Location = new System.Drawing.Point(454, 424);
closeButton.Name = "closeButton";
closeButton.Size = new System.Drawing.Size(140, 23);
closeButton.TabIndex = 5;
closeButton.Text = "Exit SharpDevelop";
closeButton.Click += new System.EventHandler(this.CloseButtonClick);
label3 = new System.Windows.Forms.Label();
this.closeButton.Location = new System.Drawing.Point(445, 424);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(141, 23);
this.closeButton.TabIndex = 5;
this.closeButton.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.ExitSharpDevelop}";
this.closeButton.Click += new System.EventHandler(this.CloseButtonClick);
//
// label3
//
label3.Location = new System.Drawing.Point(232, 152);
label3.Name = "label3";
label3.Size = new System.Drawing.Size(448, 23);
label3.TabIndex = 9;
label3.Text = "Thank you for helping make SharpDevelop a better program for everyone!";
label2 = new System.Windows.Forms.Label();
this.label3.Location = new System.Drawing.Point(230, 159);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(448, 23);
this.label3.TabIndex = 9;
this.label3.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.ThankYouMsg}";
//
// label2
//
label2.Location = new System.Drawing.Point(232, 64);
label2.Name = "label2";
label2.Size = new System.Drawing.Size(448, 80);
label2.TabIndex = 8;
label2.Text = "How to report errors efficiently: We have set up a Web-based forum to report and track errors that are reported by users of SharpDevelop. To minimize necessary questions by the team members, in addition to providing the error message that is copied to the clipboard for easier pasting in the error report, we ask that you provide us with an as detailed as possible step-by-step procedure to reproduce this bug.";
label = new System.Windows.Forms.Label();
this.label2.Location = new System.Drawing.Point(232, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(448, 95);
this.label2.TabIndex = 8;
this.label2.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.HelpText2}";
//
// label
//
label.Location = new System.Drawing.Point(232, 8);
label.Name = "label";
label.Size = new System.Drawing.Size(448, 48);
label.TabIndex = 6;
label.Text = "An unhandled exception has occurred in SharpDevelop. This is unexpected and we\'d " +
"ask you to help us improve SharpDevelop by reporting this error to the SharpDeve" +
"lop team.";
continueButton = new System.Windows.Forms.Button();
this.label.Location = new System.Drawing.Point(232, 8);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(448, 48);
this.label.TabIndex = 6;
this.label.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.HelpText1}";
//
// continueButton
//
continueButton.Location = new System.Drawing.Point(600, 424);
continueButton.Name = "continueButton";
continueButton.Size = new System.Drawing.Size(75, 23);
continueButton.TabIndex = 6;
continueButton.Text = "Continue";
continueButton.Click += new System.EventHandler(this.continueButtonClick);
reportButton = new System.Windows.Forms.Button();
this.continueButton.Location = new System.Drawing.Point(592, 424);
this.continueButton.Name = "continueButton";
this.continueButton.Size = new System.Drawing.Size(88, 23);
this.continueButton.TabIndex = 6;
this.continueButton.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.Continue}";
this.continueButton.Click += new System.EventHandler(this.continueButtonClick);
//
// reportButton
//
reportButton.Location = new System.Drawing.Point(232, 424);
reportButton.Name = "reportButton";
reportButton.Size = new System.Drawing.Size(216, 23);
reportButton.TabIndex = 4;
reportButton.Text = "Report Error to SharpDevelop Team";
reportButton.Click += new System.EventHandler(this.buttonClick);
copyErrorCheckBox = new System.Windows.Forms.CheckBox();
this.reportButton.Location = new System.Drawing.Point(230, 424);
this.reportButton.Name = "reportButton";
this.reportButton.Size = new System.Drawing.Size(209, 23);
this.reportButton.TabIndex = 4;
this.reportButton.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.ReportError}";
this.reportButton.Click += new System.EventHandler(this.buttonClick);
//
// copyErrorCheckBox
//
copyErrorCheckBox.Checked = true;
copyErrorCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
copyErrorCheckBox.Location = new System.Drawing.Point(232, 368);
copyErrorCheckBox.Name = "copyErrorCheckBox";
copyErrorCheckBox.Size = new System.Drawing.Size(440, 24);
copyErrorCheckBox.TabIndex = 2;
copyErrorCheckBox.Text = "Copy error message to clipboard";
exceptionTextBox = new System.Windows.Forms.TextBox();
this.copyErrorCheckBox.Checked = true;
this.copyErrorCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.copyErrorCheckBox.Location = new System.Drawing.Point(230, 373);
this.copyErrorCheckBox.Name = "copyErrorCheckBox";
this.copyErrorCheckBox.Size = new System.Drawing.Size(440, 24);
this.copyErrorCheckBox.TabIndex = 2;
this.copyErrorCheckBox.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.CopyToClipboard}";
//
// exceptionTextBox
//
exceptionTextBox.Location = new System.Drawing.Point(232, 176);
exceptionTextBox.Multiline = true;
exceptionTextBox.Name = "exceptionTextBox";
exceptionTextBox.ReadOnly = true;
exceptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
exceptionTextBox.Size = new System.Drawing.Size(448, 184);
exceptionTextBox.TabIndex = 1;
exceptionTextBox.Text = "textBoxExceptionText";
pictureBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(pictureBox)).BeginInit();
this.exceptionTextBox.Location = new System.Drawing.Point(230, 183);
this.exceptionTextBox.Multiline = true;
this.exceptionTextBox.Name = "exceptionTextBox";
this.exceptionTextBox.ReadOnly = true;
this.exceptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.exceptionTextBox.Size = new System.Drawing.Size(448, 184);
this.exceptionTextBox.TabIndex = 1;
this.exceptionTextBox.Text = "textBoxExceptionText";
//
// pictureBox
//
pictureBox.Location = new System.Drawing.Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new System.Drawing.Size(224, 464);
pictureBox.TabIndex = 0;
pictureBox.TabStop = false;
((System.ComponentModel.ISupportInitialize)(pictureBox)).EndInit();
this.Controls.Add(closeButton);
this.Controls.Add(label3);
this.Controls.Add(label2);
this.Controls.Add(label);
this.Controls.Add(continueButton);
this.Controls.Add(reportButton);
this.Controls.Add(copyErrorCheckBox);
this.Controls.Add(exceptionTextBox);
this.Controls.Add(pictureBox);
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(224, 464);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// ExceptionBox
//
this.ClientSize = new System.Drawing.Size(688, 453);
this.Controls.Add(this.closeButton);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label);
this.Controls.Add(this.continueButton);
this.Controls.Add(this.reportButton);
this.Controls.Add(this.copyErrorCheckBox);
this.Controls.Add(this.exceptionTextBox);
this.Controls.Add(this.pictureBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ExceptionBox";
this.Text = "Unhandled exception has occured";
this.SuspendLayout();
this.Text = "${res:ICSharpCode.SharpDevelop.ExceptionBox.Title}";
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save