Skip to content

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

TSN496 - Check double rendering of the iframe for opening files (#1239)

Stanimir67d02c4506af
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index 6f49bb269..284e2bf46 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -64,7 +64,6 @@ import {
OpenedEntry,
NotificationTypes,
isReadOnlyMode,
- getDirectoryContent,
actions as AppActions
} from '-/reducers/app';
import useEventListener from '-/utils/useEventListener';
@@ -177,8 +176,8 @@ interface Props {
removeTags: () => void;
// editTagForEntry: () => void;
openFsEntry: (fsEntry: FileSystemEntry) => void;
- getNextFile: (path: string) => string;
- getPrevFile: (path: string) => string;
+ openPrevFile: (path: string) => void;
+ openNextFile: (path: string) => void;
openFileNatively: (path: string) => void;
openURLExternally: (url: string) => void;
showNotification: (
@@ -200,7 +199,6 @@ interface Props {
updateThumbnailUrl: (path: string, thumbUrl: string) => void;
setLastSelectedEntry: (path: string) => void;
setSelectedEntries: (selectedEntries: Array<Object>) => void;
- directoryContent: Array<FileSystemEntry>;
currentDirectoryPath: string | null;
}
@@ -215,7 +213,7 @@ const EntryContainer = (props: Props) => {
boolean
>(false);
const [isFullscreen, setFullscreen] = useState<boolean>(false);
- const [editingSupported, setEditingSupported] = useState<boolean>(false);
+ // const [editingSupported, setEditingSupported] = useState<boolean>(true);
const [
isSaveBeforeCloseConfirmDialogOpened,
setSaveBeforeCloseConfirmDialogOpened
@@ -266,25 +264,16 @@ const EntryContainer = (props: Props) => {
useEffect(() => {
if (props.openedFiles.length > 0) {
// / setPropertiesPanelVisible
- if (!openedFile.isFile) {
+ if (!openedFile.isFile && !isPropertiesPanelVisible) {
// always open for dirs
setPropertiesPanelVisible(true);
}
- // / setEditingSupported
- if (props.isReadOnlyMode) {
- setEditingSupported(false);
- } else {
- setEditingSupported(
- openedFile.editingExtensionId &&
- openedFile.editingExtensionId.length > 3
- );
- if (
- openedFile.editMode &&
- openedFile.changed &&
- openedFile.shouldReload === false
- ) {
- setSaveBeforeReloadConfirmDialogOpened(true);
- }
+ if (
+ openedFile.editMode &&
+ openedFile.changed &&
+ openedFile.shouldReload === false
+ ) {
+ setSaveBeforeReloadConfirmDialogOpened(true);
}
}
}, [props.openedFiles, props.isReadOnlyMode, props.settings]);
@@ -295,24 +284,14 @@ const EntryContainer = (props: Props) => {
}
}, [isPropertiesPanelVisible]);
- // isPropertiesEditMode = false; // TODO rethink this! why exist?
-
- // let isChanged = false;
- // let shouldReload = false;
-
- // logEventsFromExtensions = event => {
- // console.log('Ext. Logging >>> ', event.message);
- // };
-
- // handleMessageProxy = event => {
- // this.handleMessage(JSON.stringify(event.channel));
- // };
+ const editingSupported: boolean =
+ !props.isReadOnlyMode &&
+ openedFile.editingExtensionId !== undefined &&
+ openedFile.editingExtensionId.length > 3;
const handleMessage = (data: any) => {
let message;
let textFilePath;
- let nextFilePath;
- let nextFile;
let decodedURI;
switch (data.command) {
@@ -330,13 +309,7 @@ const EntryContainer = (props: Props) => {
editFile();
break;
case 'playbackEnded':
- nextFilePath = props.getNextFile(openedFile.path);
- nextFile = props.directoryContent.find(
- (dirEntry: any) => dirEntry.path === nextFilePath
- );
- props.openFsEntry(nextFile);
- props.setLastSelectedEntry(nextFilePath);
- props.setSelectedEntries([nextFile]);
+ props.openNextFile(openedFile.path);
break;
case 'openLinkExternally':
// console.log('Open link externally: ' + data.link);
@@ -477,7 +450,7 @@ const EntryContainer = (props: Props) => {
const closeFile = () => {
props.closeAllFiles();
- setEditingSupported(false);
+ // setEditingSupported(false);
};
const startSavingFile = () => {
@@ -622,27 +595,11 @@ const EntryContainer = (props: Props) => {
};
const openNextFile = () => {
- if (openedFile.path) {
- const nextFilePath = props.getNextFile(openedFile.path);
- const nextFile = props.directoryContent.find(
- (dirEntry: FileSystemEntry) => dirEntry.path === nextFilePath
- );
- props.openFsEntry(nextFile);
- props.setLastSelectedEntry(nextFilePath);
- props.setSelectedEntries([nextFile]);
- }
+ props.openNextFile(openedFile.path);
};
const openPrevFile = () => {
- if (openedFile.path) {
- const prevFilePath = props.getPrevFile(openedFile.path);
- const prevFile = props.directoryContent.find(
- (dirEntry: FileSystemEntry) => dirEntry.path === prevFilePath
- );
- props.openFsEntry(prevFile);
- props.setLastSelectedEntry(prevFilePath);
- props.setSelectedEntries([prevFile]);
- }
+ props.openPrevFile(openedFile.path);
};
const openNatively = () => {
@@ -1275,7 +1232,6 @@ function mapStateToProps(state) {
return {
settings: state.settings,
isReadOnlyMode: isReadOnlyMode(state),
- directoryContent: getDirectoryContent(state),
keyBindings: getKeyBindingObject(state)
};
}
@@ -1291,8 +1247,8 @@ function mapActionCreatorsToProps(dispatch) {
openFileNatively: AppActions.openFileNatively,
openURLExternally: AppActions.openURLExternally,
showNotification: AppActions.showNotification,
- getNextFile: AppActions.getNextFile,
- getPrevFile: AppActions.getPrevFile,
+ openNextFile: AppActions.openNextFile,
+ openPrevFile: AppActions.openPrevFile,
deleteFile: AppActions.deleteFile,
toggleEntryFullWidth: AppActions.toggleEntryFullWidth,
addTags: TaggingActions.addTags,
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 0db03b567..911391880 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -626,8 +626,6 @@ function mapActionCreatorsToProps(dispatch) {
toggleCreateFileDialog: AppActions.toggleCreateFileDialog,
deleteFile: AppActions.deleteFile,
renameFile: AppActions.renameFile,
- getNextFile: AppActions.getNextFile,
- getPrevFile: AppActions.getPrevFile,
openDirectory: AppActions.openDirectory,
showInFileManager: AppActions.showInFileManager,
openFsEntry: AppActions.openFsEntry,
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 12f828afe..93d77a0b4 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -188,8 +188,8 @@ interface Props {
openFsEntry: (fsEntry: FileSystemEntry) => void; // needed by electron-menus
openFileNatively: (url: string) => void; // needed by electron-menus
openURLExternally: (url: string) => void;
- getNextFile: () => void; // needed by electron-menus
- getPrevFile: () => void; // needed by electron-menus
+ openNextFile: (path?: string) => void; // needed by electron-menus
+ openPrevFile: (path?: string) => void; // needed by electron-menus
openLocationManagerPanel: () => void;
openTagLibraryPanel: () => void;
openSearchPanel: () => void;
@@ -943,8 +943,8 @@ function mapDispatchToProps(dispatch) {
openURLExternally: AppActions.openURLExternally,
setEntryFullWidth: AppActions.setEntryFullWidth,
setUpdateAvailable: AppActions.setUpdateAvailable,
- getNextFile: AppActions.getNextFile,
- getPrevFile: AppActions.getPrevFile,
+ openNextFile: AppActions.openNextFile,
+ openPrevFile: AppActions.openPrevFile,
toggleShowUnixHiddenEntries: SettingsActions.toggleShowUnixHiddenEntries,
setLeftVerticalSplitSize: SettingsActions.setLeftVerticalSplitSize,
setMainVerticalSplitSize: SettingsActions.setMainVerticalSplitSize,
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index a05b4187e..a9e67e05d 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -74,8 +74,8 @@ interface Props {
supportedFileTypes: Array<any>;
isReadOnlyMode: boolean;
openFsEntry: (fsEntry: FileSystemEntry) => void;
- getNextFile: () => any;
- getPrevFile: () => any;
+ openNextFile: () => any;
+ openPrevFile: () => any;
deleteFile: (path: string) => void;
deleteDirectory: (path: string) => void;
loadDirectoryContent: (path: string) => void;
@@ -702,26 +702,8 @@ class GridPerspective extends React.Component<Props, State> {
};
keyBindingHandlers = {
- nextDocument: () => {
- const nextFilePath = this.props.getNextFile();
- if (nextFilePath) {
- const nextFile = this.props.directoryContent.filter(
- entry => entry.path === nextFilePath
- );
- this.props.setLastSelectedEntry(nextFilePath);
- this.props.setSelectedEntries(nextFile);
- }
- },
- prevDocument: () => {
- const prevFilePath = this.props.getPrevFile();
- if (prevFilePath) {
- const prevFile = this.props.directoryContent.filter(
- entry => entry.path === prevFilePath
- );
- this.props.setLastSelectedEntry(prevFilePath);
- this.props.setSelectedEntries(prevFile);
- }
- },
+ nextDocument: () => this.props.openNextFile(),
+ prevDocument: () => this.props.openPrevFile(),
selectAll: () => this.toggleSelectAllFiles(),
deleteDocument: () => {
if (this.state.fileOperationsEnabled) {
@@ -972,8 +954,8 @@ function mapActionCreatorsToProps(dispatch) {
showNotification: AppActions.showNotification,
openFileNatively: AppActions.openFileNatively,
openURLExternally: AppActions.openURLExternally,
- getNextFile: AppActions.getNextFile,
- getPrevFile: AppActions.getPrevFile,
+ openNextFile: AppActions.openNextFile,
+ openPrevFile: AppActions.openPrevFile,
addTags: TaggingActions.addTags
},
dispatch
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index f059e504a..8b0862cae 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -686,6 +686,79 @@ export default (state: any = initialState, action: any) => {
}
};
+function getNextFile(
+ pivotFilePath?: string,
+ lastSelectedEntry?: string,
+ currentDirectoryEntries?: Array<FileSystemEntry>
+): FileSystemEntry {
+ const currentEntries = currentDirectoryEntries
+ ? currentDirectoryEntries.filter(entry => entry.isFile)
+ : [];
+ let filePath = pivotFilePath;
+ if (!filePath) {
+ if (lastSelectedEntry) {
+ filePath = lastSelectedEntry;
+ } else if (currentEntries.length > 0) {
+ filePath = currentEntries[0].path;
+ } else {
+ return undefined;
+ }
+ }
+ let nextFile;
+ currentEntries.forEach((entry, index) => {
+ if (entry.path === filePath) {
+ const nextIndex = index + 1;
+ if (nextIndex < currentEntries.length) {
+ nextFile = currentEntries[nextIndex];
+ } else {
+ // eslint-disable-next-line prefer-destructuring
+ nextFile = currentEntries[0];
+ }
+ }
+ });
+ if (nextFile === undefined) {
+ // eslint-disable-next-line prefer-destructuring
+ nextFile = currentEntries[0];
+ }
+ return nextFile;
+}
+
+function getPrevFile(
+ pivotFilePath?: string,
+ lastSelectedEntry?: string,
+ currentDirectoryEntries?: Array<FileSystemEntry>
+): FileSystemEntry {
+ const currentEntries = currentDirectoryEntries
+ ? currentDirectoryEntries.filter(entry => entry.isFile)
+ : [];
+ let filePath = pivotFilePath;
+ if (!filePath) {
+ if (lastSelectedEntry) {
+ filePath = lastSelectedEntry;
+ } else if (currentEntries.length > 0) {
+ filePath = currentEntries[0].path;
+ } else {
+ return undefined;
+ }
+ }
+ let prevFile;
+ currentEntries.forEach((entry, index) => {
+ if (entry.path === filePath) {
+ const prevIndex = index - 1;
+ if (prevIndex >= 0) {
+ prevFile = currentEntries[prevIndex];
+ } else {
+ prevFile = currentEntries[currentEntries.length - 1];
+ }
+ }
+ });
+ if (prevFile === undefined) {
+ // eslint-disable-next-line prefer-destructuring
+ prevFile = currentEntries[0];
+ }
+ return prevFile;
+}
+
export const actions = {
goOnline: () => ({ type: types.DEVICE_ONLINE }),
goOffline: () => ({ type: types.DEVICE_OFFLINE }),
@@ -1404,67 +1477,36 @@ export const actions = {
type: types.SET_ENTRY_FULLWIDTH,
isFullWidth
}),
- getNextFile: (pivotFilePath?: string) => (
+ openNextFile: (path?: string) => (
dispatch: (actions: Object) => void,
getState: () => any
) => {
- const currentEntries = getState().app.currentDirectoryEntries.filter(
- entry => entry.isFile
+ const nextFile = getNextFile(
+ path,
+ getState().app.lastSelectedEntry,
+ getState().app.currentDirectoryEntries
);
- const { lastSelectedEntry } = getState().app;
- let filePath = pivotFilePath;
- if (!filePath) {
- if (lastSelectedEntry) {
- filePath = lastSelectedEntry;
- } else if (currentEntries.length > 0) {
- filePath = currentEntries[0].path;
- } else {
- return false;
- }
+ if (nextFile !== undefined) {
+ dispatch(actions.openFsEntry(nextFile));
+ dispatch(actions.setLastSelectedEntry(nextFile.path));
+ dispatch(actions.setSelectedEntries([nextFile]));
+ return nextFile;
}
- let nextFilePath;
- currentEntries.forEach((entry, index) => {
- if (entry.path === filePath) {
- const nextIndex = index + 1;
- if (nextIndex < currentEntries.length) {
- nextFilePath = currentEntries[nextIndex].path;
- } else {
- nextFilePath = currentEntries[0].path;
- }
- }
- });
- return nextFilePath;
},
- getPrevFile: (pivotFilePath?: string) => (
+ openPrevFile: (path?: string) => (
dispatch: (actions: Object) => void,
getState: () => any
) => {
- const currentEntries = getState().app.currentDirectoryEntries.filter(
- entry => entry.isFile
+ const prevFile = getPrevFile(
+ path,
+ getState().app.lastSelectedEntry,
+ getState().app.currentDirectoryEntries
);
- const { lastSelectedEntry } = getState().app;
- let filePath = pivotFilePath;
- if (!filePath) {
- if (lastSelectedEntry) {
- filePath = lastSelectedEntry;
- } else if (currentEntries.length > 0) {
- filePath = currentEntries[0].path;
- } else {
- return false;
- }
+ if (prevFile !== undefined) {
+ dispatch(actions.openFsEntry(prevFile));
+ dispatch(actions.setLastSelectedEntry(prevFile.path));
+ dispatch(actions.setSelectedEntries([prevFile]));
}
- let prevFilePath;
- currentEntries.forEach((entry, index) => {
- if (entry.path === filePath) {
- const prevIndex = index - 1;
- if (prevIndex >= 0) {
- prevFilePath = currentEntries[prevIndex].path;
- } else {
- prevFilePath = currentEntries[currentEntries.length - 1].path;
- }
- }
- });
- return prevFilePath;
},
closeAllFiles: () => ({ type: types.CLOSE_ALL_FILES }),
reflectDeleteEntryInt: (path: string) => ({
diff --git a/app/services/electron-menus.ts b/app/services/electron-menus.ts
index 16cbdabb8..528afcc71 100644
--- a/app/services/electron-menus.ts
+++ b/app/services/electron-menus.ts
@@ -19,13 +19,12 @@
import i18n from './i18n';
import PlatformIO from './platform-io';
import AppConfig from '../config';
-import { FileSystemEntry, getAllPropertiesPromise } from '-/services/utils-io';
let ipcRenderer;
if (AppConfig.isElectron && window.require) {
const electron = window.require('electron');
- ipcRenderer = electron.ipcRenderer;
+ ({ ipcRenderer } = electron);
}
export default function buildDesktopMenu(mainPageProps: any) {
@@ -46,35 +45,11 @@ export default function buildDesktopMenu(mainPageProps: any) {
// console.log('showAudioRecordingDialog');
break;
case 'next-file': {
- const path = mainPageProps.getNextFile();
- getAllPropertiesPromise(path)
- .then((fsEntry: FileSystemEntry) => {
- mainPageProps.openFsEntry(fsEntry);
- mainPageProps.setLastSelectedEntry(path);
- mainPageProps.setSelectedEntries([path]);
- return true;
- })
- .catch(error =>
- console.warn(
- 'Error getting properties for entry: ' + path + ' - ' + error
- )
- );
+ mainPageProps.openNextFile();
break;
}
case 'previous-file': {
- const path = mainPageProps.getPrevFile();
- getAllPropertiesPromise(path)
- .then((fsEntry: FileSystemEntry) => {
- mainPageProps.openFsEntry(fsEntry);
- mainPageProps.setLastSelectedEntry(path);
- mainPageProps.setSelectedEntries([path]);
- return true;
- })
- .catch(error =>
- console.warn(
- 'Error getting properties for entry: ' + path + ' - ' + error
- )
- );
+ mainPageProps.openPrevFile();
break;
}
default:
diff --git a/app/services/electron-tray-menu.ts b/app/services/electron-tray-menu.ts
index bb4e8d42a..d90ed6aa5 100644
--- a/app/services/electron-tray-menu.ts
+++ b/app/services/electron-tray-menu.ts
@@ -20,7 +20,6 @@
import PlatformIO from './platform-io';
import i18n from './i18n';
import AppConfig from '../config';
-import { FileSystemEntry, getAllPropertiesPromise } from '-/services/utils-io';
export default function buildTrayIconMenu(mainPageProps: any) {
if (!AppConfig.isElectron) {
@@ -30,35 +29,11 @@ export default function buildTrayIconMenu(mainPageProps: any) {
const cKey = AppConfig.isMacLike ? ' - Cmd' : ' - Ctrl';
function openNextFile() {
- const path = mainPageProps.getNextFile();
- getAllPropertiesPromise(path)
- .then((fsEntry: FileSystemEntry) => {
- mainPageProps.openFsEntry(fsEntry);
- mainPageProps.setLastSelectedEntry(path);
- mainPageProps.setSelectedEntries([path]);
- return true;
- })
- .catch(error =>
- console.warn(
- 'Error getting properties for entry: ' + path + ' - ' + error
- )
- );
+ mainPageProps.openNextFile();
}
function openPrevFile() {
- const path = mainPageProps.getPrevFile();
- getAllPropertiesPromise(path)
- .then((fsEntry: FileSystemEntry) => {
- mainPageProps.openFsEntry(fsEntry);
- mainPageProps.setLastSelectedEntry(path);
- mainPageProps.setSelectedEntries([path]);
- return true;
- })
- .catch(error =>
- console.warn(
- 'Error getting properties for entry: ' + path + ' - ' + error
- )
- );
+ mainPageProps.openPrevFile();
}
function playResumePlayback() {