Add FileDirName and FileParentDir macros

This commit is contained in:
Fedor Korotkov
2013-02-14 13:31:25 +04:00
parent ecfd5acf5e
commit 25aec994eb
5 changed files with 80 additions and 0 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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());
@@ -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
@@ -85,6 +85,8 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
"ColumnNumber",
"FileClass",
"FileDir",
"FileParentDir",
"FileDirName",
"FileDirRelativeToProjectRoot",
"/FileDirRelativeToProjectRoot",
"FileDirRelativeToSourcepath",