1: using System;
2: using System.Security.Permissions;
3: using Microsoft.SharePoint.Security;
4: using Microsoft.SharePoint.WebPartPages;
5: using Microsoft.SharePoint;
6: using Microsoft.SharePoint.WebControls;
7: using System.Web.UI.WebControls.WebParts;
8: using System.Diagnostics;
9: using System.Xml;
10: using System.Collections.Generic;
11: using System.Reflection;
12: using System.Text;
13:
14: namespace ik.SharePoint2010.SPCustomTabRibbonDemo.Layouts.SPCustomTabRibbonDemo
15: {
16: public partial class AllItems : WebPartPage
17: {
18: protected void Page_Load(object sender, EventArgs e)
19: {
20: }
21:
22: private string tab = @"
23: <Tab Id=""ik.SharePoint2010.Ribbon.CustomTab"" Title=""ik-ribbon"" Description=""Ingo's Command Group"" Sequence=""501"">
24: <Scaling Id=""ik.SharePoint2010.Ribbon.CustomTab.Scaling"">
25: <MaxSize Id=""ik.SharePoint2010.Ribbon.CustomTab.Group1.MaxSize""
26: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group1""
27: Size=""OneLarge""/>
28: <Scale Id=""ik.SharePoint2010.Ribbon.CustomTab.Group1.Scaling.CustomTabScaling""
29: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group1""
30: Size=""OneLarge""/>
31: <MaxSize Id=""ik.SharePoint2010.Ribbon.CustomTab.Group2.MaxSize""
32: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group2""
33: Size=""OneLarge""/>
34: <Scale Id=""ik.SharePoint2010.Ribbon.CustomTab.Group2.Scaling.CustomTabScaling""
35: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group2""
36: Size=""OneLarge""/>
37: <MaxSize Id=""ik.SharePoint2010.Ribbon.CustomTab.Group3.MaxSize""
38: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group3""
39: Size=""OneLarge""/>
40: <Scale Id=""ik.SharePoint2010.Ribbon.CustomTab.Group3.Scaling.CustomTabScaling""
41: GroupId=""ik.SharePoint2010.Ribbon.CustomTab.Group3""
42: Size=""OneLarge""/>
43: </Scaling>
44: <Groups Id=""ik.SharePoint2010.Ribbon.CustomTab.Groups"">
45: <Group Id=""ik.SharePoint2010.Ribbon.CustomTab.Group1""
46: Description=""Ingo's Custom Ribbon Demo 1""
47: Title=""Ingo's Custom Ribbon Demo 1""
48: Sequence=""10""
49: Template=""ik.SharePoint2010.Ribbon.Templates.OneLarge"">
50: <Controls Id=""ik.SharePoint2010.Ribbon.CustomTab.Group1.Controls"">
51: <Button Id=""ik.SharePoint2010.Ribbon.CustomTab.Group1.Button1""
52: Command=""ik.SharePoint2010.Command.Button1""
53: Description=""Do something""
54: Sequence=""10""
55: LabelText=""Do something""
56: Image16by16=""/_layouts/images/DOC16.GIF""
57: Image32by32=""/_layouts/images/DOC32.GIF""
58: TemplateAlias=""cust1""/>
59: </Controls>
60: </Group>
61: <Group Id=""ik.SharePoint2010.Ribbon.CustomTab.Group3""
62: Description=""Ingo's Custom Ribbon Demo 3""
63: Title=""Ingo's Custom Ribbon Demo 3""
64: Sequence=""30""
65: Template=""ik.SharePoint2010.Ribbon.Templates.OneLarge"">
66: <Controls Id=""ik.SharePoint2010.Ribbon.CustomTab.Group3.Controls"">
67: <Button Id=""ik.SharePoint2010.Ribbon.CustomTab.Group3.Button3""
68: Command=""ik.SharePoint2010.Command.Button3""
69: Description=""Do more""
70: Sequence=""10""
71: LabelText=""Do more""
72: Image32by32=""/_layouts/images/PPEOPLE.GIF""
73: TemplateAlias=""cust1""/>
74: </Controls>
75: </Group>
76: <Group Id=""ik.SharePoint2010.Ribbon.CustomTab.Group2""
77: Description=""Ingo's Custom Ribbon Demo 2""
78: Title=""Ingo's Custom Ribbon Demo 2""
79: Sequence=""20""
80: Template=""ik.SharePoint2010.Ribbon.Templates.OneLarge"">
81: <Controls Id=""ik.SharePoint2010.Ribbon.CustomTab.Group2.Controls"">
82: <Button Id=""ik.SharePoint2010.Ribbon.CustomTab.Group2.Button2""
83: Command=""ik.SharePoint2010.Command.Button2""
84: Description=""Do nothing""
85: Sequence=""10""
86: LabelText=""Do nothing""
87: Image32by32=""/_layouts/images/PPEOPLE.GIF""
88: TemplateAlias=""cust1""/>
89: </Controls>
90: </Group>
91: </Groups>
92: </Tab>
93:
94: " ;
95: private string tabTempl = @"
96: <GroupTemplate Id=""ik.SharePoint2010.Ribbon.Templates.OneLarge"">
97: <Layout Title=""OneLarge"" LayoutTitle=""OneLarge"">
98: <Section Alignment=""Top"" Type=""OneRow"">
99: <Row>
100: <ControlRef DisplayMode=""Large"" TemplateAlias=""cust1"" />
101: </Row>
102: </Section>
103: </Layout>
104: </GroupTemplate>
105: " ;
106:
107: protected override void OnPreRender(EventArgs e)
108: {
109: //Debugger.Break();
110: SPRibbon r = Microsoft.SharePoint.WebControls.SPRibbon .GetCurrent(this .Page);
111: XmlDocument rx = new XmlDocument ();
112: rx.LoadXml(tab);
113: r.RegisterDataExtension(rx.FirstChild, "Ribbon.Tabs._children" );
114: rx.LoadXml(tabTempl);
115: r.RegisterDataExtension(rx.FirstChild, "Ribbon.Templates._children" );
116:
117: List <IRibbonCommand > commands = new List <IRibbonCommand >();
118: commands.Add(new SPRibbonCommand ("ik.SharePoint2010.Command.Button1" , "ikSharePoint2010CommandButton1Action()" , "true" ));
119: commands.Add(new SPRibbonCommand ("ik.SharePoint2010.Command.Button2" , "ikSharePoint2010CommandButton2Action()" , "ikSharePoint2010CommandButton2Enable()" ));
120: commands.Add(new SPRibbonCommand ("ik.SharePoint2010.Command.Button3" , "ikSharePoint2010CommandButton3Action()" , "ikSharePoint2010CommandButton3Enable()" ));
121:
122: SPRibbonScriptManager rsm = new SPRibbonScriptManager ();
123:
124: ScriptLink .RegisterScriptAfterUI(this .Page, "SP.Runtime.js" , false , true );
125: ScriptLink .RegisterScriptAfterUI(this .Page, "SP.js" , false , true );
126: ScriptLink .RegisterScriptAfterUI(this .Page, "CUI.js" , false , true );
127: ScriptLink .RegisterScriptAfterUI(this .Page, "SP.Ribbon.js" , false , true );
128: ScriptLink .RegisterScriptAfterUI(this .Page, "ik.SharePoint2010.SPCustomTabRibbonDemo/ikactions.js" , false , true );
129: ScriptLink .RegisterScriptAfterUI(this .Page, "ik.SharePoint2010.SPCustomTabRibbonDemo/ikribbon.UI.js" , false , true );
130:
131: rsm.RegisterGetCommandsFunction(this .Page, "getGlobalCommands" , commands);
132: rsm.RegisterCommandEnabledFunction(this .Page, "commandEnabled" , commands);
133: rsm.RegisterHandleCommandFunction(this .Page, "handleCommand" , commands);
134:
135: string script = @"
136: <script language=""javascript"" defer=""true"">
137: //<![CDATA[
138: function ikribbonInit1() {
139: ikribbonInit();
140: }
141: ExecuteOrDelayUntilScriptLoaded(ikribbonInit1,');
142: //]]>
143: </script>" ;
144: ClientScript.RegisterClientScriptBlock(this .GetType(), "InitPageComponent" , script);
145:
146: r.MakeTabAvailable("ik.SharePoint2010.Ribbon.CustomTab" );
147: r.SetInitialTabId("ik.SharePoint2010.Ribbon.CustomTab" , "" );
148: base .OnPreRender(e);
149: }
150:
151: protected override void OnInitComplete(EventArgs e)
152: {
153: base .OnInitComplete(e);
154: }
155: }
156: }
157:
158: