Created
August 8, 2017 21:47
-
-
Save mrpotatoes/778fab79921a6d949e8d03d211076032 to your computer and use it in GitHub Desktop.
This file contains 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
// ------------------------------------------------------------------------------------------------------------------------ | |
// active-editor-info.js | |
// ------------------------------------------------------------------------------------------------------------------------ | |
'use babel'; | |
import ActiveEditorInfoView from './active-editor-info-view'; | |
import { CompositeDisposable, Disposable } from 'atom'; | |
export default { | |
activeEditorInfoView: null, | |
modalPanel: null, | |
subscriptions: null, | |
getTitle() { | |
return 'Active Editor Info'; | |
}, | |
getURI() { | |
return 'atom://active-editor-info'; | |
}, | |
getDefaultLocation() { | |
return 'right'; | |
}, | |
getAllowedLocations() { | |
// The locations into which the item can be moved. | |
return ['left', 'right', 'bottom']; | |
}, | |
activate(state) { | |
this.subscriptions = new CompositeDisposable( | |
// Add an opener for our view. | |
atom.workspace.addOpener(uri => { | |
if (uri === 'atom://active-editor-info') { | |
return new ActiveEditorInfoView(); | |
} | |
}), | |
// Register command that toggles this view | |
atom.commands.add('atom-workspace', { | |
'active-editor-info:toggle': () => this.toggle() | |
}), | |
// Destroy any ActiveEditorInfoViews when the package is deactivated. | |
new Disposable(() => { | |
atom.workspace.getPaneItems().forEach(item => { | |
if (item instanceof ActiveEditorInfoView) { | |
item.destroy(); | |
} | |
}); | |
}) | |
); | |
}, | |
deactivate() { | |
this.modalPanel.destroy(); | |
this.subscriptions.dispose(); | |
this.activeEditorInfoView.destroy(); | |
}, | |
deserializeActiveEditorInfoView(serialized) { | |
return new ActiveEditorInfoView(); | |
}, | |
serialize() { | |
return { | |
activeEditorInfoViewState: this.activeEditorInfoView.serialize() | |
}; | |
}, | |
toggle() { | |
console.log('in it to win it') | |
atom.workspace.toggle('atom://active-editor-info'); | |
} | |
}; | |
// ------------------------------------------------------------------------------------------------------------------------ | |
// active-editor-info-vew.js | |
// ------------------------------------------------------------------------------------------------------------------------ | |
'use babel'; | |
export default class ActiveEditorInfoView { | |
constructor(serializedState) { | |
// Create root element | |
this.element = document.createElement('div'); | |
this.element.classList.add('active-editor-info'); | |
// Create message element | |
const message = document.createElement('div'); | |
message.textContent = 'The ActiveEditorInfo package is Alive! It\'s ALIVE!'; | |
message.classList.add('message'); | |
this.element.appendChild(message); | |
this.subscriptions = atom.workspace.getCenter().observeActivePaneItem(item => { | |
if (!atom.workspace.isTextEditor(item)) { | |
message.innerText = 'Open a file to see important information about it.'; | |
return; | |
} | |
message.innerHTML = ` | |
<h2>${item.getFileName() || 'untitled'}</h2> | |
HEY GUY, WHY NO SHOW?!?!?! | |
<ul> | |
<li><b>Soft Wrap:</b> ${item.softWrapped}</li> | |
<li><b>Tab Length:</b> ${item.getTabLength()}</li> | |
<li><b>Encoding:</b> ${item.getEncoding()}</li> | |
<li><b>Line Count:</b> ${item.getLineCount()}</li> | |
</ul> | |
`; | |
}); | |
} | |
// Returns an object that can be retrieved when package is activated | |
serialize() {} | |
// Tear down any state and detach | |
destroy() { | |
this.element.remove(); | |
this.subscriptions.dispose(); | |
} | |
getElement() { | |
return this.element; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment