Skip to content

Commit

Permalink
Allow the user to control display order of convenience options. (#49)
Browse files Browse the repository at this point in the history
* Allow the user to control display order of convenience options. Closes #45

* Update README and CHANGELOG
  • Loading branch information
Nick Giancola authored Dec 17, 2017
1 parent 064f9a7 commit 1046fa6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# HEAD

## What's New
* Control the order of top convenient options ("last selection", "current file",
etc) via config setting `advancedNewFile.convenienceOptions`

# 1.0.0

## What's New
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ files anywhere in your workspace.

* Fuzzy-matching autocomplete to create new file relative to existing path
* Create new directories while creating a new file
* Create a directory instead of a file by suffixing the file path with `/` as in `somedirectory/` to create the directory (thanks to [maximilianschmitt](https://github.com/maximilianschmitt))
* Create a directory instead of a file by suffixing the file path with `/` as
in `somedirectory/` to create the directory (thanks to
[maximilianschmitt](https://github.com/maximilianschmitt))
* Ignores gitignored and workspace `files.exclude` settings.
* Additional option of adding `advancedNewFile.exclude` settings to workspace settings just like native `files.exlude` except it explicitly effects AdvancedNewFile plugin only. (thanks to [Kaffiend](https://github.com/Kaffiend))
* Additional option of adding `advancedNewFile.exclude` settings to workspace
settings just like native `files.exlude` except it explicitly effects
AdvancedNewFile plugin only. (thanks to [Kaffiend](https://github.com/Kaffiend))
* Control the order of top convenient options ("last selection", "current file",
etc) via config setting `advancedNewFile.convenienceOptions`

## Configuration Example

```
"advancedNewFile.exclude": {
"node_modules": true,
"node_modules_electron": true,
"dev": true,
"dist": true
"node_modules": true,
"node_modules_electron": true,
"dev": true,
"dist": true
},
"advancedNewFile.showInformationMessages": true
"advancedNewFile.showInformationMessages": true,
"advancedNewFile.convenienceOptions": ["last", "current", "root"]
```

## Usage
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
"type": "boolean",
"default": true,
"description": "Control whether top-bar notifications display"
},
"advancedNewFile.convenienceOptions": {
"type": "array",
"default": ["last", "current", "root"],
"description": "Convenience options display at the top of the list. Control which ones you see and in what order."
}
}
}
Expand Down
29 changes: 22 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ export function currentEditorPathOption(
};
}

function convenienceOptions(
roots: WorkspaceRoot[],
cache: Cache): vscode.QuickPickItem[] {

const config: string[] = vscode.workspace
.getConfiguration('advancedNewFile').get('convenienceOptions');

const optionsByName = {
last: [buildQuickPickItem(lastSelection(cache), '- last selection')],
current: [
buildQuickPickItem(currentEditorPathOption(roots), '- current file')
],
root: rootOptions(roots).map(o => buildQuickPickItem(o, '- workspace root'))
};

const options = config
.map<vscode.QuickPickItem[]>(c => optionsByName[c]).reduce(flatten);

return compact<vscode.QuickPickItem>(options);
}

export async function dirQuickPickItems(
roots: WorkspaceRoot[],
cache: Cache): Promise<vscode.QuickPickItem[]> {
Expand All @@ -281,13 +302,7 @@ export async function dirQuickPickItems(
let quickPickItems =
dirOptions.reduce(flatten).map(o => buildQuickPickItem(o));

const convenienceOptions: vscode.QuickPickItem[] = [
buildQuickPickItem(lastSelection(cache), '- last selection'),
buildQuickPickItem(currentEditorPathOption(roots), '- current file'),
...rootOptions(roots).map(o => buildQuickPickItem(o, '- workspace root'))
];

quickPickItems.unshift(...compact(convenienceOptions));
quickPickItems.unshift(...convenienceOptions(roots, cache));

return quickPickItems;
}
Expand Down

0 comments on commit 1046fa6

Please sign in to comment.