From e6856e0e7a6b0f67cda1c9edafeb2b836caeed02 Mon Sep 17 00:00:00 2001 From: Serge Baranov Date: Thu, 9 Feb 2012 21:15:19 +0400 Subject: [PATCH] File Encoding Macro (useful for external encoding converters, like iconv) --- .../intellij/ide/macro/FileEncodingMacro.java | 38 +++++++++++++++++++ .../com/intellij/ide/macro/MacroManager.java | 1 + .../application/options/PathMacrosImpl.java | 1 + .../src/messages/IdeBundle.properties | 1 + 4 files changed, 41 insertions(+) create mode 100644 platform/lang-impl/src/com/intellij/ide/macro/FileEncodingMacro.java diff --git a/platform/lang-impl/src/com/intellij/ide/macro/FileEncodingMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/FileEncodingMacro.java new file mode 100644 index 000000000000..bca25790a331 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/macro/FileEncodingMacro.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.intellij.ide.macro; + +import com.intellij.ide.IdeBundle; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.vfs.VirtualFile; + +public final class FileEncodingMacro extends Macro { + public String getName() { + return "FileEncoding"; + } + + public String getDescription() { + return IdeBundle.message("macro.file.encoding"); + } + + public String expand(DataContext dataContext) { + VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); + if (file == null) return null; + return file.getCharset().displayName(); + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java b/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java index 378ad9777bc3..e130ee2001cb 100644 --- a/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java +++ b/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java @@ -51,6 +51,7 @@ public final class MacroManager { registerMacro(new FileNameMacro()); registerMacro(new FileNameWithoutExtension()); registerMacro(new FilePathMacro()); + registerMacro(new FileEncodingMacro()); registerMacro(new FileDirRelativeToProjectRootMacro()); registerMacro(new FilePathRelativeToProjectRootMacro()); registerMacro(new FileDirRelativeToSourcepathMacro()); diff --git a/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java b/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java index 27e2c6448614..823588c76192 100644 --- a/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java +++ b/platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java @@ -104,6 +104,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, "/FileRelativeDir", "FileRelativePath", "/FileRelativePath", + "FileEncoding", "JavaDocPath", "JDKPath", "LineNumber", diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index a2613b7af5c5..f985fba72fd6 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -449,6 +449,7 @@ macro.file.directory.relative=File directory relative to the project file macro.file.directory.relative.fwd.slash=File directory relative to the project file (with forward slashes) macro.file.path.relative=File path relative to the project file macro.file.path.relative.fwd.slash=File path relative to the project file (with forward slashes) +macro.file.encoding=File encoding macro.javadoc.output.directory=JavaDoc output directory macro.jdk.path=JDK path macro.line.number=Line number