Skip to content

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
Fix incorrect behavior of UI elements. Now they should appear correctly depending on the current active text editor.
  • Loading branch information
deiteris committed Apr 28, 2021
1 parent f643594 commit 84fbf9b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 38 deletions.
8 changes: 7 additions & 1 deletion extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.1

This is a hotfix release.

Fix incorrect behavior of UI elements. Now they should appear correctly depending on the current active text editor.

## 1.0.0

First public release.
First public release.
4 changes: 2 additions & 2 deletions extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "API Contractor",
"description": "Define, edit, validate and preview your API contracts in RAML and OpenAPI (Swagger)",
"publisher": "deiteris",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"icon": "images/icon.png",
"engines": {
Expand Down
1 change: 0 additions & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export async function activate(ctx: ExtensionContext) {
ctx.subscriptions.push(client.start())

fileFormatStatusBar = new FileFormatStatusBar('API format of the current file.')
fileFormatStatusBar.changeApiFormat()
ctx.subscriptions.push(fileFormatStatusBar)

mainFileStatusBar = new MainFileStatusBar(ExtensionCommands.SetMainApiFile, 'Select root API file.', documentSelector)
Expand Down
24 changes: 10 additions & 14 deletions extension/src/features/status-bars/file-format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { workspace, commands, window, StatusBarItem, StatusBarAlignment, Disposable } from 'vscode'
import { workspace, commands, window, StatusBarItem, StatusBarAlignment, Disposable, TextDocument } from 'vscode'
import { readApiFileFormat } from '../../helpers'

export class FileFormatStatusBar extends Disposable {
Expand All @@ -11,6 +11,7 @@ export class FileFormatStatusBar extends Disposable {
this.statusBarItem.tooltip = tooltip

this.disposables.push(this.statusBarItem)
this.changeApiFormat(window.activeTextEditor?.document)
this.registerEvents()
}

Expand All @@ -19,16 +20,16 @@ export class FileFormatStatusBar extends Disposable {
}

// TODO: FileFormatStatusBar controls the context on which preview buttons depends. This is not what normally should be expected...
async changeApiFormat() {
const apiFormat = await readApiFileFormat()
async changeApiFormat(document: TextDocument | undefined) {
const apiFormat = await readApiFileFormat(document)
if (apiFormat) {
commands.executeCommand('setContext', 'ac.isApiFile', true)
this.updateText(`${apiFormat.type}`)
this.show()
} else {
commands.executeCommand('setContext', 'ac.isApiFile', false)
this.hide()
return
}
commands.executeCommand('setContext', 'ac.isApiFile', false)
this.hide()
}

show() {
Expand All @@ -40,16 +41,11 @@ export class FileFormatStatusBar extends Disposable {
}

private registerEvents() {
this.disposables.push(workspace.onDidCloseTextDocument(async () => {
await this.changeApiFormat()
this.disposables.push(window.onDidChangeActiveTextEditor(async (editor) => {
await this.changeApiFormat(editor?.document)
}))

this.disposables.push(workspace.onDidOpenTextDocument(async () => {
await this.changeApiFormat()
}))

this.disposables.push(workspace.onDidSaveTextDocument(async () => {
await this.changeApiFormat()
await this.changeApiFormat(window.activeTextEditor?.document)
}))
}

Expand Down
26 changes: 9 additions & 17 deletions extension/src/features/status-bars/main-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { workspace, window, StatusBarItem, StatusBarAlignment, Disposable, DocumentFilter } from 'vscode'
import { window, StatusBarItem, StatusBarAlignment, Disposable, DocumentFilter, TextDocument } from 'vscode'

export class MainFileStatusBar extends Disposable {
private statusBarItem: StatusBarItem
Expand All @@ -13,33 +13,25 @@ export class MainFileStatusBar extends Disposable {
this.statusBarItem.tooltip = tooltip

this.disposables.push(this.statusBarItem)
this.toggle(window.activeTextEditor?.document)
this.registerEvents()
}

updateText(text: string) {
this.statusBarItem.text = text
}

show() {
this.statusBarItem.show()
}

hide() {
toggle(document: TextDocument | undefined) {
if (document && this.documentFilter.some(filter => filter.language === document.languageId)) {
this.statusBarItem.show()
return
}
this.statusBarItem.hide()
}

private registerEvents() {
this.disposables.push(workspace.onDidCloseTextDocument(async () => {
const document = window.activeTextEditor?.document
if (!document || !this.documentFilter.some(filter => filter.language === document.languageId)) {
this.statusBarItem.hide()
}
}))
this.disposables.push(workspace.onDidOpenTextDocument(async () => {
const document = window.activeTextEditor?.document
if (document && this.documentFilter.some(filter => filter.language === document.languageId)) {
this.statusBarItem.show()
}
this.disposables.push(window.onDidChangeActiveTextEditor(async (editor) => {
this.toggle(editor?.document)
}))
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as child_process from "child_process"
import { window, workspace } from "vscode"
import { TextDocument, window, workspace } from "vscode"
import { ApiSearch, ApiFormat } from "./features/api-search"

export async function readApiFileFormat(document = window.activeTextEditor?.document): Promise<ApiFormat | undefined> {
export async function readApiFileFormat(document: TextDocument | undefined): Promise<ApiFormat | undefined> {
if (document && document.uri.scheme === 'file') {
const workspaceRoot = workspace.rootPath
if (!workspaceRoot) {
Expand Down

0 comments on commit 84fbf9b

Please sign in to comment.