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

Commit

Permalink
fix(menu): rename open-styleguide item, no hard-coded page ID
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReincarnator committed Dec 15, 2017
1 parent 6281d51 commit 2be9a05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/component/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import globalStyles from '../lsg/patterns/global-styles';
import { IconName, IconRegistry } from '../lsg/patterns/icons';
import { JsonObject } from '../store/json';
import Layout, { MainArea, SideBar } from '../lsg/patterns/layout';
import { createMenu } from './menu';
import { createMenu } from '../electron/menu';
import * as MobX from 'mobx';
import { observer } from 'mobx-react';
import DevTools from 'mobx-react-devtools';
Expand Down
2 changes: 1 addition & 1 deletion src/component/container/element_list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ElementWrapper } from './elementWrapper';
import { ListItemProps } from '../../lsg/patterns/list';
import { createMenu } from '../menu';
import { createMenu } from '../../electron/menu';
import { observer } from 'mobx-react';
import { Page } from '../../store/page';
import { PageElement } from '../../store/page/page_element';
Expand Down
7 changes: 5 additions & 2 deletions src/component/menu.ts → src/electron/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ export function createMenu(store: Store): void {
label: '&File',
submenu: [
{
label: '&Open Project',
label: '&Open Styleguide',
accelerator: 'CmdOrCtrl+O',
click: () => {
dialog.showOpenDialog({ properties: ['openDirectory'] }, filePaths => {
store.openStyleguide(filePaths[0]);
store.openPage('homepage');
store.openFirstPage();
});
}
},
{
type: 'separator'
},
{
label: 'New &Page',
accelerator: 'CmdOrCtrl+N'
Expand Down
13 changes: 13 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ export class Store {
});
}

public openFirstPage(): void {
if (!this.projects.length) {
return;
}

const pages: PageRef[] = this.projects[0].getPages();
if (!pages.length) {
return;
}

this.openPage(pages[0].getId());
}

public openPage(id: string): void {
MobX.transaction(() => {
const pagePath: string = PathUtils.join(this.getPagesPath(), `page-${id}.yaml`);
Expand Down

0 comments on commit 2be9a05

Please sign in to comment.