-
Notifications
You must be signed in to change notification settings - Fork 513
Show formatting status in status bar #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+130
−3
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ca0e93
Add formatting status to status bar
8456749
Add animated formatting status
00c6a13
Add animated status bar creation method
19b20d2
Use cached strings to display states
e592d5a
Add copyright to anmiatedStatusBar.ts
6a438d2
Add access modifiers to AnimatedStatusBar fields
99a17cc
Fix typo in class name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import { | ||
StatusBarItem, | ||
StatusBarAlignment, | ||
Disposable, | ||
window} from "vscode"; | ||
|
||
export function setAnimatedStatusBarMessage(text: string, hideWhenDone: Thenable<any>): Disposable { | ||
let animatedStatusBarItem: AnimatedStatusBarItem = new AnimatedStatusBarItem(text); | ||
animatedStatusBarItem.show(hideWhenDone); | ||
return animatedStatusBarItem; | ||
} | ||
|
||
class AnimatedStatusBarItem implements StatusBarItem { | ||
private readonly animationRate: number; | ||
private statusBarItem: StatusBarItem; | ||
private maxCount: number; | ||
private counter: number; | ||
private baseText: string; | ||
private timerInterval: number; | ||
private elapsedTime: number; | ||
private intervalId: NodeJS.Timer; | ||
private suffixStates: string[]; | ||
|
||
public get alignment(): StatusBarAlignment { | ||
return this.statusBarItem.alignment; | ||
} | ||
|
||
public get priority(): number { | ||
return this.statusBarItem.priority; | ||
} | ||
|
||
public get text(): string { | ||
return this.statusBarItem.text; | ||
} | ||
|
||
public set text(value: string) { | ||
this.statusBarItem.text = value; | ||
} | ||
|
||
public get tooltip(): string { | ||
return this.statusBarItem.tooltip; | ||
} | ||
|
||
public set tooltip(value: string) { | ||
this.statusBarItem.tooltip = value; | ||
} | ||
|
||
public get color(): string { | ||
return this.statusBarItem.color; | ||
} | ||
|
||
public set color(value: string) { | ||
this.statusBarItem.color = value; | ||
} | ||
|
||
public get command(): string { | ||
return this.statusBarItem.command; | ||
} | ||
|
||
public set command(value: string) { | ||
this.statusBarItem.command = value; | ||
} | ||
|
||
constructor(baseText: string, alignment?: StatusBarAlignment, priority?: number) { | ||
this.animationRate = 1; | ||
this.statusBarItem = window.createStatusBarItem(alignment, priority); | ||
this.baseText = baseText; | ||
this.counter = 0; | ||
this.suffixStates = [" ", ". ", ".. ", "..."]; | ||
this.maxCount = this.suffixStates.length; | ||
this.timerInterval = ((1/this.maxCount) * 1000) / this.animationRate; | ||
this.elapsedTime = 0; | ||
} | ||
|
||
public show(hideWhenDone?: Thenable<any>): void { | ||
this.statusBarItem.show(); | ||
this.start(); | ||
if (hideWhenDone !== undefined) { | ||
hideWhenDone.then(() => this.hide()); | ||
} | ||
} | ||
|
||
public hide(): void { | ||
this.stop(); | ||
this.statusBarItem.hide(); | ||
} | ||
|
||
public dispose(): void { | ||
this.statusBarItem.dispose(); | ||
} | ||
|
||
private updateCounter(): void { | ||
this.counter = (this.counter + 1) % this.maxCount; | ||
this.elapsedTime = this.elapsedTime + this.timerInterval; | ||
} | ||
|
||
private updateText(): void { | ||
this.text = this.baseText + this.suffixStates[this.counter]; | ||
} | ||
|
||
private update(): void { | ||
this.updateCounter(); | ||
this.updateText(); | ||
} | ||
|
||
private reset(): void { | ||
this.counter = 0; | ||
this.updateText(); | ||
} | ||
|
||
private start(): void { | ||
this.reset(); | ||
this.intervalId = setInterval(() => this.update(), this.timerInterval); | ||
} | ||
|
||
private stop(): void { | ||
clearInterval(this.intervalId); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend a more obvious string like "PowerShell code formatting in progress"