private void createUIComponents() { myRepositoryURL = new EditorComboBox(""); final GitRememberedInputs rememberedInputs = GitRememberedInputs.getInstance(); myRepositoryURL.setHistory( ArrayUtil.toObjectArray(rememberedInputs.getVisitedUrls(), String.class)); myRepositoryURL.addDocumentListener( new com.intellij.openapi.editor.event.DocumentAdapter() { @Override public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) { // enable test button only if something is entered in repository URL final String url = getCurrentUrlText(); myTestButton.setEnabled(url.length() != 0); if (myDefaultDirectoryName.equals(myDirectoryName.getText()) || myDirectoryName.getText().length() == 0) { // modify field if it was unmodified or blank myDefaultDirectoryName = defaultDirectoryName(url); myDirectoryName.setText(myDefaultDirectoryName); } updateButtons(); } }); }
public void prependToHistory(final String item) { myRepositoryURL.prependItem(item); }
private String getCurrentUrlText() { return myRepositoryURL.getText().trim(); }
public void setData( final Project project, final PsiDirectory initialTargetDirectory, final Pass<String> errorMessageUpdater, final EditorComboBox editorComboBox) { myInitialTargetDirectory = initialTargetDirectory; mySourceRoots = ProjectRootManager.getInstance(project).getContentSourceRoots(); new ComboboxSpeedSearch(getComboBox()) { @Override protected String getElementText(Object element) { if (element == NULL_WRAPPER) return LEAVE_IN_SAME_SOURCE_ROOT; if (element instanceof DirectoryChooser.ItemWrapper) { final VirtualFile virtualFile = ((DirectoryChooser.ItemWrapper) element).getDirectory().getVirtualFile(); final Module module = ModuleUtil.findModuleForFile(virtualFile, project); if (module != null) { return module.getName(); } } return super.getElementText(element); } }; final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); getComboBox() .setRenderer( new ListCellRendererWrapper<DirectoryChooser.ItemWrapper>(getComboBox().getRenderer()) { @Override public void customize( JList list, DirectoryChooser.ItemWrapper itemWrapper, int index, boolean selected, boolean hasFocus) { if (itemWrapper != NULL_WRAPPER && itemWrapper != null) { setIcon(itemWrapper.getIcon(fileIndex)); setText(itemWrapper.getRelativeToProjectPath()); } else { setText(LEAVE_IN_SAME_SOURCE_ROOT); } } }); final VirtualFile initialSourceRoot = initialTargetDirectory != null ? fileIndex.getSourceRootForFile(initialTargetDirectory.getVirtualFile()) : null; final VirtualFile[] selection = new VirtualFile[] {initialSourceRoot}; addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualFile root = MoveClassesOrPackagesUtil.chooseSourceRoot( new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), mySourceRoots, initialTargetDirectory); if (root == null) return; final ComboBoxModel model = getComboBox().getModel(); for (int i = 0; i < model.getSize(); i++) { DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper) model.getElementAt(i); if (item != NULL_WRAPPER && fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()) == root) { getComboBox().setSelectedItem(item); getComboBox().repaint(); return; } } setComboboxModel( getComboBox(), root, root, fileIndex, mySourceRoots, project, true, errorMessageUpdater); } }); editorComboBox.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { JComboBox comboBox = getComboBox(); DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem(); setComboboxModel( comboBox, selectedItem != null && selectedItem != NULL_WRAPPER ? fileIndex.getSourceRootForFile(selectedItem.getDirectory().getVirtualFile()) : initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater); } }); setComboboxModel( getComboBox(), initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater); getComboBox() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selectedItem = getComboBox().getSelectedItem(); updateErrorMessage(errorMessageUpdater, fileIndex, selectedItem); if (selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) { PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory(); if (directory != null) { selection[0] = fileIndex.getSourceRootForFile(directory.getVirtualFile()); } } } }); }