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

Feat: support hide treeview and entry #477

Merged
merged 8 commits into from
Aug 28, 2020
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
1 change: 1 addition & 0 deletions extensions/iceworks-app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 0.4.7
- feat: auto focus field
- chore: quick entries title and detail
- feat: hide some entries and treeview in pegasus project

## 0.4.6

Expand Down
4 changes: 2 additions & 2 deletions extensions/iceworks-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
{
"id": "pages",
"name": "%iceworksApp.view.pages.name%",
"when": "!iceworks:isNotTargetProject"
"when": "!iceworks:isNotTargetProject && !iceworks:isPegasusProject"
},
{
"id": "components",
"name": "%iceworksApp.view.components.name%",
"when": "!iceworks:isNotTargetProject"
"when": "!iceworks:isNotTargetProject && !iceworks:isPegasusProject"
},
{
"id": "nodeDependencies",
Expand Down
53 changes: 0 additions & 53 deletions extensions/iceworks-app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,3 @@ export const showExtensionsQuickPickCommandId = 'iceworksApp.showEntriesQuickPic

export const editorTitleRunDebugCommandId = 'npmScripts-editor-title-run-dev';
export const editorTitleRunBuildCommandId = 'npmScripts-editor-title-run-build';

export const entryOptions = [
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.projectCreater.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.projectCreater.detail'),
command: 'iceworks-project-creator.start',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.detail'),
command: 'iceworks-ui-builder.generate-component',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.pageBuilder.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.pageBuilder.detail'),
command: 'iceworks-ui-builder.generate-page',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.materialImport.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.materialImport.detail'),
command: 'iceworks-material-helper.start',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.showMaterialDocs.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.showMaterialDocs.detail'),
command: 'iceworks-material-helper.showMaterialDocs',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.runDebug.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.runDebug.detail'),
command: 'iceworksApp.editorMenu.runDebug',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.runBuild.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.runBuild.detail'),
command: 'iceworksApp.editorMenu.runBuild',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.reinstall.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.reinstall.detail'),
command: 'iceworksApp.nodeDependencies.reinstall',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.addDepsAndDevDeps.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.addDepsAndDevDeps.detail'),
command: 'iceworksApp.nodeDependencies.addDepsAndDevDeps',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.openSettings.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.openSettings.detail'),
command: 'iceworksApp.configHelper.start',
},
];
16 changes: 10 additions & 6 deletions extensions/iceworks-app/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { window, ViewColumn } from 'vscode';
import { connectService, getHtmlForWebview } from '@iceworks/vscode-webview/lib/vscode';
import { getProjectType } from '@iceworks/project-service';
import { getProjectType, checkIsPegasusProject } from '@iceworks/project-service';
import { Recorder, recordDAU } from '@iceworks/recorder';
import { initExtension, checkIsAliInternal, registerCommand } from '@iceworks/common-service';
import { createNpmScriptsTreeView } from './views/npmScriptsView';
Expand All @@ -24,17 +24,20 @@ const recorder = new Recorder(name, version);
export async function activate(context: vscode.ExtensionContext) {
const { subscriptions, extensionPath } = context;

const projectType = await getProjectType();
const isPegasusProject = checkIsPegasusProject();
vscode.commands.executeCommand('setContext', 'iceworks:isPegasusProject', isPegasusProject);
// auto set configuration
initExtension(context);

// init statusBarItem
const extensionsStatusBar = createExtensionsStatusBar();
subscriptions.push(extensionsStatusBar);
subscriptions.push(
registerCommand(showExtensionsQuickPickCommandId, () => {
registerCommand(showExtensionsQuickPickCommandId, async () => {
recorder.recordActivate();

showEntriesQuickPick();
await showEntriesQuickPick();
})
);

Expand Down Expand Up @@ -80,9 +83,11 @@ export async function activate(context: vscode.ExtensionContext) {

treeViews.push(createQuickEntriesTreeView(context));
treeViews.push(createNpmScriptsTreeView(context));
treeViews.push(createComponentsTreeView(context));
treeViews.push(createPagesTreeView(context));
treeViews.push(createNodeDependenciesTreeView(context));
if (!isPegasusProject) {
treeViews.push(createComponentsTreeView(context));
treeViews.push(createPagesTreeView(context));
}
let didSetViewContext;
treeViews.forEach((treeView) => {
const { title } = treeView;
Expand Down Expand Up @@ -110,7 +115,6 @@ export async function activate(context: vscode.ExtensionContext) {
});

// init editor title menu
const projectType = await getProjectType();
if (projectType !== 'unknown') {
vscode.commands.executeCommand('setContext', 'iceworks:isAliInternal', await checkIsAliInternal());
vscode.commands.executeCommand('setContext', 'iceworks:showScriptIconInEditorTitleMenu', true);
Expand Down
69 changes: 69 additions & 0 deletions extensions/iceworks-app/src/getQuickEntryOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { getProjectFramework } from '@iceworks/project-service';
import i18n from './i18n';

const entries = [
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.projectCreater.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.projectCreater.detail'),
command: 'iceworks-project-creator.start',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.pageBuilder.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.pageBuilder.detail'),
command: 'iceworks-ui-builder.generate-page',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.materialImport.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.materialImport.detail'),
command: 'iceworks-material-helper.start',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.showMaterialDocs.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.showMaterialDocs.detail'),
command: 'iceworks-material-helper.showMaterialDocs',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.runDebug.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.runDebug.detail'),
command: 'iceworksApp.editorMenu.runDebug',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.runBuild.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.runBuild.detail'),
command: 'iceworksApp.editorMenu.runBuild',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.reinstall.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.reinstall.detail'),
command: 'iceworksApp.nodeDependencies.reinstall',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.addDepsAndDevDeps.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.addDepsAndDevDeps.detail'),
command: 'iceworksApp.nodeDependencies.addDepsAndDevDeps',
},
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.openSettings.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.openSettings.detail'),
command: 'iceworksApp.configHelper.start',
},
];

const optionalEntries = [
{
label: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.label'),
detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.detail'),
command: 'iceworks-ui-builder.generate-component',
},
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得比较好的实现方式可能是:

[
  {
    label: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.label'),
    detail: i18n.format('extension.iceworksApp.showEntriesQuickPick.generateComponent.detail'),
    command: 'iceworks-ui-builder.generate-component',
    supportProjectTypes: ['react', 'rax'],
    supportProjectFrameworks: ['icejs'],
  },
]

这样?

当下可以先简单做。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


export default async () => {
const projectFramework = await getProjectFramework();
if (projectFramework === 'icejs') {
const newEntries = [...entries];
newEntries.splice(1, 0, ...optionalEntries);
return newEntries;
} else {
return entries;
}
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as vscode from 'vscode';
import { entryOptions } from '../constants';
import getQuickEntryOptions from '../getQuickEntryOptions';

const { window, commands } = vscode;

export default function showEntriesQuickPick() {
export default async function showEntriesQuickPick() {
const quickPick = window.createQuickPick();
const entryOptions = await getQuickEntryOptions();
quickPick.items = entryOptions.map((options) => ({ label: options.label, detail: options.detail }));
quickPick.onDidChangeSelection((selection) => {
if (selection[0]) {
Expand Down
7 changes: 4 additions & 3 deletions extensions/iceworks-app/src/views/quickEntriesView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { registerCommand, executeCommand } from '@iceworks/common-service';
import { entryOptions } from '../constants';
import getQuickEntryOptions from '../getQuickEntryOptions';

export class QuickEntriesProvider implements vscode.TreeDataProvider<QuickEntryItem> {
private extensionContext: vscode.ExtensionContext;
Expand All @@ -14,11 +14,12 @@ export class QuickEntriesProvider implements vscode.TreeDataProvider<QuickEntryI
}

async getChildren() {
const quickEntries = this.getEntries();
const quickEntries = await this.getEntries();
return Promise.resolve(quickEntries);
}

private getEntries() {
private async getEntries() {
const entryOptions = await getQuickEntryOptions();
return entryOptions.map((option) => {
const { label, detail, command } = option;
const entryCommand: vscode.Command = {
Expand Down
2 changes: 1 addition & 1 deletion packages/project-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iceworks/project-service",
"version": "0.1.16",
"version": "0.1.17",
"description": "Iceworks project service for VSCode extension.",
"files": [
"lib"
Expand Down
13 changes: 13 additions & 0 deletions packages/project-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export async function getProjectType() {
}
}

export async function checkIsPegasusProject() {
let isPegasus = false;
const abcConfigFile = path.join(projectPath, 'abc.json');
if (fsExtra.existsSync(abcConfigFile)) {
const abcConfig = await fsExtra.readJSON(abcConfigFile);
if (abcConfig.type === 'pegasus' && abcConfig.group && abcConfig.name) {
isPegasus = true;
}
}

return isPegasus;
}

export async function getProjectFramework() {
const { dependencies = {}, devDependencies = {} } = await readPackageJSON(projectPath);
if (dependencies['rax-app']) {
Expand Down