Add tab coloring by server group (#383)

This commit is contained in:
Matt Irvine
2017-12-20 18:21:48 -08:00
committed by GitHub
parent 3ffafbe5bc
commit b1b3a92717
14 changed files with 152 additions and 8 deletions

View File

@@ -220,6 +220,8 @@ export interface IConnectionManagementService {
canChangeConnectionConfig(profile: ConnectionProfile, newGroupID: string): boolean;
getTabColorForUri(uri: string): string;
/**
* Sends a notification that the language flavor for a given URI has changed.
* For SQL, this would be the specific SQL implementation being used.

View File

@@ -148,6 +148,11 @@ export class ConnectionManagementService implements IConnectionManagementService
this.disposables.push(this._onAddConnectionProfile);
this.disposables.push(this._onDeleteConnectionProfile);
// Refresh editor titles when connections start/end/change to ensure tabs are colored correctly
this.onConnectionChanged(() => this.refreshEditorTitles());
this.onConnect(() => this.refreshEditorTitles());
this.onDisconnect(() => this.refreshEditorTitles());
}
// Event Emitters
@@ -1219,6 +1224,7 @@ export class ConnectionManagementService implements IConnectionManagementService
public editGroup(group: ConnectionProfileGroup): Promise<any> {
return new Promise<string>((resolve, reject) => {
this._connectionStore.editGroup(group).then(groupId => {
this.refreshEditorTitles();
this._onAddConnectionProfile.fire();
resolve(null);
}).catch(err => {
@@ -1323,4 +1329,25 @@ export class ConnectionManagementService implements IConnectionManagementService
}
return Promise.reject('The given URI is not currently connected');
}
public getTabColorForUri(uri: string): string {
if (!WorkbenchUtils.getSqlConfigValue<string>(this._workspaceConfigurationService, 'enableTabColors')) {
return undefined;
}
let connectionProfile = this.getConnectionProfile(uri);
if (!connectionProfile) {
return undefined;
}
let matchingGroup = this._connectionStore.getGroupFromId(connectionProfile.groupId);
if (!matchingGroup) {
return undefined;
}
return matchingGroup.color;
}
private refreshEditorTitles(): void {
if (this._editorGroupService instanceof EditorPart) {
this._editorGroupService.refreshEditorTitles();
}
}
}

View File

@@ -19,7 +19,6 @@ import { ConfigurationEditingService } from 'vs/workbench/services/configuration
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import * as data from 'data';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
const MAX_CONNECTIONS_DEFAULT = 25;
@@ -490,6 +489,11 @@ export class ConnectionStore {
return result;
}
public getGroupFromId(groupId: string): IConnectionProfileGroup {
let groups = this._connectionConfig.getAllGroups();
return groups.find(group => group.id === groupId);
}
private getMaxRecentConnectionsCount(): number {
let config = this._workspaceConfigurationService.getConfiguration(Constants.sqlConfigSectionName);