feat: make layouts togglable

This commit is contained in:
Mikhail Zolotukhin 2021-11-01 13:41:35 +03:00
parent a9f16cb3b5
commit 8ebffbe639
5 changed files with 32 additions and 37 deletions

View File

@ -355,7 +355,7 @@ describe("action", () => {
fakeEngine = createMock<Engine>({
cycleLayout: jest.fn(),
setLayout: jest.fn(),
toggleLayout: jest.fn(),
currentWindow: jest.fn().mockReturnValue(fakeCurrentWindow),
});
});
@ -382,11 +382,11 @@ describe("action", () => {
describe("set layout", () => {
it("executes correctly when asking to set Monocle Layout", () => {
const action = new Action.SetMonocleLayout(fakeEngine, fakeLog);
const action = new Action.ToggleMonocleLayout(fakeEngine, fakeLog);
action.execute();
expect(fakeEngine.setLayout).toBeCalledWith("MonocleLayout");
expect(fakeEngine.toggleLayout).toBeCalledWith("MonocleLayout");
});
});
});

View File

@ -452,7 +452,7 @@ export class SwitchToPreviousLayout extends ActionImpl implements Action {
}
}
abstract class SetCurrentLayout extends ActionImpl implements Action {
abstract class ToggleCurrentLayout extends ActionImpl implements Action {
constructor(
protected engine: Engine,
protected layoutId: string,
@ -465,11 +465,11 @@ abstract class SetCurrentLayout extends ActionImpl implements Action {
}
public executeWithoutLayoutOverride(): void {
this.engine.setLayout(this.layoutId);
this.engine.toggleLayout(this.layoutId);
}
}
export class SetTileLayout extends SetCurrentLayout {
export class ToggleTileLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
@ -482,7 +482,7 @@ export class SetTileLayout extends SetCurrentLayout {
}
}
export class SetMonocleLayout extends SetCurrentLayout {
export class ToggleMonocleLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
@ -495,7 +495,7 @@ export class SetMonocleLayout extends SetCurrentLayout {
}
}
export class SetThreeColumnLayout extends SetCurrentLayout {
export class ToggleThreeColumnLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
@ -508,7 +508,7 @@ export class SetThreeColumnLayout extends SetCurrentLayout {
}
}
export class SetSpreadLayout extends SetCurrentLayout {
export class ToggleSpreadLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
@ -521,7 +521,7 @@ export class SetSpreadLayout extends SetCurrentLayout {
}
}
export class SetStairLayout extends SetCurrentLayout {
export class ToggleStairLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
@ -534,7 +534,7 @@ export class SetStairLayout extends SetCurrentLayout {
}
}
export class SetFloatingLayout extends SetCurrentLayout {
export class ToggleFloatingLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
// NOTE: space is intentional (Temporary)
super(
@ -548,7 +548,7 @@ export class SetFloatingLayout extends SetCurrentLayout {
}
}
export class SetQuarterLayout extends SetCurrentLayout {
export class ToggleQuarterLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,

View File

@ -403,13 +403,13 @@ export class ControllerImpl implements Controller {
new Action.SwitchToNextLayout(this.engine, this.log),
new Action.SwitchToPreviousLayout(this.engine, this.log),
new Action.SetTileLayout(this.engine, this.log),
new Action.SetMonocleLayout(this.engine, this.log),
new Action.SetThreeColumnLayout(this.engine, this.log),
new Action.SetStairLayout(this.engine, this.log),
new Action.SetSpreadLayout(this.engine, this.log),
new Action.SetFloatingLayout(this.engine, this.log),
new Action.SetQuarterLayout(this.engine, this.log),
new Action.ToggleTileLayout(this.engine, this.log),
new Action.ToggleMonocleLayout(this.engine, this.log),
new Action.ToggleThreeColumnLayout(this.engine, this.log),
new Action.ToggleStairLayout(this.engine, this.log),
new Action.ToggleSpreadLayout(this.engine, this.log),
new Action.ToggleFloatingLayout(this.engine, this.log),
new Action.ToggleQuarterLayout(this.engine, this.log),
new Action.Rotate(this.engine, this.log),
new Action.RotatePart(this.engine, this.log),

View File

@ -146,7 +146,7 @@ export interface Engine {
/**
* Set the layout of the current surface to the specified layout.
*/
setLayout(layoutClassID: string): void;
toggleLayout(layoutClassID: string): void;
/**
* Minimize all windows on the surface except the given window.
@ -584,8 +584,8 @@ export class EngineImpl implements Engine {
}
}
public setLayout(layoutClassID: string): void {
const layout = this.layouts.setLayout(
public toggleLayout(layoutClassID: string): void {
const layout = this.layouts.toggleLayout(
this.controller.currentSurface,
layoutClassID
);

View File

@ -45,16 +45,14 @@ export class LayoutStoreEntry {
return this.loadLayout(this.currentID);
}
public setLayout(targetID: string): WindowsLayout {
public toggleLayout(targetID: string): WindowsLayout {
const targetLayout = this.loadLayout(targetID);
if (
targetLayout instanceof MonocleLayout &&
this.currentLayout instanceof MonocleLayout
) {
/* toggle Monocle "OFF" */
// Toggle if requested, set otherwise
if (this.currentID === targetID) {
this.currentID = this.previousID;
this.previousID = targetID;
} else if (this.currentID !== targetID) {
} else {
this.previousID = this.currentID;
this.currentID = targetID;
}
@ -80,10 +78,7 @@ export class LayoutStoreEntry {
export default class LayoutStore {
private store: { [key: string]: LayoutStoreEntry };
private config: Config;
constructor(config: Config) {
this.config = config;
constructor(private config: Config) {
this.store = {};
}
@ -100,14 +95,14 @@ export default class LayoutStore {
return this.getEntry(srf.id).cycleLayout(step);
}
public setLayout(
srf: DriverSurface,
public toggleLayout(
surf: DriverSurface,
layoutClassID: string
): WindowsLayout | null {
if (srf.ignore) {
if (surf.ignore) {
return null;
}
return this.getEntry(srf.id).setLayout(layoutClassID);
return this.getEntry(surf.id).toggleLayout(layoutClassID);
}
private getEntry(key: string): LayoutStoreEntry {