Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Source/Terminals.Plugins.Vnc/VNCConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,35 @@ internal class VNCConnection : Connection

private string vncPassword = string.Empty;

private bool viewOnly;

/// <summary>
/// Gets whether the live session currently ignores local mouse and keyboard input.
/// </summary>
public bool ViewOnly
{
get { return this.viewOnly; }
}

public void SendSpecialKeys(VncSharp.SpecialKeys Keys)
{
rd.SendSpecialKeys(Keys);
}

/// <summary>
/// Toggles the View Only mode of the running session and returns the new state.
/// In View Only mode local mouse and keyboard events are not sent to the host.
/// </summary>
public bool ToggleViewOnly()
{
if (rd == null)
return this.viewOnly;

this.viewOnly = !this.viewOnly;
rd.SetInputMode(this.viewOnly);
return this.viewOnly;
}
Comment on lines +36 to +44

public override bool Connect()
{
try
Expand All @@ -42,6 +66,7 @@ public override bool Connect()
Text = "Connecting to VNC Server...";

VncOptions options = this.Favorite.ProtocolProperties as VncOptions;
this.viewOnly = options.ViewOnly;
rd.Connect(Favorite.ServerName, options.DisplayNumber, options.ViewOnly, options.AutoScale);

rd.BringToFront();
Expand Down
27 changes: 26 additions & 1 deletion Source/Terminals.Plugins.Vnc/VncMenuVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal class VncMenuVisitor : IToolbarExtender
private readonly ICurrenctConnectionProvider connectionProvider;
private ToolStripDropDownButton vncActionButton;

private ToolStripMenuItem viewOnlyToolStripMenuItem;

private ToolStripMenuItem sendALTKeyToolStripMenuItem;

private ToolStripMenuItem sendALTF4KeyToolStripMenuItem;
Expand All @@ -31,8 +33,13 @@ public void Visit(ToolStrip standardToolbar)
{
this.EnusereMenuCreated(standardToolbar);

bool commandsAvailable = this.connectionProvider.CurrentConnection is VNCConnection;
var vnc = this.connectionProvider.CurrentConnection as VNCConnection;
bool commandsAvailable = vnc != null;
this.vncActionButton.Visible = commandsAvailable;

// Reflect the actual state of the current session, so switching tabs keeps the toggle in sync.
if (commandsAvailable)
this.viewOnlyToolStripMenuItem.Checked = vnc.ViewOnly;
}

private void EnusereMenuCreated(ToolStrip standardToolbar)
Expand All @@ -43,6 +50,7 @@ private void EnusereMenuCreated(ToolStrip standardToolbar)

private void CreateViewOnlyButton(ToolStrip standardToolbar)
{
this.CreateViewOnlyMenuItem();
this.CreateAltKeyMenuItem();
this.CreateAltF4MenuItem();
this.CreateCtrlKeyMenuItem();
Expand All @@ -58,6 +66,7 @@ private void CreateActionButton()
this.vncActionButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.vncActionButton.DropDownItems.AddRange(new ToolStripItem[]
{
this.viewOnlyToolStripMenuItem,
this.sendALTKeyToolStripMenuItem,
this.sendALTF4KeyToolStripMenuItem,
this.sendCTRLKeyToolStripMenuItem,
Expand All @@ -72,6 +81,22 @@ private void CreateActionButton()
this.vncActionButton.Visible = false;
}

private void CreateViewOnlyMenuItem()
{
this.viewOnlyToolStripMenuItem = new ToolStripMenuItem();
this.viewOnlyToolStripMenuItem.Name = "viewOnlyToolStripMenuItem";
this.viewOnlyToolStripMenuItem.Size = new Size(202, 22);
this.viewOnlyToolStripMenuItem.Text = "View Only";
Comment on lines +86 to +89
this.viewOnlyToolStripMenuItem.Click += new EventHandler(this.ViewOnlyToolStripMenuItem_Click);
}

private void ViewOnlyToolStripMenuItem_Click(object sender, EventArgs e)
{
var vnc = this.connectionProvider.CurrentConnection as VNCConnection;
if (vnc != null)
this.viewOnlyToolStripMenuItem.Checked = vnc.ToggleViewOnly();
}

private void CreateAltKeyMenuItem()
{
this.sendALTKeyToolStripMenuItem = new ToolStripMenuItem();
Expand Down
14 changes: 13 additions & 1 deletion Source/Tests/UserInterface/VncMenuVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ public void EmptyToolBar_UpdateMenu_CreatesNewButtons()
var menuVisitor = new VncMenuVisitor(sut.MockProvider.Object);
menuVisitor.Visit(sut.Toolbar);
int itemsCount = ((ToolStripDropDownButton)sut.Toolbar.Items[0]).DropDownItems.Count;
Assert.AreEqual(5, itemsCount, "First visit should update the menu by add its own drop donw menu items");
Assert.AreEqual(6, itemsCount, "First visit should update the menu by add its own drop donw menu items");
}

[TestMethod]
public void UpdateMenu_AddsViewOnlyToggle()
{
var sut = new MenuVisitorSut();
var menuVisitor = new VncMenuVisitor(sut.MockProvider.Object);
menuVisitor.Visit(sut.Toolbar);
var dropDown = (ToolStripDropDownButton)sut.Toolbar.Items[0];
ToolStripItem viewOnly = dropDown.DropDownItems["viewOnlyToolStripMenuItem"];
Assert.IsNotNull(viewOnly, "VNC actions menu has to offer a View Only toggle (issue #202).");
Assert.AreEqual("View Only", viewOnly.Text, "The toggle has to be labelled View Only.");
}
}
}