Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BiLinkDialog with option to hide #1620

Merged
merged 1 commit into from
Oct 19, 2024
Merged
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
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