Skip to content

Commit

Permalink
Add new file menu entries for different file types.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 1, 2019
1 parent 5b65bb3 commit 10ec386
Show file tree
Hide file tree
Showing 6 changed files with 69 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 @@ -67,24 +67,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 @@ -95,7 +77,7 @@ export default {
label: action.name,
icon: action.icon,
onClick: () => {
this.openFileAction(action, file)
this.openFileAction(action, file.path)
}
}
})
Expand Down
28 changes: 20 additions & 8 deletions apps/files/src/components/FilesAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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 @@ -97,14 +100,15 @@ export default {
newFolderName: '',
newFileName: '',
createFile: false,
newFileAction: null,
path: '',
searchedFiles: [],
fileFolderCreationLoading: false,
actionsKey: Math.floor(Math.random() * 20),
linkCopied: false
}),
computed: {
...mapGetters(['getToken', 'configuration']),
...mapGetters(['getToken', 'configuration', 'newFileHandlers']),
...mapGetters('Files', ['activeFiles', 'inProgress', 'searchTerm', 'atSearchPage', 'currentFolder', 'davProperties', 'quota', 'selectedFiles', 'overwriteDialogTitle', 'overwriteDialogMessage', 'publicLinkPassword']),
...mapState(['route']),
searchLabel () {
Expand Down Expand Up @@ -161,7 +165,6 @@ export default {
}
return this.currentFolder.canUpload()
},
$_ocFilesAppBar_showActions () {
return this.$route.meta.hideFilelistActions !== true
},
Expand Down Expand Up @@ -334,9 +337,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 @@ -349,17 +353,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 @@ -457,6 +457,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 10ec386

Please sign in to comment.