Skip to content

Commit

Permalink
example-app: keep WIP vcs tool window hidden by default
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezamirian committed Jan 30, 2024
1 parent e2ecd30 commit 906937c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ https://user-images.githubusercontent.com/3150694/232305636-e8b63780-4777-4d27-8
<td>✅</td>
</tr>
<tr>
<td rowspan="3"><a href="https://jetbrains.github.io/ui/controls/menu_list/">Menu List</a> <sup>2</sup></td>
<td rowspan="3"><a href="https://jetbrains.github.io/ui/controls/menu_list/">Menu List</a> <sup>1</sup></td>
</tr>
<tr>
<td colspan="2">Basic</td>
Expand Down Expand Up @@ -271,7 +271,7 @@ https://user-images.githubusercontent.com/3150694/232305636-e8b63780-4777-4d27-8
<td>✅</td>
</tr>
<tr>
<td colspan="2">View Mode - Window <sup>4</sup></td>
<td colspan="2">View Mode - Window <sup>2</sup></td>
<td>❌</td>
</tr>
<tr>
Expand All @@ -284,7 +284,7 @@ https://user-images.githubusercontent.com/3150694/232305636-e8b63780-4777-4d27-8
</tr>
<tr>
<td colspan="2">Gear icon actions</td>
<td>✅<sup>5</sup></td>
<td>✅</td>
</tr>
<tr>
<td rowspan="1" colspan="3"><a href="https://jetbrains.github.io/ui/components/dialog_window/">ModalWindow</a></td>
Expand Down Expand Up @@ -331,12 +331,9 @@ https://user-images.githubusercontent.com/3150694/232305636-e8b63780-4777-4d27-8

🧬: higher level "molecule" components that capture a common usage of two or more atomic components, together.

1. Not exactly a list feature. But more about checking feasibility of it
2. It seems in Intellij UI, such menu lists are only used in popups. Maybe only
1. It seems in Intellij UI, such menu lists are only used in popups. Maybe only
FlatSpeedSearchPopup
3. Most probably will not be implemented.
4. Keyboard shortcuts for resizing windows depend on action system implementation and not done yet.
Also "Remove from sidebar" doesn't fit with how tool windows is implemented at the moment.
2. Most probably will not be implemented.

[//]: # "TODO: Contribution: - document code generation commands"

Expand Down
7 changes: 6 additions & 1 deletion packages/example-app/src/Project/toolWindows.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const toolWindowsState = atom({
default: new ToolWindowsState(
Object.fromEntries(
toolWindows.map(({ id, initialState }) => [id, initialState])
)
),
{
removedFromSideBarIds: toolWindows
.filter(({ showStripeButton }) => showStripeButton === false)
.map(({ id }) => id),
}
),
});
7 changes: 6 additions & 1 deletion packages/example-app/src/Project/toolWindows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ToolWindowDescriptor = {
title: string;
icon: React.ReactNode;
content: React.ReactElement;
showStripeButton?: boolean;
initialState: ToolWindowState;
};
export const toolWindows: ToolWindowDescriptor[] = [
Expand Down Expand Up @@ -64,6 +65,10 @@ export const toolWindows: ToolWindowDescriptor[] = [
<VersionControlToolWindow />
</Suspense>
),
initialState: toolWindowState({ anchor: "bottom", weight: 0.35 }),
showStripeButton: false,
initialState: toolWindowState({
anchor: "bottom",
weight: 0.35,
}),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export class ToolWindowsState {
this.lastFocusedKey = lastFocusedKey;
this.layoutToRestore = layoutToRestore;
this.removedFromSideBarIds = new Set(removedFromSideBarIds);
// TODO: instead of keeping a set of removedFromSideBarIds showStripeButton can be a boolean on each window state.
// if we want to avoid the invalid combination of `{ isVisible: true, showStripeButton: false }`, we can have a
// a single property like : visibility: 'open' | 'closed' | 'removed'
const invalidWindows = Object.keys(this.windows).filter(
(key) =>
this.removedFromSideBarIds.has(key) && this.windows[key].isVisible
Expand Down
38 changes: 28 additions & 10 deletions packages/jui/src/ToolWindowsImpl/DefaultToolWindows.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { ComponentProps, useState } from "react";
import {
DefaultToolWindow,
DefaultToolWindows,
Expand Down Expand Up @@ -30,17 +30,24 @@ const window = (id: string) => ({
const SimpleToolWindows = React.forwardRef(
(
{
removedFromSideBarIds,
initialState = {
"First window": toolWindowState({ isVisible: true }),
"Second window": toolWindowState({ anchor: "bottom", isVisible: true }),
"First window": toolWindowState({
isVisible: !removedFromSideBarIds?.includes("First window"),
}),
"Second window": toolWindowState({
anchor: "bottom",
isVisible: !removedFromSideBarIds?.includes("Second window"),
}),
},
}: {
initialState?: { [key: string]: ToolWindowState };
removedFromSideBarIds?: string[];
},
ref: React.ForwardedRef<ToolWindowRefValue>
) => {
const [state, setState] = useState(
() => new ToolWindowsState(initialState)
() => new ToolWindowsState(initialState, { removedFromSideBarIds })
);

return (
Expand Down Expand Up @@ -235,14 +242,25 @@ describe("DefaultToolWindowActions", () => {
cy.realPress(["Meta", "2"]);
cy.findByTestId("main content focusable").should("have.focus");
});

it("adds the tool window to the sidebar and opens it, if it's currently removed from sidebar", () => {
cy.mount(
<ThemeProvider theme={new Theme(darculaThemeJson as any)}>
<WithActivateToolWindowKeymap
removedFromSideBarIds={["First window"]}
/>
</ThemeProvider>
);
cy.realPress(["Meta", "1"]);
cy.findByTestId("First window").should("exist");
cy.findByTestId("First window").find("input").eq(0).should("be.focused");
});
});
});

function WithActivateToolWindowKeymap({
initialState,
}: {
initialState?: Record<string, ToolWindowState>;
}) {
function WithActivateToolWindowKeymap(
props: ComponentProps<typeof SimpleToolWindows>
) {
return (
<KeymapProvider
keymap={{
Expand All @@ -266,7 +284,7 @@ function WithActivateToolWindowKeymap({
],
}}
>
<SimpleToolWindows initialState={initialState} />
<SimpleToolWindows {...props} />
</KeymapProvider>
);
}
1 change: 0 additions & 1 deletion packages/jui/src/ToolWindowsImpl/useToolWindowsActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
HIDE_ALL_WINDOWS_ACTION_ID,
JUMP_TO_LAST_WINDOW_ACTION_ID,
} from "./ToolWindowActionIds";
import { zipObj } from "ramda";

interface DefaultToolWindowActionsProps {
toolWindowsState: Readonly<ToolWindowsState>;
Expand Down

0 comments on commit 906937c

Please sign in to comment.