Skip to content

Commit ed742c7

Browse files
Merge branch 'master' into feature/autoBracketMatching
2 parents 9bc291e + 3f77cb2 commit ed742c7

File tree

18 files changed

+212
-133
lines changed

18 files changed

+212
-133
lines changed

browser/components/CodeEditor.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ export default class CodeEditor extends React.Component {
7878
this.scrollToLineHandeler = this.scrollToLine.bind(this)
7979

8080
this.formatTable = () => this.handleFormatTable()
81-
this.contextMenuHandler = function (editor, event) {
82-
const menu = buildEditorContextMenu(editor, event)
83-
if (menu != null) {
84-
setTimeout(() => menu.popup(remote.getCurrentWindow()), 30)
81+
82+
if (props.switchPreview !== 'RIGHTCLICK') {
83+
this.contextMenuHandler = function (editor, event) {
84+
const menu = buildEditorContextMenu(editor, event)
85+
if (menu != null) {
86+
setTimeout(() => menu.popup(remote.getCurrentWindow()), 30)
87+
}
8588
}
8689
}
90+
8791
this.editorActivityHandler = () => this.handleEditorActivity()
8892

8993
this.turndownService = new TurndownService()
@@ -152,10 +156,7 @@ export default class CodeEditor extends React.Component {
152156
}
153157

154158
componentDidMount () {
155-
const {
156-
rulers,
157-
enableRulers
158-
} = this.props
159+
const { rulers, enableRulers, switchPreview } = this.props
159160
const expandSnippet = this.expandSnippet.bind(this)
160161
eventEmitter.on('line:jump', this.scrollToLineHandeler)
161162

@@ -257,7 +258,9 @@ export default class CodeEditor extends React.Component {
257258
this.editor.on('blur', this.blurHandler)
258259
this.editor.on('change', this.changeHandler)
259260
this.editor.on('paste', this.pasteHandler)
260-
this.editor.on('contextmenu', this.contextMenuHandler)
261+
if (switchPreview !== 'RIGHTCLICK') {
262+
this.editor.on('contextmenu', this.contextMenuHandler)
263+
}
261264
eventEmitter.on('top:search', this.searchHandler)
262265

263266
eventEmitter.emit('code:init')

browser/components/MarkdownEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class MarkdownEditor extends React.Component {
281281
onChange={(e) => this.handleChange(e)}
282282
onBlur={(e) => this.handleBlur(e)}
283283
spellCheck={config.editor.spellcheck}
284+
switchPreview={config.editor.switchPreview}
284285
/>
285286
<MarkdownPreview styleName={this.state.status === 'PREVIEW'
286287
? 'preview'

browser/components/MarkdownPreview.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,7 @@ export default class MarkdownPreview extends React.Component {
291291
}
292292

293293
handleSaveAsMd () {
294-
this.exportAsDocument('md', (noteContent, exportTasks) => {
295-
let result = noteContent
296-
if (this.props && this.props.storagePath && this.props.noteKey) {
297-
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
298-
noteContent,
299-
this.props.storagePath
300-
)
301-
attachmentsAbsolutePaths.forEach(attachment => {
302-
exportTasks.push({
303-
src: attachment,
304-
dst: attachmentManagement.DESTINATION_FOLDER
305-
})
306-
})
307-
result = attachmentManagement.removeStorageAndNoteReferences(
308-
noteContent,
309-
this.props.noteKey
310-
)
311-
}
312-
return result
313-
})
294+
this.exportAsDocument('md')
314295
}
315296

316297
handleSaveAsHtml () {
@@ -339,11 +320,6 @@ export default class MarkdownPreview extends React.Component {
339320
)
340321
let body = this.markdown.render(noteContent)
341322
const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
342-
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
343-
noteContent,
344-
this.props.storagePath
345-
)
346-
347323
files.forEach(file => {
348324
if (global.process.platform === 'win32') {
349325
file = file.replace('file:///', '')
@@ -355,16 +331,6 @@ export default class MarkdownPreview extends React.Component {
355331
dst: 'css'
356332
})
357333
})
358-
attachmentsAbsolutePaths.forEach(attachment => {
359-
exportTasks.push({
360-
src: attachment,
361-
dst: attachmentManagement.DESTINATION_FOLDER
362-
})
363-
})
364-
body = attachmentManagement.removeStorageAndNoteReferences(
365-
body,
366-
this.props.noteKey
367-
)
368334

369335
let styles = ''
370336
files.forEach(file => {
@@ -397,8 +363,9 @@ export default class MarkdownPreview extends React.Component {
397363
if (filename) {
398364
const content = this.props.value
399365
const storage = this.props.storagePath
366+
const nodeKey = this.props.noteKey
400367

401-
exportNote(storage, content, filename, contentFormatter)
368+
exportNote(nodeKey, storage, content, filename, contentFormatter)
402369
.then(res => {
403370
dialog.showMessageBox(remote.getCurrentWindow(), {
404371
type: 'info',

browser/components/MarkdownSplitEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class MarkdownSplitEditor extends React.Component {
175175
onChange={this.handleOnChange.bind(this)}
176176
onScroll={this.handleScroll.bind(this)}
177177
spellCheck={config.editor.spellcheck}
178+
switchPreview={config.editor.switchPreview}
178179
/>
179180
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
180181
<div styleName='slider-hitbox' />

browser/main/Detail/InfoPanel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ class InfoPanel extends React.Component {
7070
<hr />
7171

7272
<div id='export-wrap'>
73-
<button styleName='export--enable' onClick={(e) => exportAsMd(e)}>
73+
<button styleName='export--enable' onClick={(e) => exportAsMd(e, 'export-md')}>
7474
<i className='fa fa-file-code-o' />
7575
<p>{i18n.__('.md')}</p>
7676
</button>
7777

78-
<button styleName='export--enable' onClick={(e) => exportAsTxt(e)}>
78+
<button styleName='export--enable' onClick={(e) => exportAsTxt(e, 'export-txt')}>
7979
<i className='fa fa-file-text-o' />
8080
<p>{i18n.__('.txt')}</p>
8181
</button>
8282

83-
<button styleName='export--enable' onClick={(e) => exportAsHtml(e)}>
83+
<button styleName='export--enable' onClick={(e) => exportAsHtml(e, 'export-html')}>
8484
<i className='fa fa-html5' />
8585
<p>{i18n.__('.html')}</p>
8686
</button>
8787

88-
<button styleName='export--enable' onClick={(e) => print(e)}>
88+
<button styleName='export--enable' onClick={(e) => print(e, 'print')}>
8989
<i className='fa fa-print' />
9090
<p>{i18n.__('Print')}</p>
9191
</button>

browser/main/Detail/InfoPanelTrashed.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ const InfoPanelTrashed = ({
3131
</div>
3232

3333
<div id='export-wrap'>
34-
<button styleName='export--enable' onClick={(e) => exportAsMd(e)}>
34+
<button styleName='export--enable' onClick={(e) => exportAsMd(e, 'export-md')}>
3535
<i className='fa fa-file-code-o' />
3636
<p>.md</p>
3737
</button>
3838

39-
<button styleName='export--enable' onClick={(e) => exportAsTxt(e)}>
39+
<button styleName='export--enable' onClick={(e) => exportAsTxt(e, 'export-txt')}>
4040
<i className='fa fa-file-text-o' />
4141
<p>.txt</p>
4242
</button>
4343

44-
<button styleName='export--enable' onClick={(e) => exportAsHtml(e)}>
44+
<button styleName='export--enable' onClick={(e) => exportAsHtml(e, 'export-html')}>
4545
<i className='fa fa-html5' />
4646
<p>.html</p>
4747
</button>

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,18 @@ class SnippetNoteDetail extends React.Component {
645645
if (infoPanel.style) infoPanel.style.display = infoPanel.style.display === 'none' ? 'inline' : 'none'
646646
}
647647

648-
showWarning () {
648+
showWarning (e, msg) {
649+
const warningMessage = (msg) => ({
650+
'export-txt': 'Text export',
651+
'export-md': 'Markdown export',
652+
'export-html': 'HTML export',
653+
'print': 'Print'
654+
})[msg]
655+
649656
dialog.showMessageBox(remote.getCurrentWindow(), {
650657
type: 'warning',
651658
message: i18n.__('Sorry!'),
652-
detail: i18n.__('md/text import is available only a markdown note.'),
659+
detail: i18n.__(warningMessage(msg) + ' is available only in markdown notes.'),
653660
buttons: [i18n.__('OK')]
654661
})
655662
}
@@ -803,7 +810,9 @@ class SnippetNoteDetail extends React.Component {
803810
createdAt={formatDate(note.createdAt)}
804811
exportAsMd={this.showWarning}
805812
exportAsTxt={this.showWarning}
813+
exportAsHtml={this.showWarning}
806814
type={note.type}
815+
print={this.showWarning}
807816
/>
808817
</div>
809818
</div>

browser/main/NoteList/index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ class NoteList extends React.Component {
6464
this.focusHandler = () => {
6565
this.refs.list.focus()
6666
}
67-
this.alertIfSnippetHandler = () => {
68-
this.alertIfSnippet()
67+
this.alertIfSnippetHandler = (event, msg) => {
68+
this.alertIfSnippet(msg)
6969
}
7070
this.importFromFileHandler = this.importFromFile.bind(this)
7171
this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this)
7272
this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this)
7373
this.getNoteKeyFromTargetIndex = this.getNoteKeyFromTargetIndex.bind(this)
74+
this.cloneNote = this.cloneNote.bind(this)
7475
this.deleteNote = this.deleteNote.bind(this)
7576
this.focusNote = this.focusNote.bind(this)
7677
this.pinToTop = this.pinToTop.bind(this)
@@ -96,6 +97,7 @@ class NoteList extends React.Component {
9697
this.refreshTimer = setInterval(() => this.forceUpdate(), 60 * 1000)
9798
ee.on('list:next', this.selectNextNoteHandler)
9899
ee.on('list:prior', this.selectPriorNoteHandler)
100+
ee.on('list:clone', this.cloneNote)
99101
ee.on('list:focus', this.focusHandler)
100102
ee.on('list:isMarkdownNote', this.alertIfSnippetHandler)
101103
ee.on('import:file', this.importFromFileHandler)
@@ -118,6 +120,7 @@ class NoteList extends React.Component {
118120

119121
ee.off('list:next', this.selectNextNoteHandler)
120122
ee.off('list:prior', this.selectPriorNoteHandler)
123+
ee.off('list:clone', this.cloneNote)
121124
ee.off('list:focus', this.focusHandler)
122125
ee.off('list:isMarkdownNote', this.alertIfSnippetHandler)
123126
ee.off('import:file', this.importFromFileHandler)
@@ -277,12 +280,6 @@ class NoteList extends React.Component {
277280
ee.emit('top:new-note')
278281
}
279282

280-
// D key
281-
if (e.keyCode === 68) {
282-
e.preventDefault()
283-
this.deleteNote()
284-
}
285-
286283
// E key
287284
if (e.keyCode === 69) {
288285
e.preventDefault()
@@ -495,14 +492,21 @@ class NoteList extends React.Component {
495492
})
496493
}
497494

498-
alertIfSnippet () {
495+
alertIfSnippet (msg) {
496+
const warningMessage = (msg) => ({
497+
'export-txt': 'Text export',
498+
'export-md': 'Markdown export',
499+
'export-html': 'HTML export',
500+
'print': 'Print'
501+
})[msg]
502+
499503
const targetIndex = this.getTargetIndex()
500504
if (this.notes[targetIndex].type === 'SNIPPET_NOTE') {
501505
dialog.showMessageBox(remote.getCurrentWindow(), {
502506
type: 'warning',
503507
message: i18n.__('Sorry!'),
504-
detail: i18n.__('md/text import is available only a markdown note.'),
505-
buttons: [i18n.__('OK'), i18n.__('Cancel')]
508+
detail: i18n.__(warningMessage(msg) + ' is available only in markdown notes.'),
509+
buttons: [i18n.__('OK')]
506510
})
507511
}
508512
}

browser/main/SideNav/StorageItem.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class StorageItem extends React.Component {
2525
const { storage } = this.props
2626

2727
this.state = {
28-
isOpen: !!storage.isOpen
28+
isOpen: !!storage.isOpen,
29+
draggedOver: null
2930
}
3031
}
3132

@@ -204,6 +205,20 @@ class StorageItem extends React.Component {
204205
folderKey: data.folderKey,
205206
fileType: data.fileType
206207
})
208+
return data
209+
})
210+
.then(data => {
211+
dialog.showMessageBox(remote.getCurrentWindow(), {
212+
type: 'info',
213+
message: 'Exported to "' + data.exportDir + '"'
214+
})
215+
})
216+
.catch(err => {
217+
dialog.showErrorBox(
218+
'Export error',
219+
err ? err.message || err : 'Unexpected error during export'
220+
)
221+
throw err
207222
})
208223
}
209224
})
@@ -231,14 +246,20 @@ class StorageItem extends React.Component {
231246
}
232247
}
233248

234-
handleDragEnter (e) {
235-
e.dataTransfer.setData('defaultColor', e.target.style.backgroundColor)
236-
e.target.style.backgroundColor = 'rgba(129, 130, 131, 0.08)'
249+
handleDragEnter (e, key) {
250+
e.preventDefault()
251+
if (this.state.draggedOver === key) { return }
252+
this.setState({
253+
draggedOver: key
254+
})
237255
}
238256

239257
handleDragLeave (e) {
240-
e.target.style.opacity = '1'
241-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
258+
e.preventDefault()
259+
if (this.state.draggedOver === null) { return }
260+
this.setState({
261+
draggedOver: null
262+
})
242263
}
243264

244265
dropNote (storage, folder, dispatch, location, noteData) {
@@ -263,8 +284,12 @@ class StorageItem extends React.Component {
263284
}
264285

265286
handleDrop (e, storage, folder, dispatch, location) {
266-
e.target.style.opacity = '1'
267-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
287+
e.preventDefault()
288+
if (this.state.draggedOver !== null) {
289+
this.setState({
290+
draggedOver: null
291+
})
292+
}
268293
const noteData = JSON.parse(e.dataTransfer.getData('note'))
269294
this.dropNote(storage, folder, dispatch, location, noteData)
270295
}
@@ -291,16 +316,22 @@ class StorageItem extends React.Component {
291316
<SortableStorageItemChild
292317
key={folder.key}
293318
index={index}
294-
isActive={isActive}
319+
isActive={isActive || folder.key === this.state.draggedOver}
295320
handleButtonClick={(e) => this.handleFolderButtonClick(folder.key)(e)}
296321
handleContextMenu={(e) => this.handleFolderButtonContextMenu(e, folder)}
297322
folderName={folder.name}
298323
folderColor={folder.color}
299324
isFolded={isFolded}
300325
noteCount={noteCount}
301-
handleDrop={(e) => this.handleDrop(e, storage, folder, dispatch, location)}
302-
handleDragEnter={this.handleDragEnter}
303-
handleDragLeave={this.handleDragLeave}
326+
handleDrop={(e) => {
327+
this.handleDrop(e, storage, folder, dispatch, location)
328+
}}
329+
handleDragEnter={(e) => {
330+
this.handleDragEnter(e, folder.key)
331+
}}
332+
handleDragLeave={(e) => {
333+
this.handleDragLeave(e, folder)
334+
}}
304335
/>
305336
)
306337
})

browser/main/lib/dataApi/copyFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function copyFile (srcPath, dstPath) {
1616
const dstFolder = path.dirname(dstPath)
1717
if (!fs.existsSync(dstFolder)) fs.mkdirSync(dstFolder)
1818

19-
const input = fs.createReadStream(srcPath)
19+
const input = fs.createReadStream(decodeURI(srcPath))
2020
const output = fs.createWriteStream(dstPath)
2121

2222
output.on('error', reject)

0 commit comments

Comments
 (0)