Skip to content

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

chore: optimizing entry tabs

Ilian Sapundshiev3c0e8bdca7c3
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 58018fd6b..9cc7ea13b 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -17,14 +17,11 @@
*/
import AppConfig from '-/AppConfig';
-import { CancelIcon, CloseEditIcon, SaveIcon } from '-/components/CommonIcons';
-import EditFileButton from '-/components/EditFileButton';
import EntryContainerNav from '-/components/EntryContainerNav';
import EntryContainerTabs from '-/components/EntryContainerTabs';
import EntryContainerTitle from '-/components/EntryContainerTitle';
import FileView from '-/components/FileView';
import Tooltip from '-/components/Tooltip';
-import TsButton from '-/components/TsButton';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useResolveConflictContext } from '-/components/dialogs/hooks/useResolveConflictContext';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
@@ -36,7 +33,6 @@ import { useIOActionsContext } from '-/hooks/useIOActionsContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { usePerspectiveActionsContext } from '-/hooks/usePerspectiveActionsContext';
-import { Pro } from '-/pro';
import { AppDispatch } from '-/reducers/app';
import {
actions as SettingsActions,
@@ -47,9 +43,8 @@ import {
isRevisionsEnabled,
} from '-/reducers/settings';
import { TS } from '-/tagspaces.namespace';
-import { Switch, useMediaQuery } from '@mui/material';
+import { useMediaQuery } from '@mui/material';
import Box from '@mui/material/Box';
-import ButtonGroup from '@mui/material/ButtonGroup';
import { useTheme } from '@mui/material/styles';
import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
import React, {
@@ -195,10 +190,6 @@ function EntryContainer() {
(success) => {
if (success) {
setFileChanged(false);
- // showNotification(
- // t('core:fileSavedSuccessfully'),
- // NotificationTypes.default
- // );
}
// change state will not render DOT before file name too
isSavingInProgress.current = false;
@@ -388,7 +379,6 @@ function EntryContainer() {
event.stopPropagation();
}
if (openedEntry && fileChanged && isEditMode) {
- // openedEntry.changed
setSaveBeforeCloseConfirmDialogOpened(true);
} else {
closeFile();
@@ -397,7 +387,6 @@ function EntryContainer() {
const closeFile = () => {
closeOpenedEntries();
- // setEditingSupported(false);
};
const startSavingFile = () => {
@@ -452,26 +441,6 @@ function EntryContainer() {
setEditMode(true);
};
- /*const setPercent = (p: number | undefined) => {
- percent.current = p;
- // console.log('Percent ' + percent.current);
- if (p !== undefined) {
- bufferedSplitResize(() => {
- // Threshold >10% for automatically close Properties panel
- if (p <= 10) {
- // parseInt(defaultSplitSize, 10)) {
- closePanel();
- } else {
- if (entrySplitSize !== p + '%') {
- setEntryPropertiesSplitSize(p + '%');
- }
- openPanel();
- }
- });
- }
- forceUpdate();
- };*/
-
const openPanel = () => {
if (!isPanelOpened) {
setPanelOpened(true);
@@ -484,22 +453,11 @@ function EntryContainer() {
const openNextFileAction = () => {
const action: TS.PerspectiveActions = { action: 'openNext' };
setActions(action);
- // window.dispatchEvent(new Event('next-file'));
};
const openPrevFileAction = () => {
const action: TS.PerspectiveActions = { action: 'openPrevious' };
setActions(action);
- //window.dispatchEvent(new Event('previous-file'));
- };
-
- const toggleAutoSave = (event: React.ChangeEvent<HTMLInputElement>) => {
- const autoSave = event.target.checked;
- if (Pro) {
- setAutoSave(openedEntry, autoSave, openedEntry.locationID);
- } else {
- showNotification(t('core:thisFunctionalityIsAvailableInPro'));
- }
};
const toggleEntryPropertiesHeight = () => {
@@ -517,142 +475,20 @@ function EntryContainer() {
};
const tabs = () => {
- const autoSave = isEditable(openedEntry) && revisionsEnabled && (
- <Tooltip
- title={
- t('core:autosave') +
- (!Pro ? ' - ' + t('core:thisFunctionalityIsAvailableInPro') : '')
- }
- >
- <Switch
- data-tid="autoSaveTID"
- checked={openedEntry.meta && openedEntry.meta.autoSave}
- onChange={toggleAutoSave}
- size={desktopMode ? 'small' : 'medium'}
- name="autoSave"
- />
- </Tooltip>
- );
-
- let closeCancelIcon;
- if (desktopMode) {
- closeCancelIcon = fileChanged ? <CancelIcon /> : <CloseEditIcon />;
- }
-
- let editFile = null;
- if (editingSupported) {
- if (isEditMode) {
- editFile = (
- <ButtonGroup>
- <TsButton
- tooltip={t('core:cancelEditing')}
- data-tid="cancelEditingTID"
- onClick={() => {
- setEditMode(false);
- setFileChanged(false);
- }}
- style={{
- borderRadius: 'unset',
- borderTopLeftRadius: AppConfig.defaultCSSRadius,
- borderBottomLeftRadius: AppConfig.defaultCSSRadius,
- borderTopRightRadius: fileChanged
- ? 0
- : AppConfig.defaultCSSRadius,
- borderBottomRightRadius: fileChanged
- ? 0
- : AppConfig.defaultCSSRadius,
- }}
- aria-label={t('core:cancelEditing')}
- startIcon={closeCancelIcon}
- >
- <Box
- style={{
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- maxWidth: 100,
- }}
- >
- {fileChanged ? t('core:cancel') : t('core:exitEditMode')}
- </Box>
- </TsButton>
-
- {fileChanged && (
- <Tooltip
- title={
- t('core:saveFile') +
- ' (' +
- (AppConfig.isMacLike ? '⌘' : 'CTRL') +
- ' + S)'
- }
- >
- <TsButton
- disabled={false}
- onClick={startSavingFile}
- aria-label={t('core:saveFile')}
- data-tid="fileContainerSaveFile"
- startIcon={desktopMode && <SaveIcon />}
- loading={isSavingInProgress.current}
- style={{
- borderRadius: 'unset',
- borderTopRightRadius: AppConfig.defaultCSSRadius,
- borderBottomRightRadius: AppConfig.defaultCSSRadius,
- }}
- >
- {t('core:save')}
- </TsButton>
- </Tooltip>
- )}
- </ButtonGroup>
- );
- } else {
- editFile = <EditFileButton />;
- }
- }
-
const tabsComponent = useCallback(
() => (
<EntryContainerTabs
isPanelOpened={isPanelOpened}
openPanel={openPanel}
toggleProperties={toggleProperties}
+ isSavingInProgress={isSavingInProgress.current}
+ savingFile={savingFile}
/>
),
[isPanelOpened],
);
- if (!autoSave && !editFile) {
- return tabsComponent();
- }
-
- return (
- <div
- style={{
- position: 'relative',
- overflow: 'hidden',
- height: '100%',
- }}
- >
- {tabsComponent()}
- <div
- style={{
- zIndex: 1000,
- position: 'absolute',
- right: 10,
- top: 0,
- backgroundColor: theme.palette.background.default,
- // backgroundColor: 'transparent',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'column',
- borderRadius: AppConfig.defaultCSSRadius,
- }}
- >
- {editFile}
- {autoSave}
- </div>
- </div>
- );
+ return tabsComponent();
};
if (!openedEntry || openedEntry.path === undefined) {
diff --git a/src/renderer/components/EntryContainerTabs.tsx b/src/renderer/components/EntryContainerTabs.tsx
index 54cd90da8..3a5bff18a 100644
--- a/src/renderer/components/EntryContainerTabs.tsx
+++ b/src/renderer/components/EntryContainerTabs.tsx
@@ -16,23 +16,44 @@
*
*/
+import AppConfig from '-/AppConfig';
import LoadingLazy from '-/components/LoadingLazy';
import TsTabPanel from '-/components/TsTabPanel';
import { TabItem, TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useChatContext } from '-/hooks/useChatContext';
+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useEntryPropsTabsContext } from '-/hooks/useEntryPropsTabsContext';
+import { useFilePropertiesContext } from '-/hooks/useFilePropertiesContext';
+import { useIOActionsContext } from '-/hooks/useIOActionsContext';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
+import { Pro } from '-/pro';
import { AppDispatch } from '-/reducers/app';
import {
actions as SettingsActions,
getEntryContainerTab,
getMapTileServer,
+ isDesktopMode,
+ isRevisionsEnabled,
} from '-/reducers/settings';
-import { Box, Tab, Tabs, TabsProps, useMediaQuery } from '@mui/material';
+import {
+ Box,
+ ButtonGroup,
+ Switch,
+ Tab,
+ Tabs,
+ TabsProps,
+ Tooltip,
+ useMediaQuery,
+} from '@mui/material';
import { styled, useTheme } from '@mui/material/styles';
import React, { useEffect, useReducer, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
+import { CancelIcon, CloseEditIcon, SaveIcon } from './CommonIcons';
+import EditFileButton from './EditFileButton';
+import TsButton from './TsButton';
+import { useResolveConflictContext } from './dialogs/hooks/useResolveConflictContext';
interface StyledTabsProps {
children?: React.ReactNode;
@@ -65,14 +86,21 @@ interface EntryContainerTabsProps {
openPanel: () => void;
toggleProperties: () => void;
isPanelOpened: boolean;
+ isSavingInProgress: boolean;
+ savingFile: () => void;
}
function EntryContainerTabs(props: EntryContainerTabsProps) {
- const { openPanel, toggleProperties, isPanelOpened } = props;
+ const {
+ openPanel,
+ toggleProperties,
+ isPanelOpened,
+ isSavingInProgress,
+ savingFile,
+ } = props;
const { t } = useTranslation();
const { initHistory, checkOllamaModels } = useChatContext();
const { getTabsArray } = useEntryPropsTabsContext();
- const { openedEntry } = useOpenedEntryContext();
const theme = useTheme();
//const devMode: boolean = useSelector(isDevMode);
const selectedTab: (typeof TabNames)[keyof typeof TabNames] =
@@ -82,6 +110,25 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
const dispatch: AppDispatch = useDispatch();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const isTinyMode = useMediaQuery(theme.breakpoints.down('sm'));
+ const desktopMode = useSelector(isDesktopMode);
+ const { saveDescription, isEditMode, setEditMode, closeOpenedEntries } =
+ useFilePropertiesContext();
+ const { setAutoSave } = useIOActionsContext();
+ const { isEditable } = useEntryPropsTabsContext();
+ const { saveFileOpen } = useResolveConflictContext();
+ const { showNotification } = useNotificationContext();
+ const revisionsEnabled = useSelector(isRevisionsEnabled);
+ const { findLocation } = useCurrentLocationContext();
+ const {
+ openedEntry,
+ reloadOpenedFile,
+ toggleEntryFullWidth,
+ isEntryInFullWidth,
+ fileChanged,
+ setFileChanged,
+ } = useOpenedEntryContext();
+
+ const cLocation = findLocation(openedEntry.locationID);
useEffect(() => {
getTabsArray(openedEntry).then((tabs) => {
@@ -148,11 +195,6 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
return index;
}
return 0;
- /*const maxTabIndex = tabsArray.current.length - 1;
- if (tabIndex > maxTabIndex) {
- return maxTabIndex;
- }
- return tabIndex;*/
}
const selectedTabIndex = getSelectedTabIndex();
@@ -174,6 +216,124 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
return null;
}
+ const toggleAutoSave = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const autoSave = event.target.checked;
+ if (Pro) {
+ setAutoSave(openedEntry, autoSave, openedEntry.locationID);
+ } else {
+ showNotification(t('core:thisFunctionalityIsAvailableInPro'));
+ }
+ };
+
+ const autoSave = isEditable(openedEntry) && revisionsEnabled && (
+ <Tooltip
+ title={
+ t('core:autosave') +
+ (!Pro ? ' - ' + t('core:thisFunctionalityIsAvailableInPro') : '')
+ }
+ >
+ <Switch
+ data-tid="autoSaveTID"
+ checked={openedEntry.meta && openedEntry.meta.autoSave}
+ onChange={toggleAutoSave}
+ // size={desktopMode ? 'small' : 'medium'}
+ size="small"
+ name="autoSave"
+ />
+ </Tooltip>
+ );
+
+ let closeCancelIcon;
+ if (desktopMode) {
+ closeCancelIcon = fileChanged ? <CancelIcon /> : <CloseEditIcon />;
+ }
+
+ const editingSupported: boolean =
+ cLocation &&
+ !cLocation.isReadOnly &&
+ openedEntry &&
+ openedEntry.editingExtensionId !== undefined &&
+ openedEntry.editingExtensionId.length > 3;
+
+ const startSavingFile = () => {
+ if (isEditMode) {
+ savingFile();
+ } else {
+ saveDescription();
+ }
+ };
+
+ let editFile = null;
+ if (editingSupported) {
+ if (isEditMode) {
+ editFile = (
+ <ButtonGroup>
+ <TsButton
+ tooltip={t('core:cancelEditing')}
+ data-tid="cancelEditingTID"
+ onClick={() => {
+ setEditMode(false);
+ setFileChanged(false);
+ }}
+ style={{
+ borderRadius: 'unset',
+ borderTopLeftRadius: AppConfig.defaultCSSRadius,
+ borderBottomLeftRadius: AppConfig.defaultCSSRadius,
+ borderTopRightRadius: fileChanged
+ ? 0
+ : AppConfig.defaultCSSRadius,
+ borderBottomRightRadius: fileChanged
+ ? 0
+ : AppConfig.defaultCSSRadius,
+ }}
+ aria-label={t('core:cancelEditing')}
+ startIcon={closeCancelIcon}
+ >
+ <Box
+ style={{
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ maxWidth: 100,
+ }}
+ >
+ {fileChanged ? t('core:cancel') : t('core:exitEditMode')}
+ </Box>
+ </TsButton>
+
+ {fileChanged && (
+ <Tooltip
+ title={
+ t('core:saveFile') +
+ ' (' +
+ (AppConfig.isMacLike ? '⌘' : 'CTRL') +
+ ' + S)'
+ }
+ >
+ <TsButton
+ disabled={false}
+ onClick={startSavingFile}
+ aria-label={t('core:saveFile')}
+ data-tid="fileContainerSaveFile"
+ startIcon={desktopMode && <SaveIcon />}
+ loading={isSavingInProgress}
+ style={{
+ borderRadius: 'unset',
+ borderTopRightRadius: AppConfig.defaultCSSRadius,
+ borderBottomRightRadius: AppConfig.defaultCSSRadius,
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ </Tooltip>
+ )}
+ </ButtonGroup>
+ );
+ } else {
+ editFile = <EditFileButton />;
+ }
+ }
+
return (
<div
style={{
@@ -188,11 +348,9 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
: 'none',
}}
>
- {/* <Box sx={{ ...(marginRight && { marginRight }) }}> */}
<Box
style={{
- marginRight: 140,
- // borderBottom: '1px solid ' + theme.palette.divider,
+ display: 'flex',
}}
>
<StyledTabs
@@ -228,6 +386,18 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
/>
))}
</StyledTabs>
+ <Box
+ style={{
+ marginLeft: 'auto',
+ display: 'flex',
+ flexDirection: 'column',
+ marginRight: 10,
+ alignItems: 'anchor-center',
+ }}
+ >
+ {editFile}
+ {autoSave}
+ </Box>
</Box>
{tabsArray.current.map((tab, index) => (
<TsTabPanel key={tab.name} value={selectedTabIndex} index={index}>