Skip to content

Commit

Permalink
Small tweaks to PR #8155
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Jun 27, 2016
1 parent 382ebf6 commit 767009f
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/parts/emmet/node/actions/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import nls = require('vs/nls');

import * as Paths from 'vs/base/common/paths';
import {fileExists} from 'vs/base/node/pfs';
import {createPath} from '../fileAccessor';
import {EmmetEditorAction} from '../emmetActions';
import {createPath} from 'vs/workbench/parts/emmet/node/fileAccessor';
import {EmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';
import {Action} from 'vs/base/common/actions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
Expand All @@ -31,10 +31,10 @@ class EncodeDecodeDataUrlAction extends EmmetEditorAction {
super(descriptor, editor, configurationService);
}

public runEmmetAction(_module) {
public runEmmetAction(_emmet) {
const currentLine = this.editorAccessor.getCurrentLine();
if (!this.isDataURI(currentLine)) {
this.encodeDecode(_module);
this.encodeDecode(_emmet);
return;
}

Expand All @@ -56,28 +56,28 @@ class EncodeDecodeDataUrlAction extends EmmetEditorAction {
})
.then(status => {
if (!status) {
this.encodeDecode(_module, this.imageFilePath);
this.encodeDecode(_emmet, this.imageFilePath);
return;
}

const message = nls.localize('warnEscalation', "File **{0}** already exists. Do you want to overwrite the existing file?", this.imageFilePath);
const actions = [
new Action('cancel', nls.localize('cancel', "Cancel"), '', true),
new Action('ok', nls.localize('ok', "OK"), '', true, () => {
this.encodeDecode(_module, this.imageFilePath);
this.encodeDecode(_emmet, this.imageFilePath);
return null;
})
];
this.messageService.show(Severity.Warning, { message, actions });
});
}

public encodeDecode(_module: any, filepath?: string) {
public encodeDecode(_emmet: any, filepath?: string) {
this.editorAccessor.prompt = (): string => {
return filepath;
};

if (!_module.run('encode_decode_data_url', this.editorAccessor)) {
if (!_emmet.run('encode_decode_data_url', this.editorAccessor)) {
this.editorAccessor.noExpansionOccurred();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/editPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/evaluateMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/matchingPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/mergeLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/removeTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/selectItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/emmet/node/actions/splitJoinTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {BasicEmmetEditorAction} from '../emmetEditorAction';
import {BasicEmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/parts/emmet/node/actions/updateTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {EmmetEditorAction} from '../emmetActions';
import {EmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand All @@ -23,18 +23,18 @@ class UpdateTagAction extends EmmetEditorAction {
super(descriptor, editor, configurationService);
}

public runEmmetAction(_module) {
public runEmmetAction(_emmet) {
let options: IInputOptions = {
prompt: nls.localize('enterTag', 'Enter Tag'),
placeHolder: nls.localize('tag', 'Tag')
};
this.quickOpenService.input(options).then(tag => {
this.wrapAbbreviation(_module, tag);
this.wrapAbbreviation(_emmet, tag);
});
}

private wrapAbbreviation(_module: any, tag) {
if (!_module.run('update_tag', this.editorAccessor, tag)) {
private wrapAbbreviation(_emmet: any, tag) {
if (!_emmet.run('update_tag', this.editorAccessor, tag)) {
this.editorAccessor.noExpansionOccurred();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import nls = require('vs/nls');
import {EmmetEditorAction} from '../emmetActions';
import {EmmetEditorAction} from 'vs/workbench/parts/emmet/node/emmetActions';

import {CommonEditorRegistry, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
Expand All @@ -23,18 +23,18 @@ class WrapWithAbbreviationAction extends EmmetEditorAction {
super(descriptor, editor, configurationService);
}

public runEmmetAction(_module) {
public runEmmetAction(_emmet) {
let options: IInputOptions = {
prompt: nls.localize('enterAbbreviation', "Enter Abbreviation"),
placeHolder: nls.localize('abbreviation', "Abbreviation")
};
this.quickOpenService.input(options).then(abbreviation => {
this.wrapAbbreviation(_module, abbreviation);
this.wrapAbbreviation(_emmet, abbreviation);
});
}

private wrapAbbreviation(_module: any, abbreviation) {
if (!_module.run('wrap_with_abbreviation', this.editorAccessor, abbreviation)) {
private wrapAbbreviation(_emmet: any, abbreviation) {
if (!_emmet.run('wrap_with_abbreviation', this.editorAccessor, abbreviation)) {
this.editorAccessor.noExpansionOccurred();
}
}
Expand Down
48 changes: 33 additions & 15 deletions src/vs/workbench/parts/emmet/node/emmetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {IEditorActionDescriptorData, ICommonCodeEditor} from 'vs/editor/common/editorCommon';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import {EditorAccessor} from './editorAccessor';
import * as fileAccessor from './fileAccessor';

import {EditorAccessor} from 'vs/workbench/parts/emmet/node/editorAccessor';
import * as fileAccessor from 'vs/workbench/parts/emmet/node/fileAccessor';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';

interface IEmmetConfiguration {
Expand All @@ -32,52 +33,69 @@ export abstract class EmmetEditorAction extends EditorAction {
this.configurationService = configurationService;
}

private updateEmmetPreferences(_module: any) {
private updateEmmetPreferences(_emmet: any) {
let preferences = this.configurationService.getConfiguration<IEmmetConfiguration>().emmet.preferences;
for (let key in preferences) {
try {
_module.preferences.set(key, preferences[key]);
_emmet.preferences.set(key, preferences[key]);
} catch (err) {
_module.preferences.define(key, preferences[key]);
_emmet.preferences.define(key, preferences[key]);
}
}
let syntaxProfile = this.configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles;
if (Object.keys(syntaxProfile).length !== 0) {
_module.profile.reset();
_module.loadProfiles(syntaxProfile);
_emmet.profile.reset();
_emmet.loadProfiles(syntaxProfile);
}
}

private resetEmmetPreferences(_module: any) {
private resetEmmetPreferences(_emmet: any) {
let preferences = this.configurationService.getConfiguration<IEmmetConfiguration>().emmet.preferences;
for (let key in preferences) {
try {
_module.preferences.remove(key);
_emmet.preferences.remove(key);
} catch (err) {
}
}
}

abstract runEmmetAction(_module: any);
abstract runEmmetAction(_emmet: any);

public run(): TPromise<boolean> {
return new TPromise((c, e) => {
require(['emmet'], (_module) => {
_module.file(fileAccessor);
require(['emmet'], (_emmet) => {
_emmet.file(fileAccessor);

try {
if (!this.editorAccessor.isEmmetEnabledMode()) {
this.editorAccessor.noExpansionOccurred();
return;
}
this.updateEmmetPreferences(_module);
this.runEmmetAction(_module);
this.updateEmmetPreferences(_emmet);
this.runEmmetAction(_emmet);
} catch (err) {
//
} finally {
this.resetEmmetPreferences(_module);
this.resetEmmetPreferences(_emmet);
}
}, e);
});
}
}

export class BasicEmmetEditorAction extends EmmetEditorAction {

private emmetActionName: string;

constructor(descriptor: IEditorActionDescriptorData, editor: ICommonCodeEditor, @IConfigurationService configurationService: IConfigurationService, actionName: string) {
super(descriptor, editor, configurationService);
this.editorAccessor = new EditorAccessor(editor);
this.emmetActionName = actionName;
}

public runEmmetAction(_emmet) {
if (!_emmet.run(this.emmetActionName, this.editorAccessor)) {
this.editorAccessor.noExpansionOccurred();
}
}
}
29 changes: 0 additions & 29 deletions src/vs/workbench/parts/emmet/node/emmetEditorAction.ts

This file was deleted.

0 comments on commit 767009f

Please sign in to comment.