Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support toggling awt development in help center #886

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/commands/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { validateAndRecommendExtension } from "../recommendation";
import { sendInfo } from "vscode-extension-telemetry-wrapper";
import { getReleaseNotesEntries, findLatestReleaseNotes } from "../utils";
import { gt, eq } from "semver";
import { fetchInitProps } from "../welcome/index";

export async function createMavenProjectCmdHandler(_context: vscode.ExtensionContext) {
if (!await validateAndRecommendExtension("vscjava.vscode-maven", "Maven extension is recommended to help create Java projects and work with custom goals.", true)) {
Expand Down Expand Up @@ -104,3 +105,25 @@ export async function showReleaseNotesHandler(context: vscode.ExtensionContext,

return await showReleaseNotes(context, operationId, version);
}

export async function toggleAwtDevelopmentHandler(context: vscode.ExtensionContext, _operationId: string, enable: boolean) {
const workspaceConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.completion");
const disabledList: string[] = workspaceConfig.get<string[]>("filteredTypes") || [];
const filteredTypes: string[] = disabledList.filter((type) => {
return !type.startsWith("java.awt.");
});

if (!enable) {
filteredTypes.push("java.awt.*");
}

try {
await workspaceConfig.update("filteredTypes", filteredTypes, vscode.ConfigurationTarget.Workspace);
} catch (e) {
vscode.window.showErrorMessage((e as Error).message);
return;
}

fetchInitProps(context);
vscode.window.showInformationMessage(`Java AWT development is ${enable ? "enabled" : "disabled"}.`);
}
3 changes: 2 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { javaRuntimeCmdHandler } from "../java-runtime";
import { overviewCmdHandler } from "../overview";
import { webviewCmdLinkHandler } from "../utils";
import { showWelcomeWebview, showWelcomeWebviewBeside } from "../welcome";
import { createMavenProjectCmdHandler, createMicroProfileStarterProjectCmdHandler, createQuarkusProjectCmdHandler, createSpringBootProjectCmdHandler, installExtensionCmdHandler, openUrlCmdHandler, showExtensionCmdHandler, showReleaseNotesHandler } from "./handler";
import { createMavenProjectCmdHandler, createMicroProfileStarterProjectCmdHandler, createQuarkusProjectCmdHandler, createSpringBootProjectCmdHandler, installExtensionCmdHandler, openUrlCmdHandler, showExtensionCmdHandler, showReleaseNotesHandler, toggleAwtDevelopmentHandler } from "./handler";

export function initialize(context: vscode.ExtensionContext) {
registerCommandHandler(context, "java.overview", overviewCmdHandler);
Expand All @@ -35,6 +35,7 @@ export function initialize(context: vscode.ExtensionContext) {
registerCommandHandler(context, "java.classpathConfiguration", showClasspathConfigurationPage);
registerCommandHandler(context, "java.installJdk", showInstallJdkWebviewBeside);
registerCommandHandler(context, "java.installJdk.fromWalkthrough", showInstallJdkWebview);
registerCommandHandler(context, "java.toggleAwtDevelopment", toggleAwtDevelopmentHandler);
}

type CommandHandler = (context: vscode.ExtensionContext, operationId: string, ...args: any[]) => any;
Expand Down
5 changes: 3 additions & 2 deletions src/welcome/assets/components/GetStartedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TourPage from "./TourPage";
export class GetStartedPage extends React.Component<{
showWhenUsingJava: boolean,
firstTimeRun: boolean,
isAwtDisabled: boolean,
}> {

render() {
Expand All @@ -25,7 +26,7 @@ export class GetStartedPage extends React.Component<{
}

renderWelcomePage() {
const {showWhenUsingJava} = this.props;
const {showWhenUsingJava, isAwtDisabled} = this.props;
return (
<Container fluid className="root">
<Row className="mb-4">
Expand All @@ -40,7 +41,7 @@ export class GetStartedPage extends React.Component<{
</Row>
<Row className="mb-4">
<Col>
<NavigationPanel />
<NavigationPanel isAwtDisabled={isAwtDisabled}/>
</Col>
</Row>
<Row className="mb-4 footer">
Expand Down
19 changes: 17 additions & 2 deletions src/welcome/assets/components/NavigationPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as _ from "lodash";
import Tabs from "react-bootstrap/Tabs";
import Tab from "react-bootstrap/Tab";
import React from "react";
Expand All @@ -13,7 +14,9 @@ import { ListGroup } from "react-bootstrap";
import { reportTabSwitch, WEBVIEW_ID } from "../utils";
import { encodeCommandUriWithTelemetry } from "../../../utils/webview";

export default class NavigationPanel extends React.Component {
export default class NavigationPanel extends React.Component<{
isAwtDisabled: boolean;
}> {
private groups = [
{
name: "General",
Expand Down Expand Up @@ -42,14 +45,26 @@ export default class NavigationPanel extends React.Component {
{ name: "Tutorial: Running and Debugging", command: "java.helper.openUrl", args: ["https://code.visualstudio.com/docs/java/java-debugging"] },
{ name: "Tutorial: Testing", command: "java.helper.openUrl", args: ["https://code.visualstudio.com/docs/java/java-testing"] },
{ name: "Configure Sources, Dependencies, Output Folder...", command: "java.classpathConfiguration" },
{ name: "Quick Start: Jupyter Notebook for Java", command: "java.helper.openUrl", args: ["https://github.com/microsoft/vscode-java-pack/wiki/Quick-Start:-Jupyter-Notebook-for-Java"] }
{ name: "Quick Start: Jupyter Notebook for Java", command: "java.helper.openUrl", args: ["https://github.com/microsoft/vscode-java-pack/wiki/Quick-Start:-Jupyter-Notebook-for-Java"] },
{ name: "Enable AWT Development", command: "java.toggleAwtDevelopment", args: [true] },
]
},
];

private currentTab: string = this.groups[0].name;

render() {
const {isAwtDisabled} = this.props;
const studentSection = _.find(this.groups, {name: "Student"});
if (studentSection) {
for (const action of studentSection.actions) {
if (action.command === "java.toggleAwtDevelopment") {
action.name = `${isAwtDisabled ? "Enable" : "Disable"} AWT Development`;
action.args = [isAwtDisabled];
}
}
}

const itemIcon = <Icon className="codicon" icon={rocketIcon} />;
const tabItems = this.groups.map(group => {
const actionItems = group.actions.map(action => (
Expand Down
11 changes: 10 additions & 1 deletion src/welcome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ const setFirstTimeRun = (context: vscode.ExtensionContext, firstTimeRun: boolean
context.globalState.update(KEY_IS_WELCOME_PAGE_VIEWED, !firstTimeRun);
};

const fetchInitProps = async (context: vscode.ExtensionContext) => {
export const fetchInitProps = async (context: vscode.ExtensionContext) => {
welcomeView?.webview.postMessage({
command: "onDidFetchInitProps",
props: {
showWhenUsingJava: context.globalState.get(KEY_SHOW_WHEN_USING_JAVA),
firstTimeRun: context.globalState.get(KEY_IS_WELCOME_PAGE_VIEWED) !== true,
isAwtDisabled: isAwtDisabled(),
}
});
setFirstTimeRun(context, false);
Expand All @@ -141,7 +142,15 @@ const showTourPage = async (context: vscode.ExtensionContext) => {
props: {
showWhenUsingJava: context.globalState.get(KEY_SHOW_WHEN_USING_JAVA),
firstTimeRun: true,
isAwtDisabled: isAwtDisabled(),
}
});
setFirstTimeRun(context, false);
};

function isAwtDisabled(): boolean {
const filteredTypes: string[] = vscode.workspace.getConfiguration("java.completion").get<string[]>("filteredTypes") || [];
return filteredTypes.some((type: string) => {
return type.startsWith("java.awt.");
});
}