mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-18 16:10:26 +02:00
Recent file selector (ctrl+tab)
This commit is contained in:
parent
73d9d1ec59
commit
6511d6a845
11 changed files with 163 additions and 15 deletions
101
IDE/src/ui/RecentFileSelector.bf
Normal file
101
IDE/src/ui/RecentFileSelector.bf
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue