1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Recent file selector (ctrl+tab)

This commit is contained in:
Brian Fiete 2020-09-03 06:49:19 -07:00
parent 73d9d1ec59
commit 6511d6a845
11 changed files with 163 additions and 15 deletions

View file

@ -227,7 +227,7 @@ namespace Beefy.theme.dark
float popupY = mHeight + popupYOfs;
//TODO: Autocomplete didn't work on this: BFApp.sApp.GetW...
menuWidget.Init(this, popupXOfs, popupY, true, menuWindow);
menuWidget.Init(this, popupXOfs, popupY, .AllowScrollable, menuWindow);
// Why were we capturing?
mWidgetWindow.TransferMouse(menuWidget.mWidgetWindow);
if (menuWindow == null)

View file

@ -301,7 +301,7 @@ namespace Beefy.theme.dark
{
MenuWidget menuWidget = DarkTheme.sDarkTheme.CreateMenuWidget(menu);
menuWidget.Init(this, x, y, true);
menuWidget.Init(this, x, y, .AllowScrollable);
menuWidget.mWidgetWindow.mOnWindowClosed.Add(new => MenuClosed);
}
else

View file

@ -95,6 +95,14 @@ namespace Beefy.widgets
public class MenuWidget : Widget
{
enum ShowFlags
{
None,
AllowScrollable = 1,
CenterHorz = 2,
CenterVert = 4,
}
public MenuItemWidget mParentMenuItemWidget;
public Menu mMenu;
//public BFWindowBase.Flags mWindowFlags = BFWindowBase.Flags.ClientSized | BFWindowBase.Flags.NoActivate | BFWindowBase.Flags.NoMouseActivate;
@ -227,8 +235,9 @@ namespace Beefy.widgets
return 10;
}
public virtual void Init(Widget relativeWidget, float x, float y, bool allowScrollable = false, WidgetWindow widgetWindow = null)
public virtual void Init(Widget relativeWidget, float x, float y, ShowFlags showFlags = 0, WidgetWindow widgetWindow = null)
{
bool allowScrollable = showFlags.HasFlag(.AllowScrollable);
mWasInitialized = true;
float curY = y;
@ -289,6 +298,11 @@ namespace Beefy.widgets
screenX += relativeWidget.mWidgetWindow.mClientX;
screenY += relativeWidget.mWidgetWindow.mClientY;
if (showFlags.HasFlag(.CenterHorz))
screenX -= mWidth / 2;
if (showFlags.HasFlag(.CenterVert))
screenY -= mHeight / 2;
MenuContainer menuContainer;
if (curWidgetWindow == null)

View file

@ -228,6 +228,8 @@ namespace IDE
Add("Open Workspace", new => gApp.OpenWorkspace);
Add("Profile", new => gApp.[Friend]DoProfile);
Add("Quick Info", new => gApp.Cmd_QuickInfo);
Add("Recent File Next", new => gApp.ShowRecentFileNext);
Add("Recent File Prev", new => gApp.ShowRecentFilePrev);
Add("Reformat Document", new => gApp.Cmd_ReformatDocument);
Add("Reload Settings", new => gApp.ReloadSettings);
Add("Remove All Breakpoints", new => gApp.[Friend]RemoveAllBreakpoints);

View file

@ -180,7 +180,8 @@ namespace IDE
public GlobalUndoManager mGlobalUndoManager = new GlobalUndoManager() ~ delete _;
public SourceControl mSourceControl = new SourceControl() ~ delete _;
public WidgetWindow mPopupWindow;
public WidgetWindow mPopupWindow;
public RecentFileSelector mRecentFileSelector;
public IDETabbedView mActiveDocumentsTabbedView;
public static new IDEApp sApp;
@ -6158,11 +6159,32 @@ namespace IDE
public void AddToRecentDisplayedFilesList(String path)
{
//int idx = mRecentFilesList.IndexOf(path);
RecentFiles.Add(mRecentlyDisplayedFiles, path);
RecentFiles.Add(mRecentlyDisplayedFiles, path, 20);
UpdateRecentDisplayedFilesMenuItems();
}
public void ShowRecentFileNext()
{
if (mRecentFileSelector == null)
{
mRecentFileSelector = new RecentFileSelector();
mRecentFileSelector.Show();
}
else
mRecentFileSelector.Next();
}
public void ShowRecentFilePrev()
{
if (mRecentFileSelector == null)
{
mRecentFileSelector = new RecentFileSelector();
mRecentFileSelector.Show();
}
else
mRecentFileSelector.Prev();
}
void ShowRecentFile(int idx, bool setFocus = true)
{
if (idx >= mRecentlyDisplayedFiles.Count)
@ -7079,6 +7101,11 @@ namespace IDE
IDECommand.ContextFlags useFlags = .None;
var activeWindow = GetActiveWindow();
while (activeWindow.mParent != null)
activeWindow = activeWindow.mParent as WidgetWindow;
if (activeWindow == null)
return;
bool isMainWindow = activeWindow.mRootWidget is MainFrame;
bool isWorkWindow = isMainWindow || (activeWindow.mRootWidget is DarkDockingFrame);

View file

@ -276,11 +276,11 @@ namespace IDE
public Color mKeyword = 0xFFE1AE9A;
public Color mLiteral = 0XFFC8A0FF;
public Color mIdentifier = 0xFFFFFFFF;
public Color mComment = 0XFF75715E;
public Color mMethod = 0XFFA6E22A;
public Color mType = 0XFF66D9EF;
public Color mRefType = 0XFF66D9EF;
public Color mInterface = 0XFF66D9EF;
public Color mComment = 0xFF75715E;
public Color mMethod = 0xFFA6E22A;
public Color mType = 0xFF66D9EF;
public Color mRefType = 0xFF66A0EF;
public Color mInterface = 0xFF9A9EEB;
public Color mNamespace = 0xFF7BEEB7;
public Color mDisassemblyText = 0xFFB0B0B0;
public Color mDisassemblyFileName = 0XFFFF0000;
@ -695,6 +695,8 @@ namespace IDE
Add("Open File", "Ctrl+O");
Add("Open Workspace", "Ctrl+Shift+O");
Add("Quick Info", "Ctrl+K, Ctrl+I");
Add("Recent File Next", "Ctrl+Tab");
Add("Recent File Prev", "Shift+Ctrl+Tab");
Add("Reformat Document", "Ctrl+K, Ctrl+D");
Add("Remove All Breakpoints", "Ctrl+Shift+F9");
Add("Rename Symbol", "Ctrl+R");

View file

@ -1138,7 +1138,7 @@ namespace IDE.ui
if (mProject.mLocked)
menuItem.mIconImage = DarkTheme.sDarkTheme.GetImage(.Check);
MenuWidget menuWidget = DarkTheme.sDarkTheme.CreateMenuWidget(menu);
menuWidget.Init(this, x, y, true);
menuWidget.Init(this, x, y, .AllowScrollable);
}
}
}

