Skip to content
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

Adding Options tab bar and remembering window size #158

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions desktop/sources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
left.controller.addSpacer('default', 'Theme', 'Download')
left.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') })

left.controller.add("default","Options","Set Text Area Width",() => { left.operator.start('setTextAreaColumns: ')})
left.controller.add("default","Options","Save Window Size",() => { left.options.setDimensions()})

left.controller.add('reader', '*', 'About', () => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Left') }, 'CmdOrCtrl+,')
left.controller.add('reader', '*', 'Fullscreen', () => { app.toggleFullscreen() }, 'CmdOrCtrl+Enter')
left.controller.add('reader', '*', 'Hide', () => { app.toggleVisible() }, 'CmdOrCtrl+H')
Expand Down Expand Up @@ -129,6 +132,8 @@
left.controller.add('operator', 'Find', 'Find Next', () => { left.operator.find_next() }, 'CmdOrCtrl+N')
left.controller.add('operator', 'Operator', 'Stop', () => { left.operator.stop() }, 'Esc')

left.controller.add('operator', 'Options', 'setTextAreaColumns', () => { left.operator.start('setTextAreaColumns: ') })

left.controller.commit()
</script>
</body>
Expand Down
6 changes: 5 additions & 1 deletion desktop/sources/left.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ const Project = require('./scripts/project')
const Reader = require('./scripts/reader')
const Insert = require('./scripts/insert')
const Font = require('./scripts/font')
const Options = require('./scripts/options')

const EOL = '\n'

function Left () {
this.theme = new Theme({ background: '#222', f_high: '#eee', f_med: '#888', f_low: '#666', f_inv: '#00f', b_high: '#f9a', b_med: '#a9f', b_low: '#000', b_inv: '#af9' })
this.controller = new Controller()
this.dictionary = new Dictionary()
this.operator = new Operator()
this.options = new Options()
this.operator = new Operator(this.options)
this.navi = new Navi()
this.stats = new Stats()
this.go = new Go()
Expand Down Expand Up @@ -78,6 +80,7 @@ function Left () {
this.font.start()
this.dictionary.start()
this.project.start()
this.options.start()

this.go.to_page()

Expand Down Expand Up @@ -328,6 +331,7 @@ function Left () {
this.reset = () => {
this.theme.reset()
this.font.reset()
this.options.reset()
this.update()
}

Expand Down
14 changes: 13 additions & 1 deletion desktop/sources/scripts/operator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict'

const Options = require("./options");

const EOL = '\n'

function Operator () {
function Operator (options) {
this.el = document.createElement('input'); this.el.id = 'operator'
this.is_active = false
this.index = 0
this.Options = options

this.el.addEventListener('keyup', (e) => { left.operator.on_change(e, false) })
this.el.addEventListener('keydown', (e) => { left.operator.on_change(e, true) })
Expand Down Expand Up @@ -167,6 +170,15 @@ function Operator () {
left.go.to_line(target)
}
}

this.setTextAreaColumns = function (size, bang = false) {
if (size.length < 2) { return }
this.Options.setTextAreaColumns(size)

if (bang) {
setTimeout(() => { left.operator.stop() }, 250)
}
}
}

module.exports = Operator
66 changes: 66 additions & 0 deletions desktop/sources/scripts/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict'

function Options () {
this.electron = require('electron');
const root = document.documentElement
this.colWidth = 80
this.w = 900
this.h = 500


this.setDimensions = function () {
var window = this.electron.remote.getCurrentWindow();
const { w, h } = window.getSize()
this.w = window.getSize()[0]
this.h = window.getSize()[1]
this.updateVariables()
}

this.start = function () {
this.element = document.querySelector('textarea')

// If localStorage has information about the options,
// load the saved values and apply them
if (localStorage.getItem('options')) {
console.log(JSON.parse(localStorage.getItem('options')))
const { colWidth, w, h } = JSON.parse(localStorage.getItem('options'))
this.colWidth = colWidth
this.w = w
this.h = h
this.updateVariables()
}
}

this.setTextAreaColumns = function (size) {
this.colWidth = size
this.updateVariables()
}

// Update the CSS variables, save the values to localStorage
this.updateVariables = function () {
this.element.style.setProperty('width', `${this.colWidth}ch`)
var window = this.electron.remote.getCurrentWindow();
window.setSize(this.w, this.h)
window.center()
this.save()
}

// Save the font-related values to localStorage
this.save = function () {
localStorage.setItem('options', JSON.stringify({
colWidth: this.colWidth,
w: this.w,
h: this.h
}))
}

this.reset = function () {
localStorage.removeItem('options')
this.colWidth = 80
this.w = 900
this.h = 500
this.updateVariables()
}
}

module.exports = Options