-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make use of menu items extension point
Refactors apps to use the new `appMenuItem` extension point instead of the deprecated `applicationMenu` property.
- Loading branch information
1 parent
3dc9a0b
commit f554f91
Showing
11 changed files
with
185 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/web-pkg/src/composables/actions/useOpenEmptyEditor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useGettext } from 'vue3-gettext' | ||
import { useGetMatchingSpace } from '../spaces' | ||
import { useAppsStore, useResourcesStore, useSpacesStore } from '../piniaStores' | ||
import { useClientService } from '../clientService' | ||
import { EDITOR_MODE_EDIT, useFileActions } from './files' | ||
import { storeToRefs } from 'pinia' | ||
import { unref } from 'vue' | ||
import { resolveFileNameDuplicate } from '../../helpers' | ||
import { urlJoin } from '@ownclouders/web-client' | ||
|
||
// open an editor with an empty file within the current folder | ||
export const useOpenEmptyEditor = () => { | ||
const { getMatchingSpace } = useGetMatchingSpace() | ||
const spacesStore = useSpacesStore() | ||
const appsStore = useAppsStore() | ||
const resourcesStore = useResourcesStore() | ||
const clientService = useClientService() | ||
const { $gettext } = useGettext() | ||
const { openEditor } = useFileActions() | ||
const { resources, currentFolder } = storeToRefs(resourcesStore) | ||
|
||
const openEmptyEditor = async (appId: string, extension: string) => { | ||
let destinationSpace = unref(currentFolder) ? getMatchingSpace(unref(currentFolder)) : null | ||
let destinationFiles = unref(resources) | ||
let filePath = unref(currentFolder)?.path | ||
|
||
if (!destinationSpace || !unref(currentFolder).canCreate()) { | ||
destinationSpace = spacesStore.personalSpace | ||
destinationFiles = (await clientService.webdav.listFiles(destinationSpace)).children | ||
filePath = '' | ||
} | ||
|
||
let fileName = $gettext('New file') + `.${extension}` | ||
|
||
if (destinationFiles.some((f) => f.name === fileName)) { | ||
fileName = resolveFileNameDuplicate(fileName, extension, destinationFiles) | ||
} | ||
|
||
const emptyResource = await clientService.webdav.putFileContents(destinationSpace, { | ||
path: urlJoin(filePath, fileName) | ||
}) | ||
|
||
const space = getMatchingSpace(emptyResource) | ||
const appFileExtension = appsStore.fileExtensions.find( | ||
({ app, extension: ext }) => app === appId && ext === extension | ||
) | ||
|
||
openEditor(appFileExtension, space, emptyResource, EDITOR_MODE_EDIT) | ||
} | ||
|
||
return { | ||
openEmptyEditor | ||
} | ||
} |
Oops, something went wrong.