Skip to content

Adding ability to view/copy modtype id using mods panel widget #17638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/extensions/gamemode_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import * as Redux from 'redux';
import * as semver from 'semver';
import React from 'react';

import { clipboard } from 'electron';

const gameStoreLaunchers: IGameStore[] = [];

const $ = local<{
Expand Down Expand Up @@ -470,6 +472,17 @@ function genModTypeAttribute(api: IExtensionApi): ITableAttribute<IModWithState>
};
});
};

const copyToClipboard = (value: string) => {
if (value) {
clipboard.writeText(value);
api.sendNotification({
type: 'success',
message: api.translate('Copied mod type id to clipboard'),
displayMS: 2000,
});
}
};

const modTypeCalc = (mods: IModWithState | IModWithState[]) => {
const mod: IModWithState = Array.isArray(mods) ? mods[0] : mods;
Expand All @@ -489,7 +502,7 @@ function genModTypeAttribute(api: IExtensionApi): ITableAttribute<IModWithState>
calc: modTypeCalc,
customRenderer: (mods, detailCell) =>
detailCell
? React.createElement(ModTypeWidget, { mods })
? React.createElement(ModTypeWidget, { mods, copyToClipboard })
: React.createElement('span', {}, [modTypeCalc(mods)]),
cssClass: mod => (mod.type !== '')
? `mod-modtype-${mod.type}`
Expand Down
18 changes: 18 additions & 0 deletions src/extensions/gamemode_management/views/ModTypeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { useTranslation } from 'react-i18next';
import { activeGameId } from '../../profile_management/selectors';
import { midClip, truthy } from '../../../util/util';
import { util } from '../../..';
import { IconButton } from '../../../controls/TooltipControls';

export interface IModTypeWidget {
mods: IModWithState | IModWithState[];
copyToClipboard: (value: string) => void;
}

function ModTypeWidget(props: IModTypeWidget) {
Expand Down Expand Up @@ -54,6 +56,12 @@ function ModTypeWidget(props: IModTypeWidget) {
}
}, [gameMode]);

const toClipboard = React.useCallback(() => {
if (modTypeId) {
props.copyToClipboard(modTypeId);
}
}, [modTypeId, props.copyToClipboard]);

const openPath = React.useCallback(() => {
util.opn(modTypePath).catch(() => null);
}, [modTypePath]);
Expand All @@ -78,6 +86,16 @@ function ModTypeWidget(props: IModTypeWidget) {
{truthy(modTypePath)
? <div>{t('Deploys to')}&nbsp;<a onClick={openPath} title={modTypePath} className='modtype-path'>{midClip(modTypePath, 40)}</a></div>
: t('Does not deploy')}
<div>
{t('ID:')}&nbsp;<span className='modtype-id'>"{modTypeId}"</span>
&nbsp;
<IconButton
className='btn-embed'
icon='clipboard-copy'
onClick={toClipboard}
tooltip={t('Copy ID to clipboard')}
/>
</div>
</div>
);
}
Expand Down