Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: add shortcut to switch pages (#558)
Browse files Browse the repository at this point in the history
* feat(menu): add shortcut to switch pages

* fix(menu): typo

* fix(menu): disable previous shortcut on first page

* fix(menu): disable next shortcut on last page

* fix(store): alphabetize new functions

* fix(store): introduce getNextPage and getPreviousPage

* fix(store): remove unneeded functions

* fix(store): alphabetize functions

* fix(menu): fix variable name
  • Loading branch information
markusoelhafen authored and marionebl committed Jun 14, 2018
1 parent 9ff88e9 commit 76e4b8d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/electron/create-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,30 @@ export function createMenu(ctx: MenuContext): void {
{
type: 'separator'
},
{
label: 'Previous Page',
accelerator: 'CmdOrCtrl+Alt+Left',
enabled: typeof ctx.store.getPreviousPage() !== 'undefined',
click: () => {
const previousPage = ctx.store.getPreviousPage();

if (previousPage) {
ctx.store.setActivePage(previousPage);
}
}
},
{
label: 'Next Page',
accelerator: 'CmdOrCtrl+Alt+Right',
enabled: typeof ctx.store.getNextPage() !== 'undefined',
click: () => {
const nextPage = ctx.store.getNextPage();

if (nextPage) {
ctx.store.setActivePage(nextPage);
}
}
},
{
label: '&Show Elements & Components',
type: 'checkbox',
Expand Down
34 changes: 34 additions & 0 deletions src/store/view-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,23 @@ export class ViewStore {
return this.project.getElements().find(e => e.getNameEditable());
}

@Mobx.action
public getNextPage(): Model.Page | undefined {
const page = this.getCurrentPage();

if (!page) {
return;
}

const index = this.project.getPageIndex(page);

if (typeof index !== 'number') {
return;
}

return this.project.getPages()[index + 1];
}

public getPageById(id: string): Model.Page | undefined {
const project = this.getProject();

Expand Down Expand Up @@ -678,6 +695,23 @@ export class ViewStore {
return this.app.getSearchTerm();
}

@Mobx.action
public getPreviousPage(): Model.Page | undefined {
const page = this.getCurrentPage();

if (!page) {
return;
}

const index = this.project.getPageIndex(page);

if (typeof index !== 'number') {
return;
}

return this.project.getPages()[index - 1];
}

public getProject(): Model.Project {
return this.project;
}
Expand Down

0 comments on commit 76e4b8d

Please sign in to comment.