forked from cpmcgrath/codealignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlignmentViewModel.cs
More file actions
59 lines (48 loc) · 1.71 KB
/
Copy pathAlignmentViewModel.cs
File metadata and controls
59 lines (48 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Linq;
using System.Drawing;
using CMcG.CodeAlignment.Business;
namespace CMcG.CodeAlignment
{
public class AlignmentViewModel
{
Business.Options m_options = new Business.Options();
Alignment m_alignment;
AlignFunctions m_functions;
int m_lastAlignment = -1;
public AlignmentViewModel(AlignFunctions functions, Alignment alignment)
{
m_alignment = alignment;
m_functions = functions;
}
public void AlignFromPosition()
{
m_functions.AlignByDialog(alignFromCaret:true);
}
public int PerformAlign(Key key, bool forceFromCaret)
{
m_alignment.View.Refresh();
var shortcut = m_options.GetShortcut(key, m_functions.Document.FileType);
if (shortcut != null && !string.IsNullOrEmpty(shortcut.Alignment))
{
m_alignment.Finder = GetFinder(shortcut);
int minIndex = GetMinIndex(forceFromCaret, shortcut);
m_lastAlignment = m_alignment.PerformAlignment(shortcut.Alignment, minIndex, shortcut.AddSpace);
return m_lastAlignment;
}
return -1;
}
IDelimiterFinder GetFinder(KeyShortcut shortcut)
{
return shortcut.UseRegex ? new RegexDelimiterFinder() : new NormalDelimiterFinder();
}
int GetMinIndex(bool forceFromCaret, KeyShortcut shortcut)
{
if (m_lastAlignment != -1)
return m_lastAlignment + 1;
if (forceFromCaret || shortcut.AlignFromCaret)
return m_functions.Document.CaretColumn;
return 0;
}
}
}