How to show class file in explorer in idea - intellij-idea

How to show class file (not java file) in explorer in IDEA?
When I select a java file, I want to position it in the explorer, I know in Eclipse it is easy, but what I should do in IDEA?

You can do it with the External Tool like this:
This answer describes what parameters to use for the explorer.exe to select the file.
Using IntelliJ IDEA macros the Arguments field will look like this:
/select,"$OutputPath$\$FileDirRelativeToSourcepath$\$FileNameWithoutExtension$.class"
It will open Explorer with the output file selected:
For the source file located in C:\work\attaches\hotswap-bug\src\foo\bazz\Another.java the tool will select C:\work\attaches\hotswap-bug\out\production\hotswap-bug\foo\bazz\Another.class file.
This tool can be invoked from the editor right click menu while inside the source .java file:
You can also assign a keyboard shortcut to this tool or make an action in the toolbar for easier access.
Final result:
Just curious, what's the real world use case for this?

Related

Intellij IDEA Plugin to read and print the contents in a IDE editor in console

I am new to Intellij Idea plugin development using gradle! I am hoping to develop a simple plugin to read the contents of java class and print it in the console(Toolwindow) in a live manner(i.e when I type a new word in the java class it should print the work in the console even if the class is saved or not)
Currently I am refering to the Intellij plugin architecture and components in https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html. I came across concepts such as editor panes and all But I have no idea how to read the contents in IDE editor(current java file)! How can I do it?
You can grab the raw text of an editor window:
Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
editor.getDocument().getText();
If you want to get some structure from the contents of the editor window, you can use the PsiFile API:
PsiFile psi = anActionEvent.getData(CommonDataKeys.PSI_FILE);
The PsiFile API lets you walk through a file in whatever language(s) make sense. For example, for Java files there is a PsiJavaFile interface that knows about Java specific features like package name, imports, etc.
http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_files.html
Lastly, to print a message you can try normal System.out.print() or you can use the ConsoleView class to work with the IntelliJ console tool views:
TextConsoleBuilderFactory.getInstance()
.createBuilder(anActionEvent.getProject())
.getConsole()
.print("Hello", ConsoleViewContentType.NORMAL_OUTPUT);
One note: All of the above code assumes you're working with an ActionEvent. You might want to check out the TypedActionHandler interface to get notified when the editor text changes:
http://www.jetbrains.org/intellij/sdk/docs/tutorials/editor_basics/editor_events.html#handling-keystrokes-in-the-editor

How can I make qtcreator change the Project view when I open a new cpp file

There is this feature that IDEA IntelliJ has: when a new file is opened the Project tree (view) automatically jump to the file opened (handy when you follow a function defined in some other file).
I'd like to know if qtcreator provide this option
Surprised how hard it is to find the answer, since the button isn't hugely obvious.
The button you want is at the top of the Project pane, between "filter" and "split". Tooltip says "synchronize with editor".

In Intellij IDEA how to compare 2 text files that are not part of an open project

I would like to compare 2 files in intellij. Both files are not part of a specific project.
Is there a way to do so?
I am running Intellij 15 and 16.
The following works for me in IntelliJ IDEA Ultimate 14.1.7 on Windows:
Open the first file in the IDE (either by dragging from Windows Explorer into the window, or by File / Open).
In the view menu, choose "Compare With…"
In the "Select Path" dialog that appears, select the second file (either directly, or by dragging from Windows Explorer into the dialog).
It then opens up in the traditional file comparison pane. If you try to edit one of the files, it presents the usual "Are you sure you want to edit a file that's not in your project" dialog, which one can accept if that's what one is trying to do.
You can use the "compare with clipboard" feature.
From https://www.jetbrains.com/help/idea/2016.1/comparing-files.html#clipboard:
Comparing a File in the Editor with the Clipboard Contents
Open the desired file in the editor.
Right-click the editor pane and
choose Compare with Clipboard on the context menu.
View and manage
differences in the Differences Viewer for Files.
You can use intellij to compare 2 files/clipboard/blank text etc
Use command Shift+Command+A to search Actions
Type "Open Blank Diff Window" to compare random text
type diff for all diff options.
I use this on the command line (with IntelliJ IDEA CE on a Mac):
/Applications/IntelliJ\ IDEA\ CE.app/Contents/MacOS/idea diff ~/Junk/file1.txt ~/Junk/file2.txt
Window > Editor Tabs > Split Vertically
Is that what you're looking for? It's what I was looking for.
Worked for me on Mac OS High Sierra + IntelliJ IDEA 2018.3
- File -> Open
- Select file 1
- View -> Compare with ...
- Select file 2
To use intelli's difference comparison between 2 different files, you can use the Compare With (Right click the file in Project window). There is also an option to Compare File in Editor. To use that option, ensure one file is open and selected, then right click the 2nd file, clicking Compare File in Editor

IntelliJ IDEA - New Template

I'm trying to create a set of custom file templates for IntelliJ.
I basically want to go right-click, "New > My File Template" similar to the "New > Java Class" bundled with IntelliJ.
I've added my own custom file template via "Settings > File Templates", but they don't appear in my "New" context menu.
This is a Java project, and my templates extension is java. Am I missing something?
All help greatly appreciated.
No My Template >>>
If you select Java Class you can then choose the template for your new class. This is a new feature, it used to be available when selecting New.
Actually you can, sort of.
I don't know know how to do it for Java files. but
if you set the extension to txt you it will show up in the right click menu.
and here it is in the menu:
the only issue is if you're creating a java class you'll have to rename the file after creation to ${name}.java

VB.NET call desktop application from 2 shortcuts - supply different parameters

I have a desktop application which reads files from a specified folder, then deposits the files to a folder in a third party document management system based on criteria that the user provides.
My question is:
is it possible to somehow provide different parameters to the code, depending on which shortcut of the application the user clicked on to start it up?
You can add command line parameters to a shortcut icon. Here's how you can do it in Windows:
On the Start Menu, navigate to Notepad.
Right click on Notepad and choose Send To > Desktop (Create Shortcut)
Right click on the newly-created desktop icon and choose Properties
Add your command line parameters to the Target text box.
For example, if you want notepad to open up the hosts file, this would be the content of Target property:
%SystemRoot%\system32\notepad.exe "C:\WINDOWS\system32\drivers\etc\hosts"
You can put pretty much anything into the Target property of a shortcut that you would put into a command line.
Yes.
The easiest way would be to have the shortcut pass those parameters in via the command line.
You could also use conditional compilation variables, and have 2 different .exes. You should be able to find samples of both approaches (command line and conditional compilation variable) in help.