mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support opening projects by dragging files/folders on welcome screen
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user