Skip to content

Commit fdd0c84

Browse files
committed
update NoteDetail design
1 parent 8f0789b commit fdd0c84

14 files changed

Lines changed: 392 additions & 194 deletions

browser/finder/NoteDetail.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,6 @@ class NoteDetail extends React.Component {
140140
key={index}
141141
style={{zIndex: isActive ? 5 : 4}}
142142
>
143-
<div styleName='tabView-top'>
144-
<input styleName='tabView-top-name'
145-
placeholder='Filename including extensions...'
146-
value={snippet.name}
147-
readOnly
148-
/>
149-
<button styleName='tabView-top-mode'
150-
>
151-
{snippet.mode == null
152-
? 'Not selected'
153-
: syntax.name
154-
}&nbsp;
155-
</button>
156-
</div>
157143
{snippet.mode === 'markdown'
158144
? <MarkdownEditor styleName='tabView-content'
159145
config={config}

browser/finder/NoteDetail.styl

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,13 @@
6060
.tabList-plusButton
6161
navButtonColor()
6262
width 30px
63+
6364
.tabView
6465
absolute left right bottom
6566
top 110px
66-
.tabView-top
67-
absolute top left right
68-
height 30px
69-
border-bottom $ui-border
70-
display flex
71-
box-sizing border-box
72-
.tabView-top-name
73-
flex 1
74-
border none
75-
padding 0 10px
76-
font-size 14px
77-
.tabView-top-mode
78-
width 110px
79-
padding 0
80-
border none
81-
border-left $ui-border
82-
colorDefaultButton()
83-
color $ui-inactive-text-color
84-
pointer-events none
67+
8568
.tabView-content
86-
absolute left right bottom
87-
top 30px
69+
absolute top left right bottom
8870
box-sizing border-box
8971
height 100%
9072
width 100%

browser/finder/NoteItem.styl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
color white
2929
background-color transparent
3030

31-
3231
.border
3332
absolute top bottom left right
3433
border-style solid

browser/lib/context.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { remote } = require('electron')
2+
const { Menu, MenuItem } = remote
3+
4+
function popup (templates) {
5+
let menu = new Menu()
6+
templates.forEach((item) => {
7+
menu.append(new MenuItem(item))
8+
})
9+
menu.popup(remote.getCurrentWindow())
10+
}
11+
12+
const context = {
13+
popup
14+
}
15+
16+
module.export = context
17+
export default context

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 92 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dataApi from 'browser/main/lib/dataApi'
1010
import { hashHistory } from 'react-router'
1111
import ee from 'browser/main/lib/eventEmitter'
1212
import CodeMirror from 'codemirror'
13+
import SnippetTab from './SnippetTab'
1314

1415
function pass (name) {
1516
switch (name) {
@@ -238,16 +239,24 @@ class SnippetNoteDetail extends React.Component {
238239
}
239240

240241
handleTabPlusButtonClick (e) {
242+
this.addSnippet()
243+
}
244+
245+
addSnippet () {
241246
let { note } = this.state
242247

243248
note.snippets = note.snippets.concat([{
244249
name: '',
245250
mode: 'text',
246251
content: ''
247252
}])
253+
let snippetIndex = note.snippets.length - 1
248254

249255
this.setState({
250-
note
256+
note,
257+
snippetIndex
258+
}, () => {
259+
this.refs['tab-' + snippetIndex].startRenaming()
251260
})
252261
}
253262

@@ -279,15 +288,19 @@ class SnippetNoteDetail extends React.Component {
279288
let snippets = this.state.note.snippets.slice()
280289
snippets.splice(index, 1)
281290
this.state.note.snippets = snippets
291+
let snippetIndex = this.state.snippetIndex >= snippets.length
292+
? snippets.length - 1
293+
: this.state.snippetIndex
282294
this.setState({
283-
note: this.state.note
295+
note: this.state.note,
296+
snippetIndex
284297
})
285298
}
286299

287-
handleNameInputChange (e, index) {
300+
renameSnippetByIndex (index, name) {
288301
let snippets = this.state.note.snippets.slice()
289-
snippets[index].name = e.target.value
290-
let syntax = CodeMirror.findModeByFileName(e.target.value.trim())
302+
snippets[index].name = name
303+
let syntax = CodeMirror.findModeByFileName(name.trim())
291304
let mode = syntax != null ? syntax.name : null
292305
if (mode != null) snippets[index].mode = mode
293306
this.state.note.snippets = snippets
@@ -339,8 +352,62 @@ class SnippetNoteDetail extends React.Component {
339352
}
340353
}
341354

342-
handleDeleteKeyDown (e) {
343-
if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
355+
handleKeyDown (e) {
356+
switch (e.keyCode) {
357+
case 9:
358+
if (e.ctrlKey && !e.shiftKey) {
359+
e.preventDefault()
360+
this.jumpNextTab()
361+
} else if (e.ctrlKey && e.shiftKey) {
362+
e.preventDefault()
363+
this.jumpPrevTab()
364+
} else if (!e.ctrlKey && !e.shiftKey && e.target === this.refs.description) {
365+
e.preventDefault()
366+
this.focusEditor()
367+
}
368+
break
369+
case 76:
370+
let shouldFocus = global.process.platform === 'darwin'
371+
? e.metaKey
372+
: e.ctrlKey
373+
if (shouldFocus) {
374+
e.preventDefault()
375+
this.focus()
376+
}
377+
break
378+
case 84:
379+
{
380+
let shouldFocus = global.process.platform === 'darwin'
381+
? e.metaKey
382+
: e.ctrlKey
383+
if (e.shouldFocus) {
384+
e.preventDefault()
385+
this.addSnippet()
386+
}
387+
}
388+
}
389+
390+
}
391+
392+
jumpNextTab () {
393+
this.setState({
394+
snippetIndex: (this.state.snippetIndex + 1) % this.state.note.snippets.length
395+
}, () => {
396+
this.focusEditor()
397+
})
398+
}
399+
400+
jumpPrevTab () {
401+
this.setState({
402+
snippetIndex: (this.state.snippetIndex - 1 + this.state.note.snippets.length) % this.state.note.snippets.length
403+
}, () => {
404+
this.focusEditor()
405+
})
406+
}
407+
408+
focusEditor () {
409+
console.log('code-' + this.state.snippetIndex)
410+
this.refs['code-' + this.state.snippetIndex].focus()
344411
}
345412

346413
render () {
@@ -354,31 +421,19 @@ class SnippetNoteDetail extends React.Component {
354421

355422
let tabList = note.snippets.map((snippet, index) => {
356423
let isActive = this.state.snippetIndex === index
357-
return <div styleName={isActive
358-
? 'tabList-item--active'
359-
: 'tabList-item'
360-
}
424+
425+
return <SnippetTab
361426
key={index}
362-
>
363-
<button styleName='tabList-item-button'
364-
onClick={(e) => this.handleTabButtonClick(e, index)}
365-
>
366-
{snippet.name.trim().length > 0
367-
? snippet.name
368-
: <span styleName='tabList-item-unnamed'>
369-
Unnamed
370-
</span>
371-
}
372-
</button>
373-
{note.snippets.length > 1 &&
374-
<button styleName='tabList-item-deleteButton'
375-
onClick={(e) => this.handleTabDeleteButtonClick(e, index)}
376-
>
377-
<i className='fa fa-times'/>
378-
</button>
379-
}
380-
</div>
427+
ref={'tab-' + index}
428+
snippet={snippet}
429+
isActive={isActive}
430+
onClick={(e) => this.handleTabButtonClick(e, index)}
431+
onDelete={(e) => this.handleTabDeleteButtonClick(e, index)}
432+
onRename={(name) => this.renameSnippetByIndex(index, name)}
433+
isDeletable={note.snippets.length > 1}
434+
/>
381435
})
436+
382437
let viewList = note.snippets.map((snippet, index) => {
383438
let isActive = this.state.snippetIndex === index
384439

@@ -389,22 +444,6 @@ class SnippetNoteDetail extends React.Component {
389444
key={index}
390445
style={{zIndex: isActive ? 5 : 4}}
391446
>
392-
<div styleName='tabView-top'>
393-
<input styleName='tabView-top-name'
394-
placeholder='Filename including extensions...'
395-
value={snippet.name}
396-
onChange={(e) => this.handleNameInputChange(e, index)}
397-
/>
398-
<button styleName='tabView-top-mode'
399-
onClick={(e) => this.handleModeButtonClick(index)(e)}
400-
>
401-
{snippet.mode == null
402-
? 'Select Syntax...'
403-
: syntax.name
404-
}&nbsp;
405-
<i className='fa fa-caret-down'/>
406-
</button>
407-
</div>
408447
{snippet.mode === 'markdown'
409448
? <MarkdownEditor styleName='tabView-content'
410449
value={snippet.content}
@@ -432,6 +471,7 @@ class SnippetNoteDetail extends React.Component {
432471
<div className='NoteDetail'
433472
style={this.props.style}
434473
styleName='root'
474+
onKeyDown={(e) => this.handleKeyDown(e)}
435475
>
436476
<div styleName='info'>
437477
<div styleName='info-left'>
@@ -478,8 +518,8 @@ class SnippetNoteDetail extends React.Component {
478518
</div>
479519

480520
<div styleName='body'>
481-
<div styleName='body-description'>
482-
<textarea styleName='body-description-textarea'
521+
<div styleName='description'>
522+
<textarea
483523
style={{
484524
fontFamily: config.preview.fontFamily,
485525
fontSize: parseInt(config.preview.fontSize, 10)
@@ -491,8 +531,10 @@ class SnippetNoteDetail extends React.Component {
491531
/>
492532
</div>
493533
<div styleName='tabList'>
494-
{tabList}
495-
<button styleName='tabList-plusButton'
534+
<div styleName='list'>
535+
{tabList}
536+
</div>
537+
<button styleName='plusButton'
496538
onClick={(e) => this.handleTabPlusButtonClick(e)}
497539
>
498540
<i className='fa fa-plus'/>

0 commit comments

Comments
 (0)