marktext/src/renderer/mixins/index.js
冉四夕 4be72ade97
Notification (#337)
* rewrite notice module

* optimization: show some notification when export html or pdf

* optimization: style of open project button

* little bug fix

* style: uniform titlebar hight to remove some style error
2018-06-15 21:30:10 +08:00

64 lines
1.7 KiB
JavaScript

import { getFileStateFromData } from '../store/help.js'
export const tabsMixins = {
methods: {
selectFile (file) {
if (file.id !== this.currentFile.id) {
this.$store.dispatch('UPDATE_CURRENT_FILE', file)
}
},
removeFileInTab (file) {
const { isSaved } = file
if (isSaved) {
this.$store.dispatch('REMOVE_FILE_IN_TABS', file)
} else {
this.$store.dispatch('CLOSE_SINGLE_FILE', file)
}
}
}
}
export const fileMixins = {
methods: {
handleFileClick () {
const { data, isMarkdown, pathname } = this.file
if (!isMarkdown || this.currentFile.pathname === pathname) return
const { isMixed, filename, lineEnding } = data
const isOpened = this.tabs.filter(file => file.pathname === pathname)[0]
const fileState = isOpened || getFileStateFromData(data)
this.$store.dispatch('UPDATE_CURRENT_FILE', fileState)
if (isMixed && !isOpened) {
this.$notify({
title: 'Line Ending',
message: `${filename} has mixed line endings which are automatically normalized to ${lineEnding.toUpperCase()}.`,
type: 'primary',
time: 20000,
showConfirm: false
})
}
}
}
}
export const createFileOrDirectoryMixins = {
methods: {
handleInputFocus () {
this.$nextTick(() => {
if (this.$refs.input) {
this.$refs.input.focus()
this.createName = ''
if (this.folder) {
this.folder.isCollapsed = false
}
}
})
},
handleInputEnter () {
const { createName } = this
this.$store.dispatch('CREATE_FILE_DIRECTORY', createName)
}
}
}