Fixed dragging mod files to UI

This commit is contained in:
huangyuhui
2017-02-09 12:59:09 +08:00
parent 6fe451c247
commit f6bdb986dd

View File

@@ -91,6 +91,8 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
void initGui() { void initGui() {
initComponents(); initComponents();
dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F")); setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"));
setOpaque(true); setOpaque(true);
@@ -110,8 +112,6 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
Settings.profileLoadingEvent.register(onLoadingProfiles); Settings.profileLoadingEvent.register(onLoadingProfiles);
Settings.profileChangedEvent.register(onSelectedProfilesChanged); Settings.profileChangedEvent.register(onSelectedProfilesChanged);
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
} }
void initExplorationMenu() { void initExplorationMenu() {
@@ -241,11 +241,11 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
} }
} }
}); });
((NewTabPane) tabVersionEdit).initializing = true; ((NewTabPane) tabVersionEdit).initializing = true;
tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads); tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads);
((NewTabPane) tabVersionEdit).initializing = false; ((NewTabPane) tabVersionEdit).initializing = false;
((NewTabPane) tabInstallers).initializing = true; ((NewTabPane) tabInstallers).initializing = true;
for (int i = 0; i < InstallerType.values().length; i++) for (int i = 0; i < InstallerType.values().length; i++)
tabInstallers.addTab(InstallerType.values()[i].getLocalizedName(), installerPanels[i]); tabInstallers.addTab(InstallerType.values()[i].getLocalizedName(), installerPanels[i]);
@@ -1222,23 +1222,13 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
} }
//</editor-fold> //</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Installer"> // <editor-fold defaultstate="collapsed" desc="Mod">
String getMinecraftVersionFormatted() { String getMinecraftVersionFormatted() {
return minecraftVersion == null ? "" : (StrUtils.formatVersion(minecraftVersion.version) == null) ? mcVersion : minecraftVersion.version; return minecraftVersion == null ? "" : (StrUtils.formatVersion(minecraftVersion.version) == null) ? mcVersion : minecraftVersion.version;
} }
@Override @Override
public void dragEnter(DropTargetDragEvent dtde) { public void dragEnter(DropTargetDragEvent dtde) {
DataFlavor[] f = dtde.getCurrentDataFlavors();
if (f[0].match(DataFlavor.javaFileListFlavor))
try {
Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files)
Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), file);
} catch (UnsupportedFlavorException | IOException ex) {
HMCLog.warn("Failed to drop file.", ex);
}
} }
@Override @Override
@@ -1255,6 +1245,18 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
@Override @Override
public void drop(DropTargetDropEvent dtde) { public void drop(DropTargetDropEvent dtde) {
DataFlavor[] f = dtde.getCurrentDataFlavors();
if (f[0].match(DataFlavor.javaFileListFlavor))
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files)
Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), file);
reloadMods();
} catch (UnsupportedFlavorException | IOException ex) {
HMCLog.warn("Failed to drop file.", ex);
}
} }
void refreshVersions() { void refreshVersions() {