Skip to content

Commit

Permalink
Get rid of glob buttons for #27226
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jul 15, 2017
1 parent d3fb3fc commit 4db0d8a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 178 deletions.
18 changes: 12 additions & 6 deletions src/vs/platform/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ export interface IFolderQueryOptions {
fileEncoding?: string;
}

export interface IQueryOptions {
export interface ICommonQueryOptions {
extraFileResources?: uri[];
filePattern?: string;
excludePattern?: IExpression;
includePattern?: IExpression;
filePattern?: string; // file search only
fileEncoding?: string;
maxResults?: number;
sortByScore?: boolean;
cacheKey?: string;
useRipgrep?: boolean;
disregardIgnoreFiles?: boolean;
disregardExcludeSettings?: boolean;
searchPaths?: string[];
}

export interface ISearchQuery extends IQueryOptions {
export interface IQueryOptions extends ICommonQueryOptions {
excludePattern?: string;
includePattern?: string;
}

export interface ISearchQuery extends ICommonQueryOptions {
type: QueryType;

excludePattern?: IExpression;
includePattern?: IExpression;
searchPaths?: string[];
contentPattern?: IPatternInfo;
folderQueries?: IFolderQueryOptions[];
}
Expand Down
114 changes: 3 additions & 111 deletions src/vs/workbench/parts/search/browser/patternInputWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

import nls = require('vs/nls');
import * as dom from 'vs/base/browser/dom';
import strings = require('vs/base/common/strings');
import paths = require('vs/base/common/paths');
import collections = require('vs/base/common/collections');
import { $ } from 'vs/base/browser/builder';
import { Widget } from 'vs/base/browser/ui/widget';
import { IExpression, splitGlobAware } from 'vs/base/common/glob';
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { MessageType, InputBox, IInputValidator } from 'vs/base/browser/ui/inputbox/inputBox';
import { InputBox, IInputValidator } from 'vs/base/browser/ui/inputbox/inputBox';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
import CommonEvent, { Emitter } from 'vs/base/common/event';
Expand All @@ -39,8 +35,6 @@ export class PatternInputWidget extends Widget {
private placeholder: string;
private ariaLabel: string;

private pattern: Checkbox;

private domNode: HTMLElement;
private inputNode: HTMLInputElement;
protected inputBox: InputBox;
Expand All @@ -55,7 +49,6 @@ export class PatternInputWidget extends Widget {
this.placeholder = options.placeholder || '';
this.ariaLabel = options.ariaLabel || nls.localize('defaultLabel', "input");

this.pattern = null;
this.domNode = null;
this.inputNode = null;
this.inputBox = null;
Expand All @@ -67,7 +60,6 @@ export class PatternInputWidget extends Widget {

public dispose(): void {
super.dispose();
this.pattern.dispose();
if (this.inputFocusTracker) {
this.inputFocusTracker.dispose();
}
Expand Down Expand Up @@ -103,58 +95,6 @@ export class PatternInputWidget extends Widget {
}
}

public getGlob(): { expression?: IExpression, searchPaths?: string[] } {
const pattern = this.getValue();
const isGlobPattern = this.isGlobPattern();

if (!pattern) {
return {};
}

let exprSegments: string[];
let searchPaths: string[];
if (isGlobPattern) {
const segments = splitGlobAware(pattern, ',')
.map(s => s.trim())
.filter(s => !!s.length);

const groups = this.groupByPathsAndExprSegments(segments);
searchPaths = groups.searchPaths;
exprSegments = groups.exprSegments;
} else {
const segments = pattern.split(',')
.map(s => s.trim())
.filter(s => !!s.length);

const groups = this.groupByPathsAndExprSegments(segments);
searchPaths = groups.searchPaths;
exprSegments = groups.exprSegments
.map(p => {
if (p[0] === '.') {
p = '*' + p; // convert ".js" to "*.js"
}

return strings.format('{{0}/**,**/{1}}', p, p); // convert foo to {foo/**,**/foo} to cover files and folders
});
}

const expression = exprSegments.reduce((glob, cur) => { glob[cur] = true; return glob; }, Object.create(null));
return { expression, searchPaths };
}

private groupByPathsAndExprSegments(segments: string[]) {
const isSearchPath = (segment: string) => {
// A segment is a search path if it is an absolute path or starts with ./
return paths.isAbsolute(segment) || strings.startsWith(segment, './');
};

const groups = collections.groupBy(segments,
segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments');
groups.searchPaths = groups.searchPaths || [];
groups.exprSegments = groups.exprSegments || [];

return groups;
}

public select(): void {
this.inputBox.select();
Expand All @@ -168,20 +108,12 @@ export class PatternInputWidget extends Widget {
return this.inputBox.hasFocus();
}

public isGlobPattern(): boolean {
return this.pattern.checked;
}

public setIsGlobPattern(value: boolean): void {
this.pattern.checked = value;
}

private setInputWidth(): void {
this.inputBox.width = this.width - this.getSubcontrolsWidth();
this.inputBox.width = this.width;
}

protected getSubcontrolsWidth(): number {
return this.pattern.width();
return 0;
}

private render(): void {
Expand All @@ -201,35 +133,6 @@ export class PatternInputWidget extends Widget {
this.inputFocusTracker = dom.trackFocus(this.inputBox.inputElement);
this.onkeyup(this.inputBox.inputElement, (keyboardEvent) => this.onInputKeyUp(keyboardEvent));

this.pattern = new Checkbox({
actionClassName: 'pattern',
title: nls.localize('patternDescription', "Use Glob Patterns"),
isChecked: false,
onChange: (viaKeyboard) => {
this.onOptionChange(null);
if (!viaKeyboard) {
this.inputBox.focus();
}

if (this.isGlobPattern()) {
this.showGlobHelp();
} else {
this.inputBox.hideMessage();
}
}
});
this._register(attachCheckboxStyler(this.pattern, this.themeService));

$(this.pattern.domNode).on('mouseover', () => {
if (this.isGlobPattern()) {
this.showGlobHelp();
}
});

$(this.pattern.domNode).on(['mouseleave', 'mouseout'], () => {
this.inputBox.hideMessage();
});

let controls = document.createElement('div');
controls.className = 'controls';
this.renderSubcontrols(controls);
Expand All @@ -239,17 +142,6 @@ export class PatternInputWidget extends Widget {
}

protected renderSubcontrols(controlsDiv: HTMLDivElement): void {
controlsDiv.appendChild(this.pattern.domNode);
}

private showGlobHelp(): void {
this.inputBox.showMessage({
type: MessageType.INFO,
formatContent: true,
content: nls.localize('patternHelpInclude',
"The pattern to match. e.g. **\\*\\*/*.js** to match all JavaScript files or **myFolder/\\*\\*** to match that folder with all children.\n\n**Reference**:\n**\\*** matches 0 or more characters\n**?** matches 1 character\n**\\*\\*** matches zero or more directories\n**[a-z]** matches a range of characters\n**{a,b}** matches any of the patterns)"
)
}, true);
}

private onInputKeyUp(keyboardEvent: IKeyboardEvent) {
Expand Down
Loading

0 comments on commit 4db0d8a

Please sign in to comment.