support opening projects by dragging files/folders on welcome screen

This commit is contained in:
Dennis Ushakov
2018-07-13 19:04:38 +01:00
parent 6b2e648da0
commit e31af6ccca
2 changed files with 48 additions and 22 deletions
@@ -112,28 +112,7 @@ public class MacOSApplicationProvider {
List<File> list = event.getFiles();
if (list.isEmpty()) return;
submit("OpenFile", () -> {
for (File file : list) {
if (ProjectUtil.openOrImport(file.getAbsolutePath(), project, true) != null) {
LOG.debug("MacMenu: load project from ", file);
IdeaApplication.getInstance().disableProjectLoad();
return;
}
}
for (File file : list) {
if (file.exists()) {
LOG.debug("MacMenu: open file ", file);
String path = file.getAbsolutePath();
if (project != null) {
OpenFileAction.openFile(path, project);
} else {
PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
if (processor != null) {
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (virtualFile != null && virtualFile.isValid()) processor.doOpenProject(virtualFile, null, false);
}
}
}
}
tryOpenFileList( project, list, "MacMenu");
});
});
installAutoUpdateMenu();
@@ -208,4 +187,34 @@ public class MacOSApplicationProvider {
}
}
}
public static boolean tryOpenFileList(Project project, List<File> list, String location) {
for (File file : list) {
if (ProjectUtil.openOrImport(file.getAbsolutePath(), project, true) != null) {
LOG.debug(location + ": load project from ", file);
IdeaApplication.getInstance().disableProjectLoad();
return true;
}
}
boolean result = false;
for (File file : list) {
if (file.exists()) {
LOG.debug(location + ": open file ", file);
String path = file.getAbsolutePath();
if (project != null) {
OpenFileAction.openFile(path, project);
result = true;
} else {
PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
if (processor != null) {
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (virtualFile != null && virtualFile.isValid()) {
result |= processor.doOpenProject(virtualFile, null, false) != null;
}
}
}
}
}
return result;
}
}
@@ -5,7 +5,9 @@ import com.intellij.diagnostic.IdeMessagePanel;
import com.intellij.diagnostic.MessagePool;
import com.intellij.icons.AllIcons;
import com.intellij.ide.DataManager;
import com.intellij.ide.MacOSApplicationProvider;
import com.intellij.ide.RecentProjectsManager;
import com.intellij.ide.dnd.FileCopyPasteUtil;
import com.intellij.notification.NotificationType;
import com.intellij.notification.impl.IdeNotificationArea;
import com.intellij.openapi.Disposable;
@@ -259,6 +261,21 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
}
}
add(createBody(), BorderLayout.CENTER);
setTransferHandler(new TransferHandler(null) {
@Override
public boolean canImport(TransferSupport support) {
return true;
}
@Override
public boolean importData(TransferSupport support) {
List<File> list = FileCopyPasteUtil.getFileList(support.getTransferable());
if (list != null && list.size() > 0) {
return MacOSApplicationProvider.tryOpenFileList(null, list, "WelcomeFrame");
}
return false;
}
});
TouchbarDataKeys.putActionDescriptor(myTouchbarActions).setShowText(true);
}