简体   繁体   English

ActionMainMenuBar 和自动隐藏双重分隔符

[英]ActionMainMenuBar and auto-hiding doubled separators

with TMainMenu we have AutoLineReduction property to hide doubled separators when menu item is hidden, how to do the same with ActionMainMenuBar and ActionManager?对于 TMainMenu,我们有 AutoLineReduction 属性来隐藏菜单项隐藏时的双分隔符,如何对 ActionMainMenuBar 和 ActionManager 做同样的事情?

双分隔符

I didn't find an internal method for this, but we can do it manually.我没有为此找到内部方法,但我们可以手动完成。

We have to add the OnPopup method to the ActionMainMenuBar :我们必须将OnPopup方法添加到ActionMainMenuBar

procedure TFormMain.MenuBarPopup(Sender: TObject; Item: TCustomActionControl);
begin
  // Make all separators visible
  for var I := 0 to Item.ActionClient.Items.Count - 1 do begin
    var Itm := Item.ActionClient.Items[I];
    if (Itm.Caption = '-') then
      Itm.Visible := True;
  end;
  // Hide doubled separators
  for var I := 0 to Item.ActionClient.Items.Count - 1 do begin
    var Itm := Item.ActionClient.Items[I];
    if (Itm.Caption = '-') then begin // Search next separator
      var bFound := False;
      for var J := I + 1 to Item.ActionClient.Items.Count - 1 do begin
        var Itm2 := Item.ActionClient.Items[J];
        if Itm2.Visible then begin
          bFound := (Itm2.Caption <> '-');
          Break;
        end;
      end;
      Itm.Visible := bFound;
    end;
  end;
end;

Is it very strange that this component does not contain such a property...这个组件不包含这样的属性是不是很奇怪...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM