如何在 Intellij 中创建命名代码块?

发布于 2024-11-02 03:26:40 字数 143 浏览 0 评论 0原文

当 Intellij 为 UI 表单生成代码时,您可以折叠代码块,它被命名为:“UI Designer generated code”。可以折叠代码选择,但其折叠表示显示为“...”。是否可以给它一个自定义名称? 它看起来类似于 C# 中折叠的 #region 代码块。

When Intellij generates code for UI forms you can collapse the code block and it is named: "UI Designer generated code". It is possible to collapse a code selection but its collapsed representation is displayed as "...". Is it possible to give it a custom name?
It would look similar to a collapsed #region code block in C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

玻璃人 2024-11-09 03:26:40

他们现在已经实施了区域支持!

来自 http://youtrack.jetbrains.com/issue/IDEA-80636

目前 Intellij IDEA支持两种基本类型的自定义折叠注释:

类 NetBeans:

//<editor-fold desc="...">
... code ...
//</editor-fold>

和类 VisualStudio:

//region <...>
... code ...
//endregion

请注意,如果“#”字符为“region...endregion”,则行注释符号可以从“//”更改为“#”由某种语言支持。但默认情况下,自定义折叠注释使用与通常用于语言行注释的注释字符相同的注释字符。
在许多情况下,您可以使用 Ctrl+Alt+T(环绕),而不是手动输入注释。
如果您发现某些内容未按预期工作,请提交单独的问题。

They have implemented region-support now!

From http://youtrack.jetbrains.com/issue/IDEA-80636

Currently Intellij IDEA supports two basic types of custom folding comments:

NetBeans-like:

//<editor-fold desc="...">
... code ...
//</editor-fold>

And VisualStudio-like:

//region <...>
... code ...
//endregion

Note that line commenting symbols for "region...endregion" can be changed from "//" to "#" if the '#' character is supported by a language. But by default custom folding comments use the same comment characters as normally used for language line comments.
Instead of typing the comments manually, in many cases you can use Ctrl+Alt+T (surround with).
Please submit separate issues if you find that something doesn't work as expected.

伴随着你 2024-11-09 03:26:40

有一个快捷方式:

打开 Surround with 菜单,按

Linux/Windows:Ctrl +Alt+T

Mac: Option ⌥+Command ⌘+T

然后选择<编辑器折叠...>评论选项

在此处输入图像描述

或者您也可以手动执行此操作。

对于 Java/Scala 来说是:

//<editor-fold desc="DESCRIPTION">
   ___YOUR_CODE___
//</editor-fold>

对于 Python 来说几乎是一样的

# <editor-fold desc="DESCRIPTION">
   ___YOUR_CODE___
# </editor-fold>

示例:

//<editor-fold desc="Main">
public static void main(String[] args) {
    System.out.println("Hello World");
}
//</editor-fold>

There is a shortcut for that:

Open Surround with menu, by pressing

Linux/Windows: Ctrl +Alt+T

Mac: Option ⌥+Command ⌘+T

And than choose <editor-fold...> Comments option

enter image description here

Or you can do it manually.

For Java/Scala it is:

//<editor-fold desc="DESCRIPTION">
   ___YOUR_CODE___
//</editor-fold>

For Python it's almost the same

# <editor-fold desc="DESCRIPTION">
   ___YOUR_CODE___
# </editor-fold>

Example:

//<editor-fold desc="Main">
public static void main(String[] args) {
    System.out.println("Hello World");
}
//</editor-fold>
┊风居住的梦幻卍 2024-11-09 03:26:40

IDEA 尚无此类功能,请观看/投票链接的问题.

更新:此功能从 IDEA 11.1 版本开始可用。

IDEA doesn't have such feature yet, please watch/vote the linked issue.

UPDATE: this feature is available starting from IDEA 11.1 release.

偏爱自由 2024-11-09 03:26:40

您只需将 # 替换为 // ,如下所示:

//region Description

 ... Your Code ...

//endregion

You just need to replace # by // like below :

//region Description

 ... Your Code ...

//endregion
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文