Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 2609251

Browse files
committed
more fixes and change version to 1.8.0.0-beta1
1 parent f422037 commit 2609251

14 files changed

+102
-67
lines changed

App/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
// Build Number
3131
// Revision
3232
//
33-
[assembly: AssemblyVersion("1.7.2.4")]
33+
[assembly: AssemblyVersion("1.8.0.0")]

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void Main(string[] args)
104104
},
105105
Buttons = new Button[]
106106
{
107-
new Button() { Label = Constants.GitHubRepositoryText, Url = Constants.GitHubRepository }
107+
new Button() { Label = Constants.GetSPCodeText, Url = Constants.GitHubRepository }
108108
}
109109
});
110110
}

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ public void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
381381
// TODO: Poor way to fix this but atm I have no idea on how to fix this properly
382382
if (!text.Contains("for"))
383383
{
384-
var leadingIndentation =
385-
editor.Document.GetText(TextUtilities.GetLeadingWhitespace(editor.Document, line));
386-
var newLineStr = leadingIndentation +
387-
SPSyntaxTidy.TidyUp(text).Trim();
384+
var leadingIndentation = editor.Document.GetText(TextUtilities.GetLeadingWhitespace(editor.Document, line));
385+
var newLineStr = leadingIndentation + SPSyntaxTidy.TidyUp(text).Trim();
388386
editor.Document.Replace(line, newLineStr);
389387
}
390388
}
@@ -399,7 +397,7 @@ public void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
399397
break;
400398
}
401399

402-
editor.TextArea.Caret.Line -= 1;
400+
editor.TextArea.Caret.Line--;
403401
editor.TextArea.Caret.Column += Program.Indentation.Length;
404402
isBlock = false;
405403
break;
@@ -432,7 +430,7 @@ public void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
432430
editor.Document.Insert(editor.CaretOffset, closingBracket.ToString());
433431
if (editor.SelectionLength == 0)
434432
{
435-
editor.CaretOffset -= 1;
433+
editor.CaretOffset--;
436434
}
437435

438436
// If it's a code block bracket we need to update the folding
@@ -454,7 +452,7 @@ public void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
454452
editor.Document.Insert(editor.CaretOffset, e.Text);
455453
if (editor.SelectionLength == 0)
456454
{
457-
editor.CaretOffset -= 1;
455+
editor.CaretOffset--;
458456
}
459457
}
460458
}
@@ -495,25 +493,17 @@ private void TextArea_TextEntering(object sender, TextCompositionEventArgs e)
495493
break;
496494

497495
case ")":
498-
if (Program.OptionsObject.Editor_AutoCloseBrackets && editor.TextArea.Document.GetCharAt(editor.TextArea.Caret.Offset - 1) == '(')
499-
{
500-
e.Handled = true;
501-
editor.TextArea.Caret.Offset += 1;
502-
}
503-
break;
504496
case "]":
505-
if (Program.OptionsObject.Editor_AutoCloseBrackets && editor.TextArea.Document.GetCharAt(editor.TextArea.Caret.Offset - 1) == '[')
506-
{
507-
e.Handled = true;
508-
editor.TextArea.Caret.Offset += 1;
509-
}
510-
break;
511497
case "}":
512-
if (Program.OptionsObject.Editor_AutoCloseBrackets && editor.TextArea.Document.GetCharAt(editor.TextArea.Caret.Offset - 1) == '{')
498+
if (Program.OptionsObject.Editor_AutoCloseBrackets &&
499+
BracketHelpers.CheckForClosingBracket(editor.Document, editor.TextArea.Caret.Offset, e.Text))
513500
{
514501
e.Handled = true;
515-
editor.TextArea.Caret.Offset += 1;
502+
var newCaretPos = editor.TextArea.Caret.Offset + 1;
503+
var docLength = editor.Document.TextLength;
504+
editor.TextArea.Caret.Offset = newCaretPos > docLength ? docLength : newCaretPos;
516505
}
506+
517507
break;
518508

519509
case "\"":

