Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau committed Jan 10, 2025
1 parent 0b30048 commit 4ae68e8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions newIDE/app/src/MainFrame/MainFrameCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const useMainFrameCommands = (handlers: CommandHandlers) => {
handler: handlers.onCloseApp,
});

useCommand('OPEN_PROFILE', !!handlers.project, {
useCommand('OPEN_PROFILE', true, {
handler: handlers.onOpenProfile,
});

useCommand('OPEN_PROJECT_MANAGER', !!handlers.project, {
useCommand('OPEN_PROJECT_MANAGER', true, {
handler: handlers.onOpenProjectManager,
});

Expand Down
1 change: 0 additions & 1 deletion newIDE/app/src/MainFrame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3609,7 +3609,6 @@ const MainFrame = (props: Props) => {
if (isProjectClosedSoAvoidReloadingExtensions) {
return;
}
// Check if load is sufficient
eventsFunctionsExtensionsState.reloadProjectEventsFunctionsExtensions(
currentProject
);
Expand Down
64 changes: 31 additions & 33 deletions newIDE/app/src/ProjectManager/ProjectManagerMainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ const ProjectManagerMainMenu = ({
const { isMobile } = useResponsiveWindowSize();
const shouldUseNativeMenu = !isNativeMobileApp() && !isMobile;

const enhanceMenuItems = React.useCallback(
(menuItems: Array<MenuItemTemplate>): Array<MenuItemTemplate> =>
menuItems.map((menuItem, index) => {
if (menuItem.submenu) {
return {
...menuItem,
submenu: enhanceMenuItems(menuItem.submenu),
};
}

if (menuItem.click) {
const originalClick = menuItem.click;
// $FlowFixMe - Flow is not able to make the difference between checkbox & classic item.
const newMenuItem: MenuItemTemplate = {
...menuItem,
click: () => {
// Close the drawer when an item is clicked, as it's likely to be a navigation action.
originalClick();
closeDrawer();
},
};
return newMenuItem;
}

return menuItem;
}),
[closeDrawer]
);

const visibleMenuItems = React.useMemo(
() => {
let displayedMenuItems = mainMenuItems;
Expand All @@ -64,9 +93,9 @@ const ProjectManagerMainMenu = ({
displayedMenuItems = menuItem.submenu;
}

return displayedMenuItems;
return enhanceMenuItems(displayedMenuItems);
},
[mainMenuItems, selectedMainMenuItemIndices]
[mainMenuItems, selectedMainMenuItemIndices, enhanceMenuItems]
);

const isNavigatingInsideSubMenu = selectedMainMenuItemIndices.length > 0;
Expand All @@ -86,34 +115,6 @@ const ProjectManagerMainMenu = ({
[selectedMainMenuItemIndices, setSelectedMainMenuItemIndices]
);

const enhanceMenuItems = React.useCallback(
(menuItems: Array<MenuItemTemplate>): Array<MenuItemTemplate> =>
menuItems.map((menuItem, index) => {
if (menuItem.submenu) {
return {
...menuItem,
submenu: enhanceMenuItems(menuItem.submenu),
};
}

if (menuItem.click) {
const originalClick = menuItem.click;
// $FlowFixMe - TS is not able to make the difference between checkbox & classic item.
const newMenuItem: MenuItemTemplate = {
...menuItem,
click: () => {
originalClick();
closeDrawer();
},
};
return newMenuItem;
}

return menuItem;
}),
[closeDrawer]
);

const onBuildSubMenuTemplate = React.useCallback(
(topMenuIndex: number): MenuItemTemplate[] => {
const menuItem = mainMenuItems[topMenuIndex];
Expand Down Expand Up @@ -202,9 +203,6 @@ const ProjectManagerMainMenu = ({

if (item.click) {
item.click();
// Close the drawer after clicking on a menu item,
// so the user can see the result of the action.
closeDrawer();
} else if (item.submenu) {
setSelectedMainMenuItemIndices([
...selectedMainMenuItemIndices,
Expand Down
14 changes: 14 additions & 0 deletions newIDE/app/src/ProjectManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import EmptyMessage from '../UI/EmptyMessage';
import { ColumnStackLayout } from '../UI/Layout';
import { isMacLike } from '../Utils/Platform';
import optionalRequire from '../Utils/OptionalRequire';
import { useShouldAutofocusInput } from '../UI/Responsive/ScreenTypeMeasurer';
const electron = optionalRequire('electron');

export const getProjectManagerItemId = (identifier: string) =>
Expand Down Expand Up @@ -1506,6 +1507,19 @@ const ProjectManagerWithErrorBoundary = React.forwardRef<
ProjectManagerInterface
>((props, outerRef) => {
const projectManagerRef = React.useRef<?ProjectManagerInterface>(null);
const shouldAutofocusInput = useShouldAutofocusInput();

React.useEffect(
() => {
const timeoutId = setTimeout(() => {
if (props.isOpen && shouldAutofocusInput && projectManagerRef.current) {
projectManagerRef.current.focusSearchBar();
}
}, 100);
return () => clearTimeout(timeoutId);
},
[props.isOpen, shouldAutofocusInput]
);

return (
<ErrorBoundary
Expand Down

0 comments on commit 4ae68e8

Please sign in to comment.