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

Desktop: Add a menu option to reset the application layout (#7786)

This commit is contained in:
pedr 2023-02-17 10:07:18 -03:00 committed by GitHub
parent e1a8c76598
commit 3a14b76a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 0 deletions

View File

@ -177,6 +177,7 @@ packages/app-desktop/gui/MainScreen/commands/openTag.js
packages/app-desktop/gui/MainScreen/commands/print.js
packages/app-desktop/gui/MainScreen/commands/renameFolder.js
packages/app-desktop/gui/MainScreen/commands/renameTag.js
packages/app-desktop/gui/MainScreen/commands/resetLayout.js
packages/app-desktop/gui/MainScreen/commands/revealResourceFile.js
packages/app-desktop/gui/MainScreen/commands/search.js
packages/app-desktop/gui/MainScreen/commands/setTags.js

1
.gitignore vendored
View File

@ -165,6 +165,7 @@ packages/app-desktop/gui/MainScreen/commands/openTag.js
packages/app-desktop/gui/MainScreen/commands/print.js
packages/app-desktop/gui/MainScreen/commands/renameFolder.js
packages/app-desktop/gui/MainScreen/commands/renameTag.js
packages/app-desktop/gui/MainScreen/commands/resetLayout.js
packages/app-desktop/gui/MainScreen/commands/revealResourceFile.js
packages/app-desktop/gui/MainScreen/commands/search.js
packages/app-desktop/gui/MainScreen/commands/setTags.js

View File

@ -38,6 +38,7 @@ export interface AppState extends State {
watchedResources: any;
mainLayout: LayoutItem;
dialogs: AppStateDialog[];
isResettingLayout: boolean;
}
export function createAppDefaultState(windowContentSize: any, resourceEditWatcherDefaultState: any): AppState {
@ -60,6 +61,7 @@ export function createAppDefaultState(windowContentSize: any, resourceEditWatche
mainLayout: null,
startupPluginsLoaded: false,
dialogs: [],
isResettingLayout: false,
...resourceEditWatcherDefaultState,
};
}
@ -308,7 +310,15 @@ export default function(state: AppState, action: any) {
};
break;
case 'RESET_LAYOUT':
newState = {
...state,
isResettingLayout: action.value,
};
break;
}
} catch (error) {
error.message = `In reducer: ${error.message} Action: ${JSON.stringify(action)}`;
throw error;

View File

@ -78,6 +78,7 @@ interface Props {
isSafeMode: boolean;
needApiAuth: boolean;
processingShareInvitationResponse: boolean;
isResettingLayout: boolean;
}
interface ShareFolderDialogOptions {
@ -371,6 +372,15 @@ class MainScreenComponent extends React.Component<Props, State> {
name: 'promptDialog',
});
}
if (this.props.isResettingLayout) {
Setting.setValue('ui.layout', null);
this.updateMainLayout(this.buildLayout(this.props.plugins));
this.props.dispatch({
type: 'RESET_LAYOUT',
value: false,
});
}
}
layoutModeListenerKeyDown(event: any) {
@ -880,6 +890,7 @@ const mapStateToProps = (state: AppState) => {
isSafeMode: state.settings.isSafeMode,
needApiAuth: state.needApiAuth,
showInstallTemplatesPlugin: state.hasLegacyTemplates && !state.pluginService.plugins['joplin.plugin.templates'],
isResettingLayout: state.isResettingLayout,
};
};

View File

@ -20,6 +20,7 @@ import * as openTag from './openTag';
import * as print from './print';
import * as renameFolder from './renameFolder';
import * as renameTag from './renameTag';
import * as resetLayout from './resetLayout';
import * as revealResourceFile from './revealResourceFile';
import * as search from './search';
import * as setTags from './setTags';
@ -61,6 +62,7 @@ const index:any[] = [
print,
renameFolder,
renameTag,
resetLayout,
revealResourceFile,
search,
setTags,

View File

@ -0,0 +1,25 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import dialogs from '../../dialogs';
export const declaration: CommandDeclaration = {
name: 'resetLayout',
label: () => _('Reset application layout'),
};
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext) => {
const message = _('Are you sure you want to return to the default layout? The current layout configuration will be lost.');
const isConfirmed = await dialogs.confirm(message);
if (!isConfirmed) return;
context.dispatch({
type: 'RESET_LAYOUT',
value: true,
});
},
};
};

View File

@ -675,6 +675,7 @@ function useMenu(props: Props) {
label: _('&View'),
submenu: [
menuItemDic.toggleLayoutMoveMode,
menuItemDic.resetLayout,
separator(),
menuItemDic.toggleSideBar,
menuItemDic.toggleNoteList,

View File

@ -32,6 +32,7 @@ export default function() {
'textBulletedList',
'toggleExternalEditing',
'toggleLayoutMoveMode',
'resetLayout',
'toggleNoteList',
'toggleNotesSortOrderField',
'toggleNotesSortOrderReverse',