UI/Components/EditorElement/EditorElementBracketHighlighter.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,4 @@ public void Draw(TextView textView, DrawingContext drawingContext)
5555
}
5656
}
5757
}
58-
59-
60-
61-
6258
}

UI/Components/EditorElement/EditorElementIntellisenseController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ private bool ISAC_EvaluateKeyDownEvent(Key k)
465465
editor.Document.Replace(endOffset, length + 1, replaceString);
466466
if (setCaret)
467467
{
468-
editor.CaretOffset -= 1;
468+
editor.CaretOffset--;
469469
}
470470

471471
return true;

UI/Components/EditorElement/Highlighting/BracketHighlightHelpers.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
using ICSharpCode.AvalonEdit.Document;
1+
using System.Collections.Generic;
2+
using ICSharpCode.AvalonEdit.Document;
23

34
namespace SPCode.Utils
45
{
56
public static class BracketHelpers
67
{
8+
private static readonly Dictionary<string, string> BracketPairs = new()
9+
{
10+
{ "}", "{" },
11+
{ "]", "[" },
12+
{ ")", "(" }
13+
};
14+
715
public static int QuickSearchBracketBackward(IDocument document, int offset, char openBracket, char closingBracket)
816
{
917
var brackets = -1;
@@ -259,5 +267,30 @@ public static bool CheckForChar(IDocument document, int offset)
259267
}
260268
return false;
261269
}
270+
271+
/// <summary>
272+
/// Utility to determine whether to place a closing bracket if the editor has already done that automatically.
273+
/// </summary>
274+
/// <param name="document"></param>
275+
/// <param name="offset"></param>
276+
/// <param name="bracket"></param>
277+
/// <returns></returns>
278+
public static bool CheckForClosingBracket(IDocument document, int offset, string bracket)
279+
{
280+
//var a = offset + 1 < document.TextLength;
281+
//var b = document.GetCharAt(offset).ToString() == bracket;
282+
//var c = document.GetCharAt(offset - 1).ToString() == opBracket;
283+
284+
if (offset + 1 < document.TextLength)
285+
{
286+
return
287+
document.GetCharAt(offset).ToString() == bracket &&
288+
document.GetCharAt(offset - 1).ToString() == BracketPairs[bracket];
289+
}
290+
else
291+
{
292+
return true;
293+
}
294+
}
262295
}
263296
}

UI/MainWindow/MainWindow.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,14 @@
374374
</TextBox>
375375
<GridSplitter Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="5" Background="LightGray" />
376376
<DataGrid x:Name="ErrorResultGrid" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsReadOnly="True"
377-
SelectionMode="Single" AutoGenerateColumns="False" SelectionChanged="ErrorResultGrid_SelectionChanged">
377+
SelectionMode="Single" AutoGenerateColumns="true" SelectionChanged="ErrorResultGrid_SelectionChanged">
378+
379+
<DataGrid.ItemContainerStyle>
380+
<Style TargetType="DataGridRow">
381+
<EventSetter Event="MouseDown" Handler="ErrorResultGrid_Click"/>
382+
</Style>
383+
</DataGrid.ItemContainerStyle>
384+
378385
<DataGrid.Columns>
379386
<DataGridTextColumn x:Name="MenuC_FileName" Header="File Name" Width="7*" Binding="{Binding File}" />
380387
<DataGridTextColumn x:Name="MenuC_Line" Header="Line" Width="1*" Binding="{Binding Line}" />

UI/MainWindow/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public void UpdateWindowTitle()
454454
},
455455
Buttons = new Button[]
456456
{
457-
new Button() { Label = Constants.GitHubRepositoryText, Url = Constants.GitHubRepository }
457+
new Button() { Label = Constants.GetSPCodeText, Url = Constants.GitHubRepository }
458458
}
459459
});
460460
}

