Skip to content

Commit

Permalink
Add ability to hide folder arrows in explorer. (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimiC authored and robertohuertasm committed Nov 11, 2017
1 parent 7447b70 commit f1fd6e6
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 47 deletions.
2 changes: 2 additions & 0 deletions locale/lang.en.json
Expand Up @@ -24,6 +24,8 @@
"hideFoldersPresetDisabled": "Folder icons visibility will be disabled.",
"foldersAllDefaultIconPresetEnabled": "Specific folder icons will be enabled.",
"foldersAllDefaultIconPresetDisabled": "Specific folder icons will be disabled.",
"hideExplorerArrowsPresetEnabled": "Explorer folder arrows visibility will be enabled.",
"hideExplorerArrowsPresetDisabled": "Explorer folder arrows visibility will be disabled.",
"restart": "Select 'Restart' for changes to take effect.",
"ngDetected": "%extensionName% has detected an Angular project. Select 'Restart' to enable the Angular icons.",
"nonNgDetected": "%extensionName% has detected a non Angular project. Select 'Restart' to disable the Angular icons.",
Expand Down
10 changes: 10 additions & 0 deletions package.json
Expand Up @@ -103,6 +103,11 @@
"title": "%command.foldersAllDefaultIconPreset.title%",
"category": "Icons"
},
{
"command": "vscode-icons.hideExplorerArrowsPreset",
"title": "%command.hideExplorerArrowsPreset.title%",
"category": "Icons"
},
{
"command": "vscode-icons.restoreIcons",
"title": "%command.restoreIcons.title%",
Expand Down Expand Up @@ -167,6 +172,11 @@
"default": false,
"description": "%configuration.presets.foldersAllDefaultIcon.description%"
},
"vsicons.presets.hideExplorerArrows": {
"type": "boolean",
"default": false,
"description": "%configuration.presets.hideExplorerArrows.description%"
},
"vsicons.customIconFolderPath": {
"type": "string",
"default": "",
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Expand Up @@ -7,6 +7,7 @@
"command.jsonPreset.title": "Toggle Official JSON Preset (User Level)",
"command.hideFoldersPreset.title": "Toggle Folder Icons Visibility (User Level)",
"command.foldersAllDefaultIconPreset.title": "Toggle Specific Folder Icons (User Level)",
"command.hideExplorerArrowsPreset.title": "Toggle Explorer Folder Arrows Visibility (User Level)",
"command.restoreIcons.title": "Restore Default Icon Manifest",
"command.resetProjectDetectionDefaults.title": "Reset Project Detection Defaults",
"configuration.title": "vscode-icons configuration",
Expand All @@ -20,6 +21,7 @@
"configuration.presets.jsonOfficial.description": "If set to true, the extension will use the official JSON icon.",
"configuration.presets.hideFolders.description": "If set to true, all folders will be hidden.",
"configuration.presets.foldersAllDefaultIcon.description": "If set to true, all folders will have the default folder icon.",
"configuration.presets.hideExplorerArrows.description": "If set to true, the extension will hide the folder arrows in the 'Explorer'.",
"configuration.customIconFolderPath.description": "The physical path to the parent folder where the custom icons folder resides on your local machine.",
"configuration.associations.files.description": "These custom associations will override the file icon associations defined by default.",
"configuration.associations.folders.description": "These custom associations will override the folder icon associations defined by default.",
Expand Down
2 changes: 2 additions & 0 deletions package.nls.template.json
Expand Up @@ -7,6 +7,7 @@
"command.jsonPreset.title": "",
"command.hideFoldersPreset.title": "",
"command.foldersAllDefaultIconPreset.title": "",
"command.hideExplorerArrowsPreset.title": "",
"command.restoreIcons.title": "",
"command.resetProjectDetectionDefaults.title": "",
"configuration.title": "",
Expand All @@ -20,6 +21,7 @@
"configuration.presets.jsonOfficial.description": "",
"configuration.presets.hideFolders.description": "",
"configuration.presets.foldersAllDefaultIcon.description": "",
"configuration.presets.hideExplorerArrows.description": "",
"configuration.customIconFolderPath.description": "",
"configuration.associations.files.description": "",
"configuration.associations.folders.description": "",
Expand Down
17 changes: 15 additions & 2 deletions src/commands/helper.ts
@@ -1,7 +1,20 @@
import * as models from '../models';

export function isFolders(preset: string): boolean {
return preset.toLowerCase().includes('folders');
const foldersRelatedPresets = [
models.PresetNames.hideFolders,
models.PresetNames.foldersAllDefaultIcon,
];

const nonIconsRelatedPresets = [
models.PresetNames.hideExplorerArrows,
];

export function isFoldersRelated(presetName: models.PresetNames): boolean {
return foldersRelatedPresets.some(preset => preset === presetName);
}

export function isNonIconsRelatedPreset(presetName: models.PresetNames): boolean {
return nonIconsRelatedPresets.some(preset => preset === presetName);
}

export function getFunc(preset: string): (iconsJson: models.IIconSchema) => boolean {
Expand Down
20 changes: 16 additions & 4 deletions src/commands/index.ts
Expand Up @@ -4,9 +4,10 @@ import { LanguageResourceManager } from '../i18n';
import * as iconManifest from '../icon-manifest';
import { extensions as files } from '../icon-manifest/supportedExtensions';
import { extensions as folders } from '../icon-manifest/supportedFolders';
import { ManifestReader as mr } from '../icon-manifest/manifestReader';
import * as models from '../models';
import { SettingsManager, extensionSettings } from '../settings';
import { ProjectAutoDetection as pad, manageApplyCustomizations } from '../init';
import { manageApplyCustomizations } from '../init';
import * as helper from './helper';
import { initialized } from '../';
import { constants } from '../constants';
Expand Down Expand Up @@ -60,6 +61,7 @@ export function registerCommands(context: vscode.ExtensionContext): void {
registerCommand(context, 'jsonPreset', toggleJsonPresetCommand);
registerCommand(context, 'hideFoldersPreset', toggleHideFoldersPresetCommand);
registerCommand(context, 'foldersAllDefaultIconPreset', toggleFoldersAllDefaultIconPresetCommand);
registerCommand(context, 'hideExplorerArrowsPreset', toggleHideExplorerArrowsPresetCommand);
}

function registerCommand(
Expand Down Expand Up @@ -125,16 +127,22 @@ function toggleFoldersAllDefaultIconPresetCommand(): void {
togglePreset(models.PresetNames.foldersAllDefaultIcon, 'foldersAllDefaultIconPreset', true);
}

function toggleHideExplorerArrowsPresetCommand(): void {
togglePreset(models.PresetNames.hideExplorerArrows, 'hideExplorerArrowsPreset', true);
}

function togglePreset(
presetName: models.PresetNames,
presetKey: string,
reverseAction: boolean = false,
global: boolean = true): void {

const preset = models.PresetNames[presetName];
const toggledValue = helper.isFolders(preset)
? pad.folderIconsDisabled(helper.getFunc(preset))
: pad.iconsDisabled(helper.getIconName(preset));
const toggledValue = helper.isNonIconsRelatedPreset(presetName)
? !getVsiconsConfig().presets[preset]
: helper.isFoldersRelated(presetName)
? mr.folderIconsDisabled(helper.getFunc(preset))
: mr.iconsDisabled(helper.getIconName(preset));
const action = reverseAction
? toggledValue
? 'Disabled'
Expand Down Expand Up @@ -309,6 +317,10 @@ function generateManifest(
workingCustomFolders,
workingFolders,
iconGenerator);

// apply non icons related config settings
json.hidesExplorerArrows = vsicons.presets.hideExplorerArrows;

iconGenerator.persist(extensionSettings.iconJsonFileName, json);
}

Expand Down
1 change: 1 addition & 0 deletions src/icon-manifest/defaultSchema.ts
Expand Up @@ -35,4 +35,5 @@ export const schema: IIconSchema = {
fileNames: {},
languageIds: {},
},
hidesExplorerArrows: false,
};
3 changes: 2 additions & 1 deletion src/icon-manifest/iconGenerator.ts
Expand Up @@ -8,7 +8,6 @@ import * as packageJson from '../../../package.json';

export class IconGenerator implements models.IIconGenerator {
public settings: models.ISettings;

public iconsFolderBasePath: string;

private iconsFolderPath: string;
Expand Down Expand Up @@ -322,6 +321,7 @@ export class IconGenerator implements models.IIconGenerator {
return utils.pathUnixJoin(fPath, filename);
}

// Note: Non icons entries are added in 'commands.generateManifest'function
private buildJsonStructure(
files: models.IFileCollection,
folders: models.IFolderCollection,
Expand Down Expand Up @@ -351,6 +351,7 @@ export class IconGenerator implements models.IIconGenerator {
schema.light.fileExtensions = res.files.light.fileExtensions;
schema.light.fileNames = res.files.light.fileNames;
schema.light.languageIds = res.files.light.languageIds;

return schema;
}
}
1 change: 1 addition & 0 deletions src/icon-manifest/index.ts
Expand Up @@ -2,3 +2,4 @@ export * from './defaultSchema';
export * from './iconGenerator';
export * from './languages';
export * from './manifestMerger';
export * from './manifestReader';
30 changes: 30 additions & 0 deletions src/icon-manifest/manifestReader.ts
@@ -0,0 +1,30 @@
import * as fs from 'fs';
import * as path from 'path';
import * as models from '../models';
import { parseJSON } from '../utils';
import { extensionSettings } from '../settings';

export class ManifestReader {

public static iconsDisabled(name: string, isFile: boolean = true): boolean {
const iconManifest = this.getIconManifest();
const iconsJson = iconManifest && parseJSON(iconManifest) as models.IIconSchema;
return !iconsJson || !Reflect.ownKeys(iconsJson.iconDefinitions)
.filter(key => key.toString().startsWith(`_${isFile ? 'f' : 'fd'}_${name}`)).length;
}

public static folderIconsDisabled(func: (iconsJson: models.IIconSchema) => boolean): boolean {
const iconManifest = this.getIconManifest();
const iconsJson = iconManifest && parseJSON(iconManifest) as models.IIconSchema;
return !iconsJson || !func(iconsJson);
}

private static getIconManifest(): string {
const manifestFilePath = path.join(__dirname, '..', extensionSettings.iconJsonFileName);
try {
return fs.readFileSync(manifestFilePath, 'utf8');
} catch (err) {
return null;
}
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { SettingsManager } from './settings';
import * as init from './init';
import { ProjectAutoDetection as pad } from './init/projectAutoDetection';
import { ManifestReader as mr } from './icon-manifest';
import * as commands from './commands';
import { getVsiconsConfig, getConfig, findFiles } from './utils/vscode-extensions';
import { LanguageResourceManager } from './i18n';
Expand Down Expand Up @@ -31,7 +32,7 @@ function detectAngular(config: IVSIcons, results: IVSCodeUri[]): void {
const i18nManager = new LanguageResourceManager(vscode.env.language);
const presetValue = getConfig().inspect(`vsicons.presets.angular`).workspaceValue as boolean;
const detectionResult = pad.checkForAngularProject(
presetValue, pad.iconsDisabled(Projects.angular), !!projectInfo, i18nManager);
presetValue, mr.iconsDisabled(Projects.angular), !!projectInfo, i18nManager);

if (!detectionResult.apply) {
return;
Expand Down
23 changes: 0 additions & 23 deletions src/init/projectAutoDetection.ts
@@ -1,10 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as models from '../models';
import { extensionSettings } from '../settings';
import { parseJSON } from '../utils';
import { LanguageResourceManager } from '../i18n';
import { IIconSchema } from '../models/iconSchema/iconSchema';

export class ProjectAutoDetection {
public static detectProject(
Expand Down Expand Up @@ -55,18 +52,6 @@ export class ProjectAutoDetection {
return { apply: true, message, value: enableIcons || !disableIcons };
}

public static iconsDisabled(name: string, isFile: boolean = true): boolean {
const iconManifest = this._getIconManifest();
const iconsJson = iconManifest && parseJSON(iconManifest) as IIconSchema;
return !iconsJson || !Reflect.ownKeys(iconsJson.iconDefinitions)
.filter(key => key.toString().startsWith(`_${isFile ? 'f' : 'fd'}_${name}`)).length;
}

public static folderIconsDisabled(func: (iconsJson: IIconSchema) => boolean): boolean {
const iconManifest = this._getIconManifest();
const iconsJson = iconManifest && parseJSON(iconManifest) as IIconSchema;
return !iconsJson || !func(iconsJson);
}
public static getProjectInfo(results: models.IVSCodeUri[], name: models.Projects): models.IProjectInfo {
let projectInfo: models.IProjectInfo = null;
results.some(result => {
Expand Down Expand Up @@ -127,12 +112,4 @@ export class ProjectAutoDetection {
return null;
}
}
private static _getIconManifest(): string {
const manifestFilePath = path.join(__dirname, '..', extensionSettings.iconJsonFileName);
try {
return fs.readFileSync(manifestFilePath, 'utf8');
} catch (err) {
return null;
}
}
}
1 change: 1 addition & 0 deletions src/models/contributions/presetNames.ts
Expand Up @@ -5,4 +5,5 @@ export enum PresetNames {
jsonOfficial,
hideFolders,
foldersAllDefaultIcon,
hideExplorerArrows,
}
1 change: 1 addition & 0 deletions src/models/contributions/presets.ts
Expand Up @@ -5,4 +5,5 @@ export interface IPresets {
jsonOfficial: boolean;
hideFolders: boolean;
foldersAllDefaultIcon: boolean;
hideExplorerArrows: boolean;
}
2 changes: 2 additions & 0 deletions src/models/i18n/langResourceKeys.ts
Expand Up @@ -24,6 +24,8 @@ export enum LangResourceKeys {
hideFoldersPresetDisabled,
foldersAllDefaultIconPresetEnabled,
foldersAllDefaultIconPresetDisabled,
hideExplorerArrowsPresetEnabled,
hideExplorerArrowsPresetDisabled,
restart,
ngDetected,
nonNgDetected,
Expand Down
1 change: 1 addition & 0 deletions src/models/iconSchema/iconSchema.ts
Expand Up @@ -5,4 +5,5 @@ export interface IIconSchema extends IIconMapping {
iconDefinitions: IIconDefinition;
light: IIconMapping;
highContrast?: IIconMapping;
hidesExplorerArrows?: boolean;
}
12 changes: 9 additions & 3 deletions test/commands/helper.test.ts
Expand Up @@ -8,10 +8,16 @@ describe('Helper: tests', function () {

context('ensures that', function () {

it('function \'isFolders\' returns proper state',
it('function \'isFoldersRelated\' returns proper state',
function () {
expect(helper.isFolders(PresetNames[PresetNames.hideFolders])).to.be.true;
expect(helper.isFolders(PresetNames[PresetNames.jsOfficial])).to.be.false;
expect(helper.isFoldersRelated(PresetNames.hideFolders)).to.be.true;
expect(helper.isFoldersRelated(PresetNames.jsOfficial)).to.be.false;
});

it('function \'isNonIconsRelatedPreset\' returns proper state',
function () {
expect(helper.isNonIconsRelatedPreset(PresetNames.hideExplorerArrows)).to.be.true;
expect(helper.isNonIconsRelatedPreset(PresetNames.jsOfficial)).to.be.false;
});

context('function \'getIconName\'', function () {
Expand Down
2 changes: 2 additions & 0 deletions test/init/applyCustomizationsManager.test.ts
Expand Up @@ -26,6 +26,7 @@ describe('AutoApplyCustomizations: tests', function () {
jsonOfficial: false,
hideFolders: false,
foldersAllDefaultIcon: false,
hideExplorerArrows: false,
},
associations: {
files: [],
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('ApplyCustomizations: tests', function () {
jsonOfficial: false,
hideFolders: false,
foldersAllDefaultIcon: false,
hideExplorerArrows: false,
},
associations: {
files: [],
Expand Down

0 comments on commit f1fd6e6

Please sign in to comment.