diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index b55b70377..23b0ce399 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -6063,7 +6063,13 @@ namespace IDE { scope AutoBeefPerf("IDEApp.CreateMenu"); - SysMenu root = mMainWindow.mSysMenu; + SysMenu root; +#if BF_PLATFORM_WINDOWS + root = mMainWindow.mSysMenu; +#else + root = mMainFrame.mMenuBar.mSysMenuRoot; + defer mMainFrame.RehupSize(); +#endif String keyStr = scope String(); @@ -6147,11 +6153,18 @@ namespace IDE void AddLineEndingKind(String name, LineEndingKind lineEndingKind) { + bool allowLast; +#if !BF_PLATFORM_WINDOWS + allowLast = true; +#else + allowLast = false; +#endif + lineEndingMenu.AddMenuItem(name, null, new (menu) => { var sysMenu = (SysMenu)menu; - var sourceViewPanel = GetActiveSourceViewPanel(); + var sourceViewPanel = GetActiveSourceViewPanel(allowLast); if (sourceViewPanel != null) { if (sourceViewPanel.mEditData.mLineEndingKind != lineEndingKind) @@ -6166,7 +6179,7 @@ namespace IDE { var sysMenu = (SysMenu)menu; - var sourceViewPanel = GetActiveSourceViewPanel(); + var sourceViewPanel = GetActiveSourceViewPanel(allowLast); if (sourceViewPanel != null) { sysMenu.Modify(null, null, null, true, (sourceViewPanel.mEditData.mLineEndingKind == lineEndingKind) ? 1 : 0, true); diff --git a/IDE/src/ui/MainFrame.bf b/IDE/src/ui/MainFrame.bf index 3df50c1e5..d76fcdd32 100644 --- a/IDE/src/ui/MainFrame.bf +++ b/IDE/src/ui/MainFrame.bf @@ -15,7 +15,7 @@ namespace IDE.ui public StatusBar mStatusBar; public DarkDockingFrame mDockingFrame; -#if BF_PLATFORM_LINUX +#if !BF_PLATFORM_WINDOWS public MenuBar mMenuBar; #endif @@ -25,7 +25,7 @@ namespace IDE.ui AddWidget(mStatusBar); mDockingFrame = (DarkDockingFrame)ThemeFactory.mDefault.CreateDockingFrame(); AddWidget(mDockingFrame); -#if BF_PLATFORM_LINUX +#if !BF_PLATFORM_WINDOWS mMenuBar = new MenuBar(); AddWidget(mMenuBar); #endif @@ -50,7 +50,7 @@ namespace IDE.ui base.Resize(x, y, width, height); int32 statusHeight = GS!(20); -#if BF_PLATFORM_LINUX +#if !BF_PLATFORM_WINDOWS int32 menuHeight = GS!(20); mDockingFrame.Resize(0, menuHeight, width, height - statusHeight - menuHeight); mMenuBar.Resize(0, 0, width, menuHeight); diff --git a/IDE/src/ui/MenuBar.bf b/IDE/src/ui/MenuBar.bf index 77e0205bb..9aa42a9ee 100644 --- a/IDE/src/ui/MenuBar.bf +++ b/IDE/src/ui/MenuBar.bf @@ -7,11 +7,107 @@ using IDE; using IDE.util; using System; using System.Diagnostics; +using System.Collections; +using Beefy.sys; namespace IDE.ui; public class MenuBar : Widget { + class UISysMenu : SysMenu + { + public override SysMenu AddMenuItem(String text, String hotKey = null, MenuItemSelectedHandler menuItemSelectedHandler = null, + MenuItemUpdateHandler menuItemUpdateHandler = null, SysBitmap bitmap = null, bool enabled = true, int32 checkState = -1, bool radioCheck = false) + { + if (mChildren == null) + mChildren = new List(); + + UISysMenu sysMenu = new UISysMenu(); + if (text != null) + { + sysMenu.mText = new String(text); + let bindIndex = sysMenu.mText.IndexOf('&'); + if (bindIndex != -1) + sysMenu.mText.Remove(bindIndex); + } + if ((hotKey != null) && (hotKey.Length != 0) && ((hotKey.Length > 1 ) || (hotKey[0] != '#'))) + { + sysMenu.mHotKey = new String(hotKey); + sysMenu.mHotKey.TrimStart('#'); + } + + sysMenu.mBitmap = bitmap; + sysMenu.mEnabled = enabled; + sysMenu.mCheckState = checkState; + sysMenu.mRadioCheck = radioCheck; + if (menuItemSelectedHandler != null) + sysMenu.mOnMenuItemSelected.Add(menuItemSelectedHandler); + if (menuItemUpdateHandler != null) + sysMenu.mOnMenuItemUpdate.Add(menuItemUpdateHandler); + sysMenu.mNativeBFMenu = null; + sysMenu.mParent = this; + sysMenu.mWindow = mWindow; + mChildren.Add(sysMenu); + + return sysMenu; + } + + public override void Modify(String text, String hotKey = null, SysBitmap bitmap = null, bool enabled = true, int32 checkState = -1, bool radioCheck = false) + { + if (((Object)mText != text) && (text != null)) + { + if (text.Length > 0) + { + String.NewOrSet!(mText, text); + let bindIndex = mText.IndexOf('&'); + if (bindIndex != -1) + mText.Remove(bindIndex); + } + else + DeleteAndNullify!(mText); + } + + if (((Object)mHotKey != hotKey) && (hotKey != null)) + { + if ((hotKey.Length > 0) && ((hotKey.Length > 1 ) || (hotKey[0] != '#'))) + { + String.NewOrSet!(mHotKey, hotKey); + mHotKey.TrimStart('#'); + } + else + DeleteAndNullify!(mHotKey); + } + mBitmap = bitmap; + mEnabled = enabled; + mCheckState = checkState; + mRadioCheck = radioCheck; + } + } + + public class UISysMenuRoot : UISysMenu + { + public MenuBar mRootMenuBar; + public this() + { + + } + + public override SysMenu AddMenuItem(String text, String hotKey = null, MenuItemSelectedHandler menuItemSelectedHandler = null, MenuItemUpdateHandler menuItemUpdateHandler = null, + SysBitmap bitmap = null, bool enabled = true, int32 checkState = -1, bool radioCheck = false) + { + let item = base.AddMenuItem(text, hotKey, menuItemSelectedHandler, menuItemUpdateHandler, bitmap, enabled, checkState, radioCheck); + let button = new Button(); + button.Label = text; + button.mSysMenu = item; + button.mOnMouseClick.Add(new (evt) => { + mOnMenuItemSelected(this); + mRootMenuBar.ShowMenu(button); + }); + mRootMenuBar.AddItemButton(button); + return item; + } + } + public class Button : ButtonWidget { private String mLabel ~ delete _; @@ -29,6 +125,8 @@ public class MenuBar : Widget } } + public SysMenu mSysMenu; + public override void Draw(Graphics g) { base.Draw(g); @@ -53,370 +151,82 @@ public class MenuBar : Widget } } - public Button mFileButton; - public Button mEditButton; - public Button mViewButton; - public Button mBuildButton; - public Button mDebugButton; - public Button mTestButton; - public Button mWindowButton; - public Button mHelpButton; + + public append List