Skip to content

Commit

Permalink
feat: reset layout button (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimberlee Johnson authored Apr 30, 2020
1 parent f31a4e3 commit 0f85444
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/renderer/components/commands-editors.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Menu, MenuItem, Popover, Position } from '@blueprintjs/core';
import { Button, Menu, MenuDivider, MenuItem, Popover, Position } from '@blueprintjs/core';
import { observer } from 'mobx-react';
import * as React from 'react';

Expand Down Expand Up @@ -82,6 +82,18 @@ export class EditorDropdown extends React.Component<EditorDropdownProps, EditorD
);
}

result.push(
<React.Fragment key={'fragment-reset-layout'}>
<MenuDivider />
<MenuItem
icon='grid-view'
key='reset-layout'
text='Reset Layout'
onClick={appState.resetEditorLayout}
/>
</React.Fragment>
);

return result;
}

Expand Down
11 changes: 10 additions & 1 deletion src/renderer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class AppState {
this.toggleSettings = this.toggleSettings.bind(this);
this.toggleBisectDialog = this.toggleBisectDialog.bind(this);
this.updateElectronVersions = this.updateElectronVersions.bind(this);
this.resetEditorLayout = this.resetEditorLayout.bind(this);

ipcRendererManager.removeAllListeners(IpcEvents.OPEN_SETTINGS);
ipcRendererManager.removeAllListeners(IpcEvents.SHOW_WELCOME_TOUR);
Expand Down Expand Up @@ -539,7 +540,6 @@ export class AppState {
this.outputBuffer += strData;
strData = this.outputBuffer;
const parts = strData.split('\r\n');

for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
const part = parts[partIndex];
if (partIndex === parts.length - 1) {
Expand Down Expand Up @@ -635,6 +635,15 @@ export class AppState {
this.setVisibleMosaics([...currentlyVisible, id]);
}

/**
* Resets editor view to default layout
*
*
*/
@action public resetEditorLayout() {
this.mosaicArrangement = DEFAULT_MOSAIC_ARRANGEMENT;
}

/**
* Resets the view, optionally with certain view flags enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ Array [
shouldDismissPopover={true}
text="Stylesheet (styles.css)"
/>,
<React.Fragment>
<Blueprint3.MenuDivider />
<Blueprint3.MenuItem
disabled={false}
icon="grid-view"
multiline={false}
popoverProps={Object {}}
shouldDismissPopover={true}
text="Reset Layout"
/>
</React.Fragment>,
]
`;

Expand Down Expand Up @@ -112,6 +123,17 @@ exports[`EditorDropdown component renders 1`] = `
shouldDismissPopover={true}
text="Stylesheet (styles.css)"
/>
<React.Fragment>
<Blueprint3.MenuDivider />
<Blueprint3.MenuItem
disabled={false}
icon="grid-view"
multiline={false}
popoverProps={Object {}}
shouldDismissPopover={true}
text="Reset Layout"
/>
</React.Fragment>
</Blueprint3.Menu>
}
defaultIsOpen={false}
Expand Down Expand Up @@ -203,6 +225,17 @@ exports[`EditorDropdown component renders the extra button if the FIDDLE_DOCS_DE
shouldDismissPopover={true}
text="Stylesheet (styles.css)"
/>
<React.Fragment>
<Blueprint3.MenuDivider />
<Blueprint3.MenuItem
disabled={false}
icon="grid-view"
multiline={false}
popoverProps={Object {}}
shouldDismissPopover={true}
text="Reset Layout"
/>
</React.Fragment>
</Blueprint3.Menu>
}
defaultIsOpen={false}
Expand Down
16 changes: 16 additions & 0 deletions tests/renderer/state-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,20 @@ describe('AppState', () => {
});
});
});

describe('resetEditorLayout()', () => {
it('Puts editors in default arrangement', () => {
appState.hideAndBackupMosaic(EditorId.main);

expect(appState.mosaicArrangement).toEqual({
direction: 'row',
first: EditorId.renderer,
second: EditorId.html
});

appState.resetEditorLayout();

expect(appState.mosaicArrangement).toEqual(DEFAULT_MOSAIC_ARRANGEMENT);
});
});
});

0 comments on commit 0f85444

Please sign in to comment.