mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup: use lazy value and extract value into properties bundle for 'New Scratch File' action (IDEA-CR-44459)
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -56,7 +57,9 @@ public class ScratchFileActions {
|
||||
|
||||
private static final String ACTION_ID = "NewScratchFile";
|
||||
|
||||
private String myActionText;
|
||||
private NotNullLazyValue<String> myActionText = NotNullLazyValue.createValue(
|
||||
() -> NewActionGroup.isActionInNewPopupMenu(this) ? ActionsBundle.actionText(ACTION_ID) : ActionsBundle.message("action.NewScratchFile.text.with.new")
|
||||
);
|
||||
|
||||
public NewFileAction() {
|
||||
getTemplatePresentation().setIcon(ICON);
|
||||
@@ -64,7 +67,7 @@ public class ScratchFileActions {
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
getTemplatePresentation().setText(getActionText());
|
||||
getTemplatePresentation().setText(myActionText.getValue());
|
||||
|
||||
Project project = e.getProject();
|
||||
String place = e.getPlace();
|
||||
@@ -93,24 +96,17 @@ public class ScratchFileActions {
|
||||
consumer.consume(context.language);
|
||||
}
|
||||
else {
|
||||
LRUPopupBuilder.forFileLanguages(project, "New " + ActionsBundle.actionText(ACTION_ID), null, consumer).showCenteredInCurrentWindow(project);
|
||||
LRUPopupBuilder.forFileLanguages(project, ActionsBundle.message("action.NewScratchFile.text.with.new"), null, consumer).showCenteredInCurrentWindow(project);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePresentationTextAndIcon(@NotNull AnActionEvent e, @NotNull Presentation presentation) {
|
||||
presentation.setText(getActionText());
|
||||
presentation.setText(myActionText.getValue());
|
||||
presentation.setIcon(ICON);
|
||||
if (ActionPlaces.MAIN_MENU.equals(e.getPlace()) && !NewActionGroup.isActionInNewPopupMenu(this)) {
|
||||
presentation.setIcon(null);
|
||||
}
|
||||
}
|
||||
|
||||
private String getActionText() {
|
||||
if (myActionText == null) {
|
||||
myActionText = (NewActionGroup.isActionInNewPopupMenu(this) ? "" : "New ") + ActionsBundle.actionText(ACTION_ID);
|
||||
}
|
||||
return myActionText;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NewBufferAction extends DumbAwareAction {
|
||||
|
||||
@@ -642,6 +642,7 @@ action.Unscramble.description=Open console with the navigatable stack trace
|
||||
action.IdeScriptingConsole.text=IDE Scripting Console
|
||||
action.IdeScriptingConsole.description=Open IDE scripting console
|
||||
action.NewScratchFile.text=Scratch File
|
||||
action.NewScratchFile.text.with.new=New Scratch File
|
||||
action.NewScratchFile.description=Creates new scratch file with chosen language
|
||||
action.NewScratchBuffer.text=New Scratch Buffer
|
||||
action.NewScratchBuffer.description=Creates new or reuses existing scratch buffer
|
||||
|
||||
Reference in New Issue
Block a user