From 25aec994eb6d9ba9b0cc176f43dc6acf9411ccd8 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Thu, 14 Feb 2013 13:30:19 +0400 Subject: [PATCH] Add FileDirName and FileParentDir macros --- .../intellij/ide/macro/FileDirNameMacro.java | 36 ++++++++++++++++++ .../ide/macro/FileParentDirMacro.java | 38 +++++++++++++++++++ .../com/intellij/ide/macro/MacroManager.java | 2 + .../src/messages/IdeBundle.properties | 2 + .../application/options/PathMacrosImpl.java | 2 + 5 files changed, 80 insertions(+) create mode 100644 platform/lang-impl/src/com/intellij/ide/macro/FileDirNameMacro.java create mode 100644 platform/lang-impl/src/com/intellij/ide/macro/FileParentDirMacro.java diff --git a/platform/lang-impl/src/com/intellij/ide/macro/FileDirNameMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/FileDirNameMacro.java new file mode 100644 index 000000000000..03d02a349792 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/macro/FileDirNameMacro.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2013 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.vfs.VirtualFile; + +public final class FileDirNameMacro extends Macro { + public String getName() { + return "FileDirName"; + } + + public String getDescription() { + return IdeBundle.message("macro.file.directory.name"); + } + + public String expand(DataContext dataContext) { + VirtualFile vFile = getVirtualDirOrParent(dataContext); + return vFile != null ? vFile.getName() : null; + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/macro/FileParentDirMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/FileParentDirMacro.java new file mode 100644 index 000000000000..30aa840963de --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/macro/FileParentDirMacro.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2013 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.vfs.VirtualFile; + +public class FileParentDirMacro extends Macro { + public String getName() { + return "FileParentDir"; + } + + public String getDescription() { + return IdeBundle.message("macro.file.parent.directory"); + } + + public String expand(DataContext dataContext) { + VirtualFile vFile = getVirtualDirOrParent(dataContext); + if(vFile != null) { + vFile = vFile.getParent(); + } + return vFile != null ? getPath(vFile) : null; + } +} 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 d9ac7f5f9bba..db2eddd259aa 100644 --- a/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java +++ b/platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java @@ -46,6 +46,8 @@ public final class MacroManager { private MacroManager() { registerMacro(new SourcepathMacro()); registerMacro(new FileDirMacro()); + registerMacro(new FileDirNameMacro()); + registerMacro(new FileParentDirMacro()); registerMacro(new FileExtMacro()); registerMacro(new FileNameMacro()); registerMacro(new FileNameWithoutExtension()); diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 4966ff1e5851..acc6eacc58e1 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -435,6 +435,8 @@ macro.column.number=Column number exception.missing.data=No data: {0} macro.class.name=Class name macro.file.directory=File directory +macro.file.directory.name=File directory name +macro.file.parent.directory=File parent directory macro.file.dir.relative.to.root=File dir relative to the module content root the file belongs to macro.file.dir.relative.to.root.fwd.slash=File dir relative to the module content root the file belongs to (with forward slashes) macro.file.dir.relative.to.sourcepath.root=File dir relative to the sourcepath root the file belongs to diff --git a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java index de72e2f9ed2c..805f977803d2 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java +++ b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java @@ -85,6 +85,8 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, "ColumnNumber", "FileClass", "FileDir", + "FileParentDir", + "FileDirName", "FileDirRelativeToProjectRoot", "/FileDirRelativeToProjectRoot", "FileDirRelativeToSourcepath",