Commit b0eeb519 authored by JoyJ's avatar JoyJ

hint when use different card code at function

parent 44764797
......@@ -83,6 +83,7 @@ void InitForm()
{
MinFragmentLength = 2
};
this.fctb.TextChanged += this.Fctb_TextChanged;
this.popupMenu.ToolTip.Popup += this.ToolTip_Popup;
this.popupMenu.Items.Font = ft;
this.popupMenu.AutoSize = true;
......@@ -92,11 +93,16 @@ void InitForm()
this.popupMenu.Closed += new ToolStripDropDownClosedEventHandler(this.popupMenu_Closed);
this.popupMenu.SelectedColor = Color.LightGray;
this.popupMenu.VisibleChanged += this.PopupMenu_VisibleChanged;
this.popupMenu.Opened += this.PopupMenu_VisibleChanged;
this.popupMenu.Items.FocussedItemIndexChanged += this.Items_FocussedItemIndexChanged;
this.title = this.Text;
}
private void Fctb_TextChanged(object sender, TextChangedEventArgs e)
{
this.PopupMenu_VisibleChanged(null, null);
}
private void ToolTip_Popup(object sender, PopupEventArgs e)
{
e.Cancel = true;
......@@ -104,13 +110,22 @@ private void ToolTip_Popup(object sender, PopupEventArgs e)
private void PopupMenu_VisibleChanged(object sender, EventArgs e)
{
this.AdjustPopupMenuSize();
if (!this.popupMenu.Visible || this.popupMenu.Items.FocussedItem == null)
if (!this.popupMenu.Visible)
{
this.AdjustPopupMenuSize();
return;
}
if (this.popupMenu.Items.FocussedItem == null)
{
if (this.popupMenu.Items.Count == 0)
{
return;
}
this.popupMenu.Items.FocussedItemIndex = 0;
}
this.fctb.ShowTooltipWithLabel(this.popupMenu.Items.FocussedItem.ToolTipTitle,
this.popupMenu.Items.FocussedItem.ToolTipText);
this.AdjustPopupMenuSize();
}
private void AdjustPopupMenuSize()
{
......@@ -118,6 +133,7 @@ private void AdjustPopupMenuSize()
{
this.popupMenu.Size = new Size(300, 0);
this.popupMenu.MinimumSize = new Size(300, 0);
return;
}
Size s = TextRenderer.MeasureText(this.popupMenu.Items.FocussedItem.ToolTipTitle,
this.popupMenu.Items.Font, new Size(0, 0), TextFormatFlags.NoPadding);
......@@ -176,6 +192,12 @@ public bool Open(string file)
fs.Close();
}
this.nowFile = file;
FileInfo fi = new FileInfo(file);
if (fi.Name.ToUpper().EndsWith(".LUA"))
{
(this.fctb.SyntaxHighlighter as MySyntaxHighlighter).cCode
= fi.Name.Substring(0, fi.Name.Length - 4);
}
string cdb = MyPath.Combine(
Path.GetDirectoryName(file), "../cards.cdb");
this.SetCardDB(cdb);//后台加载卡片数据
......
......@@ -15,7 +15,6 @@ public class FastColoredTextBoxEx : FastColoredTextBox
{
public Label lbTooltip;
Point lastMouseCoord;
public FastColoredTextBoxEx() : base()
{
this.SyntaxHighlighter = new MySyntaxHighlighter();
......@@ -67,7 +66,10 @@ protected override void OnToolTip()
this.ShowTooltipWithLabel(ea.ToolTipTitle, ea.ToolTipText);
}
}
public void ShowTooltipWithLabel(AutocompleteItem item)
{
this.ShowTooltipWithLabel(item.ToolTipTitle, item.ToolTipText);
}
public void ShowTooltipWithLabel(string title, string text, int height)
{
this.lbTooltip.Visible = true;
......
......@@ -14,13 +14,14 @@ namespace FastColoredTextBoxNS
/// </summary>
public class MySyntaxHighlighter : SyntaxHighlighter
{
public string cCode = "";
readonly TextStyle mNumberStyle = new TextStyle(Brushes.Orange, null, FontStyle.Regular);
readonly TextStyle mStrStyle = new TextStyle(Brushes.Gold, null, FontStyle.Regular);
readonly TextStyle conStyle = new TextStyle(Brushes.YellowGreen, null, FontStyle.Regular);
readonly TextStyle mKeywordStyle = new TextStyle(Brushes.DeepSkyBlue, null, FontStyle.Regular);
readonly TextStyle mGrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular);
readonly TextStyle mFunStyle = new TextStyle(Brushes.LightGray, null, FontStyle.Bold);
readonly TextStyle mErrorStyle = new TextStyle(Brushes.Red, null, FontStyle.Bold);
/// <summary>
/// Highlights Lua code
......@@ -39,7 +40,7 @@ public override void LuaSyntaxHighlight(Range range)
= @"^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>.+)";
//clear style of changed range
range.ClearStyle(this.mStrStyle, this.mGrayStyle, this.conStyle, this.mNumberStyle, this.mKeywordStyle, this.mFunStyle);
range.ClearStyle(this.mStrStyle, this.mGrayStyle, this.conStyle, this.mNumberStyle, this.mKeywordStyle, this.mFunStyle, this.mErrorStyle);
//
if (this.LuaStringRegex == null)
{
......@@ -58,7 +59,8 @@ public override void LuaSyntaxHighlight(Range range)
range.SetStyle(this.mKeywordStyle, this.LuaKeywordRegex);
//functions highlighting
range.SetStyle(this.mFunStyle, this.LuaFunctionsRegex);
range.SetStyle(this.mNumberStyle, @"\bc\d+\b");
range.SetStyle(this.mErrorStyle, @"\bc\d+\b");
range.SetStyle(this.mNumberStyle, $@"\b{cCode}\b");
range.SetStyle(this.conStyle, @"[\s|\(|+|,]{0,1}(?<range>[A-Z_]+?)[\)|+|\s|,|;]");
//range.SetStyle(mFunStyle, @"[:|\.|\s](?<range>[a-zA-Z0-9_]*?)[\(|\)|\s]");
......
......@@ -67,16 +67,9 @@ public static void Error(LMSG msg)
}
public static bool Question(LMSG msg)
{
if (MessageBox.Show(LanguageHelper.GetMsg(msg), _question,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{
return true;
}
else
{
return false;
}
return (MessageBox.Show(LanguageHelper.GetMsg(msg), _question,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK);
}
}
}
......@@ -535,7 +535,6 @@ private void bgWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventAr
this.Init();
}
private void bgWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
//更新UI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment