|
1 | 1 | <template> |
2 | 2 | <div> |
3 | | - <div class="row" :class="{ clickable: canEdit(file) }"> |
| 3 | + <div class="row" :class="{ clickable: canEdit(file) }" v-on:contextmenu="showContextMenu"> |
4 | 4 | <div class="flex-none icon"> |
5 | 5 | <file-text-icon v-if="!file.symlink"/> |
6 | 6 | <link2-icon v-else/> |
|
10 | 10 | <div class="flex-1 text-right text-grey-dark">{{formatDate(file.modified)}}</div> |
11 | 11 | <div class="flex-none w-1/6"></div> |
12 | 12 | </div> |
| 13 | + <div class="context-menu" v-show="contextMenuVisible" ref="contextMenu"> |
| 14 | + <div> |
| 15 | + <div class="context-row"> |
| 16 | + <div class="icon"><edit3-icon/></div> |
| 17 | + <div class="action"><span>Rename</span></div> |
| 18 | + </div> |
| 19 | + <div class="context-row"> |
| 20 | + <div class="icon"><corner-up-left-icon class="h-4"/></div> |
| 21 | + <div class="action"><span class="text-left">Move</span></div> |
| 22 | + </div> |
| 23 | + <div class="context-row"> |
| 24 | + <div class="icon"><copy-icon class="h-4"/></div> |
| 25 | + <div class="action">Copy</div> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + <div> |
| 29 | + <div class="context-row"> |
| 30 | + <div class="icon"><file-plus-icon class="h-4"/></div> |
| 31 | + <div class="action">New File</div> |
| 32 | + </div> |
| 33 | + <div class="context-row"> |
| 34 | + <div class="icon"><folder-plus-icon class="h-4"/></div> |
| 35 | + <div class="action">New Folder</div> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + <div> |
| 39 | + <div class="context-row"> |
| 40 | + <div class="icon"><download-icon class="h-4"/></div> |
| 41 | + <div class="action">Download</div> |
| 42 | + </div> |
| 43 | + <div class="context-row danger"> |
| 44 | + <div class="icon"><delete-icon class="h-4"/></div> |
| 45 | + <div class="action">Delete</div> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + </div> |
13 | 49 | </div> |
14 | 50 | </template> |
15 | 51 |
|
16 | 52 | <script> |
17 | | - import { FileTextIcon, Link2Icon } from 'vue-feather-icons'; |
| 53 | + import { CopyIcon, CornerUpLeftIcon, DeleteIcon, DownloadIcon, Edit3Icon, FileTextIcon, FilePlusIcon, FolderPlusIcon, Link2Icon } from 'vue-feather-icons'; |
18 | 54 | import * as Helpers from './../../../helpers/index'; |
19 | 55 |
|
20 | 56 | export default { |
21 | 57 | name: 'file-manager-file-row', |
22 | | - components: { FileTextIcon, Link2Icon }, |
| 58 | + components: { |
| 59 | + CopyIcon, CornerUpLeftIcon, DeleteIcon, DownloadIcon, |
| 60 | + Edit3Icon, FileTextIcon, FilePlusIcon, FolderPlusIcon, |
| 61 | + Link2Icon, |
| 62 | + }, |
23 | 63 | props: { |
24 | 64 | file: {type: Object, required: true}, |
25 | 65 | editable: {type: Array, required: true} |
26 | 66 | }, |
27 | 67 |
|
| 68 | + data: function () { |
| 69 | + return { |
| 70 | + listener: null, |
| 71 | + contextMenuVisible: false, |
| 72 | + }; |
| 73 | + }, |
| 74 | +
|
28 | 75 | mounted: function () { |
| 76 | + // Handle a click anywhere in the document and hide the context menu if that click is not |
| 77 | + // a right click and isn't occurring somewhere in the currently visible context menu. |
| 78 | + this.listener = document.addEventListener('click', (e) => { |
| 79 | + if (e.button !== 2 |
| 80 | + && this.contextMenuVisible |
| 81 | + && e.target !== this.$refs.contextMenu |
| 82 | + && !this.$refs.contextMenu.contains(e.target) |
| 83 | + ) { |
| 84 | + this.contextMenuVisible = false; |
| 85 | + } |
| 86 | + }); |
29 | 87 |
|
| 88 | + // If the parent component emits the collapse menu event check if the unique ID of the component |
| 89 | + // is this one. If not, collapse the menu (we right clicked into another element). |
| 90 | + this.$parent.$on('collapse-menus', (uid) => { |
| 91 | + if (this._uid !== uid) { |
| 92 | + this.contextMenuVisible = false; |
| 93 | + } |
| 94 | + }) |
| 95 | + }, |
| 96 | +
|
| 97 | + beforeDestroy: function () { |
| 98 | + document.removeEventListener('click', this.listener); |
30 | 99 | }, |
31 | 100 |
|
32 | 101 | methods: { |
| 102 | + /** |
| 103 | + * Handle a right-click action on a file manager row. |
| 104 | + * |
| 105 | + * @param {Event} e |
| 106 | + */ |
| 107 | + showContextMenu: function (e) { |
| 108 | + e.preventDefault(); |
| 109 | + this.$parent.$emit('collapse-menus', this._uid); |
| 110 | + this.contextMenuVisible = !this.contextMenuVisible; |
| 111 | + }, |
| 112 | +
|
33 | 113 | /** |
34 | 114 | * Determine if a file can be edited on the Panel. |
35 | 115 | * |
|
0 commit comments