Skip to content

Commit

Permalink
## 1.1.0
Browse files Browse the repository at this point in the history
- Added option to show Favorite folder content (top level files). It is the response to the feature request #1.
  • Loading branch information
oleg-shilo committed Feb 11, 2018
1 parent 65a3288 commit df0a46f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 29 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Change Log

## 1.0.0
- Initial release
## 1.1.0
- Added option to show Favorite folder content (top level files). It is the response to the feature request #1.
This feature is not a substitution of the Workspace explorer view, which does by far superior job. It's just a convenience measure for a quick access of the top level folder files. The feature can be enabled/disabled with `favorites.showFolderFiles` setting.

## 1.0.1
- Updated images
Note, the feature overall experience is subject to the limitations/defects of the VSCode tree view. These defects are officially reported and being dealt with by the VSCode team:
https://github.com/Microsoft/vscode/issues/34130
https://github.com/patrys/vscode-code-outline/issues/24

## 1.0.2
- Added support for folders
- Items icons reflect if file/folder exist or not
- Added context menu for moving items up/down in the list

## 1.0.1
- Updated images

## 1.0.0
- Initial release
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Favorites - VSCode Extension

Manage and quickly access frequently used files.
<hr/>
<hr/>>

This simple extension allows in adding, removing and managing documents in the globally maintained "Favorites" list.

Expand All @@ -19,7 +19,15 @@ The functionality is self explanatory and includes following features:

