Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf081be

Browse files
committed
add context menu labels when items are selected
1 parent d7400d0 commit cf081be

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

lib/github-package.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const defaultState = {
2727

2828
export default class GithubPackage {
2929
constructor(workspace, project, commandRegistry, notificationManager, tooltips, styles, grammars, confirm, config,
30-
configDirPath, getLoadSettings) {
30+
configDirPath, getLoadSettings, contextMenu) {
3131
this.workspace = workspace;
3232
this.project = project;
3333
this.commandRegistry = commandRegistry;
@@ -37,6 +37,7 @@ export default class GithubPackage {
3737
this.styles = styles;
3838
this.grammars = grammars;
3939
this.configPath = path.join(configDirPath, 'github.cson');
40+
this.contextMenu = contextMenu;
4041

4142
this.styleCalculator = new StyleCalculator(this.styles, this.config);
4243
this.confirm = confirm;
@@ -130,6 +131,10 @@ export default class GithubPackage {
130131
await writeFile(this.configPath, '# Store non-visible GitHub package state.\n');
131132
}
132133

134+
const hasSelectedFiles = event => {
135+
return !!event.target.closest('.github-FilePatchListView').querySelector('.is-selected');
136+
};
137+
133138
this.subscriptions.add(
134139
atom.config.onDidChange('github.useLegacyPanels', ({newValue}) => {
135140
if (newValue) {
@@ -166,6 +171,52 @@ export default class GithubPackage {
166171
}
167172
}),
168173
this.workspace.addOpener(IssueishPaneItem.opener),
174+
this.contextMenu.add({
175+
'.github-UnstagedChanges .github-FilePatchListView': [
176+
{
177+
label: 'Stage',
178+
command: 'core:confirm',
179+
shouldDisplay: hasSelectedFiles,
180+
},
181+
{
182+
type: 'separator',
183+
shouldDisplay: hasSelectedFiles,
184+
},
185+
{
186+
label: 'Discard Changes',
187+
command: 'github:discard-changes-in-selected-files',
188+
shouldDisplay: hasSelectedFiles,
189+
},
190+
],
191+
'.github-StagedChanges .github-FilePatchListView': [
192+
{
193+
label: 'Unstage',
194+
command: 'core:confirm',
195+
shouldDisplay: hasSelectedFiles,
196+
},
197+
],
198+
'.github-MergeConflictPaths .github-FilePatchListView': [
199+
{
200+
label: 'Stage',
201+
command: 'core:confirm',
202+
shouldDisplay: hasSelectedFiles,
203+
},
204+
{
205+
type: 'separator',
206+
shouldDisplay: hasSelectedFiles,
207+
},
208+
{
209+
label: 'Resolve File As Ours',
210+
command: 'github:resolve-file-as-ours',
211+
shouldDisplay: hasSelectedFiles,
212+
},
213+
{
214+
label: 'Resolve File As Theirs',
215+
command: 'github:resolve-file-as-theirs',
216+
shouldDisplay: hasSelectedFiles,
217+
},
218+
],
219+
}),
169220
);
170221

171222
this.activated = true;

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const entry = {
66
pack = new GithubPackage(
77
atom.workspace, atom.project, atom.commands, atom.notifications, atom.tooltips,
88
atom.styles, atom.grammars, atom.confirm.bind(atom), atom.config, atom.getConfigDirPath(),
9-
atom.getLoadSettings.bind(atom),
9+
atom.getLoadSettings.bind(atom), atom.contextMenu,
1010
);
1111
},
1212
};

menus/git.cson

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,6 @@
3838
'command': 'github:open-file'
3939
}
4040
]
41-
'.github-UnstagedChanges .github-FilePatchListView .github-FilePatchListView-item': [
42-
{
43-
'label': 'Stage'
44-
'command': 'core:confirm'
45-
}
46-
{
47-
'type': 'separator'
48-
}
49-
{
50-
'label': 'Discard Changes'
51-
'command': 'github:discard-changes-in-selected-files'
52-
}
53-
]
54-
'.github-StagedChanges .github-FilePatchListView .github-FilePatchListView-item': [
55-
{
56-
'label': 'Unstage'
57-
'command': 'core:confirm'
58-
}
59-
]
60-
'.github-MergeConflictPaths .github-FilePatchListView .github-MergeConflictListView-item': [
61-
{
62-
'label': 'Stage'
63-
'command': 'core:confirm'
64-
},
65-
{
66-
'type': 'separator'
67-
}
68-
{
69-
'label': 'Resolve File As Ours'
70-
'command': 'github:resolve-file-as-ours'
71-
},
72-
{
73-
'label': 'Resolve File As Theirs'
74-
'command': 'github:resolve-file-as-theirs'
75-
}
76-
]
7741
'.github-FilePatchView': [
7842
{
7943
'label': 'Open File'

0 commit comments

Comments
 (0)