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 authored May 18, 2024
1 parent 03ea922 commit 0024c6b
Showing 1 changed file with 50 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,59 +218,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 0024c6b

Please sign in to comment.