mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 09:35:37 -05:00
Save query result selection/scroll when switching tabs (#2052)
This commit is contained in:
@@ -32,6 +32,7 @@ import { CodeEditor } from 'vs/editor/browser/codeEditor';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { IEditorViewState } from 'vs/editor/common/editorCommon';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
||||
import { QueryResultsInput } from 'sql/parts/query/common/queryResultsInput';
|
||||
import { QueryInput } from 'sql/parts/query/common/queryInput';
|
||||
@@ -90,6 +91,7 @@ export class QueryEditor extends BaseEditor {
|
||||
private _parseSyntaxAction: ParseSyntaxAction;
|
||||
|
||||
private _savedViewStates = new Map<IEditorInput, IEditorViewState>();
|
||||
private _resultViewStateChangeEmitters = new Map<QueryResultsInput, { onSaveViewState: Emitter<void>; onRestoreViewState: Emitter<void> }>();
|
||||
|
||||
constructor(
|
||||
@ITelemetryService _telemetryService: ITelemetryService,
|
||||
@@ -509,6 +511,11 @@ export class QueryEditor extends BaseEditor {
|
||||
}
|
||||
|
||||
if (oldInput) {
|
||||
let resultViewStateChangeEmitters = this._resultViewStateChangeEmitters.get(oldInput.results);
|
||||
if (resultViewStateChangeEmitters) {
|
||||
resultViewStateChangeEmitters.onSaveViewState.fire();
|
||||
}
|
||||
|
||||
this._disposeEditors();
|
||||
}
|
||||
|
||||
@@ -583,6 +590,9 @@ export class QueryEditor extends BaseEditor {
|
||||
.then(onEditorsCreated)
|
||||
.then(doLayout)
|
||||
.then(() => {
|
||||
if (this._resultViewStateChangeEmitters.has(newInput.results)) {
|
||||
this._resultViewStateChangeEmitters.get(newInput.results).onRestoreViewState.fire();
|
||||
}
|
||||
if (this._savedViewStates.has(newInput.sql)) {
|
||||
this._sqlEditor.getControl().restoreViewState(this._savedViewStates.get(newInput.sql));
|
||||
}
|
||||
@@ -617,6 +627,14 @@ export class QueryEditor extends BaseEditor {
|
||||
*/
|
||||
private _onResultsEditorCreated(resultsEditor: QueryResultsEditor, resultsInput: QueryResultsInput, options: EditorOptions): TPromise<void> {
|
||||
this._resultsEditor = resultsEditor;
|
||||
if (!this._resultViewStateChangeEmitters.has(resultsInput)) {
|
||||
this._resultViewStateChangeEmitters.set(resultsInput, {
|
||||
onRestoreViewState: new Emitter<void>(),
|
||||
onSaveViewState: new Emitter<void>()
|
||||
});
|
||||
}
|
||||
let emitters = this._resultViewStateChangeEmitters.get(resultsInput);
|
||||
this._resultsEditor.setViewStateChangeEvents(emitters.onRestoreViewState.event, emitters.onSaveViewState.event);
|
||||
return this._resultsEditor.setInput(resultsInput, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import { IQueryComponentParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { QueryOutputModule } from 'sql/parts/query/views/queryOutput.module';
|
||||
import { QUERY_OUTPUT_SELECTOR } from 'sql/parts/query/views/queryOutput.component';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
|
||||
export const RESULTS_GRID_DEFAULTS = {
|
||||
cellPadding: [6, 10, 5],
|
||||
@@ -95,6 +96,8 @@ export class QueryResultsEditor extends BaseEditor {
|
||||
public static AngularSelectorString: string = 'slickgrid-container.slickgridContainer';
|
||||
protected _rawOptions: BareResultsGridInfo;
|
||||
protected _input: QueryResultsInput;
|
||||
private _restoreViewStateEvent: Event<void>;
|
||||
private _saveViewStateEvent: Event<void>;
|
||||
|
||||
constructor(
|
||||
@ITelemetryService telemetryService: ITelemetryService,
|
||||
@@ -149,6 +152,11 @@ export class QueryResultsEditor extends BaseEditor {
|
||||
return TPromise.wrap<void>(null);
|
||||
}
|
||||
|
||||
public setViewStateChangeEvents(onRestoreViewStateEvent: Event<void>, onSaveViewStateEvent: Event<void>) {
|
||||
this._restoreViewStateEvent = onRestoreViewStateEvent;
|
||||
this._saveViewStateEvent = onSaveViewStateEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the angular components and record for this input that we have done so
|
||||
*/
|
||||
@@ -169,7 +177,11 @@ export class QueryResultsEditor extends BaseEditor {
|
||||
// Note: pass in input so on disposal this is cleaned up.
|
||||
// Otherwise many components will be left around and be subscribed
|
||||
// to events from the backing data service
|
||||
let params: IQueryComponentParams = { dataService: dataService };
|
||||
let params: IQueryComponentParams = {
|
||||
dataService: dataService,
|
||||
onSaveViewState: this._saveViewStateEvent,
|
||||
onRestoreViewState: this._restoreViewStateEvent
|
||||
};
|
||||
bootstrapAngular(this._instantiationService,
|
||||
QueryOutputModule,
|
||||
this.getContainer(),
|
||||
|
||||
Reference in New Issue
Block a user