JD2022-TU1/main/tools/framework/JD.Application.TeaBox/Actions/QuickOpenTab.cs

62 lines
1.9 KiB
C#

using System.Linq;
using JD.Reflection.Attributes;
using JD.TeaBoxAddinSystem.Bootstrap;
using JD.UserControls.QuickOpenDialogs;
using TeaBox;
using TeaBox.Actions;
using TeaBox.Bootstrap;
using TeaBox.Gui;
using TeaBox.ObjectModel;
using Size = System.Drawing.Size;
namespace JD.Application.Actions
{
[Export(typeof(IBootstrapCommand))]
class QuickOpenBootstrapCommand : IBootstrapCommand
{
public void Execute()
{
// Replace Ctrl+Tab key chord.
var action = global::TeaBox.ObjectModel.Application.Main.Actions["WindowActions.MruWindow"] as SimpleAction;
if (action != null)
{
action.DefaultHandler = new QuickOpenTab();
}
action = global::TeaBox.ObjectModel.Application.Main.Actions["WindowActions.LruWindow"] as SimpleAction;
if (action != null)
{
action.DefaultHandler = null;
}
}
}
class QuickOpenTab : ActionHandler
{
private IDocumentView _lastSelected;
public override void Execute(ActionExecutionContext context)
{
var form = new QuickOpenForm<IDocumentView>(global::TeaBox.ObjectModel.Application.Main.Views.OfType<IDocumentView>())
{
Caption = "Select a tab to open",
NameProvider = documentView => documentView.ActiveDocument.TitleName,
ShowAllOnEmptyText = true,
ImageSize = new Size(16, 16),
ImageProvider = documentView => documentView.Icon,
SelectedItem = _lastSelected,
};
form.ItemAccepted += FormOnItemAccepted;
form.Show();
}
private void FormOnItemAccepted(IDocumentView documentView)
{
_lastSelected = documentView;
documentView.Select();
}
}
}