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

Commit 415678c

Browse files
committed
changed GetAllEditors' return type to List<T>
1 parent c216d74 commit 415678c

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ private void ParseIncludes(object sender, EventArgs e)
664664
return;
665665
}
666666

667-
var definitions = new SMDefinition[ee.Length];
667+
var definitions = new SMDefinition[ee.Count];
668668
List<SMFunction> currentFunctions = null;
669-
for (var i = 0; i < ee.Length; ++i)
669+
for (var i = 0; i < ee.Count; ++i)
670670
{
671671
var el = ee[i];
672672
var fInfo = new FileInfo(el.FullFilePath);
@@ -794,8 +794,8 @@ public void ToggleComment(bool comment)
794794
var lineList = new List<DocumentLine>();
795795
var document = editor.TextArea.Document;
796796

797-
// Start undo transaction so undoing this doesn't result in undoing every single comment manually
798-
document.UndoStack.StartUndoGroup();
797+
// Start update so undoing this doesn't result in undoing every single comment manually
798+
document.BeginUpdate();
799799

800800
// If there's no selection, add to lineList the line the caret is standing on
801801
if (!selectionSegments.Any())
@@ -850,8 +850,8 @@ public void ToggleComment(bool comment)
850850
}
851851
}
852852

853-
// End the undo transaction
854-
document.UndoStack.EndUndoGroup();
853+
// End update
854+
document.EndUpdate();
855855
}
856856

857857
public void ChangeCase(bool toUpper = true)

UI/MainWindow/MainWindowCommands.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Text;
@@ -66,18 +67,18 @@ public DASMElement GetCurrentDASMElement()
6667
/// Gets an array of all open editor elements.
6768
/// </summary>
6869
/// <returns></returns>
69-
public EditorElement[] GetAllEditorElements()
70+
public List<EditorElement> GetAllEditorElements()
7071
{
71-
return EditorReferences.Count < 1 ? null : EditorReferences.ToArray();
72+
return EditorReferences.Count == 0 ? null : EditorReferences;
7273
}
7374

7475
/// <summary>
7576
/// Gets an array of all open DASM elements.
7677
/// </summary>
7778
/// <returns></returns>
78-
public DASMElement[] GetAllDASMElements()
79+
public List<DASMElement> GetAllDASMElements()
7980
{
80-
return DASMReferences.Count < 1 ? null : DASMReferences.ToArray();
81+
return DASMReferences.Count < 1 ? null : DASMReferences;
8182
}
8283

8384
/// <summary>
@@ -314,7 +315,7 @@ private void Command_SaveAll()
314315
return;
315316
}
316317

