Move createTitle() from keyboard mixin into service
Google-Bug-Id: b/199305453
Change-Id: I2c5b014dd782fb6fb1bf16e08909c594c1f125a9
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
index 3396e13..0400030 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
@@ -48,6 +48,7 @@
import {
KeyboardShortcutMixin,
Shortcut,
+ ShortcutSection,
} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {GrEditConstants} from '../../edit/gr-edit-constants';
import {pluralize} from '../../../utils/string-util';
@@ -563,6 +564,8 @@
private readonly commentsService = appContext.commentsService;
+ private readonly shortcuts = appContext.shortcutsService;
+
private replyDialogResizeObserver?: ResizeObserver;
override keyboardShortcuts() {
@@ -2644,6 +2647,10 @@
'#relatedChanges'
);
}
+
+ createTitle(shortcutName: Shortcut, section: ShortcutSection) {
+ return this.shortcuts.createTitle(shortcutName, section);
+ }
}
declare global {
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
index bdc6a43..8aef3c0 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
@@ -44,7 +44,12 @@
import {DiffViewMode} from '../../../constants/constants';
import {GrButton} from '../../shared/gr-button/gr-button';
import {fireEvent} from '../../../utils/event-util';
-import {KeyboardShortcutMixin} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
+import {
+ KeyboardShortcutMixin,
+ Shortcut,
+ ShortcutSection,
+} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
+import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -144,6 +149,8 @@
@property({type: Object})
revisionInfo?: RevisionInfo;
+ private readonly shortcuts = appContext.shortcutsService;
+
setDiffViewMode(mode: DiffViewMode) {
this.$.modeSelect.setMode(mode);
}
@@ -217,4 +224,8 @@
}
return 'patchInfoOldPatchSet';
}
+
+ createTitle(shortcutName: Shortcut, section: ShortcutSection) {
+ return this.shortcuts.createTitle(shortcutName, section);
+ }
}
diff --git a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.ts b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.ts
index fdd7c79..cd79bba 100644
--- a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.ts
+++ b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list.ts
@@ -257,6 +257,8 @@
private readonly reporting = appContext.reportingService;
+ private readonly shortcuts = appContext.shortcutsService;
+
scrollToMessage(messageID: string) {
const selector = `[data-message-id="${messageID}"]`;
const el = this.shadowRoot!.querySelector(selector) as
@@ -384,13 +386,13 @@
_computeExpandAllTitle(_expandAllState?: string) {
if (_expandAllState === ExpandAllState.COLLAPSE_ALL) {
- return this.createTitle(
+ return this.shortcuts.createTitle(
Shortcut.COLLAPSE_ALL_MESSAGES,
ShortcutSection.ACTIONS
);
}
if (_expandAllState === ExpandAllState.EXPAND_ALL) {
- return this.createTitle(
+ return this.shortcuts.createTitle(
Shortcut.EXPAND_ALL_MESSAGES,
ShortcutSection.ACTIONS
);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
index bb5ce94..978d98f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
@@ -37,6 +37,7 @@
import {
KeyboardShortcutMixin,
Shortcut,
+ ShortcutSection,
} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {
GeneratedWebLink,
@@ -341,6 +342,8 @@
private readonly commentsService = appContext.commentsService;
+ private readonly shortcuts = appContext.shortcutsService;
+
_throttledToggleFileReviewed?: EventListener;
_onRenderHandler?: EventListener;
@@ -1898,6 +1901,10 @@
_computeTruncatedPath(path?: string) {
return path ? computeTruncatedPath(path) : '';
}
+
+ createTitle(shortcutName: Shortcut, section: ShortcutSection) {
+ return this.shortcuts.createTitle(shortcutName, section);
+ }
}
declare global {
diff --git a/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.ts b/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.ts
index 5069ba4..a23621e 100644
--- a/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.ts
+++ b/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.ts
@@ -21,6 +21,11 @@
import {customElement, property} from '@polymer/decorators';
import {ChangeInfo} from '../../../types/common';
import {fireAlert} from '../../../utils/event-util';
+import {
+ Shortcut,
+ ShortcutSection,
+} from '../../../services/shortcuts/shortcuts-config';
+import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -48,6 +53,8 @@
@property({type: Object, notify: true})
change?: ChangeInfo;
+ private readonly shortcuts = appContext.shortcutsService;
+
_computeStarClass(starred?: boolean) {
return starred ? 'active' : '';
}
@@ -83,4 +90,8 @@
})
);
}
+
+ createTitle(shortcutName: Shortcut, section: ShortcutSection) {
+ return this.shortcuts.createTitle(shortcutName, section);
+ }
}
diff --git a/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts b/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
index 111d112..3ea612e 100644
--- a/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
+++ b/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
@@ -251,12 +251,6 @@
this.shortcuts.bindShortcut(shortcut, ...bindings);
}
- createTitle(shortcutName: Shortcut, section: ShortcutSection) {
- const desc = this.shortcuts.getDescription(section, shortcutName);
- const shortcut = this.shortcuts.getShortcut(shortcutName);
- return desc && shortcut ? `${desc} (shortcut: ${shortcut})` : '';
- }
-
_addOwnKeyBindings(shortcut: Shortcut, handler: string) {
const bindings = this.shortcuts.getBindingsForShortcut(shortcut);
if (!bindings) {
@@ -494,7 +488,6 @@
/** The interface corresponding to KeyboardShortcutMixin */
export interface KeyboardShortcutMixinInterface {
keyboardShortcuts(): {[key: string]: string | null};
- createTitle(name: Shortcut, section: ShortcutSection): string;
bindShortcut(shortcut: Shortcut, ...bindings: string[]): void;
shouldSuppressKeyboardShortcut(event: CustomKeyboardEvent): boolean;
modifierPressed(event: CustomKeyboardEvent): boolean;
diff --git a/polygerrit-ui/app/services/shortcuts/shortcuts-service.ts b/polygerrit-ui/app/services/shortcuts/shortcuts-service.ts
index 964fd7d..222ebcf 100644
--- a/polygerrit-ui/app/services/shortcuts/shortcuts-service.ts
+++ b/polygerrit-ui/app/services/shortcuts/shortcuts-service.ts
@@ -54,6 +54,12 @@
private readonly listeners = new Set<ShortcutListener>();
+ createTitle(shortcutName: Shortcut, section: ShortcutSection) {
+ const desc = this.getDescription(section, shortcutName);
+ const shortcut = this.getShortcut(shortcutName);
+ return desc && shortcut ? `${desc} (shortcut: ${shortcut})` : '';
+ }
+
bindShortcut(shortcut: Shortcut, ...bindings: string[]) {
this.bindings.set(shortcut, bindings);
}