Skip to content

Commit

Permalink
Merge pull request #2111 from owncloud/feature/new-file-menu
Browse files Browse the repository at this point in the history
Add new file menu entries for different file types.
  • Loading branch information
DeepDiver1975 authored Oct 23, 2019
2 parents bda01bc + c4bd641 commit 57636b4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 32 deletions.
7 changes: 6 additions & 1 deletion apps/draw-io/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const appInfo = {
extensions: [{
extension: 'drawio',
newTab: true,
routeName: 'draw-io-edit'
routeName: 'draw-io-edit',
newFileMenu: {
menuTitle ($gettext) {
return $gettext('Create new draw.io document…')
}
}
}
]
}
Expand Down
20 changes: 1 addition & 19 deletions apps/files/src/components/FilesApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ export default {
}
},
openFileAction (action, file) {
if (action.newTab) {
const path = this.$router.resolve({ name: action.routeName, params: { filePath: file.path } }).href
const url = window.location.origin + '/' + path
const target = `${action.routeName}-${file.path}`
const win = window.open(url, target)
win.focus()
return
}
// TODO: rewire code below ....
const appId = action.app
this.$emit('open', appId)
// TODO path to state
this.$router.push({
name: appId
})
},
openFileActionBar (file) {
this.openFile({
filePath: file.path
Expand All @@ -98,7 +80,7 @@ export default {
label: action.name,
icon: action.icon,
onClick: () => {
this.openFileAction(action, file)
this.openFileAction(action, file.path)
}
}
})
Expand Down
29 changes: 21 additions & 8 deletions apps/files/src/components/FilesAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
<file-upload :url='url' :headers="headers" @success="onFileSuccess" @error="onFileError" @progress="onFileProgress"></file-upload>
<folder-upload v-if="!isIE11()" :rootPath='item' :url='url' :headers="headers" @success="onFileSuccess" @error="onFileError" @progress="onFileProgress"></folder-upload>
<oc-nav-item @click="showCreateFolderDialog" id="new-folder-btn" icon="create_new_folder"><translate>Create new folder…</translate></oc-nav-item>
<oc-nav-item @click="showCreateFileDialog" id="new-file-btn" icon="save"><translate>Create new file…</translate></oc-nav-item>
<oc-nav-item v-for="(newFileHandler, key) in newFileHandlers"
:key="key"
@click="showCreateFileDialog(newFileHandler.ext, newFileHandler.action)" id="new-file-btn" icon="save">
{{ newFileHandler.menuTitle($gettext) }}</oc-nav-item>
</oc-nav>
</oc-drop>
</template>
Expand Down Expand Up @@ -106,6 +109,7 @@ export default {
newFolderName: '',
newFileName: '',
createFile: false,
newFileAction: null,
path: '',
searchedFiles: [],
fileFolderCreationLoading: false,
Expand All @@ -116,8 +120,8 @@ export default {
searchBarKey: 0
}),
computed: {
...mapGetters(['getToken', 'configuration']),
...mapGetters('Files', ['activeFiles', 'searchTerm', 'atSearchPage', 'currentFolder', 'davProperties', 'quota', 'selectedFiles', 'overwriteDialogTitle', 'overwriteDialogMessage', 'publicLinkPassword']),
...mapGetters(['getToken', 'configuration', 'newFileHandlers']),
...mapGetters('Files', ['activeFiles', 'inProgress', 'searchTerm', 'atSearchPage', 'currentFolder', 'davProperties', 'quota', 'selectedFiles', 'overwriteDialogTitle', 'overwriteDialogMessage', 'publicLinkPassword']),
...mapState(['route']),
searchLabel () {
return this.$gettext('Search')
Expand Down Expand Up @@ -380,9 +384,10 @@ export default {
return null
},
showCreateFileDialog () {
showCreateFileDialog (ext = 'txt', openAction = null) {
this.createFile = true
this.newFileName = this.$gettext('New file') + '.txt'
this.newFileAction = openAction
this.newFileName = this.$gettext('New file') + '.' + ext
},
addNewFile (fileName) {
if (fileName !== '') {
Expand All @@ -395,17 +400,25 @@ export default {
p.then(() => {
this.createFile = false
this.$_ocFilesFolder_getFolder()
this.fileFolderCreationLoading = false
if (this.newFileAction) {
// not cool - needs refactoring
this.$nextTick(() => {
this.openFile({
filePath: path + fileName
})
this.openFileAction(this.newFileAction, path + fileName)
})
}
})
.catch(error => {
this.fileFolderCreationLoading = false
this.showMessage({
title: this.$gettext('Creating file failed…'),
desc: error,
status: 'danger'
})
})
.finally(() => {
this.fileFolderCreationLoading = false
})
}
},
checkNewFileName (fileName) {
Expand Down
19 changes: 19 additions & 0 deletions apps/files/src/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,25 @@ export default {
item: param
}
})
},
openFileAction (action, filePath) {
if (action.newTab) {
const path = this.$router.resolve({ name: action.routeName, params: { filePath: filePath } }).href
const url = window.location.origin + '/' + path
const target = `${action.routeName}-${filePath}`
const win = window.open(url, target)
// in case popup is blocked win will be null
if (win) {
win.focus()
}
return
}
// TODO: rewire code below ....
const appId = action.app
// TODO path to state
this.$router.push({
name: appId
})
}
}
}
15 changes: 12 additions & 3 deletions apps/markdown-editor/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ const appInfo = {
icon: 'text',
isFileEditor: true,
extensions: [{
extension: 'txt'
extension: 'txt',
newFileMenu: {
menuTitle ($gettext) {
return $gettext('Create new plain text file…')
}
}
},
{
extension: 'md'
// icon: 'custom_icon_class_to_override_icon_for_filetype_md'
extension: 'md',
newFileMenu: {
menuTitle ($gettext) {
return $gettext('Create new mark-down file…')
}
}
}
]
}
Expand Down
12 changes: 11 additions & 1 deletion src/store/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const state = {
edit: false
},
extensions: {},
newFileHandlers: [],
fileSideBars: [],
meta: {}
}
Expand Down Expand Up @@ -73,13 +74,19 @@ const mutations = {
app: appInfo.id,
icon: e.icon,
newTab: e.newTab || false,
routeName: e.routeName || appInfo.id
routeName: e.routeName || appInfo.id,
newFileMenu: e.newFileMenu || null
}
if (!state.extensions[e.extension]) {
state.extensions[e.extension] = [link]
} else {
state.extensions[e.extension].push(link)
}
if (e.newFileMenu) {
e.newFileMenu.ext = e.extension
e.newFileMenu.action = link
state.newFileHandlers.push(e.newFileMenu)
}
})
}
if (appInfo.fileSideBars) {
Expand Down Expand Up @@ -113,6 +120,9 @@ const getters = {
activeFile: state => {
return state.file
},
newFileHandlers: state => {
return state.newFileHandlers
},
extensions: state => {
return fileExtension => {
const ext = state.extensions[fileExtension]
Expand Down

0 comments on commit 57636b4

Please sign in to comment.