Keep ribbon titles legible and apply compact layout on upgrade
This commit is contained in:
parent
fe793f4b7a
commit
da1357de9c
@ -14,7 +14,7 @@ public sealed partial class CloudGateway
|
||||
private DateTimeOffset retryAfter;private int retryFailures;private bool disposed;private bool stateLoaded=true,storageUnavailable;private long credentialVersion,durableCredentialVersion;
|
||||
private DateTimeOffset Now=>clock.GetUtcNow();
|
||||
private DateTimeOffset accessExpires;private DateTimeOffset revocationAfter;
|
||||
public CompanionPreferences Preferences {get{lock(gate)return new(){AdvancedMode=saved.Preferences.AdvancedMode,Width=saved.Preferences.Width,Height=saved.Preferences.Height,RememberInDocument=saved.Preferences.RememberInDocument,LastManuscript=saved.Preferences.LastManuscript};}}
|
||||
public CompanionPreferences Preferences {get{lock(gate)return new(){AdvancedMode=saved.Preferences.AdvancedMode,CompactLayoutApplied=saved.Preferences.CompactLayoutApplied,Width=saved.Preferences.Width,Height=saved.Preferences.Height,RememberInDocument=saved.Preferences.RememberInDocument,LastManuscript=saved.Preferences.LastManuscript};}}
|
||||
public void SavePreferences(CompanionPreferences preferences){lock(gate)saved.Preferences=preferences;_ = PersistSafely();}
|
||||
private static string BindingKey(string site,int account,Guid manuscript)=>$"{site}|{account}|{manuscript:D}";
|
||||
public void ForgetBinding(Guid manuscript,Guid expectedContext){lock(gate){if(authenticationContext==expectedContext&&saved.Active!=null)saved.Bindings.Remove(BindingKey(saved.Active.Site,saved.Active.AccountId,manuscript));}_=PersistSafely();}
|
||||
|
||||
@ -14,7 +14,7 @@ public sealed class CredentialRotation
|
||||
}
|
||||
public sealed class CompanionPreferences
|
||||
{
|
||||
public int Width {get;set;}=410;public int Height {get;set;}=540;public bool AdvancedMode {get;set;}public bool RememberInDocument {get;set;}public Guid LastManuscript {get;set;}
|
||||
public int Width {get;set;}=410;public int Height {get;set;}=540;public bool CompactLayoutApplied {get;set;}public bool AdvancedMode {get;set;}public bool RememberInDocument {get;set;}public Guid LastManuscript {get;set;}
|
||||
}
|
||||
public sealed class CompanionState
|
||||
{
|
||||
|
||||
@ -41,10 +41,10 @@ internal sealed class CompanionWindow:Form
|
||||
this.control=control;this.cloud=cloud;this.shutdown=shutdown;this.directory=directory;advanced=cloud.Preferences.AdvancedMode;
|
||||
Text="PlotDirector Companion";Icon=brand;Font=new("Segoe UI",10);AutoScaleMode=AutoScaleMode.Dpi;MinimumSize=new(400,460);DoubleBuffered=true;
|
||||
var preferences=cloud.Preferences;
|
||||
var previousDefault=preferences.Width==540&&preferences.Height==640;
|
||||
var firstCompactLayout=!preferences.CompactLayoutApplied;
|
||||
var workArea=Screen.FromPoint(Cursor.Position).WorkingArea.Size;
|
||||
Size=new(Math.Clamp(previousDefault?410:preferences.Width,400,Math.Max(400,Math.Min(1000,workArea.Width))),
|
||||
Math.Clamp(previousDefault?540:preferences.Height,460,Math.Max(460,Math.Min(1100,workArea.Height))));
|
||||
Size=new(Math.Clamp(firstCompactLayout?410:preferences.Width,400,Math.Max(400,Math.Min(1000,workArea.Width))),
|
||||
Math.Clamp(firstCompactLayout?510:preferences.Height,460,Math.Max(460,Math.Min(1100,workArea.Height))));
|
||||
var layout=Stack(14);layout.Dock=DockStyle.Fill;layout.AutoSize=false;layout.AutoScroll=true;Controls.Add(layout);
|
||||
var header=new TableLayoutPanel{Dock=DockStyle.Top,AutoSize=true,ColumnCount=2,Margin=new(0,0,0,8)};header.ColumnStyles.Add(new(SizeType.Percent,100));header.ColumnStyles.Add(new(SizeType.AutoSize));
|
||||
var name=Label("PlotDirector");name.Font=new("Segoe UI",24,FontStyle.Bold);header.Controls.Add(name,0,0);header.Controls.Add(Button("Settings",ShowSettings),1,0);
|
||||
@ -59,6 +59,7 @@ internal sealed class CompanionWindow:Form
|
||||
var open=Button("Open PlotDirector ↗",()=>cloud.OpenSite());open.Tag="primary";open.Dock=DockStyle.Top;open.MinimumSize=new(0,44);layout.Controls.Add(open);
|
||||
notice.Margin=new(0,12,0,0);layout.Controls.Add(notice);
|
||||
documents.SelectedIndexChanged+=(_,_)=>{if(!refreshing&&documents.SelectedItem is TrayDocument doc){selected=doc.Session;SavePreferences();RefreshState();}};
|
||||
Shown+=(_,_)=>{if(firstCompactLayout)SavePreferences();};
|
||||
ResizeEnd+=(_,_)=>SavePreferences();
|
||||
var menu=new ContextMenuStrip();menu.Items.Add("Open Companion",null,(_,_)=>Reveal());menu.Items.Add("Open PlotDirector",null,(_,_)=>Safe(()=>cloud.OpenSite()));menu.Items.Add("Settings",null,(_,_)=>{Reveal();ShowSettings();});menu.Items.Add(new ToolStripSeparator());menu.Items.Add("Exit Companion",null,(_,_)=>Exit());
|
||||
tray=new(){Icon=brand,Text="PlotDirector Companion",ContextMenuStrip=menu,Visible=true};tray.DoubleClick+=(_,_)=>Reveal();
|
||||
@ -71,7 +72,7 @@ internal sealed class CompanionWindow:Form
|
||||
private static RoundedCard Card()=>new(){Dock=DockStyle.Top,AutoSize=true,AutoSizeMode=AutoSizeMode.GrowAndShrink,Padding=new(10),Margin=new(0,0,0,8),ColumnCount=1};
|
||||
private Button Button(string text,Action action){var button=new Button{Text=text,AutoSize=true,MinimumSize=new(0,34)};button.Click+=(_,_)=>Safe(action);return button;}
|
||||
private void Safe(Action action){try{error="";action();}catch(Exception e)when(e is InvalidOperationException or ArgumentException or IOException or System.ComponentModel.Win32Exception){error=e.Message;}if(dialogNotice is {IsDisposed:false})SetText(dialogNotice,error);RefreshState();}
|
||||
private void SavePreferences(){var size=WindowState==FormWindowState.Normal?Size:RestoreBounds.Size;var prefs=cloud.Preferences;prefs.Width=size.Width;prefs.Height=size.Height;prefs.AdvancedMode=advanced;prefs.LastManuscript=Current?.Manuscript??prefs.LastManuscript;cloud.SavePreferences(prefs);}
|
||||
private void SavePreferences(){var size=WindowState==FormWindowState.Normal?Size:RestoreBounds.Size;var prefs=cloud.Preferences;prefs.CompactLayoutApplied=true;prefs.Width=size.Width;prefs.Height=size.Height;prefs.AdvancedMode=advanced;prefs.LastManuscript=Current?.Manuscript??prefs.LastManuscript;cloud.SavePreferences(prefs);}
|
||||
public void Reveal(){Show();WindowState=FormWindowState.Normal;Activate();}
|
||||
private async void ChangeBook()
|
||||
{
|
||||
|
||||
@ -57,6 +57,18 @@ namespace PlotDirector.WordAddIn
|
||||
}
|
||||
|
||||
public bool CanOpenBook(Office.IRibbonControl control) => adapter()?.HasRibbonBook == true;
|
||||
// Non-breaking padding keeps the native group wide even before Word reports a title.
|
||||
private static string TitleLabel(string title)
|
||||
{
|
||||
const int width = 58;
|
||||
if (title.Length <= width) return title.PadRight(width, '\u00a0');
|
||||
var end = char.IsHighSurrogate(title[width - 2]) ? width - 2 : width - 1;
|
||||
return title.Substring(0, end) + "…";
|
||||
}
|
||||
|
||||
public string GetBook(Office.IRibbonControl control) => TitleLabel(GetBookTip(control));
|
||||
public string GetChapter(Office.IRibbonControl control) => TitleLabel(GetChapterTip(control));
|
||||
public string GetScene(Office.IRibbonControl control) => TitleLabel(GetSceneTip(control));
|
||||
public string GetBookTip(Office.IRibbonControl control) => adapter()?.RibbonBook ?? "No linked book";
|
||||
public string GetChapterTip(Office.IRibbonControl control) => adapter()?.RibbonChapter ?? "Chapter unverified";
|
||||
public string GetSceneTip(Office.IRibbonControl control) => adapter()?.RibbonScene ?? "Scene unverified";
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
<tabs>
|
||||
<tab id="PlotDirectorTab" label="PlotDirector">
|
||||
<group id="PlotDirectorManuscript" label="Manuscript">
|
||||
<editBox id="PlotDirectorBook" label="Book" getText="GetBookTip" getSupertip="GetBookTip" enabled="false" sizeString="MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" />
|
||||
<editBox id="PlotDirectorChapter" label="Chapter" getText="GetChapterTip" getSupertip="GetChapterTip" enabled="false" sizeString="MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" />
|
||||
<editBox id="PlotDirectorScene" label="Scene" getText="GetSceneTip" getSupertip="GetSceneTip" enabled="false" sizeString="MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" />
|
||||
<labelControl id="PlotDirectorBook" getLabel="GetBook" getSupertip="GetBookTip" />
|
||||
<labelControl id="PlotDirectorChapter" getLabel="GetChapter" getSupertip="GetChapterTip" />
|
||||
<labelControl id="PlotDirectorScene" getLabel="GetScene" getSupertip="GetSceneTip" />
|
||||
</group>
|
||||
<group id="PlotDirectorWriting" label="Writing">
|
||||
<button id="PlotDirectorContext" label="Writing Context" size="large" imageMso="ReadingMode" onAction="OpenContext" getEnabled="CanOpenBook" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user