UI/MainWindow/MainWindowErrorResultGrid.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Windows;
44
using System.Windows.Controls;
5+
using System.Windows.Input;
56
using SPCode.Interop;
67
using SPCode.UI.Components;
78
using SPCode.Utils;
@@ -69,6 +70,10 @@ private void ErrorResultGrid_SelectionChanged(object sender, SelectionChangedEve
6970
}
7071
}
7172

73+
private void ErrorResultGrid_Click(object sender, MouseButtonEventArgs e)
74+
{
75+
ErrorResultGrid_SelectionChanged(null, null);
76+
}
7277
private void CloseErrorResultGrid(object sender, RoutedEventArgs e)
7378
{
7479
CompileOutputRow.Height = new GridLength(8.0);

UI/MainWindow/MainWindowObjectBrowser.cs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Windows.Media;
1212
using System.Windows.Media.Imaging;
1313
using System.Windows.Threading;
14+
using MahApps.Metro.Controls.Dialogs;
1415
using SPCode.UI.Windows;
1516
using SPCode.Utils;
1617

@@ -136,38 +137,45 @@ private void OBItemOpenFileLocation_Click(object sender, RoutedEventArgs e)
136137

137138
private void OBItemRename_Click(object sender, RoutedEventArgs e)
138139
{
139-
if (ObjectBrowser.SelectedItem is TreeViewItem file)
140+
try
140141
{
141-
// Open up the Rename Window and fetch the new name from there
142-
var fileTag = file.Tag as ObjectBrowserTag;
143-
var renameWindow = new RenameWindow(fileTag.Value);
144-
renameWindow.ShowDialog();
145-
146-
ObjectBrowser.ContextMenu = null;
147-
148-
// If we didn't receive an empty name...
149-
if (!string.IsNullOrEmpty(renameWindow.NewName))
142+
if (ObjectBrowser.SelectedItem is TreeViewItem file)
150143
{
151-
var oldFileInfo = new FileInfo(fileTag.Value);
152-
var newFileInfo = new FileInfo(oldFileInfo.DirectoryName + @"\" + renameWindow.NewName);
144+
// Open up the Rename Window and fetch the new name from there
145+
var fileTag = file.Tag as ObjectBrowserTag;
146+
var renameWindow = new RenameWindow(fileTag.Value);
147+
renameWindow.ShowDialog();
153148

154-
// Rename file
155-
File.Move(oldFileInfo.FullName, newFileInfo.FullName);
149+
ObjectBrowser.ContextMenu = null;
156150

157-
// If the new extension is not supported by SPCode, remove it from object browser
158-
// else, rename and update the item
159-
if (!FileIcons.ContainsKey(newFileInfo.Extension))
151+
// If we didn't receive an empty name...
152+
if (!string.IsNullOrEmpty(renameWindow.NewName))
160153
{
161-
file.Visibility = Visibility.Collapsed;
162-
return;
163-
}
164-
else
165-
{
166-
fileTag.Value = newFileInfo.FullName;
167-
file.Header = BuildTreeViewItemContent(renameWindow.NewName, FileIcons[newFileInfo.Extension]);
154+
var oldFileInfo = new FileInfo(fileTag.Value);
155+
var newFileInfo = new FileInfo(oldFileInfo.DirectoryName + @"\" + renameWindow.NewName);
156+
157+
// Rename file
158+
File.Move(oldFileInfo.FullName, newFileInfo.FullName);
159+
160+
// If the new extension is not supported by SPCode, remove it from object browser
161+
// else, rename and update the item
162+
if (!FileIcons.ContainsKey(newFileInfo.Extension))
163+
{
164+
file.Visibility = Visibility.Collapsed;
165+
return;
166+
}
167+
else
168+
{
169+
fileTag.Value = newFileInfo.FullName;
170+
file.Header = BuildTreeViewItemContent(renameWindow.NewName, FileIcons[newFileInfo.Extension]);
171+
}
168172
}
169173
}
170174
}
175+
catch (Exception ex)
176+
{
177+
this.ShowMessageAsync(Program.Translations.GetLanguage("Error"), ex.Message);
178+
}
171179
}
172180

173181
private void OBItemDelete_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)