Skip to content

Commit f2dd7d9

Browse files
committed
fix: 修复右键菜单多开问题
1 parent 2755932 commit f2dd7d9

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

TuneLab/UI/MainWindow/Editor/PianoWindow/PianoScrollView/PianoScrollViewOperation.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ bool DetectWaveformPrimaryButton()
138138
});
139139
menu.Items.Add(menuItem);
140140
}
141-
menu.Open(this);
141+
this.OpenContextMenu(menu);
142142
}
143143
}
144144
else
@@ -315,10 +315,7 @@ bool DetectWaveformPrimaryButton()
315315
}
316316
}
317317

318-
if (menu.ItemCount != 0)
319-
{
320-
menu.Open(this);
321-
}
318+
this.OpenContextMenu(menu);
322319
}
323320
break;
324321
default:
@@ -503,10 +500,7 @@ bool DetectWaveformPrimaryButton()
503500
}
504501
}
505502

506-
if (menu.ItemCount != 0)
507-
{
508-
menu.Open(this);
509-
}
503+
this.OpenContextMenu(menu);
510504
}
511505
break;
512506
default:

TuneLab/UI/MainWindow/Editor/TimelineView/TimelineViewOperation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected override void OnMouseDown(MouseDownEventArgs e)
9494
});
9595
menu.Items.Add(menuItem);
9696
}
97-
menu.Open(this);
97+
this.OpenContextMenu(menu);
9898
}
9999
else if (item is TimeSignatureItem timeSignatureItem)
100100
{
@@ -115,7 +115,7 @@ protected override void OnMouseDown(MouseDownEventArgs e)
115115
});
116116
menu.Items.Add(menuItem);
117117
}
118-
menu.Open(this);
118+
this.OpenContextMenu(menu);
119119
}
120120
else
121121
{
@@ -141,7 +141,7 @@ protected override void OnMouseDown(MouseDownEventArgs e)
141141
});
142142
menu.Items.Add(menuItem);
143143
}
144-
menu.Open(this);
144+
this.OpenContextMenu(menu);
145145
}
146146
}
147147
break;

TuneLab/UI/MainWindow/Editor/TrackWindow/TrackScrollView/TrackScrollViewOperation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ protected override async void OnMouseDown(MouseDownEventArgs e)
285285
}
286286
}
287287

288-
if (menu.ItemCount != 0)
289-
{
290-
menu.Open(this);
291-
}
288+
this.OpenContextMenu(menu);
292289
}
293290
break;
294291
default:

TuneLab/Utils/Extensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ public static void SetupToolTip(this Control control, string text, PlacementMode
338338
ToolTip.SetTip(control, text);
339339
}
340340

341+
static ContextMenu? mCurrentContextMenu = null;
342+
public static void OpenContextMenu(this Control control, ContextMenu menu)
343+
{
344+
if (mCurrentContextMenu != null)
345+
mCurrentContextMenu.Close();
346+
347+
if (menu.ItemCount == 0)
348+
return;
349+
350+
mCurrentContextMenu = menu;
351+
menu.Closed += (_, _) => mCurrentContextMenu = null;
352+
menu.Open(control);
353+
}
354+
341355
public static Color Lerp(this Color c1, Color c2, double ratio)
342356
{
343357
return new Color(

0 commit comments

Comments
 (0)