jquery terminal custom tab completion - jquery-terminal

Is it possible to take control of the entire tab-completion feature in JQuery.Terminal? I want to manage the autocompletion that's displayed.
For instance, I want to support templates/regex so that I can do things like "visualize campaign CAMPAIGN_NAME where config = SOMETHING". I could write my own parser and handler for all this, but I'm not sure how/where to plug it in?

In initialization settings, you need to make sure that the completion attribute is not set (default is false).
Then, you need to intercept the keydown function and handle the key you're interested in (tab in my case).
In there you can provide your own handler for auto-completion logic:
$('#terminal').terminal(function (command, term)
{
// Command handlers
},
{
keydown: function(event, term) {
if (event.keyCode == 9) //Tab
{
// Call handler to handle your auto-completion logic
// Sample to print stuff to the console and update the command
term.echo("autocompletion commands...");
term.set_command(term.get_command() + " completion text");
// Tells the terminal to not handle the tab key
return false;
}
}
});
});

Related

How to get the current tab's history in a Web Extension in Firefox?

Is there an API that makes it possible to get the current tab's history in a Web Extension in Firefox? Just like when clicking and holding on the Back button, a dropdown will appear to show the current tab's history.
No. You cannot ask for the list for a certain tab by default.
You can, however, listen for the tab events onUpdated, onCreated etc. Using the tabId which stays the same, you can keep a list of URLs in a background script (background.js) which is always running if the addon is enabled.
You would do it like this:
let arr=[]; // At the top of background.js
browser.tabs.onCreated.addListener(handleCreated); // Somewhere in background.js
function handleCreated(tab) {
let tabId = tab.id;
if(arr[tabId]==null) arr[tabId] = [];
arr[tabId].push(url);
}
function getHistoryForCurrentTab(){
function currentTabs(tabs) {
// browser.tabs.query returns an array, lets assume the first one (it's safe to assume)
let tab = tabs[0];
// tab.url requires the `tabs` permission (manifest.json)
// We will now log the tab history to the console.
for(let url of arr[tab.id]){
console.log(url);
}
}
function onError(error) {
console.log(`This should not happen: ${error}`);
}
browser.tabs.query({currentWindow: true, active: true}).then(currentTabs, onError);
}
The above code is a proof of concept. Some improvements you will need to consider: implement onClosed which resets the tab history for that id (arr[tabId] = null), implement onUpdated (will be needed for sure, same logic as in handleCreated).
Links:
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs

Kendo UI Gantt - Display a custom modal for task update

I am aware of the following http://docs.telerik.com/kendo-ui/api/javascript/ui/gantt#configuration-editable.template
but it is not what I need.
I need to display a custom modal dialog for task edition that is used in other parts of the app instead of the default kendo dialog.
Here's a possible way:
Implement a handler for the edit event and use e.preventDefault() to cancel kendo's built-in handling. This will prevent their dialog(or the template) from showing.
Now you show your own dialog(however you need to do that) and push in the GanttTask data passed to the edit event.
When your dialog is closed, you push the values of the edited data into the GanttTask...this is important! Since you cancelled the built-in functionality, it is now your responsibility to update the underlying data model.
Example edit handler:
edit: function(e) {
// Cancel the built-in editing functionality
e.preventDefault();
var editResult = showMyDialog(e.task);
if (editResult.ok) {
// User clicked OK instead of Cancel...or whatever mechanism your dialog uses.
e.task.set("title", editResult.data.title);
// other data...
}
}
Example custom dialog:
function showMyDialog(task) {
// Fetch/show your actual window, push in the data from the GanttTask
alert("This is my window: " + task.title);
// Simulate user editing of GanttTask.
var editedTitle = "NeW tAsK!";
// other data...
return {
ok: true, // or false if user clicked cancel.
data: {
title: editedTitle
// other data...
}
};
}
Simple demo: http://dojo.telerik.com/#Stephen/apEYa

Kendo Scheduler prevent editing/destruction of certain events

