How to make USE for class quickly in PhpStorm? - phpstorm

How i can quickly make
use \DateTime;
for new \DateTime();
in PhpStorm ? I saw on some videos guys do that with some hotkey or something like that.

You can find the most relevant contextual options with secondary mouse click. The one you want is Show Context Actions (you'll see your current keyboard shortcut beside, mine is Alt+Enter):
Additionally, clicking on the code and waiting for a second will often display a standalone light bulb that points to the same command:
Those are called intentions. There're two that apply here:
Replace with alias (to add use foo as bar;)
Simplify FQN (to just add use foo or remove it altogether if already in root namespace)
Your particular example is a strange use case (you only save one character worth of typing) but the feature rocks when you have nested namespaces.

Related

PhpStorm shortcut to wrap text with function call

I'm in PhpStorm and I need to select some text, press some shortcut and have that text wrapped in a function call (that I would have defined somewhere in the settings beforehand).
For example:
"Hello World" would become input("Hello World").
$_GET["foo"] would become input($_GET["foo"]).
I don't know if this is even possible, but it could help me save so much time if so.
Applying regex to solve this problem is unfortunately not possible. Manually selecting what I need to wrap isn't an issue.
Will the function name be the same every time or different?
In any case: it can be done this way:
Make a Live Template of "surround template" type with the following content:
$FUN$($SELECTION$)$END$
The $SELECTION$ variable here tells that it's a surround template.
Apply correct Context (where this template can be used)
Give it an abbreviation (name used to locate & invoke it) and brief description.
Here is mine:
NOTE: replace $FUN$ by a fixed function name if the function will always be the same. You can have additional templates with different abbreviations (that will have different hardcoded function names).
To use it:
Make a selection and invoke Code | Surround with... action where you select the right template. On Windows keymap it's Ctrl + Alt + T
In action (NOTE: it's without hardcoding the function name hence me typing the myFunc part):
(HINT: you can select the desired entry in a few keypresses if the name is unique -- just start typing the name in the popup -- the standard Speed Search work here)
P.S. Code | Surround with... can have other (possibly irrelevant for you in this case) entries. To list Live Templates only, use the shortcut for Surround with Live Template... action (Ctrl + Alt + J here on my Windows keymap). You can check the shortcut or change it in the Settings/Preferences | Keymap:
This way the popup menu will be a bit shorter:
Less keypresses:
You may be able to use Macros functionality to record the invoking the popup and selecting the right entry. You can then assign a custom shortcut to that Macros: select the text, hit the shortcut and it will playback the recorded sequence.
Sadly I cannot 100% guarantee that Macros will always work nicely (sometimes/on some setups it can "eat" keypresses).
P.S. It would be much easier if the IDE would support assigning keyboard shortcuts to specific Live Templates .. but it's in the backlog and no ideas on when this might be implemented. Anyway: https://youtrack.jetbrains.com/issue/IDEA-67811 -- watch this ticket (star/vote/comment) to get notified on any progress.
P.S. You can also try Postfix completion. It's good for writing the code and not really suitable for your case (editing small parts of it), but who knows. You will have to make a custom postfix for this -- should not be an issue though.
https://www.jetbrains.com/help/phpstorm/2021.3/auto-completing-code.html#postfix_completion

Dropdown select with delete option next to each option value

I need to implement a drop-down which has a delete 'X' option next to each option item. Somewhat like the image shown below.
The drop-down is populated dynamically and I need a way that does not inlvolve using list as an alternative.
EDIT: The icons next to each dropdown item refers to 'Edit'/'Delete'
You cannot put a checkbox into the usual <select> or multi-select HTML element.
However, here is another question where several good options are discussed.
This looks like the most useful and best suited to your purpose:
https://stackoverflow.com/a/27547021/1447509
And here is an example of how to change the default checkmark to an X:
https://stackoverflow.com/a/40123793/1447509
Sources:
How to use Checkbox inside Select Option
After selecting check box Instead of Tick symbol need X in html
UPDATE:
Given that you need both the HTML markup and the javascript to make it do what you want, you have two (possibly 3) steps to do:
This answer provides a good example of how to create the custom-rolled <select> control.
This answer shows you how to replace the checkbox created in step 1 with an icon/image of your choosing.
The javascript to remove the x'd <option> is very simple:
$(this).closest('option').remove();
IF you also need to save these results, then you also need to learn:
4a. Server-side SESSIONS (so that each user's customizations are saved for them)
4b. A login system, so you know for which user to save the current customizations.
4c. Just the basics of how to use a back-end database, such as MySQL/MariaDB, in which to store the user customizations.
4d. AJAX - so you can schlep info to the back-end for insertion into the database without refreshing (or navigating away from) the current page. AJAX replaces the ancient and no-longer-used <form> construct. Frankly, once you've used AJAX a couple of times, you'll never go back. Totally easy.
If you are in a bind and need someone to create the whole thing for you, I refer you to one of these websites - I have used such services myself and can recommend them.

PhpStorm combine multiple Predefined Live Template functions

I have a project where my files are in "lisp-case" (hyphen delimited) and I would like to use the filename as a variable in a live template, but it must be converted to CamelCase first.
I found out that you can set the expression fileNameWithoutExtension() under "Edit Template Variables" and there is also a function called camelCase() which should be able to turn my filenames into CamelCase. But I cannot figure out how to combine those two. I tried doing camelCase(fileNameWithoutExtension()) but that does not work, unfortunately.
Is it possible to achieve this some other way?
camelCase(fileNameWithoutExtension())
It's a correct syntax.
Is it possible to achieve this some other way?
Please ensure that Skip if defined checkbox is checked for this variable.
If I try to wrap fileNameWithoutExtension() inside camelCase() and press enter to save the entry the window is closed but the change is not saved
It's an IDE bug (https://youtrack.jetbrains.com/issue/IDEA-132965 -- supposed to be fixed in current 2017.1.x version).
In any case: either press Enter before leaving the field ... or click on OK button straight away (you may then reopen this window to do further changes).
Also, when editing the field it's rendered like a select box which is kind of weird. Maybe it's a bug in this specific version. I'm on PhpStorm 10.0.4 for Mac.
Not a Mac user here .. but it is an editable drop-down box indeed (it lists all possible functions).

Is there a way to remove search result from the find tab in PhpStorm?

In PhpStorm 9.0.2 (I do not know about the newer versions, but I am afraid it will be the same) when you search for something and get the results in the Find tab, you can mark certain results as irrelevat by selecting them and pressing the del key and this will strike them out.
When you search for something very common, which can have 5000+ occurences, even by striking some results out, the Find tab becomes very bloated.
Is there a way to completely remove a result from the Find tab, instead of just striking it out?
When using Find/Replace in Path functionality and you know that you will get a lot of results it's better to limit your search scope by either specific path, specific file extensions or some custom scope (using Scopes functionality).
If such "limiting" cannot not help (e.g. you really need to go trough each occurrence) then use Alt + Delete (the Remove action).
Please note that this action is most likely available since PhpStorm v10 only (it was added only recently).
You can check if you have it and what the shortcut is via content menu:
You can use this keymap shortcut : ALT + SUPPR (this remove the result out of the find tab)
instead of
keymap shortcut : SUPPR (this JUST exclude the result of the find tab with underline this not remove)
EDIT :
This is the exact response for your issue. Look at this screenshoot which say all :)

Sikuli scripts without images - Static applications

Sometimes we don't need to capture and use images for automating Desktop based application. We can simply use tab and Enter keys to achieve our task. But in some cases we need images, for example radio button, option selection, check box, etc.
Is there any way to automate these type of options without image or screen shot?
You could simply go through an order of keystrokes without needing to match any sort of pattern. Unfortunately I only make use of the Java API which may be a tad different but the idea is the same for Python (via Jython).
Screen screen = new Screen();
screen.type(Key.TAB + Key.ENTER);
If you are able to get to your radio button through a series of keystrokes, you could put them in sequential order. However using Sikuli entirely without images and patterns kind of defeats its purpose and you're better off using other alternatives such as AutoIt or if you wish to maintain it in a Python environment you could use PyAutoIt. Both are very good but the latter lacks documentation (have to read the source to understand what is going on).
It is not very clear what are you asking? Do you want to know whether you can use Sikuli just for keyboard manipulation without taking and using screenshots? If that's the case, the answer is yes. You can always run standalone commands like these:
type(Key.ENTER) #for Enter key
type("\t") #for tab