提交 edf44e41 编写于 作者: B Benjamin Pasero

some polish and bugfixing

上级 e346ba2b
......@@ -717,8 +717,12 @@ export class EditorPart extends Part implements IEditorPart {
// Side by Side Control
this.sideBySideControl = this.instantiationService.createInstance(SideBySideEditorControl, contentArea);
const unbind = this.sideBySideControl.onGroupFocusChanged(() => this.onGroupFocusChanged());
this.toUnbind.push(() => unbind.dispose());
const focusListener = this.sideBySideControl.onGroupFocusChanged(() => this.onGroupFocusChanged());
this.toUnbind.push(() => focusListener.dispose());
const titleClickListener = this.sideBySideControl.onEditorTitleDoubleclick((position) => this.onEditorTitleDoubleclick(position));
this.toUnbind.push(() => titleClickListener.dispose());
// get settings
this.memento = this.getMemento(this.storageService, MementoScope.WORKSPACE);
......@@ -726,6 +730,32 @@ export class EditorPart extends Part implements IEditorPart {
return contentArea;
}
private onGroupFocusChanged(): void {
// Update stacks model
let activePosition = this.sideBySideControl.getActivePosition();
if (typeof activePosition === 'number') {
this.stacksModel.setActive(this.groupAt(activePosition));
}
// Emit as editor input change event so that clients get aware of new active editor
let activeEditor = this.sideBySideControl.getActiveEditor();
if (activeEditor) {
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
}
// Update Title Area
this.doUpdateEditorTitleArea();
}
private onEditorTitleDoubleclick(position: Position): void {
const editor = this.visibleEditors[position];
if (editor) {
this.pinEditor(position, editor.input);
}
}
public openEditors(editors: { input: EditorInput, position: Position, options?: EditorOptions }[]): TPromise<BaseEditor[]> {
if (!editors.length) {
return TPromise.as<BaseEditor[]>([]);
......@@ -749,7 +779,7 @@ export class EditorPart extends Part implements IEditorPart {
let editorState: IEditorPartUIState = this.memento[EditorPart.EDITOR_PART_UI_STATE_STORAGE_KEY];
let widthRatios = editorState.widthRatio;
let activePosition:Position;
let activePosition: Position;
if (this.stacksModel.groups.length) {
activePosition = this.stacksModel.positionOfGroup(this.stacksModel.activeGroup);
}
......@@ -893,25 +923,6 @@ export class EditorPart extends Part implements IEditorPart {
}
}
private onGroupFocusChanged(): void {
// Update stacks model
let activePosition = this.sideBySideControl.getActivePosition();
if (typeof activePosition === 'number') {
this.stacksModel.setActive(this.groupAt(activePosition));
}
// Emit as editor input change event so that clients get aware of new active editor
let activeEditor = this.sideBySideControl.getActiveEditor();
if (activeEditor) {
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGING, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
this.emit(WorkbenchEventType.EDITOR_INPUT_CHANGED, new EditorEvent(activeEditor, activeEditor.getId(), activeEditor.input, null, activeEditor.position));
}
// Update Title Area
this.doUpdateEditorTitleArea();
}
private doUpdateEditorTitleArea(): void {
if (this.sideBySideControl) {
const titleAreaState: ITitleAreaState[] = this.getVisibleEditors().map((e, index) => {
......
......@@ -86,6 +86,10 @@
width: 12px; /* move the actions close to the label */
}
.monaco-workbench > .part.editor > .content .inactive .title .title-label-actions {
opacity: 0.5;
}
.monaco-workbench > .part.editor > .content > .one-editor-container > .title .title-label {
padding-left: 0; /* remove padding because we have the title label actions to the left */
}
......
......@@ -26,7 +26,6 @@ import DOM = require('vs/base/browser/dom');
import {IActionItem, ActionsOrientation} from 'vs/base/browser/ui/actionbar/actionbar';
import {ToolBar} from 'vs/base/browser/ui/toolbar/toolbar';
import {IWorkbenchEditorService, GroupArrangement} from 'vs/workbench/services/editor/common/editorService';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {Position, POSITIONS} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
......@@ -61,6 +60,7 @@ export interface ITitleAreaState {
export interface ISideBySideEditorControl {
onGroupFocusChanged: Event<void>;
onEditorTitleDoubleclick: Event<Position>;
show(editor: BaseEditor, container: Builder, position: Position, preserveActive: boolean, widthRatios?: number[]): void;
hide(editor: BaseEditor, container: Builder, position: Position, layoutAndRochade: boolean): Rochade;
......@@ -139,12 +139,12 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
private visibleEditorFocusTrackers: DOM.IFocusTracker[];
private _onGroupFocusChanged: Emitter<void>;
private _onEditorTitleDoubleclick: Emitter<Position>;
constructor(
parent: Builder,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IMessageService private messageService: IMessageService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@ITelemetryService private telemetryService: ITelemetryService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IEventService private eventService: IEventService,
......@@ -171,6 +171,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.mapActionsToEditors = arrays.fill(POSITIONS.length, () => Object.create(null));
this._onGroupFocusChanged = new Emitter<void>();
this._onEditorTitleDoubleclick = new Emitter<Position>();
this.closeEditorAction = POSITIONS.map((position) => this.instantiationService.createInstance(CloseEditorAction, CLOSE_EDITOR_ACTION_ID, CLOSE_EDITOR_ACTION_LABEL));
POSITIONS.map((position) => this.closeEditorAction[position].setPosition(position) || (this.closeEditorAction[position].class = 'close-editor-action'));
......@@ -205,6 +206,10 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
return this._onGroupFocusChanged.event;
}
public get onEditorTitleDoubleclick(): Event<Position> {
return this._onEditorTitleDoubleclick.event;
}
public show(editor: BaseEditor, container: Builder, position: Position, preserveActive: boolean, widthRatios?: number[]): void {
let visibleEditorCount = this.getVisibleEditorCount();
......@@ -770,14 +775,19 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
}
private fillTitleArea(parent: Builder, position: Position): void {
let ignoreClick = false;
let wasDragged = false;
// Detect double click and emit
parent.on(DOM.EventType.DBLCLICK, (e: MouseEvent) => {
DOM.EventHelper.stop(e);
this._onEditorTitleDoubleclick.fire(position);
});
// Allow to reorder positions by dragging the title
parent.on(DOM.EventType.MOUSE_DOWN, (e: MouseEvent) => {
// Reset flag
ignoreClick = false;
wasDragged = false;
// Return early if there is only one editor active or the user clicked into the toolbar
......@@ -952,13 +962,8 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.layoutContainers();
}
// Ignore next click if the user dragged the title some distance
if (wasDragged) {
ignoreClick = true;
}
// Otherwise if not dragging, make editor group active unless already active
else if (position !== this.getActivePosition()) {
// If not dragging, make editor group active unless already active
if (!wasDragged && position !== this.getActivePosition()) {
this.editorService.focusGroup(position);
}
......@@ -990,25 +995,16 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.editorTitleToolbar[position].setActions([this.closeEditorAction[position]])();
});
// Left Title Label (click opens quick open unless we are configured to ignore click or we are not the active title)
// Left Title Labe
parent.div({
'class': 'title-label'
}, (div) => {
let clickHandler = (e: MouseEvent) => {
if (ignoreClick) {
return;
}
DOM.EventHelper.stop(e, true);
this.quickOpenService.show();
};
// Clickable label (focus editor and bring up quick open)
this.titleLabel[position] = $(div).a().on(DOM.EventType.CLICK, clickHandler);
// Label
this.titleLabel[position] = $(div).a();
// Subtle Description
this.titleDescription[position] = $(div).span().on(DOM.EventType.CLICK, clickHandler);
this.titleDescription[position] = $(div).span();
});
// Right Actions Container
......@@ -1138,12 +1134,13 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
// Update all title areas that relate to given input if provided
if (arg1 instanceof EditorInput) {
const input:EditorInput = arg1;
const input: EditorInput = arg1;
// Update the input title actions in each position according to the new status
POSITIONS.forEach((position) => {
if (this.visibleEditors[position] && isInputRelated(this.visibleEditors[position].input, input)) {
this.closeEditorAction[position].class = !!input.getStatus().decoration ? 'close-editor-decorated-action' : 'close-editor-action';
const status = input.getStatus();
this.closeEditorAction[position].class = (status && status.decoration) ? 'close-editor-decorated-action' : 'close-editor-action';
}
});
}
......@@ -1269,6 +1266,10 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
// Set Primary/Secondary Actions
this.editorActionsToolbar[position].setActions(primaryActions, secondaryActions)();
// Update title actions accordingly
const status = input.getStatus();
this.closeEditorAction[position].class = (status && status.decoration) ? 'close-editor-decorated-action' : 'close-editor-action';
}
public setLoading(position: Position, input: EditorInput): void {
......@@ -1659,5 +1660,6 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
this.visibleEditorContainers = null;
this._onGroupFocusChanged.dispose();
this._onEditorTitleDoubleclick.dispose();
}
}
\ No newline at end of file
......@@ -1465,9 +1465,9 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting {
if (target.toString() !== source.toString() && positionsOfSource.length) {
let targetInput = this.instantiationService.createInstance(FileEditorInput, target, mimeOfSource, encodingOfSource);
let options: TextEditorOptions;
let options = new TextEditorOptions();
options.pinned = true;
if (selectionOfSource) {
options = new TextEditorOptions();
options.selection(selectionOfSource.startLineNumber, selectionOfSource.startColumn, selectionOfSource.endLineNumber, selectionOfSource.endColumn);
}
......@@ -1592,9 +1592,7 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting {
let encodingOfSource: string = mapUntitledToProperties[res.source.toString()] && mapUntitledToProperties[res.source.toString()].encoding;
let targetInput = this.instantiationService.createInstance(FileEditorInput, res.target, mimeOfSource, encodingOfSource);
let options = new EditorOptions();
options.preserveFocus = true;
let options = EditorOptions.create({ preserveFocus: true, pinned: true });
positions.forEach((position) => {
reopenPromises.push(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册