I've created a Kendo Scheduler that binds to a remote data source. The remote datasource is actually a combination of two separate data sources. This part is working okay.
Question is... is there any way to prevent certain events from being destroyed?
I've stopped other forms of editing by checking a certain field in the event's properties and calling e.preventDefault() on the edit, moveStart and resizeStart events if it should be read-only. This works fine, but I can't prevent deletes.
Any suggestions greatly appreciated.
Just capture the remove event and process it as you have with the edit, moveStart, and reviseStart events. You should see a remove event option off the kendo scheduler. I can see it and capture it in version 2013.3.1119.340.
I think better way is to prevent user from going to remove event in the first place. Handling the remove event still has its validity as you can delete event for example by pressing "Delete" key).
In example below I'm assuming event has custom property called category and events with category equal to "Holiday" can't be deleted.
remove: function(e)
{
var event = e.event;
if (event.category === "Holiday")
{
e.preventDefault();
e.stopPropagation();
}
},
dataBound: function(e)
{
var scheduler = e.sender;
$(".k-event").each(function() {
var uid = $(this).data("uid");
var event = scheduler.occurrenceByUid(uid);
if (event.category === "Holiday")
{
// use .k-event-delete,.k-resize-handle if you want to prevent also resizing
$(this).find(".k-event-delete").hide();
}
});
},
edit: function (e) {
var event = e.event;
if (event.category === "Holiday")
{
e.container.find(".k-scheduler-delete").hide();
}
}
FYI, you can do this...
#(Html.Kendo().Scheduler<ScheduledEventViewModel>()
.Name("scheduler")
.Editable(e => e.Confirmation(false))
)
which will deactivate the default confirmation prompt for the scheduler. Then you can do your own prompt on items you want.
There is also a
.Editable(e => e.Destroy(false))
that you can do to remove the X on the event window. This particular example would remove it for all of the events, but there might be a way to remove it for specific ones.

map keyboard keys with mootools

I am looking to make the enter key behave exactly like the tab key on a form.
I am stuck on the fireEvent section.
var inputs = $$('input, textarea');
$each(inputs,function(el,i) {
el.addEvent('keypress',function(e) {
if(e.key == 'enter') {
e.stop();
el.fireEvent('keypress','tab');
}
});
});
How do I fire a keypress event with a specified key? Any help would be greatly appreciated.
this will work but it relies on dom order and not tabindex
var inputs = $$('input,textarea');
inputs.each(function(el,i){
el.addEvent('keypress',function(e) {
if(e.key == 'enter'){
e.stop();
var next = inputs[i+1];
if (next){
next.focus();
}
else {
// inputs[0].focus(); or form.submit() etc.
}
}
});
});
additionally, textarea enter capture? why, it's multiline... anyway, to do it at keyboard level, look at Syn. https://github.com/bitovi/syn
the above will fail with hidden elements (you can filter) and disabled elements etc. you get the idea, though - focus(). not sure what it will do on input[type=radio|checkbox|range] etc.
p.s. your code won't work because .fireEvent() will only call the bound event handler, not actually create the event for you.
Take a look at the class keyboard (MooTools More).
It can fire individual events for keys and provides methodology to disable and enable the listeners assigned to a Keyboard instance.
The manual has some examples how to work with this class, here's just a simple example how I implemented it in a similar situation:
var myKeyEv1 = new Keyboard({
defaultEventType: 'keydown'
});
myKeyEv1.addEvents({
'shift+h': myApp.help() // <- calls a function opening a help screen
});
Regarding the enter key in your example, you have to return false somewhere to prevent the enter-event from firing. Check out this SO post for more details.

Ignore mouse and keyboard events in Qt

In Qt, how can I ignore all mouse and keyboard events and later stop ignoring them? That is: click a button, ignore all events in children; click again, not ignore. Is that clear?
I have the following lines, but maybe I'm doing something wrong:
setAttribute(Qt::WA_TransparentForMouseEvents);
setFocusPolicy(Qt::NoFocus);
Dont use setFocusPolicy(Qt::NoFocus); and it will propagate events to the parent. Use only setAttribute(Qt::WA_TransparentForMouseEvents);
You can use Events' filters on your mouse and keyboard events to filter some keypress or mouseclick when you need so :
yourWidget->installEventFilter(this);
...
bool YourFrm::eventFilter(QObject* pObject, QEvent* pEvent)
{
if (pEvent->type() == QEvent::KeyPress)
{
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>(pEvent);
int PressedKey = pKeyEvent->key();
if(PressedKey == Qt::Key_Return)
{
// Filter Return key....
return true;
}
// standard event processing
return QObject::eventFilter(pObject, pEvent);
}
else if (pEvent->type() == QEvent::MouseButtonPress)
{
QMouseEvent* pMouseEvent = static_cast<QMouseEvent*>(pEvent);
... // etc...
}
else
{
// standard event processing
return QObject::eventFilter(pObject, pEvent);
}
}
More informations on this : http://qt.nokia.com/doc/4.6/eventsandfilters.html
Hope it helps !
You could use:
QWidget::setEnabled(false)
it disable mouse and keyboard events for a widget.
Do you mean for a QGraphicsItem ?
If yes, you can call
void QGraphicsItem::setEnabled ( bool enabled )
And to activate the event later, as the item doesn't receive events any more, you have to pass by the Scene, because you can't receive directly event on the item.
If your problem is not using GraphicsView Frameworks, but other part of qt, it's almost the same process :
You can call :
QWidget::setEnabled(false) //like Massimo said
In order to reactive the widget, just detect press event inside an object in your application to be able to call `setEnable(true) on your widget !
Hope it helps !
`

Resources