1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Desktop: Fixes #3810: Only disable relevant toolbar buttons when editor is read-only

This commit is contained in:
Laurent Cozic 2020-09-23 10:21:24 +01:00
parent 59599d318c
commit b6779a8074
6 changed files with 30 additions and 39 deletions

View File

@ -164,6 +164,7 @@ ElectronClient/gui/style/StyledInput.js
ElectronClient/gui/style/StyledTextInput.js ElectronClient/gui/style/StyledTextInput.js
ElectronClient/gui/ToggleEditorsButton/styles/index.js ElectronClient/gui/ToggleEditorsButton/styles/index.js
ElectronClient/gui/ToggleEditorsButton/ToggleEditorsButton.js ElectronClient/gui/ToggleEditorsButton/ToggleEditorsButton.js
ElectronClient/gui/ToolbarBase.js
ElectronClient/gui/ToolbarButton/styles/index.js ElectronClient/gui/ToolbarButton/styles/index.js
ElectronClient/gui/ToolbarButton/ToolbarButton.js ElectronClient/gui/ToolbarButton/ToolbarButton.js
ReactNativeClient/lib/AsyncActionQueue.js ReactNativeClient/lib/AsyncActionQueue.js

1
.gitignore vendored
View File

@ -157,6 +157,7 @@ ElectronClient/gui/style/StyledInput.js
ElectronClient/gui/style/StyledTextInput.js ElectronClient/gui/style/StyledTextInput.js
ElectronClient/gui/ToggleEditorsButton/styles/index.js ElectronClient/gui/ToggleEditorsButton/styles/index.js
ElectronClient/gui/ToggleEditorsButton/ToggleEditorsButton.js ElectronClient/gui/ToggleEditorsButton/ToggleEditorsButton.js
ElectronClient/gui/ToolbarBase.js
ElectronClient/gui/ToolbarButton/styles/index.js ElectronClient/gui/ToolbarButton/styles/index.js
ElectronClient/gui/ToolbarButton/ToolbarButton.js ElectronClient/gui/ToolbarButton/ToolbarButton.js
ReactNativeClient/lib/AsyncActionQueue.js ReactNativeClient/lib/AsyncActionQueue.js

View File

