-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement tab visibility snapshots
- Loading branch information
1 parent
be905c8
commit 58d7431
Showing
8 changed files
with
228 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Menu, MenuGroup, MenuItem, showModal } from 'decky-frontend-lib'; | ||
import { VFC, Fragment } from 'react'; | ||
import { TabMasterManager } from '../../state/TabMasterManager'; | ||
import { CreateSnapshotModal, OverwriteSnapshotModal } from '../modals/SnapshotModals'; | ||
import { gamepadContextMenuClasses } from '../../lib/GamepadContextMenuClasses'; | ||
|
||
interface SnapshotMenuProps { | ||
tabMasterManager: TabMasterManager, | ||
} | ||
|
||
export const SnapshotMenu: VFC<SnapshotMenuProps> = ({ tabMasterManager }) => { | ||
return <Menu label='Manage Tab Visibility Snapshots'> | ||
<SnapshotMenuItems tabMasterManager={tabMasterManager} /> | ||
</Menu>; | ||
}; | ||
|
||
|
||
export const SnapshotMenuItems: VFC<SnapshotMenuProps> = ({ tabMasterManager }) => { | ||
return ( | ||
<> | ||
<MenuItem onClick={() => showModal(<CreateSnapshotModal tabMasterManager={tabMasterManager} />)}> | ||
New | ||
</MenuItem> | ||
<OverwriteSnapshotMenuGroup tabMasterManager={tabMasterManager} /> | ||
<div className={gamepadContextMenuClasses.ContextMenuSeparator} /> | ||
<ApplySnapshotMenuGroup label='Apply' tabMasterManager={tabMasterManager} /> | ||
</> | ||
); | ||
}; | ||
|
||
export const OverwriteSnapshotMenuGroup: VFC<SnapshotMenuProps> = ({ tabMasterManager }) => { | ||
|
||
return ( | ||
<MenuGroup label='Overwrite'> | ||
{Object.keys(tabMasterManager.snapshotManager?.snapshots ?? {}).map(snapshotName => { | ||
return ( | ||
<MenuItem onClick={() => showModal(<OverwriteSnapshotModal snapshotName={snapshotName} tabMasterManager={tabMasterManager} />)}> | ||
{snapshotName} | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuGroup> | ||
); | ||
}; | ||
|
||
interface ApplySnapshotMenuGroupProps extends SnapshotMenuProps { | ||
label: string; | ||
} | ||
|
||
export const ApplySnapshotMenuGroup: VFC<ApplySnapshotMenuGroupProps> = ({ label, tabMasterManager }) => { | ||
|
||
return ( | ||
<MenuGroup label={label}> | ||
{Object.keys(tabMasterManager.snapshotManager?.snapshots ?? {}).map(snapshotName => { | ||
return ( | ||
<MenuItem onClick={() => tabMasterManager.snapshotManager?.apply(snapshotName, tabMasterManager)}> | ||
{snapshotName} | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuGroup> | ||
); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ConfirmModal, TextField } from 'decky-frontend-lib'; | ||
import { VFC, useState } from 'react'; | ||
import { TabMasterManager } from '../../state/TabMasterManager'; | ||
|
||
export interface CreateSnapshotModalProps { | ||
tabMasterManager: TabMasterManager, | ||
closeModal?: () => void, | ||
} | ||
|
||
export const CreateSnapshotModal: VFC<CreateSnapshotModalProps> = ({ tabMasterManager, closeModal }) => { | ||
const [name, setName] = useState<string>(''); | ||
const visibleTabs = tabMasterManager.getTabs().visibleTabsList; | ||
|
||
return ( | ||
<ConfirmModal | ||
onOK={() => { | ||
tabMasterManager.snapshotManager?.write(name, visibleTabs.map(tabContainer => tabContainer.id)); | ||
closeModal!(); | ||
}} | ||
onCancel={() => closeModal!()} | ||
> | ||
<TextField value={name} placeholder="The name for this snapshot" onChange={e => setName(e?.target.value)} /> | ||
{visibleTabs.map(tabContainer => <div>{tabContainer.title}</div>)} | ||
</ConfirmModal> | ||
); | ||
}; | ||
|
||
export interface OverwriteSnapshotModalProps extends CreateSnapshotModalProps { | ||
snapshotName: string; | ||
} | ||
|
||
export const OverwriteSnapshotModal: VFC<OverwriteSnapshotModalProps> = ({ snapshotName, tabMasterManager, closeModal }) => { | ||
const { visibleTabsList, tabsMap } = tabMasterManager.getTabs(); | ||
const existingTabs = tabMasterManager.snapshotManager!.snapshots[snapshotName].map(tabId => tabsMap.get(tabId)); | ||
|
||
return ( | ||
<ConfirmModal | ||
onOK={() => { | ||
tabMasterManager.snapshotManager?.write(snapshotName, visibleTabsList.map(tabContainer => tabContainer.id)); | ||
closeModal!(); | ||
}} | ||
onCancel={() => closeModal!()} | ||
> | ||
<div style={{ display: 'flex', flexDirection: 'row' }}> | ||
<div> | ||
New Tabs: | ||
{visibleTabsList.map(tabContainer => <div>{tabContainer.title}</div>)} | ||
</div> | ||
<div> | ||
Existing Tabs: | ||
{existingTabs.map(tabContainer => <div>{tabContainer?.title}</div>)} | ||
</div> | ||
</div> | ||
</ConfirmModal> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { PythonInterop } from '../lib/controllers/PythonInterop'; | ||
import { TabMasterManager } from './TabMasterManager'; | ||
|
||
export type SnapshotDictionary = { | ||
[name: string]: string[]; //array of ordered tab ids | ||
}; | ||
|
||
export class SnapshotManager { | ||
snapshots: SnapshotDictionary; | ||
|
||
constructor(snapshots: SnapshotDictionary) { | ||
this.snapshots = snapshots; | ||
} | ||
|
||
write(snapshotName: string, tabIds: string[]) { | ||
this.snapshots[snapshotName] = tabIds; | ||
this.save(); | ||
} | ||
|
||
|
||
apply(snapshotName: string, tabMasterManager: TabMasterManager) { | ||
tabMasterManager.getTabs().tabsMap.forEach(tabContainer => tabContainer.position = -1); | ||
tabMasterManager.reorderTabs(this.snapshots[snapshotName]); | ||
} | ||
|
||
private save() { | ||
PythonInterop.setSnapshots(this.snapshots); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters