148 lines
5.2 KiB
C#
Executable File
148 lines
5.2 KiB
C#
Executable File
/* Ribbon.cs
|
|
* part of zaaReloaded2
|
|
*
|
|
* Copyright 2015 Daniel Kraus
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Drawing;
|
|
using System.Windows.Resources;
|
|
using Office = Microsoft.Office.Core;
|
|
|
|
// TODO: Follow these steps to enable the Ribbon (XML) item:
|
|
|
|
// 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
|
|
|
|
// protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
|
|
// {
|
|
// return new Ribbon();
|
|
// }
|
|
|
|
// 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
|
|
// actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
|
|
// move your code from the event handlers to the callback methods and modify the code to work with the
|
|
// Ribbon extensibility (RibbonX) programming model.
|
|
|
|
// 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.
|
|
|
|
// For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
|
|
|
|
|
|
namespace zaaReloaded2
|
|
{
|
|
[ComVisible(true)]
|
|
public class Ribbon : Office.IRibbonExtensibility
|
|
{
|
|
private Office.IRibbonUI ribbon;
|
|
|
|
public Ribbon()
|
|
{
|
|
}
|
|
|
|
#region IRibbonExtensibility Members
|
|
|
|
public string GetCustomUI(string ribbonID)
|
|
{
|
|
return GetResourceText("zaaReloaded2.Ribbon.xml");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Ribbon Callbacks
|
|
//Create callback methods here. For more information about adding callback methods, visit http://go.microsoft.com/fwlink/?LinkID=271226
|
|
|
|
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
|
|
{
|
|
this.ribbon = ribbonUI;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles ribbon button clicks. This method also contains the try...catch
|
|
/// structure that invokes the central exception handler in the event of an
|
|
/// exception.
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
public void Ribbon_Click(Office.IRibbonControl control)
|
|
{
|
|
try
|
|
{
|
|
switch (control.Id)
|
|
{
|
|
case "zrlAbout":
|
|
ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel();
|
|
vm.InjectInto<Views.AboutView>().ShowDialog();
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException("No operation defined for " + control.Id);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Bovender.ExceptionHandler.CentralHandler.Manage(this, e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns an Image object for the ribbon.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The image file is expected to be a WPF resource file, not an embedded resource.
|
|
/// To be consistent accross the application which uses WPF resources for its WPF
|
|
/// windows, all images are to be built as resources rather than embedded resources.
|
|
/// </remarks>
|
|
/// <param name="imageId">The file name (without path) of the image.</param>
|
|
/// <returns>Image object</returns>
|
|
public object Ribbon_LoadImage(string imageId)
|
|
{
|
|
string initPackScheme = System.IO.Packaging.PackUriHelper.UriSchemePack;
|
|
StreamResourceInfo sri = Application.GetResourceStream(
|
|
new Uri(@"pack://application:,,,/zaaReloaded2;component/Icons/" + imageId));
|
|
return Image.FromStream(sri.Stream);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Helpers
|
|
|
|
private static string GetResourceText(string resourceName)
|
|
{
|
|
Assembly asm = Assembly.GetExecutingAssembly();
|
|
string[] resourceNames = asm.GetManifestResourceNames();
|
|
for (int i = 0; i < resourceNames.Length; ++i)
|
|
{
|
|
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
|
|
{
|
|
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
|
|
{
|
|
if (resourceReader != null)
|
|
{
|
|
return resourceReader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|