Skip to content

Commit

Permalink
first edit window 🎚
Browse files Browse the repository at this point in the history
  • Loading branch information
felixerdy committed Jun 23, 2017
1 parent 0ae91a9 commit abf09b9
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 39 deletions.
86 changes: 86 additions & 0 deletions lib/touchbar-edit-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** @babel */
/** @jsx etch.dom */

import {Disposable} from 'atom'
import etch from 'etch'
const {app, BrowserWindow, TouchBar} = require('remote')
const {TouchBarLabel, TouchBarButton, TouchBarSpacer, TouchBarSlider} = TouchBar

var touchBarItems = []


export default class TimecopView {
constructor ({uri}) {
this.uri = uri
etch.initialize(this)
if (atom.packages.getActivePackages().length > 0) {
this.populateViews()
} else {
// Render on next tick so packages have been activated
setImmediate(() => { this.populateViews() })
}
}

update () {}

destroy () {
return etch.destroy(this)
}

render () {
return (
<div>
<div>
<div>
<b>Current objects in TouchBar:</b>
<ul ref="activeObjects"></ul>
</div>
</div>
</div>
)
}

populateViews() {
if(BrowserWindow.getFocusedWindow()._touchBar !== null) {
touchBarItems = Object.values(BrowserWindow.getFocusedWindow()._touchBar.items)
console.log(touchBarItems)
touchBarItems.map((obj) => {
const li = document.createElement('div')

const a = document.createElement('a')
a.textContent = `${obj.type} ${obj.label}`
li.appendChild(a)

this.refs.activeObjects.appendChild(li)
})
}
}


serialize () {
return {
deserializer: this.constructor.name,
uri: this.getURI()
}
}

getURI () {
return this.uri
}

getTitle () {
return 'Touchbar Editor'
}

getIconName () {
return 'dashboard'
}

onDidChangeTitle () {
return new Disposable(function () {})
}

onDidChangeModified () {
return new Disposable(function () {})
}
}
29 changes: 0 additions & 29 deletions lib/touchbar-view.js

This file was deleted.

25 changes: 16 additions & 9 deletions lib/touchbar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use babel';

import TouchbarView from './touchbar-view';
import TouchbarView from './touchbar-edit-view';
import { CompositeDisposable } from 'atom';

const {app, BrowserWindow, TouchBar} = require('remote')

const {TouchBarLabel, TouchBarButton, TouchBarSpacer, TouchBarSlider} = TouchBar

const EditViewURI = 'atom://touchbar-edit-view'



let touchBarEnabled = false;
Expand Down Expand Up @@ -34,7 +36,7 @@ export default {
},
color: {
type: 'color',
default: 'basalt'
default: 'darkgrey'
}
}
},
Expand All @@ -51,18 +53,14 @@ export default {
},
color: {
type: 'color',
default: 'basalt'
default: 'darkgrey'
}
}
}
},

activate(state) {
this.touchbarView = new TouchbarView(state.touchbarViewState);
this.modalPanel = atom.workspace.addModalPanel({
item: this.touchbarView.getElement(),
visible: false
});
this.touchbarView = new TouchbarView(EditViewURI);

// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable();
Expand Down Expand Up @@ -92,7 +90,6 @@ export default {
})

atom.config.observe('touchbar.touchBarButtonTwo.color', (newValue) => {
console.log(newValue)
buttonTwo.backgroundColor = newValue.toHexString()
})

Expand All @@ -113,6 +110,11 @@ export default {
this.subscriptions.add(atom.commands.add('atom-workspace', {
'touchbar:toggle': () => this.toggle()
}));

// Register command that opens the edit window
this.subscriptions.add(atom.commands.add('atom-workspace', {
'touchbar:edit': () => this.openEditWindow()
}));
},

deactivate() {
Expand All @@ -131,6 +133,11 @@ export default {
toggle() {
BrowserWindow.getFocusedWindow().setTouchBar(touchBarEnabled ? null : globalTouchBar)
touchBarEnabled = !touchBarEnabled
},

openEditWindow() {
let tbev = new TouchbarView(EditViewURI)
atom.workspace.open(tbev)
}

};
4 changes: 4 additions & 0 deletions menus/touchbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
{
"label": "Toggle",
"command": "touchbar:toggle"
},
{
"label": "Edit",
"command": "touchbar:edit"
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {}
"dependencies": {
"etch": "^0.12.4"
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


etch@^0.12.4:
version "0.12.4"
resolved "https://registry.yarnpkg.com/etch/-/etch-0.12.4.tgz#6c8b9500eeeda22a1e0962f58f94e2cf9573ac92"

0 comments on commit abf09b9

Please sign in to comment.