View file

@ -0,0 +1,101 @@
using System;
using Beefy.widgets;
using Beefy.theme;
using Beefy.theme.dark;
using System.IO;
namespace IDE.ui
{
class RecentFileSelector
{
class RecentMenuWidget : DarkMenuWidget
{
public this(Menu menu) : base(menu)
{
}
public override void Update()
{
if ((!mWidgetWindow.IsKeyDown(.Control)) &&
(!mWidgetWindow.IsKeyDown(.Shift)) &&
(!mWidgetWindow.IsKeyDown(.Menu)))
{
SubmitSelection();
Close();
}
}
}
RecentMenuWidget mMenuWidget;
public void Show()
{
if (gApp.mRecentlyDisplayedFiles.IsEmpty)
{
Closed();
return;
}
bool hadActiveDocument = gApp.GetActiveDocumentPanel() != null;
Widget parentWidget = gApp.GetActiveDocumentPanel();
if (parentWidget != null)
{
if (parentWidget.mParent is TabbedView)
parentWidget = parentWidget.mParent;
}
if (parentWidget == null)
parentWidget = gApp.mMainWindow.mRootWidget;
Menu menu = new Menu();
Menu item;
for (var recentItem in gApp.mRecentlyDisplayedFiles)
{
String fileName = scope .();
Path.GetFileName(recentItem, fileName);
item = menu.AddItem(fileName);
item.mOnMenuItemSelected.Add(new (menu) =>
{
gApp.[Friend]ShowRecentFile(@recentItem.Index);
mMenuWidget.Close();
});
}
mMenuWidget = new RecentMenuWidget(menu);
mMenuWidget.Init(parentWidget, parentWidget.mWidth / 2, GS!(20), .CenterHorz);
mMenuWidget.mWidgetWindow.mOnWindowKeyDown.Add(new => gApp.[Friend]SysKeyDown);
mMenuWidget.mOnKeyDown.Add(new (keyboardEvent) =>
{
if (keyboardEvent.mKeyCode == .Right)
{
if (mMenuWidget.mSelectIdx != -1)
gApp.[Friend]ShowRecentFile(mMenuWidget.mSelectIdx, false);
}
});
mMenuWidget.mOnRemovedFromParent.Add(new (widget, prevParent, widgetWindow) => Closed());
if (!hadActiveDocument)
mMenuWidget.SetSelection(0);
else
mMenuWidget.SetSelection(1);
}
public void Next()
{
mMenuWidget.KeyDown(.Down, false);
}
public void Prev()
{
mMenuWidget.KeyDown(.Up, false);
}
void Closed()
{
gApp.mRecentFileSelector = null;
delete this;
}
}
}

View file

@ -6551,7 +6551,7 @@ namespace IDE.ui
AddLockType("When not Hot Swappable", .WhenNotHotSwappable);
MenuWidget menuWidget = DarkTheme.sDarkTheme.CreateMenuWidget(menu);
menuWidget.Init(this, x, y, true);
menuWidget.Init(this, x, y, .AllowScrollable);
}
}

View file

@ -641,7 +641,7 @@ namespace IDE.ui
});
MenuWidget menuWidget = DarkTheme.sDarkTheme.CreateMenuWidget(menu);
menuWidget.Init(this, x, y, true);
menuWidget.Init(this, x, y, .AllowScrollable);
menu.mOnMenuClosed.Add(new (menu, itemSelected) =>
{

View file

@ -49,8 +49,10 @@ namespace IDE.util
int offset = showSplit ? 1 : 0;
int itemCount = Math.Min(items.Count, 10);
int32 i;
for (i = 0; i < items.Count; i++)
for (i = 0; i < itemCount; i++)
{
String title = scope String();
if (i + 1 == 10)