Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit dac29c5

Browse files
nikmrward
authored andcommitted
Allow keyboard shortcuts to be set for file tab strip menu.
Keyboard shortcuts assigned to the file tab strip menu's items (/SharpDevelop/Workbench/OpenFileTab/ContextMenu) were ignored because InputBindingOwner was not set in MenuCreateContext while creating these menu items. As a result the MenuCommand's AddGestureToInputBindingOwner method refused to register any keyboard shortcuts assigned to these menu items. Make AvalonWorkbenchWindow register itself as InputBindingOwner in MenuCreateContext when creating the file tab strip menu items and hence make shortcuts assigned to them work. And make "Alt-Shift-L" the default shortcut for the NavigateToFileInProjectBrowser menu command. Cherry picked from pull request #729
1 parent 336b105 commit dac29c5

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/Main/Base/Project/ICSharpCode.SharpDevelop.addin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@
12781278
class = "ICSharpCode.SharpDevelop.Commands.TabStrip.CopyPathName"/>
12791279
<MenuItem id = "NavigateToFileInProjectBrowser"
12801280
label = "${res:ICSharpCode.SharpDevelop.Commands.TabStrip.NavigateToFileInProjectBrowser}"
1281+
shortcut = "Alt|Shift|L"
12811282
class = "ICSharpCode.SharpDevelop.Commands.TabStrip.NavigateToFileInProjectBrowser"/>
12821283
<MenuItem id = "OpenFolderContainingFileFromTab"
12831284
label = "${res:OpenFileTabEventHandler.FileContainingFolderInExplorer}"

src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ public override void Run()
105105

106106
string GetActiveFileName()
107107
{
108-
if ((this.Owner is IWorkbenchWindow) && (((IWorkbenchWindow)this.Owner).ActiveViewContent != null)) {
109-
return (Owner as IWorkbenchWindow).ActiveViewContent.PrimaryFileName;
108+
var workbenchWindow = Owner as IWorkbenchWindow;
109+
if (workbenchWindow == null)
110+
workbenchWindow = SD.Workbench.ActiveWorkbenchWindow;
111+
112+
if (workbenchWindow != null && workbenchWindow.ActiveViewContent != null) {
113+
return workbenchWindow.ActiveViewContent.PrimaryFileName;
110114
}
115+
111116
return null;
112117
}
113118

src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,31 @@ public static void UpdateText(IEnumerable menuItems)
114114

115115
public static ContextMenu CreateContextMenu(object owner, string addInTreePath)
116116
{
117-
IList items = CreateUnexpandedMenuItems(
117+
return CreateContextMenu(
118118
new MenuCreateContext { ActivationMethod = "ContextMenu" },
119+
owner,
120+
addInTreePath);
121+
}
122+
123+
public static ContextMenu CreateContextMenu(UIElement inputBindingOwner, object owner, string addInTreePath)
124+
{
125+
return CreateContextMenu(
126+
new MenuCreateContext {
127+
InputBindingOwner = inputBindingOwner,
128+
ActivationMethod = "ContextMenu"
129+
},
130+
owner,
131+
addInTreePath);
132+
}
133+
134+
static ContextMenu CreateContextMenu(MenuCreateContext context, object owner, string addInTreePath)
135+
{
136+
IList items = CreateUnexpandedMenuItems(
137+
context,
119138
AddInTree.BuildItems<MenuItemDescriptor>(addInTreePath, owner, false));
120139
return CreateContextMenu(items);
121140
}
122-
141+
123142
public static ContextMenu ShowContextMenu(UIElement parent, object owner, string addInTreePath)
124143
{
125144
ContextMenu menu = new ContextMenu();

src/Main/SharpDevelop/Workbench/AvalonWorkbenchWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public override void OnApplyTemplate()
293293
base.OnApplyTemplate();
294294

295295
if (this.DragEnabledArea != null) {
296-
this.DragEnabledArea.ContextMenu = MenuService.CreateContextMenu(this, contextMenuPath);
296+
this.DragEnabledArea.ContextMenu = MenuService.CreateContextMenu(this, this, contextMenuPath);
297297
UpdateInfoTip(); // set tooltip
298298
}
299299
}

0 commit comments

Comments
 (0)