Ticket #2301: copy-paste-files-to.patch
File copy-paste-files-to.patch, 7.2 KB (added by deni, 15 years ago) |
---|
-
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ResourceImportLogic.java
### Eclipse Workspace Patch 1.0 #P sophie
11 11 12 12 import org.sophie2.base.commons.util.position.ImmPoint; 13 13 import org.sophie2.base.dialogs.DialogManager; 14 import org.sophie2.base.dnd.ClipboardManager; 14 15 import org.sophie2.base.dnd.DndTransferable; 15 16 import org.sophie2.base.dnd.SophieDragDropHandler; 16 17 import org.sophie2.base.dnd.SophieDragDropHandler.DndImport; … … 374 375 filter.setEventId(SophieDragDropHandler.TransferEventIds.DND_IMPORT); 375 376 } 376 377 378 @SuppressWarnings("synthetic-access") 377 379 public boolean handle(EventR3 event) { 378 380 379 381 PageWorkArea pwa = event.getSource(PageWorkArea.class); … … 382 384 DndImport.class); 383 385 ImmPoint pos = event.getEventParam( 384 386 SophieDragDropHandler.TransferEventIds.POINT_PARAM_INDEX, ImmPoint.class); 385 386 BookH book = pwa.bookView().get().model().get(); 387 ElementView parentView = pwa.getSel().getEditScope(); 388 ElementH parent = parentView.model().get(); 389 387 390 388 FileListData transferable = dndImport.getTransferable().getDndData(FileListData.class); 391 389 if (transferable == null) { 392 390 return false; 393 391 } 394 392 395 List<File> invalidFiles = new ArrayList<File>(); 396 List<File> files = addArchived(transferable.getFiles()); 397 for (final File file : files) { 398 399 ResourceImportProvider provider = 400 SimpleResourceImportProvider.getProvider(new ProviderMatcher() { 393 importFilesInNewFrames(transferable, pwa, pos); 394 395 return true; 396 } 397 }, 398 399 /** 400 * Handles pasting one or multiple files in the current edit scope. 401 * 402 * @author deni 403 */ 404 @SortKey("eee-on-paste-file-list") 405 ON_PASTE_FILE { 401 406 402 @Override 403 public boolean check(ResourceImportProvider curProvider) { 404 return curProvider.getFileFilter() != null 405 && curProvider.getFileFilter().accept(file); 406 } 407 }); 408 409 if (provider == null) { 410 invalidFiles.add(file); 411 continue; 412 } 413 414 // TODO: copied from ON_INSERT_FRAME... maybe move in a helper method 415 // May be bad... Think of a better way --meddle 2009-10-24 416 if (provider.getImportManager() instanceof SophieFormatImportManager) { 417 SophieFormatImportManager manager = 418 (SophieFormatImportManager) provider.getImportManager(); 419 if (!manager.isInitialized()) { 420 AppMainWindow mainWindow = AppViewUtil.findMainWindow(pwa); 421 ResourceLocator locator = mainWindow.locator().get(); 422 manager.initLocator(locator); 423 } 424 } 425 426 boolean inserted = ResourceImportUtil.dropFile(provider, book, parent, pos, file); 427 if (!inserted) { 428 invalidFiles.add(file); 429 } 407 public void defineFilter(EventFilterBuilder filter) { 408 filter.setSourceClass(VisualElement.class); 409 filter.setEventId(SophieDragDropHandler.TransferEventIds.PASTE); 410 } 430 411 431 pos = pos.translate(50, 50); 412 @SuppressWarnings("synthetic-access") 413 public boolean handle(EventR3 event) { 414 415 VisualElement source = event.getSource(VisualElement.class); 416 BookDocView docView = AppViewUtil.getCurrentBookDocView(source); 417 if (docView == null) { 418 return false; 432 419 } 420 PageWorkArea pwa = docView.workArea().get(); 421 422 ClipboardManager manager = ClipboardManager.get(); 423 DndTransferable transferable = manager.getContents(); 433 424 434 ResourceImportUtil.showInvalidInfo(invalidFiles); 425 FileListData fileListData = transferable.getDndData(FileListData.class); 426 if (fileListData == null) { 427 return false; 428 } 435 429 430 importFilesInNewFrames(fileListData, pwa, null); 431 436 432 return true; 437 433 } 438 434 }, … … 441 437 * Handles drop of a resource over page work area. New event is constructed and fired depending on 442 438 * the imported role of the resource transfered. 443 439 */ 444 @SortKey(" eee-on-drop-resource-revision")440 @SortKey("fff-on-drop-resource-revision") 445 441 ON_DROP_RESOURCE { 446 442 447 443 public void defineFilter(EventFilterBuilder filter) { … … 660 656 return refs; 661 657 } 662 658 659 private static void importFilesInNewFrames(FileListData fileListData, PageWorkArea pwa, 660 ImmPoint pos) { 661 662 BookH book = pwa.bookView().get().model().get(); 663 ElementView parentView = pwa.getSel().getEditScope(); 664 ElementH parent = parentView.model().get(); 665 666 ImmPoint currentPos = pos; 667 if (currentPos == null) { 668 currentPos = parent.selectInsertLocation(); 669 } 670 671 List<File> invalidFiles = new ArrayList<File>(); 672 List<File> files = addArchived(fileListData.getFiles()); 673 for (final File file : files) { 674 675 ResourceImportProvider provider = 676 SimpleResourceImportProvider.getProvider(new ProviderMatcher() { 677 678 @Override 679 public boolean check(ResourceImportProvider curProvider) { 680 return curProvider.getFileFilter() != null 681 && curProvider.getFileFilter().accept(file); 682 } 683 }); 684 685 if (provider == null) { 686 invalidFiles.add(file); 687 continue; 688 } 689 690 // TODO: copied from ON_INSERT_FRAME... maybe move in a helper method 691 // May be bad... Think of a better way --meddle 2009-10-24 692 if (provider.getImportManager() instanceof SophieFormatImportManager) { 693 SophieFormatImportManager manager = 694 (SophieFormatImportManager) provider.getImportManager(); 695 if (!manager.isInitialized()) { 696 AppMainWindow mainWindow = AppViewUtil.findMainWindow(pwa); 697 ResourceLocator locator = mainWindow.locator().get(); 698 manager.initLocator(locator); 699 } 700 } 701 702 boolean inserted = ResourceImportUtil.dropFile(provider, book, parent, currentPos, file); 703 if (!inserted) { 704 invalidFiles.add(file); 705 } 706 707 currentPos = currentPos.translate(ElementH.X_OFFSET, ElementH.Y_OFFSET); 708 } 709 710 ResourceImportUtil.showInvalidInfo(invalidFiles); 711 } 712 663 713 } -
modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/ElementH.java
53 53 public ElementH(ResourceAccess access) { 54 54 super(access); 55 55 } 56 57 /** 58 * The X-offset to use when trying to choose location for a new child 59 * (so that it is not too near to another one). 60 */ 61 public static final int X_OFFSET = 50; 62 63 /** 64 * The Y-offset to use when trying to choose location for a new child 65 * (so that it is not too near to another one). 66 */ 67 public static final int Y_OFFSET = 50; 56 68 57 69 /** 58 70 * Calculates the bound area of this element in the selected … … 462 474 } 463 475 } 464 476 if (duplicate) { 465 location = location.translate( 50, 50);477 location = location.translate(X_OFFSET, Y_OFFSET); 466 478 } 467 479 } 468 480 return location;