You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
feat: add context menu (#3343)
Co-authored-by: Henrique Dias <mail@hacdias.com>
This commit is contained in:
@@ -207,7 +207,10 @@
|
||||
<h2 v-if="fileStore.req?.numDirs ?? false">
|
||||
{{ t("files.folders") }}
|
||||
</h2>
|
||||
<div v-if="fileStore.req?.numDirs ?? false">
|
||||
<div
|
||||
v-if="fileStore.req?.numDirs ?? false"
|
||||
@contextmenu="showContextMenu"
|
||||
>
|
||||
<item
|
||||
v-for="item in dirs"
|
||||
:key="base64(item.name)"
|
||||
@@ -223,8 +226,13 @@
|
||||
</item>
|
||||
</div>
|
||||
|
||||
<h2 v-if="fileStore.req?.numFiles ?? false">{{ t("files.files") }}</h2>
|
||||
<div v-if="fileStore.req?.numFiles ?? false">
|
||||
<h2 v-if="fileStore.req?.numFiles ?? false">
|
||||
{{ t("files.files") }}
|
||||
</h2>
|
||||
<div
|
||||
v-if="fileStore.req?.numFiles ?? false"
|
||||
@contextmenu="showContextMenu"
|
||||
>
|
||||
<item
|
||||
v-for="item in files"
|
||||
:key="base64(item.name)"
|
||||
@@ -239,6 +247,53 @@
|
||||
>
|
||||
</item>
|
||||
</div>
|
||||
<context-menu
|
||||
:show="isContextMenuVisible"
|
||||
:pos="contextMenuPos"
|
||||
@hide="hideContextMenu"
|
||||
>
|
||||
<action
|
||||
v-if="headerButtons.share"
|
||||
icon="share"
|
||||
:label="t('buttons.share')"
|
||||
show="share"
|
||||
/>
|
||||
<action
|
||||
v-if="headerButtons.rename"
|
||||
icon="mode_edit"
|
||||
:label="t('buttons.rename')"
|
||||
show="rename"
|
||||
/>
|
||||
<action
|
||||
v-if="headerButtons.copy"
|
||||
id="copy-button"
|
||||
icon="content_copy"
|
||||
:label="t('buttons.copyFile')"
|
||||
show="copy"
|
||||
/>
|
||||
<action
|
||||
v-if="headerButtons.move"
|
||||
id="move-button"
|
||||
icon="forward"
|
||||
:label="t('buttons.moveFile')"
|
||||
show="move"
|
||||
/>
|
||||
<action
|
||||
v-if="headerButtons.delete"
|
||||
id="delete-button"
|
||||
icon="delete"
|
||||
:label="t('buttons.delete')"
|
||||
show="delete"
|
||||
/>
|
||||
<action
|
||||
v-if="headerButtons.download"
|
||||
icon="file_download"
|
||||
:label="t('buttons.download')"
|
||||
@action="download"
|
||||
:counter="fileStore.selectedCount"
|
||||
/>
|
||||
<action icon="info" :label="t('buttons.info')" show="info" />
|
||||
</context-menu>
|
||||
|
||||
<input
|
||||
style="display: none"
|
||||
@@ -291,6 +346,7 @@ import HeaderBar from "@/components/header/HeaderBar.vue";
|
||||
import Action from "@/components/header/Action.vue";
|
||||
import Search from "@/components/Search.vue";
|
||||
import Item from "@/components/files/ListingItem.vue";
|
||||
import ContextMenu from "@/components/ContextMenu.vue";
|
||||
import {
|
||||
computed,
|
||||
inject,
|
||||
@@ -310,6 +366,8 @@ const columnWidth = ref<number>(280);
|
||||
const dragCounter = ref<number>(0);
|
||||
const width = ref<number>(window.innerWidth);
|
||||
const itemWeight = ref<number>(0);
|
||||
const isContextMenuVisible = ref<boolean>(false);
|
||||
const contextMenuPos = ref<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
@@ -438,7 +496,7 @@ watch(req, () => {
|
||||
|
||||
onMounted(() => {
|
||||
// Check the columns size for the first time.
|
||||
colunmsResize();
|
||||
columnsResize();
|
||||
|
||||
// How much every listing item affects the window height
|
||||
setItemWeight();
|
||||
@@ -642,7 +700,7 @@ const paste = (event: Event) => {
|
||||
action(overwrite, rename);
|
||||
};
|
||||
|
||||
const colunmsResize = () => {
|
||||
const columnsResize = () => {
|
||||
// Update the columns size based on the window width.
|
||||
const items_ = css(["#listing.mosaic .item", ".mosaic#listing .item"]);
|
||||
if (items_ === null) return;
|
||||
@@ -850,7 +908,7 @@ const toggleMultipleSelection = () => {
|
||||
};
|
||||
|
||||
const windowsResize = throttle(() => {
|
||||
colunmsResize();
|
||||
columnsResize();
|
||||
width.value = window.innerWidth;
|
||||
|
||||
// Listing element is not displayed
|
||||
@@ -977,4 +1035,17 @@ const revealPreviousItem = () => {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const showContextMenu = (event: MouseEvent) => {
|
||||
event.preventDefault();
|
||||
isContextMenuVisible.value = true;
|
||||
contextMenuPos.value = {
|
||||
x: event.clientX + 8,
|
||||
y: event.clientY + Math.floor(window.scrollY),
|
||||
};
|
||||
};
|
||||
|
||||
const hideContextMenu = () => {
|
||||
isContextMenuVisible.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user