Skip to content

Commit 89675c3

Browse files
committed
refactor: move data-only structures and enums to SourceGit.Models
Signed-off-by: leo <longshuang@msn.cn>
1 parent 4516b00 commit 89675c3

File tree

4 files changed

+127
-175
lines changed

4 files changed

+127
-175
lines changed

src/Models/Conflict.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Collections.Generic;
2+
3+
namespace SourceGit.Models
4+
{
5+
public enum ConflictResolution
6+
{
7+
None,
8+
UseOurs,
9+
UseTheirs,
10+
UseBothMineFirst,
11+
UseBothTheirsFirst,
12+
}
13+
14+
public enum ConflictMarkerType
15+
{
16+
Start, // <<<<<<<
17+
Base, // ||||||| (diff3 style)
18+
Separator, // =======
19+
End, // >>>>>>>
20+
}
21+
22+
public enum ConflictPanelType
23+
{
24+
Mine,
25+
Theirs,
26+
Result
27+
}
28+
29+
public enum ConflictLineState
30+
{
31+
Normal,
32+
ConflictBlockStart,
33+
ConflictBlock,
34+
ConflictBlockEnd,
35+
ResolvedBlockStart,
36+
ResolvedBlock,
37+
ResolvedBlockEnd,
38+
}
39+
40+
public record ConflictSelectedChunk(
41+
double Y,
42+
double Height,
43+
int ConflictIndex,
44+
ConflictPanelType Panel,
45+
bool IsResolved
46+
);
47+
48+
public class ConflictMarkerInfo
49+
{
50+
public int LineNumber { get; set; }
51+
public int StartOffset { get; set; }
52+
public int EndOffset { get; set; }
53+
public ConflictMarkerType Type { get; set; }
54+
}
55+
56+
public class ConflictRegion
57+
{
58+
public int StartLineInOriginal { get; set; }
59+
public int EndLineInOriginal { get; set; }
60+
public List<string> OursContent { get; set; } = new();
61+
public List<string> TheirsContent { get; set; } = new();
62+
public bool IsResolved { get; set; } = false;
63+
64+
// Line indices in the built static panels (0-based)
65+
public int PanelStartLine { get; set; } = -1;
66+
public int PanelEndLine { get; set; } = -1;
67+
68+
// Content chosen when resolved (null = unresolved, empty list = deleted)
69+
public List<string> ResolvedContent { get; set; } = null;
70+
71+
// Real markers from the file
72+
public string StartMarker { get; set; } = "<<<<<<<";
73+
public string SeparatorMarker { get; set; } = "=======";
74+
public string EndMarker { get; set; } = ">>>>>>>";
75+
76+
// Track the type of resolution
77+
public ConflictResolution ResolutionType { get; set; } = ConflictResolution.None;
78+
}
79+
}

src/Models/MergeConflict.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/ViewModels/MergeConflictEditor.cs

Lines changed: 23 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,6 @@
99

