Skip to content

Commit

Permalink
feat: add setting to remove toolbar button
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 3, 2021
1 parent 7079fb6 commit 6b66057
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ let toolbar: ToolBarManager

export function consumeToolBar(getToolBar: getToolBarManager) {
toolbar = getToolBar("atomic-terminal") // getting toolbar object
toolbar.addButton({
icon: "terminal",
tooltip: "Open Terminal",
callback: "atomic-terminal:open",
})
if (atom.config.get("atomic-toolbar.toolbarButton")) {
addToolbarButton();
}
}

export function addToolbarButton() {
if (toolbar) {
toolbar.addButton({
icon: "terminal",
tooltip: "Open Terminal",
callback: "atomic-terminal:open",
})
}
}

export function removeToolbarButton() {
if (toolbar) {
toolbar.removeItems();
}
}
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export const config = configOrder({
type: "boolean",
default: true,
},
toolbarButton: {
title: "Add Toolbar Button",
description: "Add button to open a terminal from the toolbar.",
type: "boolean",
default: true,
},
colors: {
title: "Colors",
description: "Settings for the terminal colors.",
Expand Down
10 changes: 10 additions & 0 deletions src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CompositeDisposable, Workspace, Dock, Pane, WorkspaceOpenOptions } from

import { TerminalElement } from "./element"
import { TerminalModel } from "./model"
import { addToolbarButton, removeToolbarButton } from "./button"
export * from "./button"

import { v4 as uuidv4 } from "uuid"
Expand Down Expand Up @@ -99,6 +100,14 @@ class Terminal {
TerminalModel.recalculateActive(this.terminalsSet)
}),

atom.config.onDidChange("atomic-terminal.toolbarButton", ({newValue}) => {
if (newValue) {
addToolbarButton()
} else {
removeToolbarButton()
}
}),

// Add commands.
// @ts-ignore
atom.commands.add("atom-workspace", {
Expand Down Expand Up @@ -169,6 +178,7 @@ class Terminal {

destroy() {
this.exitAllTerminals()
removeToolbarButton()
this.disposables.dispose()
}

Expand Down

0 comments on commit 6b66057

Please sign in to comment.