SHIFT-F6 as menu shortcut - d

In my current code I have the code
MenuItem runFileItem = new MenuItem(
(MenuItem mi) => pm.runFile(),
"_Run file",
"activate", true, accelGroup, 'r',
ModifierType.CONTROL_MASK | ModifierType.SHIFT_MASK,
AccelFlags.VISIBLE);
which works as expected - I can execute the handler pm.runFile() by pressing CTRL+SHIFT+r. Reason why I did it this way is because I could not figure out how to implement the preferred SHIFT+F6 that I wanted to use for this purpose. It would be good if I could put GDK_F6 GDK Keysym (from the gdk.Keysyms module), but could not find a way to use it. I've also asked the same question on GtkD forum (https://forum.gtkd.org/groups/GtkD/thread/2976/) without luck.
So the question is how to modify the above code to make SHIFT+F6 combination be handled properly as originally planned?
UPDATE:
Based on Adam's answer, the following code works:
MenuItem runFileItem = new MenuItem("_Run file", (MenuItem mi) => pm.runFile(), "activate");
runFileItem.addAccelerator("activate", accelGroup, GdkKeysyms.GDK_F6, ModifierType.SHIFT_MASK, AccelFlags.VISIBLE);

This constructor you're calling: https://api.gtkd.org/gtk.MenuItem.MenuItem.this.3.html
Forwards some of its arguments to this function on the base class:
https://api.gtkd.org/gtk.Widget.Widget.addAccelerator.html
Notice the ctor takes char but that other function takes uint so it should be able to take more values.
So I'd suggest trying:
auto mi = new MenuItem(label, action);
mi.addAccelerator(
"activate", accelGroup, GDK_F6,
ModifierType.SHIFT_MASK,
AccelFlags.VISIBLE
);
and see if it works.

Related

How to add form alter hook in drupal 8

I am very much new to drupal 8, I am trying to alter a form under custom content type "Question". The form has an id "node-question-form".
I have setup a module and trying to add hook_FORM_ID_alter() but its never getting called. Even the simplest hook is not working. eg:
function constellator_form_alter(&$form, &$form_state, $form_id){
echo "alter the form"; exit;
}
where 'constellator' is the module name.
I have been stuck with since morning and nothing is working for me, Any help will be greatly appriciated.
Cheers
hook_form_alter() and hook_FORM_ID_alter() are called while a form is being created and before displaying it on the screen.
These functions are written in the .module file.
Always clear the cache after writing any hook function. This makes Drupal understand that such a function has been declared.
Use drush cr if using drush version 8 else click on Manage->Drupal 8 logo->Flush all Caches to clear the caches.
Now you can check if the function is being called or not.
The best way to check that is to install the Devel module, enable it. Along with Devel, Kint is installed. Enable Kint too from the Admin UI.
After doing that,you can check whether the hook is being called or not in the following way:
function constellator_form_alter(&$form, &$form_state, $form_id){
kint($form);
}
This will print all the form variables for all forms in the page.
If you want to target a particular form in the page, for eg. you form, node-question-form, type:
function node_question_form_form_alter(&$form, &$form_state, $form_id){
kint($form);
}
Using echo, the way you did, you can confirm whether the function is being called or not, without any hassle, by viewing the Source Code for the page and then searching for the text that you have echoed, using some search option of browser, like, Ctrl+f in case of Google Chrome.
If you want to change sorting options and/or direction (ASC / DESC), you can use this example (tested with Drupal 9).
Here I force the sorting direction according to the "sort by option" set by the user in an exposed filter. (if the user want to sort by relevance, we set the order to ASC, if the user want to sort by date, we set the order to DESC to have the latest content first).
/**
* Force sorting direction for search by date
*
*/
function MYTHEME_form_alter(&$form, &$form_state, $form_id)
{
if (!$form_id == 'views_exposed_form"' || !$form['#id'] == 'views-exposed-form-search-custom-page-1') {
return;
}
$user_input = $form_state->getUserInput();
if (empty($user_input['sort_by'])) {
return;
}
if ($user_input['sort_by'] == 'relevance') {
$user_input['sort_order'] = 'ASC';
} elseif ($user_input['sort_by'] == 'created') {
$user_input['sort_order'] = 'DESC';
}
$form_state->setUserInput($user_input);
}
Note that "views-exposed-form-search-custom-page-1" is the id of my form,
"relevance" and "created" are the sort field identifier set in drupal admin.
function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
echo 'inside form alter';
}

