Skip to content

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

Use only tags from the tag-library for tagging in extconfig (#2290)

Stanimir2bab00bd7dda
diff --git a/src/renderer/components/TagsSelect.tsx b/src/renderer/components/TagsSelect.tsx
index b9b151c57..b81296ad6 100644
--- a/src/renderer/components/TagsSelect.tsx
+++ b/src/renderer/components/TagsSelect.tsx
@@ -25,6 +25,7 @@ import {
getTagColor,
getTagTextColor,
isDesktopMode,
+ useOnlyTagsFromTagLibrary,
} from '-/reducers/settings';
import { getAllTags } from '-/services/taglibrary-utils';
import { tagsValidation } from '-/services/utils-io';
@@ -55,6 +56,7 @@ function TagsSelect(props: Props) {
const { t } = useTranslation();
const { readOnlyMode } = useCurrentLocationContext();
const desktopMode = useSelector(isDesktopMode);
+ const isUseOnlyTagsFromTagLibrary = useSelector(useOnlyTagsFromTagLibrary);
const [tagMenuAnchorEl, setTagMenuAnchorEl] = useState<null | HTMLElement>(
null,
);
@@ -178,7 +180,7 @@ function TagsSelect(props: Props) {
multiple
options={!readOnlyMode ? allTags.current : []}
getOptionLabel={(option: TS.Tag) => option.title}
- freeSolo
+ freeSolo={!isUseOnlyTagsFromTagLibrary}
disableClearable={true}
autoSelect
autoComplete
diff --git a/src/renderer/components/dialogs/components/SettingsGeneral.tsx b/src/renderer/components/dialogs/components/SettingsGeneral.tsx
index e38167c79..ba11845c1 100644
--- a/src/renderer/components/dialogs/components/SettingsGeneral.tsx
+++ b/src/renderer/components/dialogs/components/SettingsGeneral.tsx
@@ -312,6 +312,31 @@ function SettingsGeneral() {
checked={settings.addTagsToLibrary}
/>
</ListItem>
+ <ListItem
+ title={
+ window.ExtUseOnlyTagsFromTagLibrary !== undefined
+ ? t('core:settingExternallyConfigured')
+ : ''
+ }
+ >
+ <ListItemText primary={t('core:useOnlyTagsFromTagLibrary')} />
+ <Switch
+ disabled={window.ExtUseOnlyTagsFromTagLibrary !== undefined}
+ data-tid="useOnlyTagsFromTagLibraryTID"
+ onClick={() =>
+ dispatch(
+ SettingsActions.setUseOnlyTagsFromTagLibrary(
+ !settings.useOnlyTagsFromTagLibrary,
+ ),
+ )
+ }
+ checked={
+ window.ExtUseOnlyTagsFromTagLibrary !== undefined
+ ? window.ExtUseOnlyTagsFromTagLibrary
+ : settings.useOnlyTagsFromTagLibrary
+ }
+ />
+ </ListItem>
<ListItem>
<ListItemText primary={t('core:useGenerateThumbnails')} />
<Switch
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 74e243cd0..9d27ec6a0 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -961,5 +961,6 @@
"compareAndUpgrade": "Compare & Upgrade",
"start": "Start",
"backgroundColorInfo": "The background color will not be visible if you have set a background image",
+ "useOnlyTagsFromTagLibrary": "Use only tags from tag library for tagging",
"-": "-"
}
diff --git a/src/renderer/reducers/settings-default.ts b/src/renderer/reducers/settings-default.ts
index 6aa77d2f1..c994feee4 100644
--- a/src/renderer/reducers/settings-default.ts
+++ b/src/renderer/reducers/settings-default.ts
@@ -36,6 +36,10 @@ let filenameTagPlacedAtEnd = true;
if (window.ExtFilenameTagPlacedAtEnd !== undefined) {
filenameTagPlacedAtEnd = window.ExtFilenameTagPlacedAtEnd;
}
+let useOnlyTagsFromTagLibrary = false;
+if (window.ExtUseOnlyTagsFromTagLibrary !== undefined) {
+ useOnlyTagsFromTagLibrary = window.ExtUseOnlyTagsFromTagLibrary;
+}
export default {
//isLoading: false,
@@ -80,6 +84,7 @@ export default {
useOCR: false,
useTextExtraction: false,
useGenerateThumbnails: true,
+ useOnlyTagsFromTagLibrary,
tagTextColor: 'white',
tagBackgroundColor: '#61DD61',
currentTheme: 'light',
diff --git a/src/renderer/reducers/settings.ts b/src/renderer/reducers/settings.ts
index 5b39eb6c2..152de7682 100644
--- a/src/renderer/reducers/settings.ts
+++ b/src/renderer/reducers/settings.ts
@@ -42,6 +42,7 @@ export const types = {
SET_ENTRY_CONTAINER_TAB: 'SETTINGS/SET_ENTRY_CONTAINER_TAB',
//SET_SHOW_DETAILS: 'SETTINGS/SET_SHOW_DETAILS',
SET_DESKTOPMODE: 'SETTINGS/SET_DESKTOPMODE',
+ SET_USEONLYTAGSFROMTAGLIBRARY: 'SETTINGS/SET_USEONLYTAGSFROMTAGLIBRARY',
SET_DEVMODE: 'SETTINGS/SET_DEVMODE',
SET_ENABLE_WS: 'SETTINGS/SET_ENABLE_WS',
WARNING_OPENING_FILES_EXTERNALLY: 'SETTINGS/WARNING_OPENING_FILES_EXTERNALLY',
@@ -185,6 +186,12 @@ export default (state: any = defaultSettings, action: any) => {
case types.SET_DESKTOPMODE: {
return { ...state, desktopMode: action.desktopMode };
}
+ case types.SET_USEONLYTAGSFROMTAGLIBRARY: {
+ return {
+ ...state,
+ useOnlyTagsFromTagLibrary: action.useOnlyTagsFromTagLibrary,
+ };
+ }
case types.SET_DEVMODE: {
return { ...state, devMode: action.devMode };
}
@@ -615,6 +622,10 @@ export const actions = {
type: types.SET_DESKTOPMODE,
desktopMode,
}),
+ setUseOnlyTagsFromTagLibrary: (useOnlyTagsFromTagLibrary: boolean) => ({
+ type: types.SET_USEONLYTAGSFROMTAGLIBRARY,
+ useOnlyTagsFromTagLibrary,
+ }),
setDevMode: (devMode: boolean) => ({
type: types.SET_DEVMODE,
devMode,
@@ -1061,6 +1072,8 @@ export const getTagDelimiter = (state: any) => state.settings.tagDelimiter;
export const getMaxSearchResults = (state: any) =>
state.settings.maxSearchResult;
export const isDesktopMode = (state: any) => state.settings.desktopMode;
+export const useOnlyTagsFromTagLibrary = (state: any) =>
+ state.settings.useOnlyTagsFromTagLibrary;
export const getStoredSearchesVisible = (state: any) =>
state.settings.storedSearchesVisible;
export const getShowBookmarks = (state: any) => state.settings.showBookmarks;
diff --git a/src/renderer/tagspaces.d.ts b/src/renderer/tagspaces.d.ts
index 9ca2f3d0d..486f03023 100644
--- a/src/renderer/tagspaces.d.ts
+++ b/src/renderer/tagspaces.d.ts
@@ -74,6 +74,7 @@ declare interface Window {
ExtExtensionsFound?: Array<any>;
ExtSearchTypeGroups?: any;
ExtDefaultMapBounds?: any;
+ ExtUseOnlyTagsFromTagLibrary?: boolean;
}
declare interface NodeModule {