Skip to content

Commit 0f861c8

Browse files
authored
Merge pull request #59 from hansu/56-add-select-in-branches-dropdown-also-for-show-all
56 add select in branches dropdown also for show all
2 parents c7deb44 + 6100336 commit 0f861c8

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

web/contextMenu.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const CLASS_CONTEXT_MENU_ACTIVE = 'contextMenuActive';
33
interface ContextMenuAction {
44
readonly title: string;
55
readonly visible: boolean;
6-
readonly onClick: () => void;
6+
readonly onClick: (e?: MouseEvent) => void;
77
readonly checked?: boolean; // Required in checked context menus
88
}
99

@@ -46,15 +46,15 @@ class ContextMenu {
4646
* @param className An optional class name to add to the context menu.
4747
*/
4848
public show(actions: ContextMenuActions, checked: boolean, target: ContextMenuTarget | null, event: MouseEvent, frameElem: HTMLElement, onClose: (() => void) | null = null, className: string | null = null) {
49-
let html = '', handlers: (() => void)[] = [], handlerId = 0;
49+
let html = '', handlers: ((e?: MouseEvent) => void)[] = [], handlerId = 0;
5050
this.close();
5151

5252
for (let i = 0; i < actions.length; i++) {
5353
let groupHtml = '';
5454
for (let j = 0; j < actions[i].length; j++) {
5555
if (actions[i][j].visible) {
5656
groupHtml += '<li class="contextMenuItem" data-index="' + handlerId++ + '">' + (checked ? '<span class="contextMenuItemCheck">' + (actions[i][j].checked ? SVG_ICONS.check : '') + '</span>' : '') + actions[i][j].title + '</li>';
57-
handlers.push(actions[i][j].onClick);
57+
handlers.push((e?: MouseEvent) => actions[i][j].onClick(e));
5858
}
5959
}
6060

@@ -92,7 +92,9 @@ class ContextMenu {
9292
// The user clicked on a context menu item => call the corresponding handler
9393
e.stopPropagation();
9494
this.close();
95-
handlers[parseInt((<HTMLElement>(<Element>e.target).closest('.contextMenuItem')!).dataset.index!)]();
95+
const handlerIndex = parseInt((<HTMLElement>(<Element>e.target).closest('.contextMenuItem')!).dataset.index!);
96+
const handler = handlers[handlerIndex];
97+
handler?.(e instanceof MouseEvent ? e : undefined);
9698
});
9799

98100
menu.addEventListener('click', (e) => {

web/dropdown.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,26 @@ class Dropdown {
140140
return false;
141141
}
142142

143+
/**
144+
* Is Show All selected in the dropdown
145+
* @returns TRUE => Show All is selected, FALSE => Show All is not selected
146+
*/
147+
public isShowAllSelected() {
148+
return this.optionsSelected[0];
149+
}
150+
143151
/**
144152
* Select a specific value in the dropdown.
145153
* @param value The value to select.
146154
*/
147-
public selectOption(value: string) {
155+
public selectOption(value: string, event: MouseEvent | undefined) {
148156
const optionIndex = this.options.findIndex((option) => value === option.value);
149157
if (optionIndex < 0 && (this.optionsSelected[0] || this.optionsSelected[optionIndex])) return;
150-
if (this.multipleAllowed && !this.selectMultipleWithCtrl) {
158+
if (this.multipleAllowed && !this.optionsSelected[0] && (!this.selectMultipleWithCtrl || (event && (event.ctrlKey || event.metaKey)))) {
151159
// Select the option with the specified value
152160
this.optionsSelected[optionIndex] = true;
153161
} else {
154-
for (let i = 1; i < this.optionsSelected.length; i++) {
162+
for (let i = 0; i < this.optionsSelected.length; i++) {
155163
this.optionsSelected[i] = false;
156164
}
157165
this.optionsSelected[optionIndex] = true;

web/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,8 @@ class GitGraphView {
11341134
},
11351135
{
11361136
title: 'Select in Branches Dropdown',
1137-
visible: visibility.selectInBranchesDropdown && !isSelectedInBranchesDropdown,
1138-
onClick: () => this.branchDropdown.selectOption(refName)
1137+
visible: visibility.selectInBranchesDropdown && (!isSelectedInBranchesDropdown || this.branchDropdown.isShowAllSelected()),
1138+
onClick: (e) => this.branchDropdown.selectOption(refName, e)
11391139
},
11401140
{
11411141
title: 'Unselect in Branches Dropdown',
@@ -1373,7 +1373,7 @@ class GitGraphView {
13731373
{
13741374
title: 'Select in Branches Dropdown',
13751375
visible: visibility.selectInBranchesDropdown && !isSelectedInBranchesDropdown,
1376-
onClick: () => this.branchDropdown.selectOption(prefixedRefName)
1376+
onClick: (e) => this.branchDropdown.selectOption(prefixedRefName, e)
13771377
},
13781378
{
13791379
title: 'Unselect in Branches Dropdown',

0 commit comments

Comments
 (0)