-
Notifications
You must be signed in to change notification settings - Fork 28.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce share links in more places via a contrib #177311
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,15 +98,18 @@ export class MenuId { | |
static readonly MenubarViewMenu = new MenuId('MenubarViewMenu'); | ||
static readonly MenubarHomeMenu = new MenuId('MenubarHomeMenu'); | ||
static readonly OpenEditorsContext = new MenuId('OpenEditorsContext'); | ||
static readonly OpenEditorsContextShare = new MenuId('OpenEditorsContextShare'); | ||
static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext'); | ||
static readonly SCMChangeContext = new MenuId('SCMChangeContext'); | ||
static readonly SCMResourceContext = new MenuId('SCMResourceContext'); | ||
static readonly SCMResourceContextShare = new MenuId('SCMResourceContextShare'); | ||
static readonly SCMResourceFolderContext = new MenuId('SCMResourceFolderContext'); | ||
static readonly SCMResourceGroupContext = new MenuId('SCMResourceGroupContext'); | ||
static readonly SCMSourceControl = new MenuId('SCMSourceControl'); | ||
static readonly SCMTitle = new MenuId('SCMTitle'); | ||
static readonly SearchContext = new MenuId('SearchContext'); | ||
static readonly SearchActionMenu = new MenuId('SearchActionContext'); | ||
static readonly Share = new MenuId('Share'); | ||
static readonly StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu'); | ||
static readonly StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu'); | ||
static readonly StickyScrollContext = new MenuId('StickyScrollContext'); | ||
|
@@ -477,7 +480,9 @@ export class MenuItemAction implements IAction { | |
run(...args: any[]): Promise<void> { | ||
let runArgs: any[] = []; | ||
|
||
if (this._options?.arg) { | ||
if (this._options?.arg && Array.isArray(this._options.arg)) { | ||
runArgs = [...runArgs, ...this._options.arg]; | ||
} else if (this._options?.arg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have unfortunately limited capacities for a deeper look but this seems breaking for those cases where use have been using an array as argument, right? |
||
runArgs = [...runArgs, this._options.arg]; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/vs/workbench/contrib/share/browser/share.contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { DisposableStore } from 'vs/base/common/lifecycle'; | ||
import { IMenuService, MenuId, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions'; | ||
import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; | ||
import { Registry } from 'vs/platform/registry/common/platform'; | ||
import { Extensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; | ||
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; | ||
import * as nls from 'vs/nls'; | ||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; | ||
|
||
const menuIds: [MenuId, MenuId | undefined, ContextKeyExpression | undefined][] = [ | ||
[MenuId.EditorContext, MenuId.EditorContextShare, ContextKeyExpr.and(ContextKeyExpr.notEquals('resourceScheme', 'output'), EditorContextKeys.editorTextFocus)], | ||
[MenuId.EditorTitleContext, MenuId.EditorTitleContextShare, undefined], | ||
[MenuId.ExplorerContext, MenuId.ExplorerContextShare, undefined], | ||
[MenuId.OpenEditorsContext, MenuId.OpenEditorsContextShare, undefined], | ||
[MenuId.SCMResourceContext, MenuId.SCMResourceContextShare, undefined], | ||
[MenuId.EditorLineNumberContext, undefined, undefined], | ||
]; | ||
|
||
for (const [menuId, submenuId, when] of menuIds) { | ||
if (submenuId !== undefined) { | ||
MenuRegistry.appendMenuItem(menuId, { submenu: submenuId, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1, when }); | ||
} | ||
} | ||
|
||
class ShareContribution { | ||
|
||
private readonly disposableStore = new DisposableStore(); | ||
private readonly menu = this.menuService.createMenu(MenuId.Share, this.contextKeyService); | ||
|
||
constructor( | ||
@IMenuService private readonly menuService: IMenuService, | ||
@IContextKeyService private readonly contextKeyService: IContextKeyService, | ||
) { | ||
this.ensureActions(); | ||
this.menu.onDidChange(() => this.ensureActions()); | ||
} | ||
|
||
private ensureActions(): void { | ||
this.disposableStore.clear(); | ||
|
||
const allActions = this.menu.getActions(); | ||
|
||
for (const [_, actions] of allActions) { | ||
for (const action of actions) { | ||
if (action instanceof SubmenuItemAction || !action.enabled) { | ||
continue; | ||
} | ||
for (const [menuId, submenuId] of menuIds) { | ||
this.disposableStore.add(MenuRegistry.appendMenuItem( | ||
submenuId ?? menuId, | ||
{ command: action.item } | ||
)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(ShareContribution, LifecyclePhase.Eventually); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not OK because it is a conceptual layer breaker. It introduces extension host types to the renderer, e.g this new argument is wrong for all "internal" context menu actions and wrong for monaco-editor use-cases.