317-
if (editors.Length > 0)
318+
if (editors.Count > 0)
318319
{
319320
foreach (var editor in editors)
320321
{
@@ -362,7 +363,7 @@ private async void Command_CloseAll()
362363
var editors = GetAllEditorElements();
363364
var dasm = GetAllDASMElements();
364365

365-
if (editors == null || editors.Any(x => x.IsTemplateEditor) || editors.Length == 0 || editors.Any(x => x.ClosingPromptOpened))
366+
if (editors == null || editors.Any(x => x.IsTemplateEditor) || editors.Count == 0 || editors.Any(x => x.ClosingPromptOpened))
366367
{
367368
return;
368369
}
@@ -555,7 +556,7 @@ private void Command_TidyCode(bool All)
555556
{
556557
try
557558
{
558-
var editors = All ? GetAllEditorElements() : new[] { GetCurrentEditorElement() };
559+
var editors = All ? GetAllEditorElements() : new() { GetCurrentEditorElement() };
559560
if (editors == null)
560561
{
561562
return;

UI/MainWindow/MainWindowMenuHandler.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@ public partial class MainWindow
2222
#region Events
2323
private void FileMenu_Open(object sender, RoutedEventArgs e)
2424
{
25-
var editors = GetAllEditorElements();
26-
var EditorsAreOpen = false;
27-
if (editors != null)
28-
{
29-
EditorsAreOpen = editors.Length > 0;
30-
}
31-
25+
var EditorsAreOpen = GetAllEditorElements() != null;
3226
var EditorIsSelected = GetCurrentEditorElement() != null;
27+
3328
MenuI_Save.IsEnabled = EditorIsSelected;
3429
MenuI_SaveAs.IsEnabled = EditorIsSelected;
3530
MenuI_Close.IsEnabled = EditorIsSelected;

UI/Windows/FindReplaceWindow.xaml.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public partial class FindReplaceWindow
1717
{
1818
#region Variables
1919
private EditorElement _editor;
20-
private EditorElement[] _allEditors;
20+
private List<EditorElement> _allEditors;
2121
private LayoutDocumentPane _dockingPane;
2222
private bool IsSearchFieldOpen;
2323
private readonly string Selection;
@@ -228,17 +228,17 @@ private void Search()
228228
LoadEditorsInfo();
229229
var editors = GetEditorElementsForFraction(out var editorIndex);
230230
var regex = GetSearchRegex();
231-
if (editors == null || editors.Length < 1 || editors[0] == null || regex == null)
231+
if (editors == null || editors.Count < 1 || editors[0] == null || regex == null)
232232
{
233233
return;
234234
}
235235

236236
var startFileCaretOffset = 0;
237237
var foundOccurence = false;
238238

239-
for (var i = editorIndex; i < (editors.Length + editorIndex + 1); ++i)
239+
for (var i = editorIndex; i < (editors.Count + editorIndex + 1); ++i)
240240
{
241-
var index = ValueUnderMap(i, editors.Length);
241+
var index = ValueUnderMap(i, editors.Count);
242242
string searchText;
243243
var addToOffset = 0;
244244
if (i == editorIndex)
@@ -248,7 +248,7 @@ private void Search()
248248
if (startFileCaretOffset < 0) { startFileCaretOffset = 0; }
249249
searchText = editors[index].editor.Text.Substring(startFileCaretOffset);
250250
}
251-
else if (i == (editors.Length + editorIndex))
251+
else if (i == (editors.Count + editorIndex))
252252
{
253253
searchText = startFileCaretOffset == 0 ?
254254
string.Empty :
@@ -286,17 +286,17 @@ private void Replace()
286286
LoadEditorsInfo();
287287
var editors = GetEditorElementsForFraction(out var editorIndex);
288288
var regex = GetSearchRegex();
289-
if (editors == null || editors.Length < 1 || editors[0] == null || regex == null)
289+
if (editors == null || editors.Count < 1 || editors[0] == null || regex == null)
290290
{
291291
return;
292292
}
293293

294294
var replaceString = ReplaceBox.Text;
295295
var startFileCaretOffset = 0;
296296
var foundOccurence = false;
297-
for (var i = editorIndex; i < (editors.Length + editorIndex + 1); ++i)
297+
for (var i = editorIndex; i < (editors.Count + editorIndex + 1); ++i)
298298
{
299-
var index = ValueUnderMap(i, editors.Length);
299+
var index = ValueUnderMap(i, editors.Count);
300300
string searchText;
301301
var addToOffset = 0;
302302
if (i == editorIndex)
@@ -306,7 +306,7 @@ private void Replace()
306306
if (startFileCaretOffset < 0) { startFileCaretOffset = 0; }
307307
searchText = editors[index].editor.Text.Substring(startFileCaretOffset);
308308
}
309-
else if (i == (editors.Length + editorIndex))
309+
else if (i == (editors.Count + editorIndex))
310310
{
311311
searchText = startFileCaretOffset == 0 ?
312312
string.Empty :
@@ -345,7 +345,7 @@ private void ReplaceAll()
345345
LoadEditorsInfo();
346346
var editors = GetEditorElementsForFraction(out _);
347347
var regex = GetSearchRegex();
348-
if (editors == null || editors.Length < 1 || editors[0] == null || regex == null)
348+
if (editors == null || editors.Count < 1 || editors[0] == null || regex == null)
349349
{
350350
return;
351351
}
@@ -380,7 +380,7 @@ private void Count()
380380
LoadEditorsInfo();
381381
var editors = GetEditorElementsForFraction(out _);
382382
if (editors == null) { return; }
383-
if (editors.Length < 1) { return; }
383+
if (editors.Count < 1) { return; }
384384
if (editors[0] == null) { return; }
385385
var regex = GetSearchRegex();
386386
if (regex == null) { return; }
@@ -454,20 +454,20 @@ private Regex GetSearchRegex()
454454
return regex;
455455
}
456456

457-
private EditorElement[] GetEditorElementsForFraction(out int editorIndex)
457+
private List<EditorElement> GetEditorElementsForFraction(out int editorIndex)
458458
{
459459
LoadEditorsInfo();
460460
var editorStartIndex = 0;
461-
EditorElement[] editors;
461+
List<EditorElement> editors;
462462
if (FindDestinies.SelectedIndex == 0)
463-
{ editors = new[] { _editor }; }
463+
{ editors = new() { _editor }; }
464464
else
465465
{
466466
editors = _allEditors;
467467
var checkElement = _dockingPane.SelectedContent?.Content;
468468
if (checkElement is EditorElement)
469469
{
470-
for (var i = 0; i < editors.Length; ++i)
470+
for (var i = 0; i < editors.Count; ++i)
471471
{
472472
if (editors[i] == checkElement)
473473
{

0 commit comments

Comments
 (0)