1010
namespace SourceGit.ViewModels
1111
{
12-
public enum MergeConflictPanelType
13-
{
14-
Mine,
15-
Theirs,
16-
Result
17-
}
18-
19-
public enum MergeConflictLineType
20-
{
21-
Normal,
22-
ConflictBlockStart,
23-
ConflictBlock,
24-
ConflictBlockEnd,
25-
ResolvedBlockStart,
26-
ResolvedBlock,
27-
ResolvedBlockEnd,
28-
}
29-
30-
public record MergeConflictSelectedChunk(
31-
double Y,
32-
double Height,
33-
int ConflictIndex,
34-
MergeConflictPanelType Panel,
35-
bool IsResolved
36-
);
37-
38-
// Represents a single conflict region with its original content and panel positions
39-
public class ConflictRegion
40-
{
41-
public int StartLineInOriginal { get; set; }
42-
public int EndLineInOriginal { get; set; }
43-
public List<string> OursContent { get; set; } = new();
44-
public List<string> TheirsContent { get; set; } = new();
45-
public bool IsResolved { get; set; } = false;
46-
47-
// Line indices in the built static panels (0-based)
48-
public int PanelStartLine { get; set; } = -1;
49-
public int PanelEndLine { get; set; } = -1;
50-
51-
// Content chosen when resolved (null = unresolved, empty list = deleted)
52-
public List<string> ResolvedContent { get; set; } = null;
53-
54-
// Real markers from the file
55-
public string StartMarker { get; set; } = "<<<<<<<";
56-
public string SeparatorMarker { get; set; } = "=======";
57-
public string EndMarker { get; set; } = ">>>>>>>";
58-
59-
// Track the type of resolution
60-
public Models.ConflictResolution ResolutionType { get; set; } = Models.ConflictResolution.None;
61-
}
62-
6312
public class MergeConflictEditor : ObservableObject
6413
{
6514
public string FilePath
@@ -139,13 +88,13 @@ public Vector ScrollOffset
13988
set => SetProperty(ref _scrollOffset, value);
14089
}
14190

142-
public MergeConflictSelectedChunk SelectedChunk
91+
public Models.ConflictSelectedChunk SelectedChunk
14392
{
14493
get => _selectedChunk;
14594
set => SetProperty(ref _selectedChunk, value);
14695
}
14796

148-
public IReadOnlyList<ConflictRegion> ConflictRegions => _conflictRegions;
97+
public IReadOnlyList<Models.ConflictRegion> ConflictRegions => _conflictRegions;
14998
public bool HasUnresolvedConflicts => _unresolvedConflictCount > 0;
15099
public bool HasUnsavedChanges => _isModified && !_resultContent.Equals(_originalContent, StringComparison.Ordinal);
151100
public bool CanSave => _unresolvedConflictCount == 0 && _isModified;
@@ -193,11 +142,11 @@ public async Task LoadAsync()
193142
}
194143
}
195144

196-
public MergeConflictLineType GetLineType(int line)
145+
public Models.ConflictLineState GetLineState(int line)
197146
{
198-
if (line >= 0 && line < _lineTypes.Count)
199-
return _lineTypes[line];
200-
return MergeConflictLineType.Normal;
147+
if (line >= 0 && line < _lineStates.Count)
148+
return _lineStates[line];
149+
return Models.ConflictLineState.Normal;
201150
}
202151

203152
public void AcceptOursAtIndex(int conflictIndex)
@@ -380,7 +329,7 @@ private void ParseOriginalConflicts(string content)
380329

381330
if (line.StartsWith("<<<<<<<", StringComparison.Ordinal))
382331
{
383-
var region = new ConflictRegion { StartLineInOriginal = i };
332+
var region = new Models.ConflictRegion { StartLineInOriginal = i };
384333
// Capture the start marker (e.g., "<<<<<<< HEAD")
385334
region.StartMarker = line;
386335
i++;
@@ -554,7 +503,7 @@ private void BuildAlignedResultPanel()
554503
// Build RESULT panel aligned with MINE/THEIRS panels
555504
// This ensures all three panels have the same number of lines for scroll sync
556505
var resultLines = new List<Models.TextDiffLine>();
557-
_lineTypes.Clear();
506+
_lineStates.Clear();
558507

559508
if (_oursDiffLines == null || _oursDiffLines.Count == 0)
560509
{
@@ -569,7 +518,7 @@ private void BuildAlignedResultPanel()
569518
while (currentLine < _oursDiffLines.Count)
570519
{
571520
// Check if we're at a conflict region
572-
ConflictRegion currentRegion = null;
521+
Models.ConflictRegion currentRegion = null;
573522
if (conflictIdx < _conflictRegions.Count)
574523
{
575524
var region = _conflictRegions[conflictIdx];
@@ -636,41 +585,41 @@ private void BuildAlignedResultPanel()
636585
resultLines.Add(new Models.TextDiffLine());
637586

638587
int added = resultLines.Count - oldLineCount;
639-
_lineTypes.Add(MergeConflictLineType.ResolvedBlockStart);
588+
_lineStates.Add(Models.ConflictLineState.ResolvedBlockStart);
640589
for (var i = 0; i < added - 2; i++)
641-
_lineTypes.Add(MergeConflictLineType.ResolvedBlock);
642-
_lineTypes.Add(MergeConflictLineType.ResolvedBlockEnd);
590+
_lineStates.Add(Models.ConflictLineState.ResolvedBlock);
591+
_lineStates.Add(Models.ConflictLineState.ResolvedBlockEnd);
643592
}
644593
else
645594
{
646595
// Unresolved - show conflict markers with content, aligned with Mine/Theirs
647596
// First line: start marker (use real marker from file)
648597
resultLines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, currentRegion.StartMarker, 0, 0));
649-
_lineTypes.Add(MergeConflictLineType.ConflictBlockStart);
598+
_lineStates.Add(Models.ConflictLineState.ConflictBlockStart);
650599

651600
// Mine content lines (matches the deleted lines in Ours panel)
652601
foreach (var line in currentRegion.OursContent)
653602
{
654603
resultLines.Add(new Models.TextDiffLine(
655604
Models.TextDiffLineType.Deleted, line, 0, resultLineNumber++));
656-
_lineTypes.Add(MergeConflictLineType.ConflictBlock);
605+
_lineStates.Add(Models.ConflictLineState.ConflictBlock);
657606
}
658607

659608
// Separator marker between Mine and Theirs
660609
resultLines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, currentRegion.SeparatorMarker, 0, 0));
661-
_lineTypes.Add(MergeConflictLineType.ConflictBlock);
610+
_lineStates.Add(Models.ConflictLineState.ConflictBlock);
662611

