Skip to content

Commit

Permalink
Add BiLinkDialog with option to hide
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Oct 19, 2024
1 parent 32ad7f5 commit c0ae047
Show file tree
Hide file tree
Showing 5 changed files with 3,221 additions and 2 deletions.
17 changes: 15 additions & 2 deletions OneMore/Commands/References/BiLinkCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Settings;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand All @@ -22,6 +23,8 @@ namespace River.OneMoreAddIn.Commands
/// </summary>
internal class BiLinkCommand : Command
{
public const string SettingsName = "bilink";

// TODO: consider moving these to a global state cache that can be pruned
// rather than holding on to them indefinitely as statics....

Expand Down Expand Up @@ -54,8 +57,18 @@ public override async Task Execute(params object[] args)
return;
}

if (anchorText.Length > 20) { anchorText = $"{anchorText.Substring(0, 20)}..."; }
ShowInfo(string.Format(Resx.BiLinkCommand_Marked, anchorText));
var settings = new SettingsProvider().GetCollection(SettingsName);
if (!settings.Get("hideStartMessage", false))
{
using var dialog = new BiLinkDialog();
if (anchorText.Length > 20)
{
anchorText = $"{anchorText.Substring(0, 20)}...";
}

dialog.SetAnchorText(anchorText);
dialog.ShowDialog(owner);
}
}
else
{
Expand Down
170 changes: 170 additions & 0 deletions OneMore/Commands/References/BiLinkDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions OneMore/Commands/References/BiLinkDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//************************************************************************************************
// Copyright © 2024 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Settings;
using River.OneMoreAddIn.UI;
using System.Drawing;
using System.Windows.Forms;
using Resx = Properties.Resources;


internal partial class BiLinkDialog : MoreForm
{

public BiLinkDialog()
{
InitializeComponent();

if (NeedsLocalizing())
{
Text = Resx.ProgramName;

Localize(new string[]
{
"okButton=word_OK"
});
}

iconBox.Image = SystemIcons.Information.ToBitmap();
messageBox.Clear();
}


public void SetAnchorText(string text)
{
text = string.Format(Resx.BiLinkCommand_Marked, text);

var size = TextRenderer.MeasureText(
text, messageBox.Font, messageBox.Size, TextFormatFlags.NoClipping);

// leave a little room (is this good?)
var preferred = size.Height + messageBox.Font.Height;
if (preferred > messageBox.Height)
{
Height += preferred - messageBox.Height;
}

messageBox.Text = text;
}


private void HideSelection(object sender, System.EventArgs e)
{
// move the cursor to the end
if (messageBox.SelectionStart != messageBox.TextLength)
{
messageBox.SelectionStart = messageBox.TextLength;
okButton.Focus();
}
}


private void DoKeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers != Keys.None)
{
return;
}

if (e.KeyCode == Keys.Escape)
{
e.Handled = true;
DialogResult = DialogResult.Cancel;
Close();
}
}


private void DoClick(object sender, System.EventArgs e)
{
// check if user wants to hide this in the future
if (hideBox.Checked)
{
var settings = new SettingsProvider();
var collection = settings.GetCollection(BiLinkCommand.SettingsName);
collection.Add("hideStartMessage", true);
settings.SetCollection(collection);
settings.Save();
}
}
}
}
Loading

0 comments on commit c0ae047

Please sign in to comment.