markus / KCOM / Extensions / MacroHelper.cs @ b74a9c91
이력 | 보기 | 이력해설 | 다운로드 (6.76 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 |
public static void MacroAction() |
59 |
{ |
60 |
var menu = ViewerDataModel.Instance.SystemMain.dzMainMenu; |
61 |
|
62 |
var currentItem = Common.ViewerDataModel.Instance.MacroItems.Find(x => x.IsCurrent); |
63 |
|
64 |
if(currentItem != null) |
65 |
{ |
66 |
if (TextControlType.Contains(currentItem.ControlType)) |
67 |
{ |
68 |
var arrowtext_item = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as ArrowTextControl) != null && (data as ArrowTextControl).IsEditingMode == true).FirstOrDefault(); |
69 |
|
70 |
var text_item = ViewerDataModel.Instance.MarkupControls_USER.Where(data => (data as TextControl) != null && (data as TextControl).IsEditingMode == true).FirstOrDefault(); |
71 |
|
72 |
if (arrowtext_item != null || text_item != null) |
73 |
{ |
74 |
System.Diagnostics.Debug.WriteLine("MacroAction return = Text Control Edit Mode"); |
75 |
return; |
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
Common.ViewerDataModel.Instance.MacroItems.ForEach(x =>x.IsCurrent = false); |
81 |
|
82 |
if (Common.ViewerDataModel.Instance.MacroCommandIndex < Common.ViewerDataModel.Instance.MacroItems.Count) |
83 |
{ |
84 |
Common.ViewerDataModel.Instance.IsMacroCommand = true; |
85 |
|
86 |
var item = Common.ViewerDataModel.Instance.MacroItems[Common.ViewerDataModel.Instance.MacroCommandIndex]; |
87 |
|
88 |
item.IsCurrent = true; |
89 |
item.IsDraw = true; |
90 |
menu.controlType = item.ControlType; |
91 |
menu.txtBatch.Visibility = System.Windows.Visibility.Visible; |
92 |
menu.txtBatch.Text = $"Draw a {item.Desc}"; |
93 |
|
94 |
Common.ViewerDataModel.Instance.MacroCommandIndex++; |
95 |
} |
96 |
else |
97 |
{ |
98 |
Common.ViewerDataModel.Instance.IsMacroCommand = false; |
99 |
Common.ViewerDataModel.Instance.MacroCommandIndex = 0; |
100 |
Common.ViewerDataModel.Instance.MacroItems.ForEach(x => |
101 |
{ |
102 |
x.IsCurrent = false; |
103 |
x.IsDraw = false; |
104 |
}); |
105 |
|
106 |
menu.controlType = MarkupToPDF.Controls.Common.ControlType.None; |
107 |
menu.txtBatch.Visibility = System.Windows.Visibility.Collapsed; |
108 |
menu.mouseHandlingMode = IKCOM.MouseHandlingMode.None; |
109 |
var TogList = menu.Parent.ChildrenOfType<Telerik.Windows.Controls.RadToggleButton>(); |
110 |
|
111 |
foreach (var tog in TogList) |
112 |
{ |
113 |
tog.IsChecked = false; |
114 |
} |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
public static List<MarkupMenuItem> TopMenuItems() |
120 |
{ |
121 |
List<MarkupMenuItem> result = new List<MarkupMenuItem>(); |
122 |
|
123 |
var menu = ViewerDataModel.Instance.SystemMain.dzTopMenu; |
124 |
|
125 |
result.AddRange(ItemCollectionToMenuItem(menu.LineControlGroup.Items,"Line")); |
126 |
result.AddRange(ItemCollectionToMenuItem(menu.ShapeControlGroup.Items, "Shape")); |
127 |
result.AddRange(ItemCollectionToMenuItem(menu.TextControlGroup.Items, "Text")); |
128 |
result.AddRange(ItemCollectionToMenuItem(menu.PenControlGroup.Items, "Pen")); |
129 |
result.AddRange(ItemCollectionToMenuItem(menu.AppStampControlGroup.Items, "Approval Stamp")); |
130 |
|
131 |
return result; |
132 |
} |
133 |
|
134 |
private static IEnumerable<MarkupMenuItem> ItemCollectionToMenuItem(ItemCollection collection,string GroupName) |
135 |
{ |
136 |
foreach (var item in collection) |
137 |
{ |
138 |
foreach (var control in (item as System.Windows.DependencyObject).FindAllChildren(c => c is ButtonBase)) |
139 |
{ |
140 |
Uri iconUri = null; |
141 |
|
142 |
if ((control as ButtonBase).CommandParameter != null) |
143 |
{ |
144 |
if ((control as ButtonBase).Content is Image) |
145 |
{ |
146 |
var uri = (((control as ButtonBase).Content as Image).Source as System.Windows.Markup.IUriContext); |
147 |
|
148 |
if (uri != null) |
149 |
{ |
150 |
iconUri = new Uri(uri.ToString()); |
151 |
} |
152 |
} |
153 |
|
154 |
yield return new MarkupMenuItem |
155 |
{ |
156 |
GroupName = GroupName, |
157 |
Name = (control as ButtonBase).CommandParameter?.ToString(), |
158 |
Tooltip = (control as ButtonBase).CommandParameter?.ToString(), |
159 |
Icon = iconUri |
160 |
}; |
161 |
} |
162 |
else |
163 |
{ |
164 |
|
165 |
} |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
} |
171 |
} |