Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Update Plant UML theme choices and options (#45)
Browse files Browse the repository at this point in the history
* Update to 0.13.1 to support decorators

* update engine version to prevent packaging failure

* Update Plant UML theme choices and options
  • Loading branch information
m-g-k authored and Simon Stone committed Oct 1, 2017
1 parent 399dd00 commit bc7cfe4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
21 changes: 15 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,27 @@
"type": "object",
"title": "Composer configuration",
"properties": {
"composer.pUML.keepSourceFileOpen": {
"composer.UML.keepSourceFileOpen": {
"type": "boolean",
"default": true,
"description": "Keeps open the 'composer.puml' source file after generating the diagram."
},
"composer.pUML.autoShowDiagam": {
"composer.UML.autoShowDiagam": {
"type": "boolean",
"default": true,
"description": "If true, the pUML diagram will automatically be shown. If false, a 'composer.puml' files will be created without showing the diagram."
"description": "If true, the PlantUML diagram will automatically be shown. If false, a 'composer.puml' files will be created without showing the diagram."
},
"composer.pUML.includeSystemNamespace": {
"composer.UML.includeSystemNamespace": {
"type": "string",
"enum": [
"none",
"all",
"simple"
],
"default": "simple",
"description": "Options to control System Namespace inlusion in pUML diagrams. 'all' will include all System Namespace artifacts. 'none' will remove all System Namespace artifacts. 'simple' keeps the bare minimum of System Namesapce artifacts. The more artifacts kept, the more cluttered the diagram will be."
"description": "Options to control System Namespace inlusion in PlantUML diagrams. 'all' will include all System Namespace artifacts. 'none' will remove all System Namespace artifacts. 'simple' keeps the bare minimum of System Namesapce artifacts. The more artifacts kept, the more cluttered the diagram will be."
},
"composer.pUML.diagramStyle": {
"composer.UML.diagramStyle": {
"type": "string",
"enum": [
"normal",
Expand All @@ -93,6 +93,15 @@
"default": "normal",
"description": "Style of diagram to draw."
},
"composer.UML.diagramTheme": {
"type": "string",
"enum": [
"yellow",
"blue"
],
"default": "yellow",
"description": "Diagram PlantUML theme. 'yellow' gives the default yellow diagram theme, where as 'blue' uses the newer blue theme"
},
"composer.contributor": {
"type": "boolean",
"default": false,
Expand Down
26 changes: 15 additions & 11 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function activate(context: ExtensionContext) {

/**
* Client handler for 'composer.generateUML' Command
* @param {string} docContent - info passed from server - pUML text as a string
* @param {string} docContent - info passed from server - UML text as a string
* @param {string} originatingFileName - name of the cto file command was activated on as passed to server
* note that this can be undefined if the command was activated by a keyboard shortcut!
*/
Expand All @@ -115,8 +115,9 @@ async function handleGenerateUml(docContent: string, originatingFileName: string

//get config info we need to set flags
let allConfig = workspace.getConfiguration();
let keepSrcFileOpen = allConfig.get('composer.pUML.keepSourceFileOpen');
let autoShowDiagam = allConfig.get('composer.pUML.autoShowDiagam');
let keepSrcFileOpen = allConfig.get('composer.UML.keepSourceFileOpen');
let autoShowDiagam = allConfig.get('composer.UML.autoShowDiagam');
let diagramTheme = allConfig.get('composer.UML.diagramTheme');

//if we are to try and show the diagram, we need the plantUML extention installed.
if (autoShowDiagam) {
Expand Down Expand Up @@ -144,20 +145,23 @@ async function handleGenerateUml(docContent: string, originatingFileName: string
let configPlantUml = allConfig['plantuml'];
configPlantUml.previewAutoUpdate = false;
configPlantUml.previewFileType = 'svg';
if (diagramTheme === 'blue') {
configPlantUml.includes = ['styles/blue'];
}
}

//Note: This looks like it should work but does not. TODO: Raise vscode issue
//allConfig.update('plantuml.previewAutoUpdate',false,false);
}
}

//construct temp file name
var fileName = os.tmpdir() + path.sep + "composer.puml";
var umlDocUri = Uri.file(fileName)

//make sure file exists - needed as a workaround to vscode issue #29156
if( ! fs.existsSync(fileName)) {
fs.writeFileSync(fileName,"");
if (!fs.existsSync(fileName)) {
fs.writeFileSync(fileName, "");
}

//open file - contents will always be replaced later on.
Expand All @@ -171,7 +175,7 @@ async function handleGenerateUml(docContent: string, originatingFileName: string
}
let textEditor = await window.showTextDocument(document, options);
return await textEditor.edit(async (editBuilder) => {
//edit doc to replace all doc content with new puml syntax
//edit doc to replace all doc content with new PlantUML syntax
var lastLineLength = document.lineAt(document.lineCount - 1).text.length;
editBuilder.replace(new Range(new Position(0, 0), new Position(textEditor.document.lineCount - 1, lastLineLength)), docContent);
}).then(async editApplied => {
Expand All @@ -183,7 +187,7 @@ async function handleGenerateUml(docContent: string, originatingFileName: string

//save the file whilst it's the active one
var saved = await document.save();
if(!saved) {
if (!saved) {
console.log("Client could not save doc: " + umlDocUri.toString());
}

Expand All @@ -199,8 +203,8 @@ async function handleGenerateUml(docContent: string, originatingFileName: string
if (result !== undefined) {
//console.log("Client preview returned: " + result); //debug
}
//check for option to close .puml file

//check for option to close the composer.puml file
if (!keepSrcFileOpen) {
//make sure we are closing the correct window, just in case
if (window.activeTextEditor) {
Expand All @@ -222,7 +226,7 @@ async function handleGenerateUml(docContent: string, originatingFileName: string
}

//reset the correct cto editor as active if we are showing the diagram
//otherwise let the omposer.puml file have focus
//otherwise let the composer.puml file have focus
if (autoShowDiagam) {
//Note that the visibleTextEditors list is the nost accurate as it contains
//the correct view column. However, we're not always present in this list
Expand Down
25 changes: 17 additions & 8 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ interface Settings {
interface ComposerSettings {
contributor: boolean
maxNumberOfProblems: number
pUML: {
UML: {
keepSourceFileOpen: boolean
autoShowDiagam: boolean
includeSystemNamespace: string
diagramStyle: string
diagramTheme: string
}
}

Expand Down Expand Up @@ -144,7 +145,7 @@ connection.onExecuteCommand((params) => {

/**
* Server processor for 'composer.generateUML' Command
* @param {string} diagramTitle - pUML diagram title
* @param {string} diagramTitle - UML diagram title
* @param {string} originatingFileName - name of the cto file command was activated on as passed to server
* note that this can be undefined if the command was activated by a keyboard shortcut!
*/
Expand All @@ -162,7 +163,7 @@ function handleGenerateUml(diagramTitle: string, originatingFileName: string) {
for (let n = 0; n < modelFiles.length; n++) {
const modelFile: ModelFile = modelFiles[n];
//we exclude models from the system namespace by default
if (options.pUML.includeSystemNamespace === "all") {
if (options.UML.includeSystemNamespace === "all") {
result = result.concat(modelFile.getAllDeclarations());
} else if (modelFile.getNamespace() != ModelUtil.getSystemNamespace()) {
result = result.concat(modelFile.getAllDeclarations());
Expand All @@ -173,14 +174,22 @@ function handleGenerateUml(diagramTitle: string, originatingFileName: string) {
parameters.fileWriter.writeLine(0, "@startuml composer");
parameters.fileWriter.writeLine(0, "'** Auto generated content, any changes may be lost **'");
parameters.fileWriter.writeLine(0, "!define DATE %date[EEE, MMM d, ''yy 'at' HH:mm]%");
if (options.UML.diagramTheme === 'yellow') {
parameters.fileWriter.writeLine(0, "skinparam titleBackgroundColor LightYellow");
} else {
parameters.fileWriter.writeLine(0, "'AutoInclude") //include the blue style
parameters.fileWriter.writeLine(0, "skinparam titleBackgroundColor AliceBlue");
}
parameters.fileWriter.writeLine(0, "skinparam titleBorderThickness 0.5");
parameters.fileWriter.writeLine(0, "skinparam titleBorderRoundCorner 6");
parameters.fileWriter.writeLine(0, "skinparam titleBackgroundColor LightYellow");
if (options.pUML.diagramStyle === 'handwritten') {
parameters.fileWriter.writeLine(0, "skinparam titleFontColor Black");
parameters.fileWriter.writeLine(0, "skinparam titleFontSize 18");

if (options.UML.diagramStyle === 'handwritten') {
parameters.fileWriter.writeLine(0, "skinparam handwritten true")
} else if (options.pUML.diagramStyle === 'monochrome') {
} else if (options.UML.diagramStyle === 'monochrome') {
parameters.fileWriter.writeLine(0, "skinparam monochrome true");
} else if (options.pUML.diagramStyle === 'monochrome-reverse') {
} else if (options.UML.diagramStyle === 'monochrome-reverse') {
parameters.fileWriter.writeLine(0, "skinparam monochrome reverse");
}

Expand All @@ -194,7 +203,7 @@ function handleGenerateUml(diagramTitle: string, originatingFileName: string) {
decl.accept(visitor, parameters);
});

if (options.pUML.includeSystemNamespace === "none") {
if (options.UML.includeSystemNamespace === "none") {
//skip system namespace artifacts. Note that we can only hide classes that already exist,
//so for now simply search for the relevant string to check for existance. This is
//not a failsafe solution but should work well enough for now.
Expand Down

0 comments on commit bc7cfe4

Please sign in to comment.