-
Notifications
You must be signed in to change notification settings - Fork 4
/
WebPageItemExtensionModule.cs
82 lines (76 loc) · 3.85 KB
/
WebPageItemExtensionModule.cs
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
81
82
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors.Repository;
using DevExpress.DashboardWin.CustomItemExtension.CustomItems.WebPageItem;
namespace DevExpress.DashboardWin.CustomItemExtension
{
public class WebPageItemExtensionModule : IExtensionModule {
BarEditItem urlBarItem;
IDashboardControl dashboardControl;
DashboardDesigner designer { get { return dashboardControl as DashboardDesigner; } }
CustomDashboardItem<WebPageItemMetadata> selectedCustomItem {
get { return designer.SelectedDashboardItem as CustomDashboardItem<WebPageItemMetadata>; }
}
public void AttachViewer(DashboardViewer viewer) {
AttachDashboardControl(viewer);
}
public void AttachDesigner(DashboardDesigner designer) {
AttachDashboardControl(designer);
designer.CreateCustomItemBars(typeof(WebPageItemMetadata));
InitializeUrlBarItem();
designer.DashboardItemSelected += Designer_DashboardItemSelected;
// Other code specific for Designer
}
private void Designer_DashboardItemSelected(object sender, DashboardItemSelectedEventArgs e) {
if(designer.SelectedDashboardItem is CustomDashboardItem<WebPageItemMetadata>)
urlBarItem.EditValue = selectedCustomItem.Metadata.URI;
}
void AttachDashboardControl(IDashboardControl dashboardControl) {
if(dashboardControl != null) {
this.dashboardControl = dashboardControl;
dashboardControl.CustomDashboardItemControlCreating += OnCustomDashboardItemControlCreating;
}
}
public void DetachViewer() {
Detach();
}
public void DetachDesigner() {
Detach();
}
void Detach() {
if(dashboardControl != null)
dashboardControl.CustomDashboardItemControlCreating -= OnCustomDashboardItemControlCreating;
}
void OnCustomDashboardItemControlCreating(object sender, CustomDashboardItemControlCreatingEventArgs e) {
if(e.MetadataType == typeof(WebPageItemMetadata))
e.CustomControlProvider = new WebPageItemControlProvider(dashboardControl.Dashboard.Items[e.DashboardItemName] as CustomDashboardItem<WebPageItemMetadata>);
}
void InitializeUrlBarItem() {
RibbonPage page = designer.Ribbon.GetDashboardRibbonPage(typeof(WebPageItemMetadata), DashboardRibbonPage.Design);
RibbonPageGroup group = page.GetGroupByName("URI");
if(group == null) {
group = new RibbonPageGroup("URI") { Name = "URI" };
page.Groups.Add(group);
group.AllowTextClipping = false;
}
RepositoryItemButtonEdit buttonEdit = new RepositoryItemButtonEdit();
buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
buttonEdit.ButtonClick += ButtonEdit_ButtonClick;
urlBarItem = new BarEditItem(designer.Ribbon.Manager, buttonEdit);
urlBarItem.Caption = "URI Pattern";
urlBarItem.EditWidth = 150;
group.ItemLinks.Add(urlBarItem);
}
private void ButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) {
using(UriEditForm dlg = new UriEditForm()) {
dlg.UriPattern = selectedCustomItem.Metadata.URI;
if(dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
selectedCustomItem.Metadata.URI = dlg.UriPattern;
urlBarItem.EditValue = dlg.UriPattern;
}
}
}
}
}