30 lines
2.2 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
namespace PlotDirector.WordAddIn
{
public sealed class ConnectWindow:Form
{
public ConnectWindow(WordAdapter adapter)
{
Text="Connect PlotDirector";Font=new Font("Segoe UI",9F);Width=640;Height=290;MinimumSize=new Size(520,270);AutoScaleMode=AutoScaleMode.Dpi;
var layout=new TableLayoutPanel{Dock=DockStyle.Fill,Padding=new Padding(12),ColumnCount=1,RowCount=5};
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,100));
for(var row=0;row<4;row++)layout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
layout.RowStyles.Add(new RowStyle(SizeType.Percent,100));
layout.Controls.Add(new Label{Text="PlotDirector HTTPS site address (no password or API key):",AutoSize=true},0,0);
var address=new TextBox{Dock=DockStyle.Fill,Text=adapter.ServerUrl,Margin=new Padding(0,8,0,8)};layout.Controls.Add(address,0,1);
var actions=new FlowLayoutPanel{Dock=DockStyle.Fill,AutoSize=true,WrapContents=true};
var feedback=new Label{Dock=DockStyle.Fill,AutoSize=true,Text="Approve the connection in your normal browser, then check the ribbon or manuscript review for connection status."};
var connect=new Button{Text="Sign in in browser",AutoSize=true};connect.Click+=(_,__)=>{
var value=address.Text.Trim();Uri site;
if(!Uri.TryCreate(value,UriKind.Absolute,out site)||site.Scheme!=Uri.UriSchemeHttps||site.AbsolutePath!="/"||!string.IsNullOrEmpty(site.UserInfo)||!string.IsNullOrEmpty(site.Query)||!string.IsNullOrEmpty(site.Fragment))
{feedback.Text="Enter the HTTPS site root, with no username, password, page path or query. No sign-in request was sent.";address.Focus();return;}
adapter.ConnectToServer(value);Close();
};
var signout=new Button{Text="Disconnect / forget sign-in",AutoSize=true};signout.Click+=(_,__)=>{adapter.SignOut();Close();};
actions.Controls.Add(connect);actions.Controls.Add(signout);layout.Controls.Add(actions,0,2);layout.Controls.Add(feedback,0,4);Controls.Add(layout);
}
}
}