![image](https://raw.githubusercontent.com/oleg-shilo/Favorites.vscode/master/resources/images/favorites_vscode.gif)

Note: by default VSCode opens any file clicked from the _Favorites_ list in the so called "preview mode". Thus the document tabs are reused and every new file is opened in the same tab. If you prefer to open a clicked _Favorites_ document in ane tab then you need to disable document the previewMode is the settings:
1. Use _Command Palette_ to open your settings file ("Preferences: Open User Settings")
2. Add the "workbench.editor.enablePreview" property, and set it's value to _false_.
The extension also allow showing Favorite folder item content (top level files).
This feature is not a substitution of the Workspace explorer view, which does by far superior job. It's just a convenience measure for a quick access of the top level folder files. The feature can be enabled/disabled with `favorites.showFolderFiles` setting.

## Limitations
* _ShowFolderFiles_ feature overall experience is subject to the limitations/defects of the VSCode tree view. These defects are officially reported and being dealt with by the VSCode team:<br/>
https://github.com/Microsoft/vscode/issues/34130<br/>
https://github.com/patrys/vscode-code-outline/issues/24<br/>

* By default VSCode opens any file clicked from the _Favorites_ list in the so called "preview mode". Thus the document tabs are reused and every new file is opened in the same tab. If you prefer to open a clicked _Favorites_ document in a new tab then you need to disable document the previewMode is the settings:
1. Use _Command Palette_ to open your settings file ("Preferences: Open User Settings")
2. Add the "workbench.editor.enablePreview" property, and set it's value to _false_.

13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "favorites",
"displayName": "Favorites",
"description": "Manage and quickly access frequently used documents",
"version": "1.0.2",
"version": "1.1.0",
"publisher": "oleg-shilo",
"engines": {
"vscode": "^1.13.0"
Expand Down Expand Up @@ -121,6 +121,17 @@
]
}
},
"configuration": {
"type": "object",
"title": "Favorites configuration",
"properties": {
"favorites.showFolderFiles": {
"type": "boolean",
"default": true,
"description": "Show folder children. The children are the top-level files present in the folder."
}
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
Expand Down
14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import { FavoritesTreeProvider, Dependency } from './tree_view';
import { FavoritesTreeProvider, FavoriteItem } from './tree_view';
import { Uri, commands } from 'vscode';

function get_favorites_items() {
return Utils.read_all_lines(Utils.fav_file).filter(x => x != '');
}

function add_workspace(element: Dependency) {
function add_workspace(element: FavoriteItem) {
if (vscode.workspace.rootPath)
_add(vscode.workspace.rootPath);
}

function add(element: Dependency) {
function add(element: FavoriteItem) {
let document = vscode.window.activeTextEditor.document.fileName;
_add(document);
}
Expand All @@ -37,7 +37,7 @@ function _add(document: string) {
}
}

function up(element: Dependency) {
function up(element: FavoriteItem) {

let lines = Utils.read_all_lines(Utils.fav_file).filter(x => x != '');

Expand All @@ -52,7 +52,7 @@ function up(element: Dependency) {
commands.executeCommand('favorites.refresh');
}

function down(element: Dependency) {
function down(element: FavoriteItem) {

let lines = Utils.read_all_lines(Utils.fav_file).filter(x => x != '');

Expand All @@ -67,7 +67,7 @@ function down(element: Dependency) {
commands.executeCommand('favorites.refresh');
}

function remove(element: Dependency) {
function remove(element: FavoriteItem) {
let lines: string[] = [];

Utils.read_all_lines(Utils.fav_file)
Expand Down Expand Up @@ -111,7 +111,7 @@ class Utils {
Utils._fav_file = Utils.ensure_fav_file();
return Utils._fav_file;
}

public static read_all_lines(file: string): string[] {
let text = fs.readFileSync(file, 'utf8');
return text.split(/\r?\n/g);
Expand Down
50 changes: 37 additions & 13 deletions src/tree_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as fs from 'fs';
import * as path from 'path';
import { Uri, commands } from "vscode";

export class FavoritesTreeProvider implements vscode.TreeDataProvider<Dependency> {
export class FavoritesTreeProvider implements vscode.TreeDataProvider<FavoriteItem> {

private _onDidChangeTreeData: vscode.EventEmitter<Dependency | undefined> = new vscode.EventEmitter<Dependency | undefined>();
readonly onDidChangeTreeData: vscode.Event<Dependency | undefined> = this._onDidChangeTreeData.event;
private _onDidChangeTreeData: vscode.EventEmitter<FavoriteItem | undefined> = new vscode.EventEmitter<FavoriteItem | undefined>();
readonly onDidChangeTreeData: vscode.Event<FavoriteItem | undefined> = this._onDidChangeTreeData.event;

constructor(private aggregateItems: () => string[]) {
vscode.window.onDidChangeActiveTextEditor(editor => {
Expand All @@ -21,21 +21,41 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<Dependency
this._onDidChangeTreeData.fire();
}

getTreeItem(element: Dependency): vscode.TreeItem {
getTreeItem(element: FavoriteItem): vscode.TreeItem {
return element;
}

getChildren(element?: Dependency): Thenable<Dependency[]> {
getChildren(element?: FavoriteItem): Thenable<FavoriteItem[]> {
return new Promise(resolve => {
if (element) {
resolve([]);
let nodes = [];
let dir = element.context;
fs.readdirSync(dir).forEach(fileName => {
var file = path.join(dir, fileName);
if (fs.lstatSync(file).isFile()) {
let node = new FavoriteItem(
fileName,
vscode.TreeItemCollapsibleState.None,
{
command: 'vscode.open',
title: '',
tooltip: file,
arguments: [Uri.file(file)],
},
null,
file
);
nodes.push(node);
}
})
resolve(nodes);
} else {
resolve(this.getScriptItems());
}
});
}

private getScriptItems(): Dependency[] {
private getScriptItems(): FavoriteItem[] {

let nodes = [];

Expand All @@ -44,19 +64,23 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<Dependency
if (file != '') {

let commandValue = 'vscode.open';
let iconName = 'document.svg'
let iconName = 'document.svg';
let collapsableState = vscode.TreeItemCollapsibleState.None;
let showFolderFiles = vscode.workspace.getConfiguration("favorites").get('showFolderFiles', true);

try {
if (fs.lstatSync(file).isDirectory()) {
if (path.isAbsolute(file) && fs.lstatSync(file).isDirectory()) {
commandValue = 'vscode.openFolder';
iconName='folder.svg'
iconName = 'folder.svg';
if (showFolderFiles)
collapsableState = vscode.TreeItemCollapsibleState.Collapsed;
}
} catch (error) {
}

let node = new Dependency(
let node = new FavoriteItem(
path.basename(file),
vscode.TreeItemCollapsibleState.None,
collapsableState,
{
command: commandValue,
title: '',
Expand Down Expand Up @@ -87,7 +111,7 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<Dependency
}
}

export class Dependency extends vscode.TreeItem {
export class FavoriteItem extends vscode.TreeItem {

constructor(
public readonly label: string,
Expand Down

0 comments on commit df0a46f

Please sign in to comment.