Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: introduction of tstogglebutton

Ilian Sapundshievac7258731250
diff --git a/src/renderer/components/EditSearchQuery.tsx b/src/renderer/components/EditSearchQuery.tsx
index 819351737..3f6165074 100644
--- a/src/renderer/components/EditSearchQuery.tsx
+++ b/src/renderer/components/EditSearchQuery.tsx
@@ -35,8 +35,10 @@ import {
import TagsSelect from '-/components/TagsSelect';
import TooltipTS from '-/components/Tooltip';
import TsDatePicker from '-/components/TsDatePicker';
+import TsIconButton from '-/components/TsIconButton';
import TsSelect from '-/components/TsSelect';
import TsTextField from '-/components/TsTextField';
+import TsToggleButton from '-/components/TsToggleButton';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
import { useSearchQueryContext } from '-/hooks/useSearchQueryContext';
import { isDesktopMode } from '-/reducers/settings';
@@ -46,7 +48,6 @@ import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import InputAdornment from '@mui/material/InputAdornment';
import MenuItem from '@mui/material/MenuItem';
-import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import Typography from '@mui/material/Typography';
import { LocalizationProvider } from '@mui/x-date-pickers';
@@ -55,7 +56,6 @@ import { formatFileSize } from '@tagspaces/tagspaces-common/misc';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
-import TsIconButton from './TsIconButton';
interface Props {
executeSearchOnEnter?: boolean;
@@ -239,21 +239,35 @@ function EditSearchQuery(props: Props) {
style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.searchBoxing}
>
- <ToggleButton value="location">
- <TooltipTS title={t('searchPlaceholder')}>
- <div>{t('location')}</div>
- </TooltipTS>
- </ToggleButton>
- <ToggleButton value="folder">
- <TooltipTS title={t('searchCurrentFolderWithSubFolders')}>
- <div>{t('folder')}</div>
- </TooltipTS>
- </ToggleButton>
- <ToggleButton value="global">
- <TooltipTS title={t('searchInAllLocationTooltip')}>
- <div>{t('globalSearch')}</div>
- </TooltipTS>
- </ToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopRightRadius: 0,
+ borderBottomRightRadius: 0,
+ }}
+ tooltip={t('searchPlaceholder')}
+ value="location"
+ >
+ {t('location')}
+ </TsToggleButton>
+ <TsToggleButton
+ style={{
+ borderRadius: 0,
+ }}
+ tooltip={t('searchCurrentFolderWithSubFolders')}
+ value="folder"
+ >
+ {t('folder')}
+ </TsToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopLeftRadius: 0,
+ borderBottomLeftRadius: 0,
+ }}
+ tooltip={t('searchInAllLocationTooltip')}
+ value="global"
+ >
+ {t('globalSearch')}
+ </TsToggleButton>
</ToggleButtonGroup>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
@@ -264,21 +278,38 @@ function EditSearchQuery(props: Props) {
style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.searchType}
>
- <ToggleButton value="fuzzy" data-tid="fuzzySearchTID">
- <TooltipTS title={t('searchTypeFuzzyTooltip')}>
- <div>{t('searchTypeFuzzy')}</div>
- </TooltipTS>
- </ToggleButton>
- <ToggleButton value="semistrict" data-tid="semiStrictSearchTID">
- <TooltipTS title={t('searchTypeSemiStrictTooltip')}>
- <div>{t('searchTypeSemiStrict')}</div>
- </TooltipTS>
- </ToggleButton>
- <ToggleButton value="strict" data-tid="strictSearchTID">
- <TooltipTS title={t('searchTypeStrictTooltip')}>
- <div>{t('searchTypeStrict')}</div>
- </TooltipTS>
- </ToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopRightRadius: 0,
+ borderBottomRightRadius: 0,
+ }}
+ tooltip={t('searchTypeFuzzyTooltip')}
+ value="fuzzy"
+ data-tid="fuzzySearchTID"
+ >
+ {t('searchTypeFuzzy')}
+ </TsToggleButton>
+ <TsToggleButton
+ style={{
+ borderRadius: 0,
+ }}
+ tooltip={t('searchTypeSemiStrictTooltip')}
+ value="semistrict"
+ data-tid="semiStrictSearchTID"
+ >
+ {t('searchTypeSemiStrict')}
+ </TsToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopLeftRadius: 0,
+ borderBottomLeftRadius: 0,
+ }}
+ tooltip={t('searchTypeStrictTooltip')}
+ value="strict"
+ data-tid="strictSearchTID"
+ >
+ {t('searchTypeStrict')}
+ </TsToggleButton>
</ToggleButtonGroup>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
@@ -293,16 +324,27 @@ function EditSearchQuery(props: Props) {
style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.forceIndexing}
>
- <ToggleButton value={false}>
- <TooltipTS title={t('useCurrentIndexTooltip')}>
- <div>{t('useCurrentIndex')}</div>
- </TooltipTS>
- </ToggleButton>
- <ToggleButton value={true} data-tid="forceIndexingTID">
- <TooltipTS title={t('forceReindexTooltip')}>
- <div>{t('forceReindex')}</div>
- </TooltipTS>
- </ToggleButton>
+ <TsToggleButton
+ tooltip={t('useCurrentIndexTooltip')}
+ style={{
+ borderTopRightRadius: 0,
+ borderBottomRightRadius: 0,
+ }}
+ value={false}
+ >
+ {t('useCurrentIndex')}
+ </TsToggleButton>
+ <TsToggleButton
+ tooltip={t('forceReindexTooltip')}
+ style={{
+ borderTopLeftRadius: 0,
+ borderBottomLeftRadius: 0,
+ }}
+ value={true}
+ data-tid="forceIndexingTID"
+ >
+ {t('forceReindex')}
+ </TsToggleButton>
</ToggleButtonGroup>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
diff --git a/src/renderer/components/TsToggleButton.tsx b/src/renderer/components/TsToggleButton.tsx
new file mode 100644
index 000000000..648611c7f
--- /dev/null
+++ b/src/renderer/components/TsToggleButton.tsx
@@ -0,0 +1,60 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2025-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import AppConfig from '-/AppConfig';
+import TooltipTS from '-/components/Tooltip';
+import { isDesktopMode } from '-/reducers/settings';
+import { ToggleButton } from '@mui/material';
+import { ButtonPropsVariantOverrides } from '@mui/material/Button';
+import { ToggleButtonProps } from '@mui/material/ToggleButton';
+import { OverridableStringUnion } from '@mui/types';
+import { useSelector } from 'react-redux';
+
+export type TSToggleButtonProps = ToggleButtonProps & {
+ tooltip?: string;
+ variant?: OverridableStringUnion<
+ 'text' | 'outlined' | 'contained',
+ ButtonPropsVariantOverrides
+ >;
+};
+
+function TsToggleButton(props: TSToggleButtonProps) {
+ const { children, style, tooltip, selected, ...rest } = props;
+ const desktopMode = useSelector(isDesktopMode);
+ let button = (
+ <ToggleButton
+ size={desktopMode ? 'small' : 'medium'}
+ variant="outlined" // text outlined contained
+ {...rest}
+ style={{
+ borderRadius: AppConfig.defaultCSSRadius,
+ textTransform: 'none', //'capitalize',
+ fontSize: 14,
+ // fontWeight: selected ? 'bold' : 'normal',
+ fontWeight: 'normal',
+ ...style,
+ }}
+ >
+ {children}
+ </ToggleButton>
+ );
+
+ return tooltip ? <TooltipTS title={tooltip}>{button}</TooltipTS> : button;
+}
+
+export default TsToggleButton;
diff --git a/src/renderer/components/dialogs/OnboardingDialog.tsx b/src/renderer/components/dialogs/OnboardingDialog.tsx
index a103d48d2..7d4586f11 100644
--- a/src/renderer/components/dialogs/OnboardingDialog.tsx
+++ b/src/renderer/components/dialogs/OnboardingDialog.tsx
@@ -22,6 +22,7 @@ import WizardFinished from '-/assets/images/computer-desk.svg';
import NewLook from '-/assets/images/desktop.svg';
import Organize from '-/assets/images/organize.svg';
import TsButton from '-/components/TsButton';
+import TsToggleButton from '-/components/TsToggleButton';
import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';
import { AppDispatch } from '-/reducers/app';
import {
@@ -38,7 +39,6 @@ import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
-import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
@@ -176,10 +176,25 @@ function OnboardingDialog(props: Props) {
onChange={(event, theme) => {
setCurrentTheme(theme);
}}
- style={{ boxShadow: 'none' }}
>
- <ToggleButton value="light">Light</ToggleButton>
- <ToggleButton value="dark">Dark</ToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopRightRadius: 0,
+ borderBottomRightRadius: 0,
+ }}
+ value="light"
+ >
+ Light
+ </TsToggleButton>
+ <TsToggleButton
+ style={{
+ borderTopLeftRadius: 0,
+ borderBottomLeftRadius: 0,
+ }}
+ value="dark"
+ >
+ Dark
+ </TsToggleButton>
</ToggleButtonGroup>
</div>
</div>
diff --git a/src/renderer/components/dialogs/components/SettingsKeyBindings.tsx b/src/renderer/components/dialogs/components/SettingsKeyBindings.tsx
index 8de35debd..efbd74b05 100644
--- a/src/renderer/components/dialogs/components/SettingsKeyBindings.tsx
+++ b/src/renderer/components/dialogs/components/SettingsKeyBindings.tsx
@@ -16,25 +16,24 @@
*
*/
-import React from 'react';
-import { styled } from '@mui/material/styles';
-import { useSelector, useDispatch } from 'react-redux';
+import AppConfig from '-/AppConfig';
+import InfoIcon from '-/components/InfoIcon';
import TsTextField from '-/components/TsTextField';
-import Switch from '@mui/material/Switch';
-import ListItem from '@mui/material/ListItem';
-import ListItemText from '@mui/material/ListItemText';
-import { isStr } from '@tagspaces/tagspaces-common/misc';
+import { AppDispatch } from '-/reducers/app';
import {
actions as SettingsActions,
getKeyBindings,
isGlobalKeyBindingEnabled,
} from '-/reducers/settings';
import DefaultSettings from '-/reducers/settings-default';
-import { AppDispatch } from '-/reducers/app';
-import { useTranslation } from 'react-i18next';
-import Typography from '@mui/material/Typography';
import { setGlobalShortcuts } from '-/services/utils-io';
-import AppConfig from '-/AppConfig';
+import ListItem from '@mui/material/ListItem';
+import ListItemText from '@mui/material/ListItemText';
+import Switch from '@mui/material/Switch';
+import Typography from '@mui/material/Typography';
+import { isStr } from '@tagspaces/tagspaces-common/misc';
+import { useTranslation } from 'react-i18next';
+import { useDispatch, useSelector } from 'react-redux';
function SettingsKeyBindings() {
const { t } = useTranslation();
@@ -70,7 +69,14 @@ function SettingsKeyBindings() {
</Typography>
{AppConfig.isElectron && (
<ListItem style={{ paddingLeft: 0, paddingRight: 0 }}>
- <ListItemText primary={t('core:enableGlobalKeyboardShortcuts')} />
+ <ListItemText
+ primary={
+ <>
+ {t('core:enableGlobalKeyboardShortcuts')}
+ <InfoIcon tooltip="Enables global shortcut for creating new files, file navigation, play/pause audio files or opening the search. Global shortcuts are working even if the app window is not currently in focus or visible." />
+ </>
+ }
+ />
<Switch
onClick={() => {
setGlobalKeyBinding(!globalKeyBindingEnabled);
@@ -85,10 +91,9 @@ function SettingsKeyBindings() {
)[0];
return (
<TsTextField
- style={{ marginTop: 10, marginBottom: 10 }}
+ style={{ marginTop: 0, marginBottom: 10 }}
key={keyBinding.name}
autoComplete="off"
- InputLabelProps={{ shrink: true }}
onBlur={(event) =>
setKeyBinding(keyBinding.name, event.target.value)
}