mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add right click to switch edit/preview option to app settings
This commit is contained in:
@@ -191,8 +191,8 @@ CodeEditor.propTypes = {
|
|||||||
key: PropTypes.string
|
key: PropTypes.string
|
||||||
}),
|
}),
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
onChange: PropTypes.func,
|
|
||||||
onBlur: PropTypes.func,
|
onBlur: PropTypes.func,
|
||||||
|
onChange: PropTypes.func,
|
||||||
readOnly: PropTypes.bool
|
readOnly: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,42 @@ import ReactDOM from 'react-dom'
|
|||||||
import MarkdownPreview from 'browser/components/MarkdownPreview'
|
import MarkdownPreview from 'browser/components/MarkdownPreview'
|
||||||
import CodeEditor from 'browser/components/CodeEditor'
|
import CodeEditor from 'browser/components/CodeEditor'
|
||||||
import activityRecord from 'browser/lib/activityRecord'
|
import activityRecord from 'browser/lib/activityRecord'
|
||||||
|
import fetchConfig from 'browser/lib/fetchConfig'
|
||||||
|
|
||||||
|
const electron = require('electron')
|
||||||
|
const ipc = electron.ipcRenderer
|
||||||
|
|
||||||
export const PREVIEW_MODE = 'PREVIEW_MODE'
|
export const PREVIEW_MODE = 'PREVIEW_MODE'
|
||||||
export const EDIT_MODE = 'EDIT_MODE'
|
export const EDIT_MODE = 'EDIT_MODE'
|
||||||
|
|
||||||
|
let config = fetchConfig()
|
||||||
|
ipc.on('config-apply', function (e, newConfig) {
|
||||||
|
config = newConfig
|
||||||
|
})
|
||||||
|
|
||||||
export default class ArticleEditor extends React.Component {
|
export default class ArticleEditor extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
|
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
|
||||||
this.isMouseDown = false
|
this.isMouseDown = false
|
||||||
this.state = {
|
this.state = {
|
||||||
status: PREVIEW_MODE,
|
status: PREVIEW_MODE,
|
||||||
cursorPosition: null,
|
cursorPosition: null,
|
||||||
firstVisibleRow: null
|
firstVisibleRow: null,
|
||||||
|
switchPreview: config['switch-preview']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
console.log(this.state.switchPreview)
|
||||||
|
ipc.on('config-apply', this.configApplyHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
ipc.removeListener('config-apply', this.configApplyHandler)
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.article.key !== this.props.article.key) {
|
if (nextProps.article.key !== this.props.article.key) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -26,6 +47,12 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleConfigApply (e, newConfig) {
|
||||||
|
this.setState({
|
||||||
|
switchPreview: newConfig['switch-preview']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
resetCursorPosition () {
|
resetCursorPosition () {
|
||||||
this.setState({
|
this.setState({
|
||||||
cursorPosition: null,
|
cursorPosition: null,
|
||||||
@@ -70,14 +97,15 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePreviewMouseDown (e) {
|
handlePreviewMouseDown (e) {
|
||||||
if (e.button === 2) return true
|
if (this.state.switchPreview === 'blur' && e.button === 0) {
|
||||||
this.isDrag = false
|
this.isDrag = false
|
||||||
this.isMouseDown = true
|
this.isMouseDown = true
|
||||||
this.moveCount = 0
|
this.moveCount = 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handlePreviewMouseMove () {
|
handlePreviewMouseMove () {
|
||||||
if (this.isMouseDown) {
|
if (this.state.switchPreview === 'blur' && this.isMouseDown) {
|
||||||
this.moveCount++
|
this.moveCount++
|
||||||
if (this.moveCount > 5) {
|
if (this.moveCount > 5) {
|
||||||
this.isDrag = true
|
this.isDrag = true
|
||||||
@@ -86,17 +114,32 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePreviewMouseUp (e) {
|
handlePreviewMouseUp (e) {
|
||||||
if (e.button === 2) return true
|
if (this.state.switchPreview === 'blur' && e.button === 0) {
|
||||||
this.isMouseDown = false
|
this.isMouseDown = false
|
||||||
this.moveCount = 0
|
this.moveCount = 0
|
||||||
if (!this.isDrag) {
|
if (!this.isDrag) {
|
||||||
this.switchEditMode()
|
this.switchEditMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRightClickPreview (e) {
|
||||||
|
let { article } = this.props
|
||||||
|
if (this.state.switchPreview !== 'rightclick' || article.mode !== 'markdown') return true
|
||||||
|
|
||||||
|
this.switchEditMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRightClickCodeEditor (e) {
|
||||||
|
let { article } = this.props
|
||||||
|
if (this.state.switchPreview !== 'rightclick' || article.mode !== 'markdown') return true
|
||||||
|
|
||||||
|
this.switchPreviewMode()
|
||||||
|
}
|
||||||
|
|
||||||
handleBlurCodeEditor (e) {
|
handleBlurCodeEditor (e) {
|
||||||
let isFocusingToThis = e.relatedTarget === ReactDOM.findDOMNode(this)
|
let isFocusingToThis = e.relatedTarget === ReactDOM.findDOMNode(this)
|
||||||
if (isFocusingToThis) {
|
if (isFocusingToThis || this.state.switchPreview !== 'blur') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +158,7 @@ export default class ArticleEditor extends React.Component {
|
|||||||
let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE
|
let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE
|
||||||
if (showPreview) {
|
if (showPreview) {
|
||||||
return (
|
return (
|
||||||
<div className='ArticleEditor'>
|
<div onContextMenu={e => this.handleRightClickPreview(e)} className='ArticleEditor'>
|
||||||
<MarkdownPreview
|
<MarkdownPreview
|
||||||
ref='preview'
|
ref='preview'
|
||||||
onMouseUp={e => this.handlePreviewMouseUp(e)}
|
onMouseUp={e => this.handlePreviewMouseUp(e)}
|
||||||
@@ -123,13 +166,18 @@ export default class ArticleEditor extends React.Component {
|
|||||||
onMouseMove={e => this.handlePreviewMouseMove(e)}
|
onMouseMove={e => this.handlePreviewMouseMove(e)}
|
||||||
content={article.content}
|
content={article.content}
|
||||||
/>
|
/>
|
||||||
<div className='ArticleDetail-panel-content-tooltip'>Click to Edit</div>
|
<div className='ArticleDetail-panel-content-tooltip' children={
|
||||||
|
this.state.switchPreview === 'blur'
|
||||||
|
? 'Click to Edit'
|
||||||
|
: 'Right Click to Edit'
|
||||||
|
}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div tabIndex='5' className='ArticleEditor'>
|
<div onContextMenu={e => this.handleRightClickCodeEditor(e)} tabIndex='5' className='ArticleEditor'>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
ref='editor'
|
ref='editor'
|
||||||
onBlur={e => this.handleBlurCodeEditor(e)}
|
onBlur={e => this.handleBlurCodeEditor(e)}
|
||||||
@@ -138,7 +186,13 @@ export default class ArticleEditor extends React.Component {
|
|||||||
/>
|
/>
|
||||||
{article.mode === 'markdown'
|
{article.mode === 'markdown'
|
||||||
? (
|
? (
|
||||||
<div className='ArticleDetail-panel-content-tooltip'>Press ESC to watch Preview</div>
|
<div className='ArticleDetail-panel-content-tooltip'
|
||||||
|
children={
|
||||||
|
this.state.switchPreview === 'blur'
|
||||||
|
? 'Press ESC to Watch Preview'
|
||||||
|
: 'Right Click to Watch Preview'
|
||||||
|
}
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,9 +138,9 @@ export default class AppSettingTab extends React.Component {
|
|||||||
<label>Editor Font Family</label>
|
<label>Editor Font Family</label>
|
||||||
<input valueLink={this.linkState('config.editor-font-family')} onKeyDown={e => this.handleConfigKeyDown(e)} type='text'/>
|
<input valueLink={this.linkState('config.editor-font-family')} onKeyDown={e => this.handleConfigKeyDown(e)} type='text'/>
|
||||||
</div>
|
</div>
|
||||||
<div className='sectionSelect'>
|
<div className='sectionMultiSelect'>
|
||||||
<label>Editor Indent Style</label>
|
<label>Editor Indent Style</label>
|
||||||
<div className='sectionSelect-input'>
|
<div className='sectionMultiSelect-input'>
|
||||||
type
|
type
|
||||||
<select valueLink={this.linkState('config.editor-indent-type')}>
|
<select valueLink={this.linkState('config.editor-indent-type')}>
|
||||||
<option value='space'>Space</option>
|
<option value='space'>Space</option>
|
||||||
@@ -162,8 +162,15 @@ export default class AppSettingTab extends React.Component {
|
|||||||
<label>Preview Font Family</label>
|
<label>Preview Font Family</label>
|
||||||
<input valueLink={this.linkState('config.preview-font-family')} onKeyDown={e => this.handleConfigKeyDown(e)} type='text'/>
|
<input valueLink={this.linkState('config.preview-font-family')} onKeyDown={e => this.handleConfigKeyDown(e)} type='text'/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className='sectionSelect'>
|
||||||
|
<label>Switching Preview</label>
|
||||||
|
<select valueLink={this.linkState('config.switch-preview')}>
|
||||||
|
<option value='blur'>When Editor Blurred</option>
|
||||||
|
<option value='rightclick'>When Right Clicking</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
{
|
{
|
||||||
true// !OSX
|
global.process.platform === 'win32'
|
||||||
? (
|
? (
|
||||||
<div className='sectionCheck'>
|
<div className='sectionCheck'>
|
||||||
<label><input onClick={e => this.handleDisableDirectWriteClick(e)} checked={this.state.config['disable-direct-write']} disabled={OSX} type='checkbox'/>Disable Direct Write<span className='sectionCheck-warn'>It will be applied after restarting</span></label>
|
<label><input onClick={e => this.handleDisableDirectWriteClick(e)} checked={this.state.config['disable-direct-write']} disabled={OSX} type='checkbox'/>Disable Direct Write<span className='sectionCheck-warn'>It will be applied after restarting</span></label>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ iptFocusBorderColor = #369DCD
|
|||||||
left 180px
|
left 180px
|
||||||
overflow-y auto
|
overflow-y auto
|
||||||
&>.section
|
&>.section
|
||||||
padding 10px
|
padding 10px 20px
|
||||||
border-bottom 1px solid borderColor
|
border-bottom 1px solid borderColor
|
||||||
overflow-y auto
|
overflow-y auto
|
||||||
&:nth-last-child(1)
|
&:nth-last-child(1)
|
||||||
@@ -102,7 +102,6 @@ iptFocusBorderColor = #369DCD
|
|||||||
&:focus
|
&:focus
|
||||||
border-color iptFocusBorderColor
|
border-color iptFocusBorderColor
|
||||||
&>.sectionSelect
|
&>.sectionSelect
|
||||||
|
|
||||||
margin-bottom 5px
|
margin-bottom 5px
|
||||||
clearfix()
|
clearfix()
|
||||||
height 33px
|
height 33px
|
||||||
@@ -111,7 +110,28 @@ iptFocusBorderColor = #369DCD
|
|||||||
padding-left 15px
|
padding-left 15px
|
||||||
float left
|
float left
|
||||||
line-height 33px
|
line-height 33px
|
||||||
.sectionSelect-input
|
select
|
||||||
|
float left
|
||||||
|
width 200px
|
||||||
|
height 25px
|
||||||
|
margin-top 4px
|
||||||
|
border-radius 5px
|
||||||
|
border 1px solid borderColor
|
||||||
|
padding 0 10px
|
||||||
|
font-size 14px
|
||||||
|
outline none
|
||||||
|
&:focus
|
||||||
|
border-color iptFocusBorderColor
|
||||||
|
&>.sectionMultiSelect
|
||||||
|
margin-bottom 5px
|
||||||
|
clearfix()
|
||||||
|
height 33px
|
||||||
|
label
|
||||||
|
width 150px
|
||||||
|
padding-left 15px
|
||||||
|
float left
|
||||||
|
line-height 33px
|
||||||
|
.sectionMultiSelect-input
|
||||||
float left
|
float left
|
||||||
select
|
select
|
||||||
width 80px
|
width 80px
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const defaultConfig = {
|
|||||||
'editor-indent-size': '4',
|
'editor-indent-size': '4',
|
||||||
'preview-font-size': '14',
|
'preview-font-size': '14',
|
||||||
'preview-font-family': 'Lato',
|
'preview-font-family': 'Lato',
|
||||||
|
'switch-preview': 'blur',
|
||||||
'disable-direct-write': false
|
'disable-direct-write': false
|
||||||
}
|
}
|
||||||
const configFile = 'config.json'
|
const configFile = 'config.json'
|
||||||
|
|||||||
Reference in New Issue
Block a user