@ -372,37 +372,37 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
/* be applied to the viewer. */ /* be applied to the viewer. */
padding-bottom: 400px !important; padding-bottom: 400px !important;
} }
.cm-header-1 { .cm-header-1 {
font-size: 1.5em; font-size: 1.5em;
} }
.cm-header-2 { .cm-header-2 {
font-size: 1.3em; font-size: 1.3em;
} }
.cm-header-3 { .cm-header-3 {
font-size: 1.1em; font-size: 1.1em;
} }
.cm-header-4, .cm-header-5, .cm-header-6 { .cm-header-4, .cm-header-5, .cm-header-6 {
font-size: 1em; font-size: 1em;
} }
.cm-header-1, .cm-header-2, .cm-header-3, .cm-header-4, .cm-header-5, .cm-header-6 { .cm-header-1, .cm-header-2, .cm-header-3, .cm-header-4, .cm-header-5, .cm-header-6 {
line-height: 1.5em; line-height: 1.5em;
} }
.cm-search-marker { .cm-search-marker {
background: ${theme.searchMarkerBackgroundColor}; background: ${theme.searchMarkerBackgroundColor};
color: ${theme.searchMarkerColor} !important; color: ${theme.searchMarkerColor} !important;
} }
.cm-search-marker-selected { .cm-search-marker-selected {
background: ${theme.selectedColor2}; background: ${theme.selectedColor2};
color: ${theme.color2} !important; color: ${theme.color2} !important;
} }
.cm-search-marker-scrollbar { .cm-search-marker-scrollbar {
background: ${theme.searchMarkerBackgroundColor}; background: ${theme.searchMarkerBackgroundColor};
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
@ -568,8 +568,6 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
editorRef.current.refresh(); editorRef.current.refresh();
}, [rootSize, styles.editor, props.visiblePanes]); }, [rootSize, styles.editor, props.visiblePanes]);
const editorReadOnly = props.visiblePanes.indexOf('editor') < 0;
function renderEditor() { function renderEditor() {
return ( return (
@ -612,7 +610,6 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
<Toolbar <Toolbar
themeId={props.themeId} themeId={props.themeId}
dispatch={props.dispatch} dispatch={props.dispatch}
disabled={editorReadOnly}
/> />
{props.noteToolbar} {props.noteToolbar}
</div> </div>

View File

@ -1,13 +1,11 @@
import * as React from 'react'; import * as React from 'react';
import CommandService from '../../../../lib/services/CommandService'; import CommandService from 'lib/services/CommandService';
import ToolbarBase from '../../../ToolbarBase';
const ToolbarBase = require('../../../Toolbar.min.js');
const { buildStyle } = require('lib/theme'); const { buildStyle } = require('lib/theme');
interface ToolbarProps { interface ToolbarProps {
themeId: number, themeId: number,
dispatch: Function, dispatch: Function,
disabled: boolean,
} }
function styles_(props:ToolbarProps) { function styles_(props:ToolbarProps) {
@ -49,5 +47,5 @@ export default function Toolbar(props:ToolbarProps) {
cmdService.commandToToolbarButton('toggleEditors'), cmdService.commandToToolbarButton('toggleEditors'),
]; ];
return <ToolbarBase disabled={props.disabled} style={styles.root} items={toolbarItems} />; return <ToolbarBase style={styles.root} items={toolbarItems} />;
} }

View File

@ -1,9 +1,9 @@
import * as React from 'react'; import * as React from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import CommandService from '../../lib/services/CommandService'; import CommandService from '../../lib/services/CommandService';
import ToolbarBase from '../ToolbarBase';
const { connect } = require('react-redux'); const { connect } = require('react-redux');
const { buildStyle } = require('lib/theme'); const { buildStyle } = require('lib/theme');
const Toolbar = require('../Toolbar.min.js');
// const Folder = require('lib/models/Folder'); // const Folder = require('lib/models/Folder');
// const { _ } = require('lib/locale'); // const { _ } = require('lib/locale');
// const { substrWithEllipsis } = require('lib/string-utils'); // const { substrWithEllipsis } = require('lib/string-utils');
@ -40,21 +40,12 @@ function styles_(props:NoteToolbarProps) {
function NoteToolbar(props:NoteToolbarProps) { function NoteToolbar(props:NoteToolbarProps) {
const styles = styles_(props); const styles = styles_(props);
const [toolbarItems, setToolbarItems] = useState([]); const [toolbarItems, setToolbarItems] = useState([]);
// const selectedNoteFolder = Folder.byId(props.folders, props.note.parent_id);
// const folderId = selectedNoteFolder ? selectedNoteFolder.id : '';
// const folderTitle = selectedNoteFolder && selectedNoteFolder.title ? selectedNoteFolder.title : '';
const cmdService = CommandService.instance(); const cmdService = CommandService.instance();
function updateToolbarItems() { function updateToolbarItems() {
const output = []; const output = [];
// if (props.watchedNoteFiles.indexOf(props.note.id) >= 0) {
// output.push(cmdService.commandToToolbarButton('stopExternalEditing'));
// } else {
// output.push(cmdService.commandToToolbarButton('startExternalEditing'));
// }
output.push(cmdService.commandToToolbarButton('editAlarm')); output.push(cmdService.commandToToolbarButton('editAlarm'));
output.push(cmdService.commandToToolbarButton('toggleVisiblePanes')); output.push(cmdService.commandToToolbarButton('toggleVisiblePanes'));
output.push(cmdService.commandToToolbarButton('showNoteProperties')); output.push(cmdService.commandToToolbarButton('showNoteProperties'));
@ -70,7 +61,7 @@ function NoteToolbar(props:NoteToolbarProps) {
}; };
}, []); }, []);
return <Toolbar style={styles.root} items={toolbarItems} />; return <ToolbarBase style={styles.root} items={toolbarItems} />;
} }
const mapStateToProps = (state:any) => { const mapStateToProps = (state:any) => {

View File

@ -5,11 +5,18 @@ const ToolbarButton = require('./ToolbarButton/ToolbarButton.js').default;
const ToolbarSpace = require('./ToolbarSpace.min.js'); const ToolbarSpace = require('./ToolbarSpace.min.js');
const ToggleEditorsButton = require('./ToggleEditorsButton/ToggleEditorsButton.js').default; const ToggleEditorsButton = require('./ToggleEditorsButton/ToggleEditorsButton.js').default;
class ToolbarComponent extends React.Component { interface Props {
themeId: number,
style: any,
items: any[],
}
class ToolbarBaseComponent extends React.Component<Props, any> {
render() { render() {
const theme = themeStyle(this.props.themeId); const theme = themeStyle(this.props.themeId);
const style = Object.assign({ const style:any = Object.assign({
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
boxSizing: 'border-box', boxSizing: 'border-box',
@ -18,15 +25,15 @@ class ToolbarComponent extends React.Component {
paddingRight: theme.mainPadding, paddingRight: theme.mainPadding,
}, this.props.style); }, this.props.style);
const groupStyle = { const groupStyle:any = {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
boxSizing: 'border-box', boxSizing: 'border-box',
}; };
const leftItemComps = []; const leftItemComps:any[] = [];
const centerItemComps = []; const centerItemComps:any[] = [];
const rightItemComps = []; const rightItemComps:any[] = [];
if (this.props.items) { if (this.props.items) {
for (let i = 0; i < this.props.items.length; i++) { for (let i = 0; i < this.props.items.length; i++) {
@ -45,8 +52,6 @@ class ToolbarComponent extends React.Component {
o o
); );
if (this.props.disabled) props.disabled = true;
if (o.name === 'toggleEditors') { if (o.name === 'toggleEditors') {
rightItemComps.push(<ToggleEditorsButton rightItemComps.push(<ToggleEditorsButton
key={o.name} key={o.name}
@ -79,10 +84,8 @@ class ToolbarComponent extends React.Component {
} }
} }
const mapStateToProps = state => { const mapStateToProps = (state:any) => {
return { themeId: state.settings.theme }; return { themeId: state.settings.theme };
}; };
const Toolbar = connect(mapStateToProps)(ToolbarComponent); export default connect(mapStateToProps)(ToolbarBaseComponent);
module.exports = Toolbar;