663612
// Theirs content lines (matches the added lines in Theirs panel)
664613
foreach (var line in currentRegion.TheirsContent)
665614
{
666615
resultLines.Add(new Models.TextDiffLine(
667616
Models.TextDiffLineType.Added, line, 0, resultLineNumber++));
668-
_lineTypes.Add(MergeConflictLineType.ConflictBlock);
617+
_lineStates.Add(Models.ConflictLineState.ConflictBlock);
669618
}
670619

671620
// End marker (use real marker from file)
672621
resultLines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, currentRegion.EndMarker, 0, 0));
673-
_lineTypes.Add(MergeConflictLineType.ConflictBlockEnd);
622+
_lineStates.Add(Models.ConflictLineState.ConflictBlockEnd);
674623
}
675624

676625
currentLine = currentRegion.PanelEndLine + 1;
@@ -693,7 +642,7 @@ private void BuildAlignedResultPanel()
693642
resultLines.Add(new Models.TextDiffLine());
694643
}
695644

696-
_lineTypes.Add(MergeConflictLineType.Normal);
645+
_lineStates.Add(Models.ConflictLineState.Normal);
697646
currentLine++;
698647
}
699648
}
@@ -852,7 +801,7 @@ private void RebuildResultContent()
852801
if (line.StartsWith("<<<<<<<", StringComparison.Ordinal))
853802
{
854803
// Get the current conflict region
855-
ConflictRegion region = null;
804+
Models.ConflictRegion region = null;
856805
if (conflictIdx < _conflictRegions.Count)
857806
region = _conflictRegions[conflictIdx];
858807

@@ -965,14 +914,14 @@ private void RebuildResultContent()
965914
private bool _isModified = false;
966915
private int _unresolvedConflictCount = 0;
967916
private int _currentConflictIndex = -1;
917+
private int _diffMaxLineNumber = 0;
968918
private List<Models.TextDiffLine> _oursDiffLines = [];
969919
private List<Models.TextDiffLine> _theirsDiffLines = [];
970920
private List<Models.TextDiffLine> _resultDiffLines = [];
971-
private int _diffMaxLineNumber = 0;
972-
private List<ConflictRegion> _conflictRegions = [];
973-
private List<MergeConflictLineType> _lineTypes = [];
921+
private List<Models.ConflictRegion> _conflictRegions = [];
922+
private List<Models.ConflictLineState> _lineStates = [];
974923
private Vector _scrollOffset = Vector.Zero;
975-
private MergeConflictSelectedChunk _selectedChunk;
924+
private Models.ConflictSelectedChunk _selectedChunk;
976925
private string _error = string.Empty;
977926
}
978927
}

0 commit comments

Comments
 (0)