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

Electron: Save state of editor/viewer toggle

This commit is contained in:
Laurent Cozic 2017-11-12 17:02:20 +00:00
parent 2879e616c1
commit f9a06bb5b9
4 changed files with 52 additions and 13 deletions

View File

@ -29,6 +29,7 @@ const appDefaultState = Object.assign({}, defaultState, {
navHistory: [],
fileToImport: null,
windowCommand: null,
noteVisiblePanes: ['editor', 'viewer'],
});
class Application extends BaseApplication {
@ -91,6 +92,29 @@ class Application extends BaseApplication {
newState.windowCommand = command;
break;
case 'NOTE_VISIBLE_PANES_TOGGLE':
let panes = state.noteVisiblePanes.slice();
if (panes.length === 2) {
panes = ['editor'];
} else if (panes.indexOf('editor') >= 0) {
panes = ['viewer'];
} else if (panes.indexOf('viewer') >= 0) {
panes = ['editor', 'viewer'];
} else {
panes = ['editor', 'viewer'];
}
newState = Object.assign({}, state);
newState.noteVisiblePanes = panes;
break;
case 'NOTE_VISIBLE_PANES_SET':
newState = Object.assign({}, state);
newState.noteVisiblePanes = action.panes;
break;
}
} catch (error) {
error.message = 'In reducer: ' + error.message + ' Action: ' + JSON.stringify(action);
@ -117,6 +141,10 @@ class Application extends BaseApplication {
app().updateMenu(newState.route.routeName);
}
if (['NOTE_VISIBLE_PANES_TOGGLE', 'NOTE_VISIBLE_PANES_SET'].indexOf(action.type) >= 0) {
Setting.setValue('noteVisiblePanes', newState.noteVisiblePanes);
}
return result;
}

View File

@ -19,7 +19,6 @@ class MainScreenComponent extends React.Component {
componentWillMount() {
this.setState({
promptOptions: null,
noteVisiblePanes: ['editor', 'viewer'],
});
}
@ -30,16 +29,9 @@ class MainScreenComponent extends React.Component {
}
toggleVisiblePanes() {
let panes = this.state.noteVisiblePanes.slice();
if (panes.length === 2) {
panes = ['editor'];
} else if (panes.indexOf('editor') >= 0) {
panes = ['viewer'];
} else if (panes.indexOf('viewer') >= 0) {
panes = ['editor', 'viewer'];
}
this.setState({ noteVisiblePanes: panes });
this.props.dispatch({
type: 'NOTE_VISIBLE_PANES_TOGGLE',
});
}
async doCommand(command) {
@ -216,7 +208,7 @@ class MainScreenComponent extends React.Component {
<Header style={headerStyle} showBackButton={false} buttons={headerButtons} />
<SideBar style={sideBarStyle} />
<NoteList itemHeight={40} style={noteListStyle} />
<NoteText style={noteTextStyle} visiblePanes={this.state.noteVisiblePanes} />
<NoteText style={noteTextStyle} visiblePanes={this.props.noteVisiblePanes} />
</div>
);
}
@ -227,6 +219,7 @@ const mapStateToProps = (state) => {
return {
theme: state.settings.theme,
windowCommand: state.windowCommand,
noteVisiblePanes: state.noteVisiblePanes,
};
};

View File

@ -34,6 +34,11 @@ async function initialize(dispatch) {
type: 'WINDOW_CONTENT_SIZE_SET',
size: bridge().windowContentSize(),
});
store.dispatch({
type: 'NOTE_VISIBLE_PANES_SET',
panes: Setting.value('noteVisiblePanes'),
});
}
class RootComponent extends React.Component {

View File

@ -142,12 +142,15 @@ class Setting extends BaseModel {
value = this.formatValue(key, value);
if (md.type == Setting.TYPE_INT) return value.toFixed(0);
if (md.type == Setting.TYPE_BOOL) return value ? '1' : '0';
if (md.type == Setting.TYPE_ARRAY) return value ? JSON.stringify(value) : '[]';
return value;
}
static formatValue(key, value) {
const md = this.settingMetadata(key);
if (md.type == Setting.TYPE_INT) return Math.floor(Number(value));
if (md.type == Setting.TYPE_BOOL) {
if (typeof value === 'string') {
value = value.toLowerCase();
@ -157,6 +160,13 @@ class Setting extends BaseModel {
}
return !!value;
}
if (md.type === Setting.TYPE_ARRAY) {
if (Array.isArray(value)) return value;
if (typeof value === 'string') return JSON.parse(value);
return [];
}
return value;
}
@ -297,6 +307,7 @@ class Setting extends BaseModel {
if (typeId === Setting.TYPE_INT) return 'int';
if (typeId === Setting.TYPE_STRING) return 'string';
if (typeId === Setting.TYPE_BOOL) return 'bool';
if (typeId === Setting.TYPE_ARRAY) return 'array';
}
}
@ -308,6 +319,7 @@ Setting.SYNC_TARGET_ONEDRIVE = 3;
Setting.TYPE_INT = 1;
Setting.TYPE_STRING = 2;
Setting.TYPE_BOOL = 3;
Setting.TYPE_ARRAY = 4;
Setting.THEME_LIGHT = 1;
Setting.THEME_DARK = 2;
@ -363,6 +375,7 @@ Setting.metadata_ = {
};
}},
'showAdvancedOptions': { value: false, type: Setting.TYPE_BOOL, public: true, appTypes: ['mobile', 'desktop'], label: () => _('Show advanced options') },
'noteVisiblePanes': { value: ['editor', 'viewer'], type: Setting.TYPE_ARRAY, public: false, appTypes: ['desktop'] },
};
// Contains constants that are set by the application and