Skip to content

Commit

Permalink
fix: Autocomplete ToolTip didn't have line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
PocketMiner82 committed Apr 20, 2024
1 parent 556733c commit 6193a4f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 33 deletions.
66 changes: 34 additions & 32 deletions pseudocodeIde/PseudocodeIDEForm.Designer.cs

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

51 changes: 51 additions & 0 deletions pseudocodeIde/PseudocodeIDEForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public partial class PseudocodeIDEForm : Form
/// </summary>
private readonly Regex _noUpdateAfter = new Regex(@"^[a-zA-Z0-9_äöüÄÖÜß]$", RegexOptions.Multiline);

/// <summary>
/// The autocomplete tooltip
/// </summary>
private readonly ToolTip _toolTip = new ToolTip();

/// <summary>
/// the code currently in the textbox
/// </summary>
Expand Down Expand Up @@ -133,6 +138,9 @@ public PseudocodeIDEForm()
CodeTextBox_TextChanged(null, null);
// on first start, the code is always saved
SetFileSaved();

_toolTip.OwnerDraw = false;
_toolTip.ShowAlways = true;
}

/// <summary>
Expand Down Expand Up @@ -238,12 +246,55 @@ private void PseudocodeIDE_FormClosing(object sender, FormClosingEventArgs e)
SaveMenuItem_Click(null, null);
}
}

_toolTip.Dispose();
}

// ---------------------------------------------
// CODE TEXTBOX (Scintilla)
// ---------------------------------------------

private void AutoCompleteMenu_Hovered(object sender, HoveredEventArgs e)
{
_toolTip.Hide(this);

if (e.Item == null)
{
Debug.WriteLine("null");
return;
}

AutocompleteItem autocompleteItem = e.Item;

string title = "Code Snippet:";
string text = autocompleteItem.ToolTipText.Replace("\t", " ");
Color? backColor = autocompleteItem.ToolTipBackColor;
Color? foreColor = autocompleteItem.ToolTipForeColor;

if (backColor != null)
{
_toolTip.BackColor = (Color)backColor;
}

if (foreColor != null)
{
_toolTip.ForeColor = (Color)foreColor;
}

Point locationOnForm = PointToClient(
((AutocompleteListView)autoCompleteMenu.ListView).Parent.PointToScreen(((AutocompleteListView)autoCompleteMenu.ListView).Location));

_toolTip.ToolTipTitle = title;
_toolTip.Show(string.IsNullOrEmpty(text) ? title : text, this,
locationOnForm.X + ((AutocompleteListView)autoCompleteMenu.ListView).Width + 10,
locationOnForm.Y + 30);
}

private void AutoCompleteMenu_Selected(object sender, SelectedEventArgs e)
{
_toolTip.Hide(this);
}

/// <summary>
/// Updates the undo stack, when user updated the code
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public PseudocodeAutocompleteItem(string snippet, string menuText = null) : base
Text = snippet.Replace("\r", "");
MenuText = menuText;
ToolTipText = snippet.Replace("^", "");
ToolTipTitle = "Snippet:";
ToolTipTitle = "";
}

/// <summary>
Expand Down

0 comments on commit 6193a4f

Please sign in to comment.