Skip to content
Open
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
24 changes: 23 additions & 1 deletion src/ui/views/LibraryListView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import vscode, { commands, l10n } from "vscode";
import vscode, { CancellationToken, commands, Event, FileDecoration, FileDecorationProvider, l10n, ProviderResult, ThemeColor, ThemeIcon, Uri, window } from "vscode";
import IBMi from "../../api/IBMi";
import { instance } from "../../instantiate";
import { ConnectionConfig, IBMiObject, LIBRARY_LIST_MIMETYPE, URI_LIST_MIMETYPE, URI_LIST_SEPARATOR, WithLibrary } from "../../typings";
Expand All @@ -14,6 +14,7 @@ export function initializeLibraryListView(context: vscode.ExtensionContext) {
canSelectMany: true,
dragAndDropController: new LibraryListDragAndDrop()
});
const liblDecorationProvider = new LiblDecorationProvider();

const updateConfig = async (config: ConnectionConfig) => {
await IBMi.connectionManager.update(config);
Expand All @@ -24,6 +25,7 @@ export function initializeLibraryListView(context: vscode.ExtensionContext) {

context.subscriptions.push(
libraryListViewViewer,
window.registerFileDecorationProvider(liblDecorationProvider),
vscode.commands.registerCommand(`code-for-ibmi.userLibraryList.enable`, () => {
commands.executeCommand(`setContext`, `code-for-ibmi:libraryListDisabled`, false);
}),
Expand Down Expand Up @@ -371,6 +373,9 @@ class LibraryListNode extends vscode.TreeItem implements WithLibrary {
super(library, vscode.TreeItemCollapsibleState.None);

this.contextValue = context;
this.iconPath = new ThemeIcon('library');
const isFound = object.text !== `*** NOT FOUND ***`;
this.resourceUri = Uri.parse(`${context}:${library}?isFound=${isFound}`);
this.description =
((context === `currentLibrary` ? `${l10n.t(`(current library)`)}` : ``)
+ (object.text !== `` && showDescInLibList ? ` ${object.text}` : ``)
Expand Down Expand Up @@ -400,4 +405,21 @@ async function changeCurrentLibrary(library: string) {
return false;
}
}
}

export class LiblDecorationProvider implements FileDecorationProvider {
onDidChangeFileDecorations?: Event<Uri | Uri[] | undefined> | undefined;
provideFileDecoration(uri: Uri, token: CancellationToken): ProviderResult<FileDecoration> {
const params = new URLSearchParams(uri.query);

if (uri.scheme === 'currentLibrary' || uri.scheme === 'library') {
const isNotFound = params.get('isFound') === 'false';
if (isNotFound) {
return {
badge: '⚠',
color: new ThemeColor('errorForeground')
};
}
}
}
}
81 changes: 49 additions & 32 deletions src/ui/views/objectBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs, { existsSync } from "fs";
import os from "os";
import path, { basename, dirname } from "path";
import vscode, { DataTransferItem, l10n, Uri } from "vscode";
import vscode, { commands, DataTransferItem, l10n, Uri } from "vscode";
import { parseFilter, singleGenericName } from "../../api/Filter";
import IBMi, { MemberParts } from "../../api/IBMi";
import { SortOptions, SortOrder } from "../../api/IBMiContent";
Expand Down Expand Up @@ -1082,45 +1082,55 @@ Do you want to replace it?`, item.name), { modal: true }, skipAllLabel, overwrit
});

if (newLibrary) {

const filters = config.objectFilters;

const createResult = await connection.runCommand({
command: `CRTLIB LIB(${newLibrary})`,
noLibList: true
});

if (createResult.code !== 0) {
vscode.window.showErrorMessage(vscode.l10n.t(`Cannot create library "{0}": {1}`, newLibrary, createResult.stderr));
}

filters.push({
name: newLibrary,
filterType: 'simple',
library: newLibrary,
object: `*ALL`,
types: [`*ALL`],
member: `*`,
memberType: `*`,
protected: false
});
const isSuccess = createResult.code === 0;
if (isSuccess) {
const config = connection.getConfig();
const libl = [config.currentLibrary, ...config.libraryList].map(library => connection.upperCaseName(library));
const existsInLibl = libl.includes(connection.upperCaseName(newLibrary));
if (existsInLibl) {
commands.executeCommand(`code-for-ibmi.refreshLibraryListView`);
}

config.objectFilters = filters;
IBMi.connectionManager.update(config);
const autoRefresh = objectBrowser.autoRefresh();

// Add to library list ?
await vscode.window.showInformationMessage(vscode.l10n.t(`Would you like to add the new library to the library list?`), vscode.l10n.t(`Yes`))
.then(async result => {
switch (result) {
case vscode.l10n.t(`Yes`):
await vscode.commands.executeCommand(`code-for-ibmi.addToLibraryList`, { library: newLibrary });
if (autoRefresh) {
vscode.commands.executeCommand(`code-for-ibmi.refreshLibraryListView`);
}
break;
}
filters.push({
name: newLibrary,
filterType: 'simple',
library: newLibrary,
object: `*ALL`,
types: [`*ALL`],
member: `*`,
memberType: `*`,
protected: false
});

config.objectFilters = filters;
IBMi.connectionManager.update(config);
const autoRefresh = objectBrowser.autoRefresh();

if(!existsInLibl) {
// Add to library list ?
await vscode.window.showInformationMessage(vscode.l10n.t(`Would you like to add the new library to the library list?`), vscode.l10n.t(`Yes`))
.then(async result => {
switch (result) {
case vscode.l10n.t(`Yes`):
await vscode.commands.executeCommand(`code-for-ibmi.addToLibraryList`, { library: newLibrary });
if (autoRefresh) {
vscode.commands.executeCommand(`code-for-ibmi.refreshLibraryListView`);
}
break;
}
});
}
} else {
vscode.window.showErrorMessage(vscode.l10n.t(`Cannot create library "{0}": {1}`, newLibrary, createResult.stderr));
}
}
}),

Expand Down Expand Up @@ -1518,9 +1528,16 @@ async function deleteObject(object: IBMiObject) {
noLibList: true
});

if (deleteResult.code !== 0) {
const isSuccess = deleteResult.code === 0;
if (isSuccess) {
const config = connection.getConfig();
const libl = [config.currentLibrary, ...config.libraryList].map(library => connection.upperCaseName(library));
if (libl.includes(connection.upperCaseName(object.name))) {
commands.executeCommand(`code-for-ibmi.refreshLibraryListView`);
}
} else {
vscode.window.showErrorMessage(vscode.l10n.t(`Error deleting object! {0}`, deleteResult.stderr));
}

return deleteResult.code === 0;
return isSuccess;
}
Loading