Skip to content

Commit

Permalink
test: disable DropTarget in UserPromptTextArea in test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilKes committed May 18, 2024
1 parent 03ea922 commit 822c008
Showing 1 changed file with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -218,59 +219,61 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}));
if (isImageActionSupported()) {
iconsPanel.add(new IconActionButton(new AttachImageAction()));
setDropTarget(new DropTarget() {
@Override
public synchronized void dragEnter(DropTargetDragEvent evt) {
isDragActive = true;
var t = evt.getTransferable();
var isSupportedFile = false;
try {
List<File> files = (List<File>) t.getTransferData(
DataFlavor.javaFileListFlavor);
isSupportedFile = files.size() == 1
&& AttachImageAction.SUPPORTED_EXTENSIONS.contains(
FilenameUtils.getExtension(files.get(0).getName().toLowerCase()));
} catch (UnsupportedFlavorException | IOException | ClassCastException ex) {
LOG.debug("Unable to get image file list:", ex);
}
if (isSupportedFile) {
textArea.getEmptyText()
.setText(CodeGPTBundle.get("toolwindow.chat.textArea.drag.allowed"));
evt.acceptDrag(DnDConstants.ACTION_COPY);
} else {
textArea.getEmptyText()
.setText(CodeGPTBundle.get("toolwindow.chat.textArea.drag.notAllowed"));
evt.rejectDrag();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
setDropTarget(new DropTarget() {
@Override
public synchronized void dragEnter(DropTargetDragEvent evt) {
isDragActive = true;
var t = evt.getTransferable();
var isSupportedFile = false;
try {
List<File> files = (List<File>) t.getTransferData(
DataFlavor.javaFileListFlavor);
isSupportedFile = files.size() == 1
&& AttachImageAction.SUPPORTED_EXTENSIONS.contains(
FilenameUtils.getExtension(files.get(0).getName().toLowerCase()));
} catch (UnsupportedFlavorException | IOException | ClassCastException ex) {
LOG.debug("Unable to get image file list:", ex);
}
if (isSupportedFile) {
textArea.getEmptyText()
.setText(CodeGPTBundle.get("toolwindow.chat.textArea.drag.allowed"));
evt.acceptDrag(DnDConstants.ACTION_COPY);
} else {
textArea.getEmptyText()
.setText(CodeGPTBundle.get("toolwindow.chat.textArea.drag.notAllowed"));
evt.rejectDrag();
}
repaint();
}
repaint();
}

@Override
public synchronized void dragExit(DropTargetEvent dte) {
isDragActive = false;
resetEmptyText();
repaint();
}
@Override
public synchronized void dragExit(DropTargetEvent dte) {
isDragActive = false;
resetEmptyText();
repaint();
}

@Override
public synchronized void drop(DropTargetDropEvent evt) {
isDragActive = false;
resetEmptyText();
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
Transferable transferable = evt.getTransferable();
List<File> files = (List<File>) transferable.getTransferData(
DataFlavor.javaFileListFlavor);
if (files.size() != 1) {
return;
@Override
public synchronized void drop(DropTargetDropEvent evt) {
isDragActive = false;
resetEmptyText();
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
Transferable transferable = evt.getTransferable();
List<File> files = (List<File>) transferable.getTransferData(
DataFlavor.javaFileListFlavor);
if (files.size() != 1) {
return;
}
AttachImageAction.addImageAttachment(project, files.get(0).getAbsolutePath());
} catch (UnsupportedFlavorException | IOException | ClassCastException ex) {
LOG.error("Unable to drop image file:", ex);
}
AttachImageAction.addImageAttachment(project, files.get(0).getAbsolutePath());
} catch (UnsupportedFlavorException | IOException | ClassCastException ex) {
LOG.error("Unable to drop image file:", ex);
}
}
});
textArea.getDropTarget().setActive(false);
});
textArea.getDropTarget().setActive(false);
}
}
iconsPanel.add(stopButton);
add(iconsPanel, BorderLayout.EAST);
Expand Down

0 comments on commit 822c008

Please sign in to comment.