A confusing point in Visual Studio Code - visual-studio-code

I used to create my new html and css files easilt throught clicking file then clicking create new file before asking me about the required technology and usually select html or css but now I get confused because the options have been changed as they appear in the attached screenshoot,
now how can I create new html and css files ???
and what the difference between new text file and new file ?
My VS after the new update

Presumably, new text file will create a simple .txt file whereas New File will allow you to choose your desired language

Related

How do you create a .fxml file in vscode?

(I am very new to coding so let me know if any wording is too vague). I am using Visual Studio Code 1.67.2. I did not use Maven or any other similar tools, I just manually pointed the JavaFX lib folder to my project. I successfully was able to "connect" a css file to my main.java application by creating a .css file and then using scene.getStylesheets().addAll("Main.css"). However, I do not see fxml as an option in the language drop down like I did with css (I just see xml). How can I create a .fxml file? Every tutorial I can find already has a blank .fxml file in the project folder ready to be edited.
Scene Builder
The easiest solution is to download and use Scene Builder, which is a WYSIWYG editor for FXML files. It can create new FXML files for you, and you rarely, if ever, have to deal with editing the FXML file yourself. You just create the UI that you want, and Scene Builder will write the FXML file for you.
Create & Write FXML File Manually
There may be an VS Code extension for this, but I'm not currently aware of one. Though it is not hard to "manually" create an FXML file. Just go to create a new file, type in the name of the file, and then add a .fxml extension. You'll end up with a completely blank FXML file. Then you just need to add two things to make it a minimally valid FXML file:
An XML header.
A root element (with namespaces + any needed import instructions).
<!-- XML header -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- Add/remove/change import instructions as needed -->
<?import javafx.scene.layout.StackPane?>
<!-- Change root element type as needed -->
<StackPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml">
<!-- Define properties and rest of scene graph -->
</StackPane>
Note: Keep in mind that an FXML file is syntactically just an XML file.
And then you can continue to modify the FXML file as needed. It may help to read Introduction to FXML in order to understand what you're doing.
SceneBuilder
I agree with previous answer left by Slaw. And most specifically the part about getting SceneBuilder from Gluon. It'd be recommended. There really isn't a reason why you should need to edit the FXML file yourself. However, if you do need to generate a new FXML file and do not want to do it through the tools mentioned for whatever reason then you are free to create a file with the .fxml extension and modify it manually.
Ease of Use
In addition, for persons coming here new to VSCode, something else I recommend getting is the
Scene Builder extension, which streamlines navigation from VSCode to Scene Builder.
While this doesn't provide a whole lot more functionality it makes VSCode feel more similar to other Java editors.

VScode "linkedEditing" not working for php files

I want to be able to easily edit HTML tags together. There is a built-in option for this in Visual Studio Code.
It works fine for HTML files. Buy why not for php files?
Does anybody know a work-around?
For example, let's say I wanted to change this div into a section. It should automatically select both opening tag and the closing tag.
Assuming you have html inside a PHP file. The simplest solution would be:
double click the element to edit
Holding control key double click the closing element ( open and close elements should be highlighted now)
type to edit the element
For now VS Code doesn't handle PHP with editor.linkedEditing.
But you can install Auto Tag Rename extension which will work for PHP files as well.
The extension will ignore certain file types if editor.linkedEditing = true, so you can install it without any conflicts.

Alternative way of creating new file in VS Code?

When creating new file in VS Code, it just opens a blank empty file right away.
Is there a way to create a specific type of new file, like in Notepad++ you can choose the language for the file. In VS Code you get to choose the file extension only when saving the file for the first time.
It'd be a bit faster to create a new, for example, JavaScript file instead of creating empty file and saving it as .js file and then writing to it.
So far I've created files with basic Notepad (with the "show file extensions" option enabled from File Explorer) and when naming the new file, writing the extension at the end instead of .txt
You could just open the integrated terminal CTRL+`` and touch your file.
The keyboard shortcuts mentioned by #CountingStuff in this comment worked.
Here are the step-by-step instructions:
Create a new file:
Ctrl+N
Change the syntax language:
Ctrl+K M
In the drop down that appears, auto-complete or manually choose a language option.
The vscode documentation for this can be found here:
https://code.visualstudio.com/docs/languages/overview#_language-id
I've remapped my keyboard shortcuts so that CTRL+N triggers the "File > New File" menu item. Now, when I press CTRL+N it adds a new entry in the file explorer and I can add a new file from there. I can also utilise VSCode's file explorer creation mechanism to create files in subfolders by pre-fixing the file with the directory structure, so typing src\index.js will create a new file named index.js in the src directory.
Reference: https://www.youtube.com/watch?v=2QBYlfSQA6s

Change VSCode Default Language for new files?

Is there a way in Visual Studio Code to change the default language that is used for new files?
By default if you open a new file, it's set for "Plain Text", I want this to be "HTML" instead.
I am often copy pasting HTML into VSC, editing a bit, then copying it back to a CMS I am using (the CMS editor is horrible). I don't want to save the code on my computer at all, just edit it a bit with HTML syntax highlighting, but I want that to be the default.
You can now set the default language at either the user or workspace settings level using files.defaultLanguage:
"files.defaultLanguage": "html"
This can be done as a one off by changing the language mode:
F1 to launch command palette
Type lang, enter
Type html, enter
Now you can do this change. Check out
"files.defaultLanguage" in settings.
With v1.42 you can either set
"files.defaultLanguage": "${activeEditorLanguage}"
and when you open a new untitled file with an html file as the last active file, the new file will automatically be assigned a languageMode of HTML.
Alternatively, pasting any html code into a new untitled file from a vscode editor will automatically be detected and the languageMode set to HTML. Unless you have specifically set
"files.defaultLanguage": "plaintext"
then the languageMode will not be automatically detected as of v1.43.
Also see https://stackoverflow.com/a/68596936/836330 for a preview language detection feature in vscode 1.59.
A slightly quicker way to accomplish what Daniel had answered:
Press Ctrl+K, then M
Type html, then press Enter
I had a similar issue with VS Code. I wanted to default to Python when opening new files.
Solution: Click on File > Preferences > Settings. In the search area, Type: "files.defaultLanguage". Then fill in the language of your choice.
Perhaps you could create a scratch file with the .html extension? Open that when you need to do some copy/paste editing.

How to change open with options in navigator depending upon name of the resource?

I am working on eclipse RCP application which implements CommonNavigator view to display navigator. I have few LinkedResources in navigator that link to files on the file system with custom extension. These custom extension files are opened in custom editor as well as in TextEditor.
One of the file named default.ext will be common to all the projects and I want to keep it read only. Is it possible to open file in custom editor only? For ex. Default.ext should be opened in only custom editor, however Test.ext should be opened in custom editor as well as text editor.
This way I could handle save action in my editor depending upon file name and keep the file read only.
Is there any other way to keep files read only?
Short answer: not possible in the way you describe.
Long answer: if somebody really wants to modify a file then there's no way or need to stop this. What you can do is either (1) hide the file from user or (2) set Read-only flag to discourage users from modifying the file.