-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactored groups to profiles
- Loading branch information
1 parent
4bedc05
commit 2ffe928
Showing
12 changed files
with
310 additions
and
208 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
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
import { Menu, MenuGroup, MenuItem, showModal } from 'decky-frontend-lib'; | ||
import { VFC, Fragment } from 'react'; | ||
import { TabMasterManager } from '../../state/TabMasterManager'; | ||
import { CreateTabProfileModal, OverwriteTabProfileModal } from '../modals/TabProfileModals'; | ||
|
||
interface TabsProfilesMenuProps { | ||
tabMasterManager: TabMasterManager, | ||
} | ||
|
||
/** | ||
* Context menu for managing Tab Profiles. | ||
*/ | ||
export const TabProfilesMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => { | ||
return <Menu label='Manage Tab Groups'> | ||
<TabProfileMenuItems tabMasterManager={tabMasterManager} /> | ||
</Menu>; | ||
}; | ||
|
||
/** | ||
* Context menu sub-menu for managing Tab Profiles. | ||
*/ | ||
export const TabProfilesSubMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => { | ||
return <MenuGroup label='Manage Tab Groups'> | ||
<TabProfileMenuItems tabMasterManager={tabMasterManager} /> | ||
</MenuGroup>; | ||
}; | ||
|
||
/** | ||
* Menu items for the Tab Profiles context menu. | ||
*/ | ||
const TabProfileMenuItems: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => { | ||
return ( | ||
<> | ||
<MenuItem onClick={() => showModal(<CreateTabProfileModal tabMasterManager={tabMasterManager} />)}> | ||
Create Profile | ||
</MenuItem> | ||
<OverwriteTabProfileMenu tabMasterManager={tabMasterManager} /> | ||
{/* <div className={gamepadContextMenuClasses.ContextMenuSeparator} /> */} | ||
<ApplyTabProfile tabMasterManager={tabMasterManager} /> | ||
</> | ||
); | ||
}; | ||
|
||
/** | ||
* The overwrite menu for Tab Profiles. | ||
*/ | ||
const OverwriteTabProfileMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => { | ||
return ( | ||
<MenuGroup label='Overwrite Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}> | ||
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => { | ||
return ( | ||
<MenuItem onClick={() => showModal(<OverwriteTabProfileModal profileName={snapshotName} tabMasterManager={tabMasterManager} />)}> | ||
{snapshotName} | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuGroup> | ||
); | ||
}; | ||
|
||
/** | ||
* The apply menu for Tab Profiles. | ||
*/ | ||
const ApplyTabProfile: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => { | ||
return ( | ||
<MenuGroup label='Apply Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}> | ||
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => { | ||
return ( | ||
<MenuItem onClick={() => tabMasterManager.tabProfileManager?.apply(snapshotName, tabMasterManager)}> | ||
{snapshotName} | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuGroup> | ||
); | ||
}; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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,103 @@ | ||
import { ConfirmModal, Field, TextField, afterPatch, quickAccessControlsClasses } from 'decky-frontend-lib'; | ||
import { VFC, useEffect, useState, Fragment } from 'react'; | ||
import { TabMasterManager } from '../../state/TabMasterManager'; | ||
import { TabMasterContextProvider } from "../../state/TabMasterContext"; | ||
import { TabProfileModalStyles } from "../styles/TabProfileModalStyles"; | ||
|
||
export interface CreateTabProfileModalProps { | ||
tabMasterManager: TabMasterManager, | ||
closeModal?: () => void, | ||
} | ||
|
||
export const CreateTabProfileModal: VFC<CreateTabProfileModalProps> = ({ tabMasterManager, closeModal }) => { | ||
const [name, setName] = useState<string>(''); | ||
const visibleTabs = tabMasterManager.getTabs().visibleTabsList; | ||
const [patchInput, setPatchInput] = useState<boolean>(true); | ||
|
||
const nameInputElement = <TextField value={name} placeholder="The name of this tab profile" onChange={onNameChange} />; | ||
|
||
//reference to input field class component instance, which has a focus method | ||
let inputComponentInstance: any; | ||
|
||
if (patchInput) { | ||
afterPatch(nameInputElement.type.prototype, 'render', function (_: any, ret: any) { | ||
//@ts-ignore get reference to instance | ||
inputComponentInstance = this; | ||
return ret; | ||
}, { singleShot: true }); | ||
} | ||
|
||
useEffect(() => { | ||
inputComponentInstance.Focus(); | ||
setPatchInput(false); | ||
}, []); | ||
|
||
function onNameChange(e: React.ChangeEvent<HTMLInputElement>) { | ||
setName(e?.target.value); | ||
} | ||
|
||
return ( | ||
<TabMasterContextProvider tabMasterManager={tabMasterManager}> | ||
<TabProfileModalStyles /> | ||
<div className="tab-master-tab-profile-modal-scope"> | ||
<ConfirmModal | ||
strTitle={"Create New Tab Profile"} | ||
onOK={() => { | ||
tabMasterManager.tabProfileManager?.write(name, visibleTabs.map(tabContainer => tabContainer.id)); | ||
closeModal!(); | ||
}} | ||
onCancel={() => closeModal!()} | ||
> | ||
<div style={{ padding: "4px 16px 1px" }} className="name-field"> | ||
<Field description={ | ||
<> | ||
<div style={{ paddingBottom: "6px" }} className={quickAccessControlsClasses.PanelSectionTitle}> | ||
Profile Name | ||
</div> | ||
{nameInputElement} | ||
</> | ||
} /> | ||
</div> | ||
{visibleTabs.map(tabContainer => <div>{tabContainer.title}</div>)} | ||
</ConfirmModal> | ||
</div> | ||
</TabMasterContextProvider> | ||
); | ||
}; | ||
|
||
export interface OverwriteTabProfileModalProps extends CreateTabProfileModalProps { | ||
profileName: string; | ||
} | ||
|
||
export const OverwriteTabProfileModal: VFC<OverwriteTabProfileModalProps> = ({ profileName, tabMasterManager, closeModal }) => { | ||
const { visibleTabsList, tabsMap } = tabMasterManager.getTabs(); | ||
const existingTabs = tabMasterManager.tabProfileManager!.tabProfiles[profileName].map(tabId => tabsMap.get(tabId)); | ||
|
||
return ( | ||
<TabMasterContextProvider tabMasterManager={tabMasterManager}> | ||
<TabProfileModalStyles /> | ||
<div className="tab-master-tab-profile-modal-scope"> | ||
<ConfirmModal | ||
strTitle={`Overwriting Profile: ${profileName}`} | ||
onOK={() => { | ||
tabMasterManager.tabProfileManager?.write(profileName, 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> | ||
</div> | ||
</TabMasterContextProvider> | ||
); | ||
}; | ||
|
Oops, something went wrong.