44 lines
2.8 KiB
C#
44 lines
2.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Forms;
|
|
using Office = Microsoft.Office.Core;
|
|
|
|
namespace PlotDirector.WordAddIn
|
|
{
|
|
[ComVisible(true)]
|
|
public sealed class NativeRibbon : Office.IRibbonExtensibility
|
|
{
|
|
private readonly Func<WordAdapter> getAdapter;
|
|
private Office.IRibbonUI ui;
|
|
public NativeRibbon(Func<WordAdapter> getAdapter) { this.getAdapter = getAdapter; }
|
|
public string GetCustomUI(string ribbonID)
|
|
{ using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("PlotDirector.WordAddIn.Ribbon.xml"))) return reader.ReadToEnd(); }
|
|
public void OnLoad(Office.IRibbonUI ribbonUI) { ui = ribbonUI; }
|
|
public void Invalidate() { try { ui?.Invalidate(); } catch(COMException) { } }
|
|
public string GetStatus(Office.IRibbonControl _) => getAdapter()?.ConnectionLabel??"PlotDirector unavailable";
|
|
public string GetScopeStatus(Office.IRibbonControl _) => Compact(getAdapter()?.BookTitle??"Select Book");
|
|
public string GetLocation(Office.IRibbonControl _) => Compact(getAdapter()?.LocationSummary??"Open a manuscript");
|
|
private static string Compact(string value)=>value.Length>75?value.Substring(0,72)+"…":value;
|
|
public bool HasDocument(Office.IRibbonControl _) => getAdapter()?.HasActiveDocument==true;
|
|
public bool CanOpenWorkspace(Office.IRibbonControl _) => getAdapter()?.CanOpenWorkspace==true;
|
|
public void SelectBook(Office.IRibbonControl _) => getAdapter()?.ShowBookSelection();
|
|
public void Workspace(Office.IRibbonControl _) => getAdapter()?.OpenBookWorkspace();
|
|
public void Context(Office.IRibbonControl _) => getAdapter()?.ShowContext();
|
|
public void Intent(Office.IRibbonControl _) => getAdapter()?.ShowIntent();
|
|
public bool CanSynchronize(Office.IRibbonControl _) => getAdapter()?.HasActiveDocument == true&&getAdapter()?.ConnectionState=="connected";
|
|
public bool CanCancel(Office.IRibbonControl _) => getAdapter()?.HasActiveWork==true;
|
|
public void Connect(Office.IRibbonControl _) { var adapter=getAdapter();if(adapter!=null)new ConnectWindow(adapter).Show(); }
|
|
public void Analyse(Office.IRibbonControl _) { getAdapter()?.AnalyseDocument(); }
|
|
public void Cancel(Office.IRibbonControl _) { getAdapter()?.CancelAnalysis(); }
|
|
public void Synchronize(Office.IRibbonControl _) { getAdapter()?.AnalyseDocument(); }
|
|
public void Settings(Office.IRibbonControl _)
|
|
{
|
|
getAdapter()?.ShowSettings();
|
|
}
|
|
public void Diagnostics(Office.IRibbonControl _) => MessageBox.Show(getAdapter()?.Diagnostics ?? "Companion did not initialize. Word remains usable. Check the Windows validation prerequisites.","PlotDirector Diagnostics — Nick Beckley");
|
|
}
|
|
}
|