Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
26,200
List<PsiElement> (final PropertiesPrefixGroup propertiesPrefixGroup) { return ContainerUtil.mapNotNull(propertiesPrefixGroup.getChildren(), treeElement -> { if (treeElement instanceof PropertyStructureViewElement) { return ((PropertyStructureViewElement)treeElement).getPsiElement(); } return null; }); }
getPsiElementsFromGroup
26,201
void (boolean showOnlyIncomplete) { myShowOnlyIncomplete = showOnlyIncomplete; }
setShowOnlyIncomplete
26,202
boolean () { return myShowOnlyIncomplete; }
isShowOnlyIncomplete
26,203
ResourceBundle () { return myResourceBundle.isValid() ? myResourceBundle : null; }
getValue
26,204
ItemPresentation () { return new ItemPresentation() { @Override public String getPresentableText() { return myResourceBundle.isValid() ? myResourceBundle.getBaseName() : null; } @Override public Icon getIcon(boolean open) { return AllIcons.FileTypes.Properties; } }; }
getPresentation
26,205
String () { return myResourceBundle.isValid() ? myResourceBundle.getBaseName() : null; }
getPresentableText
26,206
Icon (boolean open) { return AllIcons.FileTypes.Properties; }
getIcon
26,207
void (@NotNull final AnActionEvent e) { final Project project = getEventProject(e); if (project == null) { return; } ResourceBundleEditor resourceBundleEditor; final DataContext context = e.getDataContext(); FileEditor fileEditor = PlatformCoreDataKeys.FILE_EDITOR.getData(context); if (fileEditor instanceof ResourceBundleEditor) { resourceBundleEditor = (ResourceBundleEditor)fileEditor; } else { final Editor editor = CommonDataKeys.EDITOR.getData(context); resourceBundleEditor = editor != null ? editor.getUserData(ResourceBundleEditor.RESOURCE_BUNDLE_EDITOR_KEY) : null; } if (resourceBundleEditor == null) { for (FileEditor editor : FileEditorManager.getInstance(project).getSelectedEditors()) { if (editor instanceof ResourceBundleEditor) { resourceBundleEditor = (ResourceBundleEditor)editor; } } if (resourceBundleEditor == null) { return; } } final ResourceBundle bundle = resourceBundleEditor.getResourceBundle(); final VirtualFile file = bundle.getDefaultPropertiesFile().getVirtualFile(); final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(Collections.singletonList(file)); if (status.hasReadonlyFiles()) { Messages.showErrorDialog(bundle.getProject(), ResourceBundleEditorBundle.message("new.property.read.only.error.message", bundle.getBaseName()), ResourceBundleEditorBundle.message("already.exists.dialog.title")); return; } final String prefix; final String separator; final String place = e.getPlace(); if (ActionPlaces.STRUCTURE_VIEW_TOOLBAR.equals(place)) { prefix = null; separator = null; } else { final Object selectedElement = resourceBundleEditor.getSelectedElementIfOnlyOne(); if (selectedElement == null) { return; } if (selectedElement instanceof PropertiesPrefixGroup group) { prefix = group.getPrefix(); separator = group.getSeparator(); } else if (selectedElement instanceof PropertyStructureViewElement || selectedElement instanceof ResourceBundleFileStructureViewElement) { prefix = null; separator = null; } else { throw new IllegalStateException("unsupported type: " + selectedElement.getClass()); } } final ResourceBundlePropertiesUpdateManager propertiesUpdateManager = resourceBundleEditor.getPropertiesInsertDeleteManager(); final NewPropertyNameValidator nameValidator = new NewPropertyNameValidator(resourceBundleEditor, prefix, separator); final String keyToInsert; final IProperty anchor; IProperty selectedProperty = resourceBundleEditor.getSelectedProperty(); if (propertiesUpdateManager.isAlphaSorted() || !propertiesUpdateManager.isSorted() || selectedProperty == null) { keyToInsert = Messages.showInputDialog(project, ResourceBundleEditorBundle.message("new.property.dialog.name.prompt.text"), ResourceBundleEditorBundle.message("new.property.dialog.title"), Messages.getQuestionIcon(), selectedProperty == null ? getSelectedPrefixText(resourceBundleEditor) : null, nameValidator); anchor = null; } else { final Pair<String, Boolean> keyNameAndInsertPlaceModification = Messages.showInputDialogWithCheckBox(ResourceBundleEditorBundle.message("new.property.dialog.name.prompt.text"), ResourceBundleEditorBundle.message("new.property.dialog.title"), ResourceBundleEditorBundle.message("new.property.dialog.checkbox.text"), PropertiesComponent.getInstance().getBoolean(ADD_NEW_PROPERTY_AFTER_SELECTED_PROP, false), true, Messages.getQuestionIcon(), null, nameValidator); keyToInsert = keyNameAndInsertPlaceModification.getFirst(); final Boolean insertAfterSelectedProperty = keyNameAndInsertPlaceModification.getSecond(); PropertiesComponent.getInstance().setValue(ADD_NEW_PROPERTY_AFTER_SELECTED_PROP, insertAfterSelectedProperty, false); anchor = insertAfterSelectedProperty ? selectedProperty : null; } if (keyToInsert != null) { final ResourceBundlePropertiesUpdateManager updateManager = resourceBundleEditor.getPropertiesInsertDeleteManager(); final Runnable insertionAction = () -> { if (anchor == null) { updateManager.insertNewProperty(keyToInsert, ""); } else { final String anchorKey = anchor.getKey(); LOG.assertTrue(anchorKey != null); updateManager.insertAfter(keyToInsert, "", anchorKey); } }; ResourceBundleEditor finalResourceBundleEditor = resourceBundleEditor; ApplicationManager.getApplication().runWriteAction(() -> { WriteCommandAction.runWriteCommandAction(bundle.getProject(), ResourceBundleEditorBundle.message("action.NewPropertyAction.text"), null, insertionAction); finalResourceBundleEditor.flush(); }); resourceBundleEditor.updateTreeRoot(); resourceBundleEditor.getStructureViewComponent() .select(keyToInsert, false) .onProcessed(p -> finalResourceBundleEditor.selectProperty(keyToInsert)); } }
actionPerformed
26,208
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,209
void (@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null) { e.getPresentation().setEnabledAndVisible(false); return; } if (!myEnabledForce) { final FileEditor editor = e.getData(PlatformCoreDataKeys.FILE_EDITOR); e.getPresentation().setEnabledAndVisible(editor instanceof ResourceBundleEditor); } }
update
26,210
String (@NotNull ResourceBundleEditor resourceBundleEditor) { Object item = resourceBundleEditor.getSelectedElementIfOnlyOne(); if (item instanceof PropertiesPrefixGroup prefixGroup) { return prefixGroup.getPrefix() + prefixGroup.getSeparator(); } return null; }
getSelectedPrefixText
26,211
boolean (final String inputString) { return !inputString.isEmpty(); }
checkInput
26,212
boolean (final String inputString) { final String newPropertyName = myPrefix == null ? inputString : (myPrefix + mySeparator + inputString); final ResourceBundle resourceBundle = myResourceBundleEditor.getResourceBundle(); for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) { IProperty key = propertiesFile.findPropertyByKey(newPropertyName); if (key != null) { Messages.showErrorDialog(ResourceBundleEditorBundle.message("already.exists.warning.message", newPropertyName), ResourceBundleEditorBundle.message("new.property.action.text")); return false; } } return true; }
canClose
26,213
ActionGroup () { final DefaultActionGroup result = (DefaultActionGroup) super.createActionGroup(); result.add(new ContextHelpAction(getHelpID()), Constraints.LAST); return result; }
createActionGroup
26,214
void (@NotNull final DefaultActionGroup result) { super.addGroupByActions(result); result.add(createSettingsActionGroup()); result.add(new NewPropertyAction(true), Constraints.FIRST); }
addGroupByActions
26,215
ActionGroup () { DefaultActionGroup actionGroup = DefaultActionGroup.createPopupGroup(ResourceBundleEditorBundle.messagePointer("resource.bundle.editor.settings.action.title")); final Presentation presentation = actionGroup.getTemplatePresentation(); presentation.setIcon(AllIcons.General.GearPlain); actionGroup.add(new ResourceBundleEditorKeepEmptyValueToggleAction()); actionGroup.add(new ToggleAction(ResourceBundleEditorBundle.message("show.only.incomplete.action.text"), null, AllIcons.General.Error) { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.EDT; } @Override public boolean isSelected(@NotNull AnActionEvent e) { return ((ResourceBundleStructureViewModel)getTreeModel()).isShowOnlyIncomplete(); } @Override public void setSelected(@NotNull AnActionEvent e, boolean state) { ((ResourceBundleStructureViewModel)getTreeModel()).setShowOnlyIncomplete(state); rebuild(); } }); return actionGroup; }
createSettingsActionGroup
26,216
ActionUpdateThread () { return ActionUpdateThread.EDT; }
getActionUpdateThread
26,217
boolean (@NotNull AnActionEvent e) { return ((ResourceBundleStructureViewModel)getTreeModel()).isShowOnlyIncomplete(); }
isSelected
26,218
void (@NotNull AnActionEvent e, boolean state) { ((ResourceBundleStructureViewModel)getTreeModel()).setShowOnlyIncomplete(state); rebuild(); }
setSelected
26,219
void () { final DefaultActionGroup propertiesPopupGroup = new DefaultActionGroup(); propertiesPopupGroup.copyFromGroup((DefaultActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_STRUCTURE_VIEW_POPUP)); propertiesPopupGroup.add(Separator.getInstance(), Constraints.FIRST); propertiesPopupGroup.add(new NewPropertyAction(true), Constraints.FIRST); PopupHandler.installPopupMenu(getTree(), propertiesPopupGroup, IdeActions.GROUP_STRUCTURE_VIEW_POPUP); }
tunePopupActionGroup
26,220
Object (@NotNull String dataId) { if (ResourceBundle.ARRAY_DATA_KEY.is(dataId)) { return new ResourceBundle[]{myResourceBundle}; } else if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { DataProvider superProvider = (DataProvider)super.getData(dataId); JBIterable<Object> selection = JBIterable.of(getTree().getSelectionPaths()).map(TreeUtil::getLastUserObject); return CompositeDataProvider.compose(slowId -> getSlowData(slowId, selection, myResourceBundle), superProvider); } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) { return new DeleteProvider() { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.BGT; } @Override public void deleteElement(@NotNull DataContext dataContext) { PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext); if (selectedPsiElements == null) return; List<PsiFile> psiFiles = ContainerUtil.findAll(selectedPsiElements, PsiFile.class); DeleteProvider delegate; if (!psiFiles.isEmpty()) { delegate = new ResourceBundleDeleteProvider(); } else { IProperty[] properties = IProperty.ARRAY_KEY.getData(dataContext); if (properties != null && properties.length != 0) { delegate = new PropertiesDeleteProvider(((ResourceBundleEditor)getFileEditor()).getPropertiesInsertDeleteManager(), properties); } else { return; } } delegate.deleteElement(dataContext); } @Override public boolean canDeleteElement(@NotNull DataContext dataContext) { return CommonDataKeys.PROJECT.getData(dataContext) != null; } }; } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { return new CopyProvider() { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.BGT; } @Override public void performCopy(@NotNull DataContext dataContext) { PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext); if (selectedPsiElements != null) { List<String> names = new ArrayList<>(selectedPsiElements.length); for (PsiElement element : selectedPsiElements) { if (element instanceof PsiNamedElement) { names.add(((PsiNamedElement)element).getName()); } } CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n"))); } } @Override public boolean isCopyEnabled(@NotNull DataContext dataContext) { return true; } @Override public boolean isCopyVisible(@NotNull DataContext dataContext) { return true; } }; } return super.getData(dataId); }
getData
26,221
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,222
void (@NotNull DataContext dataContext) { PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext); if (selectedPsiElements == null) return; List<PsiFile> psiFiles = ContainerUtil.findAll(selectedPsiElements, PsiFile.class); DeleteProvider delegate; if (!psiFiles.isEmpty()) { delegate = new ResourceBundleDeleteProvider(); } else { IProperty[] properties = IProperty.ARRAY_KEY.getData(dataContext); if (properties != null && properties.length != 0) { delegate = new PropertiesDeleteProvider(((ResourceBundleEditor)getFileEditor()).getPropertiesInsertDeleteManager(), properties); } else { return; } } delegate.deleteElement(dataContext); }
deleteElement
26,223
boolean (@NotNull DataContext dataContext) { return CommonDataKeys.PROJECT.getData(dataContext) != null; }
canDeleteElement
26,224
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,225
void (@NotNull DataContext dataContext) { PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext); if (selectedPsiElements != null) { List<String> names = new ArrayList<>(selectedPsiElements.length); for (PsiElement element : selectedPsiElements) { if (element instanceof PsiNamedElement) { names.add(((PsiNamedElement)element).getName()); } } CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n"))); } }
performCopy
26,226
boolean (@NotNull DataContext dataContext) { return true; }
isCopyEnabled
26,227
boolean (@NotNull DataContext dataContext) { return true; }
isCopyVisible
26,228
boolean () { return false; }
showScrollToFromSourceActions
26,229
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,230
void (@NotNull final DataContext dataContext) { final List<PropertiesFile> bundlePropertiesFiles = myResourceBundle.getPropertiesFiles(); final List<PsiElement> toDelete = new ArrayList<>(); for (IProperty property : myProperties) { final String key = property.getKey(); if (key == null) { LOG.error("key must be not null " + property); } else { for (PropertiesFile propertiesFile : bundlePropertiesFiles) { for (final IProperty iProperty : propertiesFile.findPropertiesByKey(key)) { toDelete.add(iProperty.getPsiElement()); } } } } final Project project = CommonDataKeys.PROJECT.getData(dataContext); LOG.assertTrue(project != null); new SafeDeleteHandler().invoke(project, PsiUtilCore.toPsiElementArray(toDelete), dataContext); myInsertDeleteManager.reload(); }
deleteElement
26,231
boolean (@NotNull final DataContext dataContext) { return true; }
canDeleteElement
26,232
String () { return "editing.propertyFile.bundleEditor"; }
getHelpID
26,233
void (@NotNull AnActionEvent e) { final ResourceBundleEditor editor = (ResourceBundleEditor)e.getData(PlatformCoreDataKeys.FILE_EDITOR); LOG.assertTrue(editor != null); editor.selectNextIncompleteProperty(); }
actionPerformed
26,234
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,235
void (@NotNull AnActionEvent e) { e.getPresentation().setEnabled(e.getData(PlatformCoreDataKeys.FILE_EDITOR) instanceof ResourceBundleEditor); }
update
26,236
void (@NotNull String newName, @NotNull ResourceBundle targetResourceBundle, @NotNull ResourceBundle sourceResourceBundle, @NotNull Project project) { if (sourceResourceBundle.equals(targetResourceBundle)) { DataManager.getInstance() .getDataContextFromFocusAsync() .onSuccess(context -> { final FileEditor fileEditor = PlatformCoreDataKeys.FILE_EDITOR.getData(context); if (fileEditor instanceof ResourceBundleEditor resourceBundleEditor) { resourceBundleEditor.updateTreeRoot(); resourceBundleEditor.selectProperty(newName); } }); } else { for (FileEditor editor : FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(targetResourceBundle), true)) { ((ResourceBundleEditor) editor).updateTreeRoot(); ((ResourceBundleEditor) editor).selectProperty(newName); } } }
updateBundleEditors
26,237
void (@NotNull ProgressIndicator progress) { InspectionProfile profileToUse = InspectionProfileManager.getInstance().getCurrentProfile(); ResourceBundle rb = myEditor.getResourceBundle(); if (!rb.isValid()) return; final PsiFile containingFile = rb.getDefaultPropertiesFile().getContainingFile(); List<InspectionVisitorWrapper> visitors = new ArrayList<>(); HighlightDisplayKey unusedKey = HighlightDisplayKey.find(UnusedPropertyInspection.SHORT_NAME); if (profileToUse.isToolEnabled(unusedKey, containingFile)) { visitors.add(new InspectionVisitorWrapper( UnusedPropertyUtil.buildPropertyGroupVisitor(rb), profileToUse.getErrorLevel(unusedKey, containingFile).getSeverity(), unusedKey)); } HighlightDisplayKey incompleteKey = HighlightDisplayKey.find(IncompletePropertyInspection.TOOL_KEY); if (profileToUse.isToolEnabled(incompleteKey, containingFile)) { InspectionProfileEntry unwrappedTool = profileToUse.getUnwrappedTool(IncompletePropertyInspection.TOOL_KEY, containingFile); assert unwrappedTool != null; visitors.add(new InspectionVisitorWrapper( ((IncompletePropertyInspection)unwrappedTool).buildPropertyGroupVisitor(rb), profileToUse.getErrorLevel(incompleteKey, containingFile).getSeverity(), incompleteKey)); } final List<PropertiesFile> files = rb.getPropertiesFiles(); final Project project = rb.getProject(); final StructureViewModel model = myEditor.getStructureViewComponent().getTreeModel(); final Deque<TreeElement> queue = new ArrayDeque<>(1); queue.addLast(model.getRoot()); while (!queue.isEmpty()) { final TreeElement treeElement = queue.removeFirst(); if (treeElement instanceof PropertyBundleEditorStructureViewElement) { IProperty property = ((PropertyBundleEditorStructureViewElement)treeElement).getProperty(); if (property == null) continue; final String key = property.getKey(); if (key == null) continue; SortedSet<HighlightInfoType> highlightTypes = new TreeSet<>(Comparator.comparing(t -> t.getSeverity(null))); List<Pair<ResourceBundleEditorProblemDescriptor, HighlightDisplayKey>> allDescriptors = new SmartList<>(); final IProperty[] properties = files.stream().map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).toArray(IProperty[]::new); if (properties.length != 0) { for (InspectionVisitorWrapper v : visitors) { final ResourceBundleEditorProblemDescriptor[] problemDescriptors = v.getProblemVisitor().apply(properties); if (!ArrayUtil.isEmpty(problemDescriptors)) { final HighlightSeverity severity = v.getSeverity(); for (ResourceBundleEditorProblemDescriptor descriptor : problemDescriptors) { allDescriptors.add(Pair.create(descriptor, v.getKey())); final HighlightInfoType infoType = ProblemDescriptorUtil.getHighlightInfoType(descriptor.getHighlightType(), severity, SeverityRegistrar.getSeverityRegistrar(project)); highlightTypes.add(infoType); } } } ((PropertyBundleEditorStructureViewElement)treeElement).setInspectedPropertyProblems(allDescriptors.isEmpty() ? null : new InspectedPropertyProblems(allDescriptors.toArray(new Pair[0]), highlightTypes)); } } for (TreeElement element : treeElement.getChildren()) { queue.addLast(element); } } }
collectInformation
26,238
void () { myEditor.getStructureViewComponent().repaint(); }
applyInformationToEditor
26,239
HighlightSeverity () { return mySeverity; }
getSeverity
26,240
HighlightDisplayKey () { return myKey; }
getKey
26,241
ActionUpdateThread () { return ActionUpdateThread.BGT; }
getActionUpdateThread
26,242
boolean (@NotNull AnActionEvent e) { return keepEmptyProperties(); }
isSelected
26,243
void (@NotNull AnActionEvent e, boolean state) { PropertiesComponent.getInstance().setValue(SELECTION_KEY, state, true); }
setSelected
26,244
boolean () { return PropertiesComponent.getInstance().getBoolean(SELECTION_KEY, true); }
keepEmptyProperties
26,245
JPanel () { return myPanel; }
getComponent
26,246
void (TreeSelectionEvent e) { // filter out temp unselect/select events if (getSelectedElementIfOnlyOne() instanceof ResourceBundleFileStructureViewElement) { ((CardLayout)myValuesPanel.getLayout()).show(myValuesPanel, NO_PROPERTY_SELECTED); writePreviouslySelectedPropertyValue(e); selectedPropertiesFile = null; selectedProperty = null; return; } if (Comparing.equal(e.getNewLeadSelectionPath(), e.getOldLeadSelectionPath()) || getSelectedProperty() == null) return; if (!arePropertiesEquivalent(selectedProperty, getSelectedProperty()) || !Comparing.equal(selectedPropertiesFile, getSelectedPropertiesFile())) { writePreviouslySelectedPropertyValue(e); selectedProperty = getSelectedProperty(); selectedPropertiesFile = getSelectedPropertiesFile(); selectionChanged(); } }
valueChanged
26,247
void (TreeSelectionEvent e) { if (selectedProperty != null && e.getOldLeadSelectionPath() != null) { for (Map.Entry<VirtualFile, EditorEx> entry : myEditors.entrySet()) { if (entry.getValue() == mySelectedEditor) { writeEditorPropertyValue(selectedProperty.getName(), mySelectedEditor, entry.getKey()); break; } } } }
writePreviouslySelectedPropertyValue
26,248
boolean (@Nullable IProperty oldSelected, @Nullable IProperty newSelected) { if (oldSelected == newSelected) { return true; } if (oldSelected == null || newSelected == null) { return false; } final PsiElement oldPsiElement = oldSelected.getPsiElement(); if (!oldPsiElement.isValid()) { return false; } return oldPsiElement.isEquivalentTo(newSelected.getPsiElement()); }
arePropertiesEquivalent
26,249
void (@NotNull FileEditorManagerEvent event) { onSelectionChanged(event); }
selectionChanged
26,250
VirtualFile () { return myFile; }
getFile
26,251
ResourceBundle () { return myResourceBundle; }
getResourceBundle
26,252
void () { myStructureViewComponent.rebuild(); }
updateTreeRoot
26,253
ResourceBundlePropertiesUpdateManager () { return myPropertiesInsertDeleteManager; }
getPropertiesInsertDeleteManager
26,254
void (@NotNull FileEditorManagerEvent event) { if (!myResourceBundle.isValid()) return; // Ignore events which don't target current editor. FileEditor oldEditor = event.getOldEditor(); FileEditor newEditor = event.getNewEditor(); if (oldEditor != this && newEditor != this) { return; } // We want to sync selected property key on selection change. if (newEditor == this) { if (oldEditor instanceof TextEditor) { myPropertiesInsertDeleteManager.reload(); setStructureViewSelectionFromPropertiesFile(((TextEditor)oldEditor).getEditor()); } else if (myPropertyToSelectWhenVisible != null) { setStructureViewSelection(myPropertyToSelectWhenVisible); myPropertyToSelectWhenVisible = null; } } else if (newEditor instanceof TextEditor) { setPropertiesFileSelectionFromStructureView(((TextEditor)newEditor).getEditor()); } }
onSelectionChanged
26,255
void (@NotNull Editor propertiesFileEditor) { int line = propertiesFileEditor.getCaretModel().getLogicalPosition().line; Document document = propertiesFileEditor.getDocument(); if (line >= document.getLineCount()) { return; } final String propertyName = getPropertyName(document, line); if (propertyName == null) { return; } setStructureViewSelection(propertyName); }
setStructureViewSelectionFromPropertiesFile
26,256
void (@NotNull final String propertyName) { if (myStructureViewComponent.isDisposed()) { return; } JTree tree = myStructureViewComponent.getTree(); Object root = tree.getModel().getRoot(); if (isLoadingChildrenFor(root)) { boolean isEditorVisible = false; for (FileEditor editor : FileEditorManager.getInstance(myProject).getSelectedEditors()) { if (editor == this) { isEditorVisible = true; break; } } if (!isEditorVisible) { myPropertyToSelectWhenVisible = propertyName; return; } mySelectionChangeAlarm.cancelAllRequests(); mySelectionChangeAlarm.addRequest(() -> { mySelectionChangeAlarm.cancelAllRequests(); setStructureViewSelection(propertyName); }, 500); return; } Stack<TreeElement> toCheck = new Stack<>(); toCheck.push(myStructureViewComponent.getTreeModel().getRoot()); while (!toCheck.isEmpty()) { TreeElement element = toCheck.pop(); PsiElement value = element instanceof PropertyStructureViewElement ? ((PropertyStructureViewElement)element).getPsiElement() : null; final IProperty property = PropertiesImplUtil.getProperty(value); if (property != null && propertyName.equals(property.getUnescapedKey())) { myStructureViewComponent.select(property, true); selectionChanged(); return; } else { for (TreeElement treeElement : element.getChildren()) { toCheck.push(treeElement); } } } }
setStructureViewSelection
26,257
void () { myVfsListener.flush(); }
flush
26,258
boolean (Object nodeObject) { if (!(nodeObject instanceof DefaultMutableTreeNode node)) return false; int loadingNodes = 0; for (int i = 0; i < Math.min(node.getChildCount(), 2); i++) { TreeNode child = node.getChildAt(i); if (child instanceof LoadingNode) { loadingNodes++; } } return loadingNodes > 0 && loadingNodes == node.getChildCount(); }
isLoadingChildrenFor
26,259
String (@NotNull Document document, int line) { int startOffset = document.getLineStartOffset(line); int endOffset = StringUtil.indexOf(document.getCharsSequence(), '=', startOffset, document.getLineEndOffset(line)); if (endOffset <= startOffset) { return null; } String propertyName = document.getCharsSequence().subSequence(startOffset, endOffset).toString().trim(); return propertyName.isEmpty() ? null : propertyName; }
getPropertyName
26,260
void (@NotNull Editor propertiesFileEditor) { String selectedPropertyName = getSelectedPropertyName(); if (selectedPropertyName == null) { return; } Document document = propertiesFileEditor.getDocument(); for (int i = 0; i < document.getLineCount(); i++) { String propertyName = getPropertyName(document, i); if (selectedPropertyName.equals(propertyName)) { propertiesFileEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(i, 0)); return; } } }
setPropertiesFileSelectionFromStructureView
26,261
void (final @Nullable String propertyName, final @NotNull Editor editor, final @NotNull VirtualFile file) { final String currentValue = editor.getDocument().getText(); final String currentSelectedProperty = propertyName == null ? getSelectedPropertyName() : propertyName; if (currentSelectedProperty == null) { return; } if (!FileModificationService.getInstance().prepareVirtualFilesForWrite(myProject, Collections.singleton(file))) { return; } WriteAction.run(() -> WriteCommandAction.runWriteCommandAction(myProject, ResourceBundleEditorBundle.message( "resource.bundle.update.property.value"), null, () -> { PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file, myProject); if (propertiesFile != null) { if (currentValue.isEmpty() && ResourceBundleEditorKeepEmptyValueToggleAction.keepEmptyProperties() && !file.equals(myResourceBundle.getDefaultPropertiesFile().getVirtualFile())) { myPropertiesInsertDeleteManager.deletePropertyIfExist(currentSelectedProperty, propertiesFile); } else { myPropertiesInsertDeleteManager.insertOrUpdateTranslation(currentSelectedProperty, currentValue, propertiesFile); } } })); }
writeEditorPropertyValue
26,262
void () { super.updateUI(); getViewport().setBackground(UIUtil.getPanelBackground()); }
updateUI
26,263
void (KeyEvent e) { if (editor.isViewer()) { editor.setViewer(ReadonlyStatusHandler.getInstance(myProject) .ensureFilesWritable(Collections.singletonList(propertiesFile.getVirtualFile())).hasReadonlyFiles()); } }
keyTyped
26,264
void (@NotNull final Editor editor) { mySelectedEditor = editor; }
focusGained
26,265
void (@NotNull final Editor editor) { if (!editor.isViewer() && propertiesFile.getContainingFile().isValid()) { writeEditorPropertyValue(null, editor, propertiesFile.getVirtualFile()); myVfsListener.flush(); } }
focusLost
26,266
Dimension () { Insets insets = getBorder().getBorderInsets(this); return new Dimension(100,editor.getLineHeight()*4+ insets.top + insets.bottom); }
getPreferredSize
26,267
String (@Nullable final IProperty property) { if (property == null) { return ""; } else { String rawValue = property.getValue(); return rawValue == null ? "" : PropertiesResourceBundleUtil.fromPropertyValueToValueEditor(rawValue); } }
getPropertyEditorValue
26,268
ResourceBundleEditorFileListener () { final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); ResourceBundleEditorFileListener myVfsListener = new ResourceBundleEditorFileListener(this); virtualFileManager.addVirtualFileListener(myVfsListener, this); PsiTreeChangeAdapter psiTreeChangeAdapter = new PsiTreeChangeAdapter() { @Override public void childAdded(@NotNull PsiTreeChangeEvent event) { final PsiFile file = event.getFile(); if (file instanceof XmlFile) { final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file); if (propertiesFile != null) { final ResourceBundle bundle = propertiesFile.getResourceBundle(); if (bundle.equals(myResourceBundle) && !myEditors.containsKey(propertiesFile.getVirtualFile())) { recreateEditorsPanel(); } } } } @Override public void childRemoved(@NotNull PsiTreeChangeEvent event) { final PsiFile file = event.getFile(); final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file); if (propertiesFile != null) { final ResourceBundle bundle = propertiesFile.getResourceBundle(); if (bundle.equals(myResourceBundle) && myEditors.containsKey(propertiesFile.getVirtualFile())) { final IProperty property = PropertiesImplUtil.getProperty(event.getParent()); if (property != null && Objects.equals(property.getName(), getSelectedPropertyName())) { updateEditorsFromProperties(false); } } } } }; PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiTreeChangeAdapter, this); return myVfsListener; }
installPropertiesChangeListeners
26,269
void (@NotNull PsiTreeChangeEvent event) { final PsiFile file = event.getFile(); if (file instanceof XmlFile) { final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file); if (propertiesFile != null) { final ResourceBundle bundle = propertiesFile.getResourceBundle(); if (bundle.equals(myResourceBundle) && !myEditors.containsKey(propertiesFile.getVirtualFile())) { recreateEditorsPanel(); } } } }
childAdded
26,270
void (@NotNull PsiTreeChangeEvent event) { final PsiFile file = event.getFile(); final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file); if (propertiesFile != null) { final ResourceBundle bundle = propertiesFile.getResourceBundle(); if (bundle.equals(myResourceBundle) && myEditors.containsKey(propertiesFile.getVirtualFile())) { final IProperty property = PropertiesImplUtil.getProperty(event.getParent()); if (property != null && Objects.equals(property.getName(), getSelectedPropertyName())) { updateEditorsFromProperties(false); } } } }
childRemoved
26,271
void () { myBackSlashPressed.clear(); UIUtil.invokeLaterIfNeeded(() -> { updateEditorsFromProperties(true); final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); if (statusBar != null) { statusBar.setInfo(ResourceBundleEditorBundle.message("status.bar.selection.changed.message", getSelectedPropertyName())); } }); }
selectionChanged
26,272
void (final String value, final Document document, final VirtualFile propertiesFile) { @NonNls String text = myBackSlashPressed.contains(propertiesFile) ? value + "\\" : value; UndoUtil.disableUndoIn(document, () -> document.replaceString(0, document.getTextLength(), text)); }
updateDocumentFromPropertyValue
26,273
JBIterable<Object> () { if (!isValid()) { return JBIterable.empty(); } JTree tree = myStructureViewComponent.getTree(); return JBIterable.of(tree.getSelectionModel().getSelectionPaths()) .map(TreeUtil::getLastUserObject); }
getSelectedNodes
26,274
String () { final IProperty selectedProperty = getSelectedProperty(); return selectedProperty == null ? null : selectedProperty.getName(); }
getSelectedPropertyName
26,275
Collection<ResourceBundleEditorViewElement> () { return getSelectedNodes() .filter(AbstractTreeNode.class) .filterMap(AbstractTreeNode::getValue) .filter(ResourceBundleEditorViewElement.class) .toList(); }
getSelectedElements
26,276
Collection<Object> () { return getSelectedNodes() .filter(AbstractTreeNode.class) .filterMap(AbstractTreeNode::getValue) .toList(); }
getSelectedObjects
26,277
Object () { final Collection<Object> selectedElements = getSelectedObjects(); return selectedElements.size() == 1 ? ContainerUtil.getFirstItem(selectedElements) : null; }
getSelectedElementIfOnlyOne
26,278
void () { if (getSelectedNodes().size() != 1) { return; } final IProperty selectedProperty = getSelectedProperty(); if (selectedProperty == null) { return; } final ResourceBundleFileStructureViewElement root = (ResourceBundleFileStructureViewElement)myStructureViewComponent.getTreeModel().getRoot(); final Set<String> propertyKeys = ResourceBundleFileStructureViewElement.getPropertiesMap(myResourceBundle, root.isShowOnlyIncomplete()).keySet(); final boolean isAlphaSorted = myStructureViewComponent.isActionActive(Sorter.ALPHA_SORTER_ID); List<String> keysOrder = isAlphaSorted ? ContainerUtil.sorted(propertyKeys) : new ArrayList<>(propertyKeys); final String currentKey = selectedProperty.getKey(); final int idx = keysOrder.indexOf(currentKey); LOG.assertTrue(idx != -1); final IncompletePropertyInspection incompletePropertyInspection = IncompletePropertyInspection.getInstance(myResourceBundle.getDefaultPropertiesFile().getContainingFile()); for (int i = 1; i < keysOrder.size(); i++) { int trimmedIndex = (i + idx) % keysOrder.size(); final String key = keysOrder.get(trimmedIndex); if (!incompletePropertyInspection.isPropertyComplete(key, myResourceBundle)) { selectProperty(key); return; } } }
selectNextIncompleteProperty
26,279
JComponent () { return myDataProviderPanel; }
getComponent
26,280
StructureViewComponent () { return myStructureViewComponent; }
getStructureViewComponent
26,281
Object (@NotNull String dataId) { if (SelectInContext.DATA_KEY.is(dataId)) { VirtualFile file = getSelectedPropertiesFile(); return file == null ? null : new FileSelectInContext(myProject, file); } return null; }
getData
26,282
VirtualFile () { if (mySelectedEditor == null) return null; VirtualFile selectedFile = null; for (Map.Entry<VirtualFile, EditorEx> entry : myEditors.entrySet()) { Editor editor = entry.getValue(); if (editor == mySelectedEditor) { selectedFile = entry.getKey(); break; } } return selectedFile; }
getSelectedPropertiesFile
26,283
JComponent () { return myStructureViewPanel; }
getPreferredFocusedComponent
26,284
String () { return ResourceBundleEditorBundle.message("resource.bundle.editor.title"); }
getName
26,285
ResourceBundleEditorState (@NotNull FileEditorStateLevel level) { return new ResourceBundleEditorState(getSelectedPropertyName()); }
getState
26,286
void (@Nullable final String propertyName) { if (propertyName != null) { setStructureViewSelection(propertyName); } }
selectProperty
26,287
void (@NotNull FileEditorState state) { selectProperty(((ResourceBundleEditorState)state).getPropertyName()); }
setState
26,288
boolean () { return false; }
isModified
26,289
boolean () { return !myDisposed && !myProject.isDisposed(); }
isValid
26,290
void () { final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); if (statusBar != null) { statusBar.setInfo(""); } }
deselectNotify
26,291
void (@NotNull PropertyChangeListener listener) { }
addPropertyChangeListener
26,292
void (@NotNull PropertyChangeListener listener) { }
removePropertyChangeListener
26,293
BackgroundEditorHighlighter () { return myHighlighter; }
getBackgroundHighlighter
26,294
void () { if (mySelectedEditor != null) { for (final Map.Entry<VirtualFile, EditorEx> entry : myEditors.entrySet()) { if (mySelectedEditor.equals(entry.getValue())) { writeEditorPropertyValue(null, mySelectedEditor, entry.getKey()); } } } myDisposed = true; Disposer.dispose(myStructureViewComponent); releaseAllEditors(); }
dispose
26,295
void () { for (final Editor editor : myEditors.values()) { if (!editor.isDisposed()) { EditorFactory.getInstance().releaseEditor(editor); } } myEditors.clear(); }
releaseAllEditors
26,296
boolean (@NotNull FileEditorState otherState, @NotNull FileEditorStateLevel level) { return false; }
canBeMergedWith
26,297
String () { return myPropertyName; }
getPropertyName
26,298
EditorEx () { EditorFactory editorFactory = EditorFactory.getInstance(); Document document = editorFactory.createDocument(""); EditorEx editor = (EditorEx)editorFactory.createEditor(document); reinitSettings(editor); editor.putUserData(RESOURCE_BUNDLE_EDITOR_KEY, this); return editor; }
createEditor
26,299
void (final EditorEx editor) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); editor.setColorsScheme(scheme); editor.setBorder(BorderFactory.createLineBorder(JBColor.border(), 1)); EditorSettings settings = editor.getSettings(); settings.setLineNumbersShown(false); settings.setWhitespacesShown(false); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setFoldingOutlineShown(false); settings.setAdditionalColumnsCount(0); settings.setAdditionalLinesCount(0); settings.setRightMarginShown(true); settings.setRightMargin(60); settings.setVirtualSpace(false); editor.setHighlighter(new LexerEditorHighlighter(new PropertiesValueHighlighter(), scheme)); editor.setVerticalScrollbarVisible(true); editor.installPopupHandler(new ContextMenuPopupHandler() { @Override public ActionGroup getActionGroup(@NotNull EditorMouseEvent event) { DefaultActionGroup group = new DefaultActionGroup(); group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_CUT_COPY_PASTE)); group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.ACTION_EDIT_SOURCE)); group.addSeparator(); group.add(new AnAction(ResourceBundleEditorBundle.messagePointer("action.PropagateValue.text")) { @Override public void actionPerformed(@NotNull AnActionEvent e) { final String valueToPropagate = editor.getDocument().getText(); final String currentSelectedProperty = getSelectedPropertyName(); if (currentSelectedProperty == null) { return; } ApplicationManager.getApplication().runWriteAction(() -> WriteCommandAction.runWriteCommandAction(myProject, ResourceBundleEditorBundle.message("action.PropagateValue.text"), null, () -> { try { final PropertiesFile[] propertiesFiles = myResourceBundle.getPropertiesFiles().stream().filter(f -> { final IProperty property = f.findPropertyByKey(currentSelectedProperty); return property == null || !valueToPropagate.equals(property.getValue()); }).toArray(PropertiesFile[]::new); final PsiFile[] filesToPrepare = Arrays.stream(propertiesFiles).map(PropertiesFile::getContainingFile).toArray(PsiFile[]::new); if (FileModificationService.getInstance().preparePsiElementsForWrite(filesToPrepare)) { for (PropertiesFile file : propertiesFiles) { myPropertiesInsertDeleteManager.insertOrUpdateTranslation(currentSelectedProperty, valueToPropagate, file); } recreateEditorsPanel(); } } catch (final IncorrectOperationException e1) { LOG.error(e1); } })); } }); return group; } }); }
reinitSettings