mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:19:35 +08:00
parent
282d2bbc66
commit
a88fe322b4
@ -3,10 +3,10 @@
|
||||
import fs from 'fs'
|
||||
// import chokidar from 'chokidar'
|
||||
import path from 'path'
|
||||
import { app, dialog, ipcMain, BrowserWindow } from 'electron'
|
||||
import { app, BrowserWindow, dialog, ipcMain } from 'electron'
|
||||
import createWindow, { windows } from '../createWindow'
|
||||
import { EXTENSIONS, EXTENSION_HASN } from '../config'
|
||||
import { getPath, log, isMarkdownFile } from '../utils'
|
||||
import { EXTENSION_HASN, EXTENSIONS } from '../config'
|
||||
import { getPath, isMarkdownFile, log } from '../utils'
|
||||
import userPreference from '../preference'
|
||||
|
||||
const watchAndReload = (pathname, win) => { // when i build, and failed.
|
||||
@ -134,6 +134,44 @@ ipcMain.on('AGANI::window::drop', (e, fileList) => {
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('AGANI::response-file-move-to', (e, { pathname }) => {
|
||||
const win = BrowserWindow.fromWebContents(e.sender)
|
||||
if (pathname !== '') {
|
||||
let newPath = dialog.showSaveDialog(win, {
|
||||
buttonLabel: 'Move or rename',
|
||||
nameFieldLabel: 'Filename:',
|
||||
defaultPath: pathname
|
||||
})
|
||||
if (newPath === undefined) return
|
||||
if (!fs.existsSync(newPath)) {
|
||||
fs.renameSync(pathname, newPath)
|
||||
e.sender.send('AGANI::set-pathname', { pathname: newPath, filename: path.basename(newPath) })
|
||||
} else {
|
||||
dialog.showMessageBox(win, {
|
||||
type: 'warning',
|
||||
buttons: ['Replace', 'Cancel'],
|
||||
defaultId: 1,
|
||||
message: `The file ${pathname} already exists. Do you want to replace it?`,
|
||||
cancelId: 1,
|
||||
noLink: true
|
||||
}, index => {
|
||||
if (index === 0) {
|
||||
fs.renameSync(pathname, newPath)
|
||||
e.sender.send('AGANI::set-pathname', { pathname: newPath, filename: path.basename(newPath) })
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
dialog.showMessageBox(win, {
|
||||
type: 'info',
|
||||
buttons: ['OK'],
|
||||
message: `Please save the file before moving it!`,
|
||||
cancelId: 0,
|
||||
noLink: true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const exportFile = (win, type) => {
|
||||
win.webContents.send('AGANI::export', { type })
|
||||
}
|
||||
@ -144,7 +182,7 @@ export const print = win => {
|
||||
|
||||
export const open = win => {
|
||||
const filename = dialog.showOpenDialog(win, {
|
||||
properties: [ 'openFile' ],
|
||||
properties: ['openFile'],
|
||||
filters: [{
|
||||
name: 'text',
|
||||
extensions: EXTENSIONS
|
||||
@ -178,3 +216,7 @@ export const autoSave = (menuItem, browserWindow) => {
|
||||
})
|
||||
.catch(log)
|
||||
}
|
||||
|
||||
export const moveTo = win => {
|
||||
win.webContents.send('AGANI::ask-file-move-to')
|
||||
}
|
||||
|
@ -50,6 +50,13 @@ export default {
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Move To...',
|
||||
click (menuItem, browserWindow) {
|
||||
actions.moveTo(browserWindow)
|
||||
}
|
||||
}, {
|
||||
type: 'separator'
|
||||
}, {
|
||||
label: 'Export Styled HTML',
|
||||
click (menuItem, browserWindow) {
|
||||
|
@ -79,6 +79,7 @@
|
||||
dispatch('ASK_FOR_MODE')
|
||||
dispatch('LISTEN_FOR_CLOSE')
|
||||
dispatch('LISTEN_FOR_SAVE_AS')
|
||||
dispatch('LISTEN_FOR_MOVE_TO')
|
||||
dispatch('LINTEN_WIN_STATUS')
|
||||
dispatch('LISTEN_FOR_SAVE')
|
||||
dispatch('GET_FILENAME')
|
||||
|
@ -135,6 +135,13 @@ const actions = {
|
||||
})
|
||||
},
|
||||
|
||||
LISTEN_FOR_MOVE_TO ({ commit, state }) {
|
||||
ipcRenderer.on('AGANI::ask-file-move-to', () => {
|
||||
const { pathname } = state
|
||||
ipcRenderer.send('AGANI::response-file-move-to', { pathname })
|
||||
})
|
||||
},
|
||||
|
||||
GET_FILENAME ({ commit, state }) {
|
||||
ipcRenderer.on('AGANI::set-pathname', (e, { pathname, filename }) => {
|
||||
commit('SET_FILENAME', filename)
|
||||
|
Loading…
Reference in New Issue
Block a user