Swift3.1 - NSApplication.terminate or NSApplication.shared().terminate

Creating a StatusBarMenuItem using a older style, what works fine. However because of a warning, I did want to change my code conform Swift 3.1, from
menu.addItem(NSMenuItem(title: "Quit terminate", action: Selector(("terminate:")), keyEquivalent: "q" ))
to
...
menu.addItem(NSMenuItem(title: "Quit quitAction", action: #selector(quitAction), keyEquivalent: "Q"))
...
func quitAction() {
NSApplication.shared().terminate(self) // works of course
// NSApplication.terminate(self) // doesn't works of course but works in a selector
}
Then I found out that they did change the Selector(("terminate:)) part not only to #selector but also the terminate part into
menu.addItem(NSMenuItem(title: "Quit NSAppl.terminate", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q" ))
But the following is also working ( mind the '.shared()' part )
menu.addItem(NSMenuItem(title: "Quit NSAppl.shared.terminate", action: #selector(NSApplication.shared().terminate(_:)), keyEquivalent: "q" ))
But when I want to remove the .shared() part from the quitAction function then I get a compiler error. My question is; "Why can I leave the shared() part out using a selector but not in a line of code"? What is the rationale about this? Thank you.
Actually, the question should be more like; "Why can I insert the shared() part using a selector"?
added image
A selector with syntax Type.method sends the method to an instance of the Type specified in the target parameter.
I suppose in macOS a selector without specified target is sent to FirstResponder ignoring the Type. The method terminate: is exposed to FirstResponder
In code you have to send the method to an instance so shared() is required.

Does webstorm have some shortcut for console.log or console.info?

Just tired of typing console.log again and again, and do not find a way like Sysout + Control + Space in Eclipse will create System.out.println().
There's a predefined Postfix template that allows you to type .log after a JavaScript expression or string and hit Tab to transform it to console.log().
You can also create a Live template (see Preferences | Editor | Live templates) that would expand into a code snippet once you type the selected abbreviation and hit Tab.
Update: there's now also a plugin that allows you to add console.log with a shortcut: https://plugins.jetbrains.com/plugin/10986-console-log
Yes it does,
<anything>.log and press Tab key. This will result in console.log(<anything>);
ie,
<anything>.log + Tab => console.log(<anything>);
eg1: variable
let my_var = 'Hello, World!';
my_var.log + Tab => console.log(my_var);
eg2: string
'hello'.log + Tab => console.log('hello');
eg3: string and variable
'hello', my_var.log + Tab => console.log('hello', my_var);
[UPDATE 2020]
Typing log + Enter autocompletes to console.log()
I made my own template that seems to work.
It may be useful for somebody.
Abbreviation: ll
Template text:
console.log('$NAME$ ', $VALUE$);
$END$
Variables: (just select the given field values by clicking drop down box)
NAME - jsDefineParameter()
VALUE - jsSuggestVariableName
I'm including what I find to be the most efficient, which I added via live templates -> javascript -> applicable to "Everything". Hopefully someone finds it useful.
console.log('L$LINE$ $MYSTRING$ ===', $MYVAR$);$END$
What it does:
When I type cl and press tab, it creates the log and the first thing you type fills both MYSTRING and MYVAR variables. If you tab again, it selects MYVAR where you can rewrite/delete as desired. The third time you hit tab will take you to the end of the line at $END.
This snippet also prints the line number like L123 but you can easily remove that if it isn't helpful because obviously most browsers show line number anyway.
You also have to set the variables' behaviour as seen in the image below:
Edit variables setup
use Macros!
https://www.jetbrains.com/help/webstorm/using-macros-in-the-editor.html
I recorded a macro that takes the name my cursor is on and create
console.log("#### name = ", name);
on the next line.
and assigned a keyboard shortcut to it :)
super easy, and couldn't get Live Template to get the same result with 1 action.
to create a new macro: Edit -> Macros -> Start Macro Recording. then record your next moves and create the desired result.
this is mine:
This is my solution, it somewhat mimics a turbo-console approach and gives you certain freedoms to build on it.
Step 1: Go to Editor > General > Postfix Completion;
Step 2: Click on JavaScript, click the + button, select JavaScript and TypeScript;
Step 3: In the Key input, type a alias for your command, I choose 'cl' for mine;
Step 4: In the 'Minimum language level' select your desired preference, I choose ECMAScript 6+;
Step 5: In the bellow text area, add your logic, for me it is console.log('$EXPR$', $EXPR$, '$END$');
Step 6: Customize however you like.
So what does all of this do?
Lets consider the following:
const willNeedToBeLogged = 'some value you want to check';
All you need to do for a console long is type
willNeedToBeLogged.cl + press (Tab, Enter or Spance)
And you will get this
console.log('willNeedToBeLogged', willNeedToBeLogged, '');
With your cursor being on the $END$ variable, where you could write, a line, or anything you like.
Have fun!
I made a custom template. This can help you.
Abbreviation: clog
Template code:
console.log("\n\n--------------------------------");
console.log($END$);
console.log("--------------------------------\n\n");
Simplest live template text:
console.log($END$);
Maybe it is a recent addition but you can write log and hit tab and console.log() will appear with the caret in between the braces.
The answer from Ekaterina Prigara (https://stackoverflow.com/a/32975087/5653914) was very useful to me but if you want to log a string like "Test" this method is quicker.
Try a logit plugin. It provides the next logging pattern by default:
const data = 'data';
console.log('-> data', data);
You can configure it.
Try Dot Log (vscode extension), It can automatically transfer aaa.log to console.log('aaa', aaa )

ValueChanging event on Infragistics WebDataGrid

Does anyone have an idea why this doesn't work or a workaround?
I'm trying to use the ValueChanging event from inside an EditorProvider
I have defined an EditProvider
<ig:TextEditorProvider ID="tepPercent">
<EditorControl HorizontalAlign="Right" ClientEvents-ValueChanging="validatePercent4Decimals"></EditorControl>
</ig:TextEditorProvider>
And a javascript handler
function validatePercent4Decimals(sender, args) {
var oldfieldvalue = args.get_oldValue();
var newfieldvalue = args.get_value();
if (isNaN(newfieldvalue)) {
args.set_value(oldfieldvalue);
args.set_cancel(true);
}
}
I've debugged it and can see it is running, and if I enter 34r, the inNan tests true and the set_value and set_cancel are called. But the value on the grid does not change from the 34r...
What's going on?
From this post on the Infragistics forums I believe that you have a numeric column. If this is the case then you should use a NumbericEditorProvider instead. There are more details on the available editor provides in the Infragistics help:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1?page=WebDataGrid_Editor_Providers.html

Why is php_template_preprocess_page function not called in Drupal 6x?

From another forum I found the following example:
"I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.
in the template.php file for your theme:
function phptemplate_preprocess_page(&$vars) {
if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
$vars['template_file'] = 'page-ajax';
}
}
then create page-ajax.tpl.php in your theme directory with this content:
<?php print $content; ?>
"
This seems like the logical way to do it and I did this, but the phptemplate_preprocess_page function is never called ... any suggestions?
I figured it out for myself from a Drupal Support Theme Development page:
"Maybe this helps
leahcim.2707 - May 29, 2008 - 05:40
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function."
The part in bold is what did the trick ... you have to re-save the configuration so it recognizes that you've added a new function to the template.