Skip to content

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

fix-save-file-properties-on-switch-location (#2069)

Stanimir0300da6e04a6
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 8feecaebf..fd41f64e9 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -344,55 +344,53 @@ function EntryContainer() {
// if (!this.state.currentEntry.isFile) {
// textFilePath += '/index.html';
// }
- switchLocationTypeByID(openedEntry.locationId).then(
- (currentLocationId) => {
- PlatformIO.loadTextFilePromise(
- textFilePath,
- data.preview ? data.preview : false,
- )
- .then((content) => {
- const UTF8_BOM = '\ufeff';
- if (content.indexOf(UTF8_BOM) === 0) {
- // eslint-disable-next-line no-param-reassign
- content = content.substr(1);
- }
- let fileDirectory = extractContainingDirectoryPath(
- textFilePath,
- PlatformIO.getDirSeparator(),
+ switchLocationTypeByID(openedEntry.locationId).then(() => {
+ PlatformIO.loadTextFilePromise(
+ textFilePath,
+ data.preview ? data.preview : false,
+ )
+ .then((content) => {
+ const UTF8_BOM = '\ufeff';
+ if (content.indexOf(UTF8_BOM) === 0) {
+ // eslint-disable-next-line no-param-reassign
+ content = content.substr(1);
+ }
+ let fileDirectory = extractContainingDirectoryPath(
+ textFilePath,
+ PlatformIO.getDirSeparator(),
+ );
+ if (AppConfig.isWeb) {
+ fileDirectory =
+ extractContainingDirectoryPath(
+ // eslint-disable-next-line no-restricted-globals
+ location.href,
+ PlatformIO.getDirSeparator(),
+ ) +
+ '/' +
+ fileDirectory;
+ }
+ if (
+ fileViewer &&
+ fileViewer.current &&
+ fileViewer.current.contentWindow &&
+ // @ts-ignore
+ fileViewer.current.contentWindow.setContent
+ ) {
+ // @ts-ignore call setContent from iframe
+ fileViewer.current.contentWindow.setContent(
+ content,
+ fileDirectory,
+ !openedEntry.editMode,
+ theme.palette.mode,
);
- if (AppConfig.isWeb) {
- fileDirectory =
- extractContainingDirectoryPath(
- // eslint-disable-next-line no-restricted-globals
- location.href,
- PlatformIO.getDirSeparator(),
- ) +
- '/' +
- fileDirectory;
- }
- if (
- fileViewer &&
- fileViewer.current &&
- fileViewer.current.contentWindow &&
- // @ts-ignore
- fileViewer.current.contentWindow.setContent
- ) {
- // @ts-ignore call setContent from iframe
- fileViewer.current.contentWindow.setContent(
- content,
- fileDirectory,
- !openedEntry.editMode,
- theme.palette.mode,
- );
- }
- return switchCurrentLocationType();
- })
- .catch((err) => {
- console.warn('Error loading text content ' + err);
- return switchCurrentLocationType();
- });
- },
- );
+ }
+ return switchCurrentLocationType();
+ })
+ .catch((err) => {
+ console.warn('Error loading text content ' + err);
+ return switchCurrentLocationType();
+ });
+ });
break;
case 'contentChangedInEditor': {
if (!fileChanged.current) {
@@ -453,7 +451,9 @@ function EntryContainer() {
// openedEntry.changed) {
setSaveBeforeReloadConfirmDialogOpened(true);
} else {
- reloadOpenedFile();
+ return switchLocationTypeByID(openedEntry.locationId).then(() =>
+ reloadOpenedFile().then(() => switchCurrentLocationType()),
+ );
}
}
};
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index aa1ebe0be..be675b8a1 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -75,7 +75,7 @@ type OpenedEntryContextData = {
addToEntryContainer: (fsEntry: TS.OpenedEntry) => void;
closeAllFiles: () => void;
reflectUpdateOpenedFileContent: (entry: TS.FileSystemEntry) => void;
- reloadOpenedFile: () => void;
+ reloadOpenedFile: () => Promise<boolean>;
/*updateOpenedFile: (
entryPath: string,
fsEntryMeta: TS.FileSystemEntryMeta,
@@ -105,7 +105,7 @@ export const OpenedEntryContext = createContext<OpenedEntryContextData>({
addToEntryContainer: () => {},
closeAllFiles: () => {},
reflectUpdateOpenedFileContent: () => {},
- reloadOpenedFile: () => {},
+ reloadOpenedFile: undefined,
//updateOpenedFile: () => Promise.resolve(false),
openEntry: undefined,
openFsEntry: undefined,
@@ -378,7 +378,20 @@ export const OpenedEntryContextProvider = ({
function reloadOpenedFile(): Promise<boolean> {
if (currentEntry.current) {
currentEntry.current.editMode = false;
- return openEntry(currentEntry.current.path); //true);
+ //return openEntry(currentEntry.current.path); //true);
+ return getAllPropertiesPromise(currentEntry.current.path)
+ .then((fsEntry: TS.FileSystemEntry) =>
+ openFsEntry({ ...currentEntry.current, ...fsEntry }, undefined),
+ )
+ .catch((error) => {
+ console.warn(
+ 'Error getting properties for entry: ' +
+ currentEntry.current.path +
+ ' - ' +
+ error,
+ );
+ return false;
+ });
}
return Promise.resolve(false);
}
@@ -455,7 +468,7 @@ export const OpenedEntryContextProvider = ({
document.title = fsEntry.name + ' | ' + locationName;
- if (currentLocation) {
+ if (!entryForOpening.locationId && currentLocation) {
entryForOpening.locationId = currentLocation.uuid;
updateHistory(
{ ...currentLocation, path: currentLocationPath },