forked from cpmcgrath/codealignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlignFunctions.cs
More file actions
80 lines (68 loc) · 3.04 KB
/
Copy pathAlignFunctions.cs
File metadata and controls
80 lines (68 loc) · 3.04 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Linq;
using System.Drawing;
using CMcG.CodeAlignment.Business;
using CMcG.CodeAlignment.Interactions;
namespace CMcG.CodeAlignment
{
public class AlignFunctions
{
Business.Options m_options = new Business.Options();
Point m_keyGrabOffset = new Point(10, -50);
public IUIManager UIManager { get; set; }
public IDocument Document { get; set; }
public IntPtr Handle { get; set; }
public Point KeyGrabOffset
{
get { return m_keyGrabOffset; }
set { m_keyGrabOffset = value; }
}
public void AlignBy(string alignDelimiter, bool alignFromCaret = false, bool useRegex = false, bool addSpace = false)
{
if (!string.IsNullOrEmpty(alignDelimiter))
CreateAlignment(useRegex).PerformAlignment(alignDelimiter, alignFromCaret ? Document.CaretColumn : 0, addSpace);
}
public void AlignBy(Key key, bool forceFromCaret = false)
{
var shortcut = m_options.GetShortcut(key, Document.FileType);
if (shortcut != null)
AlignBy(shortcut.Alignment, forceFromCaret || shortcut.AlignFromCaret, shortcut.UseRegex, shortcut.AddSpace);
}
public void AlignByDialog(bool alignFromCaret = false)
{
var result = UIManager.PromptForAlignment(alignFromCaret);
if (result != null)
AlignBy(result.Delimiter, result.AlignFromCaret, useRegex:result.UseRegex);
}
Alignment CreateAlignment(bool useRegex = false)
{
var alignment = new Alignment { View = Document, UseIdeTabSettings = m_options.UseIdeTabSettings };
if (m_options.XmlTypes.Contains(Document.FileType))
alignment.Selector = new XmlScopeSelector
{
Start = Document.StartSelectionLineNumber,
End = Document.EndSelectionLineNumber
};
else
alignment.Selector = new GeneralScopeSelector
{
ScopeSelectorRegex = m_options.ScopeSelectorRegex,
Start = Document.StartSelectionLineNumber,
End = Document.EndSelectionLineNumber
};
if (useRegex)
alignment.Finder = new RegexDelimiterFinder();
return alignment;
}
public void AlignByKey()
{
var viewModel = new AlignmentViewModel(this, CreateAlignment());
var bounds = new LocationCalculator().CalculateBounds(Handle, KeyGrabOffset);
using (var grabber = UIManager.GetKeyGrabber(viewModel))
{
grabber.SetBounds(bounds);
grabber.Display();
}
}
}
}