markus / KCOM / Extensions / MacroHelper.cs @ 95c73392
이력 | 보기 | 이력해설 | 다운로드 (6.92 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using MarkupToPDF.Controls.Text; |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using System.Windows.Controls; |
9 |
using System.Windows.Controls.Primitives; |
10 |
using Telerik.Windows.Controls; |
11 |
|
12 |
namespace KCOM |
13 |
{ |
14 |
public static class MacroHelper |
15 |
{ |
16 |
private static List<MarkupToPDF.Controls.Common.ControlType> TextControlType = new List<MarkupToPDF.Controls.Common.ControlType> |
17 |
{ |
18 |
MarkupToPDF.Controls.Common.ControlType.TextBorder, |
19 |
MarkupToPDF.Controls.Common.ControlType.TextCloud, |
20 |
MarkupToPDF.Controls.Common.ControlType.TextControl, |
21 |
MarkupToPDF.Controls.Common.ControlType.ArrowTextBorderControl, |
22 |
MarkupToPDF.Controls.Common.ControlType.ArrowTextCloudControl, |
23 |
MarkupToPDF.Controls.Common.ControlType.ArrowTextControl, |
24 |
MarkupToPDF.Controls.Common.ControlType.ArrowTransTextBorderControl, |
25 |
MarkupToPDF.Controls.Common.ControlType.ArrowTransTextCloudControl, |
26 |
MarkupToPDF.Controls.Common.ControlType.ArrowTransTextControl, |
27 |
}; |
28 |
|
29 |
/// <summary> |
30 |
/// 버튼에 따른 macro 로드 |
31 |
/// </summary> |
32 |
/// <param name="Key">버튼의 key</param> |
33 |
/// <returns></returns> |
34 |
public static List<MacroItem> LoadMacroItems(string Key) |
35 |
{ |
36 |
List<MacroItem> result = new List<MacroItem>(); |
37 |
|
38 |
string items = CommonLib.Common.GetConfigString("MACRO", Key, ""); |
39 |
|
40 |
if(!string.IsNullOrWhiteSpace(items)) |
41 |
{ |
42 |
var controlTypes = items.Split(';'); |
43 |
|
44 |
for (int i = 0; i < controlTypes.Count(); i++) |
45 |
{ |
46 |
result.Add(new MacroItem |
47 |
{ |
48 |
IsCurrent = false, |
49 |
Index = i, |
50 |
ControlType = (MarkupToPDF.Controls.Common.ControlType)Enum.Parse(typeof(MarkupToPDF.Controls.Common.ControlType), controlTypes[i]) |
51 |
}); |
52 |
} |
53 |
} |
54 |
|
55 |
return result; |
56 |
} |
57 |
|
58 |
/// <summary> |
59 |
/// macro 초기화 |
60 |
/// </summary> |
61 |
public static void Clear() |
62 |
{ |
63 |
var menu = ViewerDataModel.Instance.SystemMain.dzMainMenu; |
64 |
|
65 |
Common.ViewerDataModel.Instance.IsMacroCommand = false; |
66 |
Common.ViewerDataModel.Instance.MacroCommandIndex = 0; |
67 |
Common.ViewerDataModel.Instance.MacroItems.ForEach(x => |
68 |
{ |
69 |
x.IsCurrent = false; |
70 |
x.IsDraw = false; |
71 |
}); |
72 |
|
73 |
menu.controlType = MarkupToPDF.Controls.Common.ControlType.None; |
74 |
menu.txtBatch.Visibility = System.Windows.Visibility.Collapsed; |
75 |
menu.mouseHandlingMode = IKCOM.MouseHandlingMode.None; |
76 |
var TogList = menu.Parent.ChildrenOfType<Telerik.Windows.Controls.RadToggleButton>(); |
77 |
|
78 |
foreach (var tog in TogList) |
79 |
{ |
80 |
tog.IsChecked = false; |
81 |
} |
82 |
} |
83 |
|
84 |
public static void MacroAction() |
85 |
{ |
86 |
var menu = ViewerDataModel.Instance.SystemMain.dzMainMenu; |
87 |
|
88 |
var currentItem = Common.ViewerDataModel.Instance.MacroItems.Find(x => x.IsCurrent); |
89 |
|
90 |
if(currentItem != null) |
91 |
{ |
92 |
if (TextControlType.Contains(currentItem.ControlType)) |
93 |
{ |
94 |
var arrowtext_item = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault(); |
95 |
|
96 |
var text_item = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as TextControl) != null && (data as TextControl).IsEditingMode == true).FirstOrDefault(); |
97 |
|
98 |
if (arrowtext_item != null || text_item != null) |
99 |
{ |
100 |
System.Diagnostics.Debug.WriteLine("MacroAction return = Text Control Edit Mode"); |
101 |
return; |
102 |
} |
103 |
} |
104 |
} |
105 |
|
106 |
Common.ViewerDataModel.Instance.MacroItems.ForEach(x =>x.IsCurrent = false); |
107 |
|
108 |
if (Common.ViewerDataModel.Instance.MacroCommandIndex < Common.ViewerDataModel.Instance.MacroItems.Count) |
109 |
{ |
110 |
Common.ViewerDataModel.Instance.IsMacroCommand = true; |
111 |
|
112 |
var item = Common.ViewerDataModel.Instance.MacroItems[Common.ViewerDataModel.Instance.MacroCommandIndex]; |
113 |
|
114 |
item.IsCurrent = true; |
115 |
item.IsDraw = true; |
116 |
menu.controlType = item.ControlType; |
117 |
menu.txtBatch.Visibility = System.Windows.Visibility.Visible; |
118 |
menu.txtBatch.Text = $"Draw a {item.Desc}"; |
119 |
|
120 |
Common.ViewerDataModel.Instance.MacroCommandIndex++; |
121 |
} |
122 |
else |
123 |
{ |
124 |
Clear(); |
125 |
} |
126 |
|
127 |
} |
128 |
|
129 |
public static List<MarkupMenuItem> TopMenuItems() |
130 |
{ |
131 |
List<MarkupMenuItem> result = new List<MarkupMenuItem>(); |
132 |
|
133 |
var menu = ViewerDataModel.Instance.SystemMain.dzTopMenu; |
134 |
|
135 |
result.AddRange(ItemCollectionToMenuItem(menu.LineControlGroup.Items,"Line")); |
136 |
result.AddRange(ItemCollectionToMenuItem(menu.ShapeControlGroup.Items, "Shape")); |
137 |
result.AddRange(ItemCollectionToMenuItem(menu.TextControlGroup.Items, "Text")); |
138 |
result.AddRange(ItemCollectionToMenuItem(menu.PenControlGroup.Items, "Pen")); |
139 |
result.AddRange(ItemCollectionToMenuItem(menu.AppStampControlGroup.Items, "Approval Stamp")); |
140 |
|
141 |
return result; |
142 |
} |
143 |
|
144 |
private static IEnumerable<MarkupMenuItem> ItemCollectionToMenuItem(ItemCollection collection,string GroupName) |
145 |
{ |
146 |
foreach (var item in collection) |
147 |
{ |
148 |
foreach (var control in (item as System.Windows.DependencyObject).FindAllChildren(c => c is ButtonBase)) |
149 |
{ |
150 |
Uri iconUri = null; |
151 |
|
152 |
if ((control as ButtonBase).CommandParameter != null) |
153 |
{ |
154 |
if ((control as ButtonBase).Content is Image) |
155 |
{ |
156 |
var uri = (((control as ButtonBase).Content as Image).Source as System.Windows.Markup.IUriContext); |
157 |
|
158 |
if (uri != null) |
159 |
{ |
160 |
iconUri = new Uri(uri.ToString()); |
161 |
} |
162 |
} |
163 |
|
164 |
yield return new MarkupMenuItem |
165 |
{ |
166 |
GroupName = GroupName, |
167 |
Name = (control as ButtonBase).CommandParameter?.ToString(), |
168 |
Tooltip = (control as ButtonBase).CommandParameter?.ToString(), |
169 |
Icon = iconUri |
170 |
}; |
171 |
} |
172 |
else |
173 |
{ |
174 |
|
175 |
} |
176 |
} |
177 |
} |
178 |
} |
179 |
|
180 |
} |
181 |
} |