tweaking cut/compy/paste + added menu handling...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-06-19 01:14:13 +03:00
parent ccd141efef
commit f69837c625
2 changed files with 21 additions and 18 deletions

View File

@ -196,13 +196,16 @@ requirejs([
make(['list', 'of', 'text']) make(['list', 'of', 'text'])
make.group( make.group(
make('$group item 0', make('$group item 0',
function(){ console.log('###', ...arguments) }), function(){ console.log('##', ...arguments) }),
'group item 1 (bare)') 'group item 1 (bare)')
// XXX Q: should we show only one if multiple lines are in sequence??? // XXX Q: should we show only one if multiple lines are in sequence???
make('---') make('---')
// embeded browser... // embeded browser...
make(browser.Browser(function(make){ make(browser.Browser(function(make){
make('inlined browser item 0') make('inlined browser item 0', {
open: function(){ console.log('!!! OPEN', ...arguments) },
menu: function(){ console.log('!!! MENU', ...arguments) },
})
make(1) make(1)
make(2) make(2)
})) }))

View File

@ -3310,7 +3310,10 @@ var BrowserPrototype = {
: object.parent(BrowserPrototype.get, this).call(this, pattern, func, ...args) }, : object.parent(BrowserPrototype.get, this).call(this, pattern, func, ...args) },
// A hack to get user pasted text... // DOM/UI Helpers...
//
// NOTE: not for direct use...
// NOTE: both of these feel hackish...
__paste: function(callback){ __paste: function(callback){
var focus = this.dom.querySelector(':focus') || this.dom var focus = this.dom.querySelector(':focus') || this.dom
@ -3336,9 +3339,12 @@ var BrowserPrototype = {
: this.load(str) : this.load(str)
}.bind(this), 5) }.bind(this), 5)
}, },
// XXX should we query navigator.permissions???
__copy: function(text){ __copy: function(text){
navigator.clipboard.writeText(text || this.path) }, navigator.permissions.query({name: 'clipboard-write'})
.then(function({state}){
;(state == 'granted' || state == 'prompt' ) ?
navigator.clipboard.writeText(text || this.path)
: console.warn('.__copy(..): clipboard-write not allowed.') }) },
// Element renderers... // Element renderers...
// //
@ -3356,7 +3362,6 @@ var BrowserPrototype = {
// </div> // </div>
// or same as .renderList(..) // or same as .renderList(..)
// //
// XXX revise...
renderFinalize: function(items, context){ renderFinalize: function(items, context){
var that = this var that = this
var d = this.renderList(items, context) var d = this.renderList(items, context)
@ -3660,17 +3665,20 @@ var BrowserPrototype = {
// already focused... // already focused...
that.focused !== item that.focused !== item
&& that.focus(item) }) && that.focus(item) })
elem.addEventListener('contextmenu',
function(evt){
evt.preventDefault()
that.menu(item) })
// user events... // user events...
Object.entries(item.events || {}) Object.entries(item.events || {})
// shorthand events... // shorthand DOM events...
.concat([ .concat([
'click',
].map(function(evt){ ].map(function(evt){
return [evt, item[evt]] })) return [evt, item[evt]] }))
// setup the handlers... // setup the handlers...
.forEach(function([evt, handler]){ .forEach(function([evt, handler]){
handler handler
&& elem.addEventListener(evt, handler) }) && elem.addEventListener(evt, handler.bind(that)) })
// buttons... // buttons...
// XXX migrate the default buttons functionality and button inheritance... // XXX migrate the default buttons functionality and button inheritance...
@ -3847,15 +3855,7 @@ var BrowserPrototype = {
keyPress: makeEventMethod('keypress', keyPress: makeEventMethod('keypress',
function(evt, key){ function(evt, key){
this.__keyboard_handler(key) }), this.__keyboard_handler(key) }),
// XXX menu: makeItemEventMethod('menu'),
menu: makeEventMethod('menu', function(){
}),
// XXX
copy: makeEventMethod('copy', function(){
}),
// XXX
paste: makeEventMethod('paste', function(){
}),
// Navigation... // Navigation...