### Eclipse Workspace Patch 1.0
#P org.sophie2.main.app.menus
|
|
|
198 | 198 | (StoredResourceAccess) mainWindow.locator().get().create( |
199 | 199 | ResourceRefR4.make(file), access.getAccessOptions(), |
200 | 200 | ((BaseResourceAccess) access).getTopRevision()); |
| 201 | if (fileAccess == null) { |
| 202 | DialogUtils.showErrorDialog(bookDocView.swingComponent().get(), |
| 203 | "The resource "+ file.getName() + " is currently in use.", |
| 204 | "Could not save template"); |
| 205 | return false; |
| 206 | } |
201 | 207 | try { |
202 | 208 | fileAccess.save(null); |
203 | 209 | bookDocView.reopen(fileAccess); |
#P org.sophie2.main.app.layout
|
|
|
13 | 13 | import org.sophie2.base.dnd.SophieDragDropHandler.DndImport; |
14 | 14 | import org.sophie2.base.layout.impl.DefaultDocView; |
15 | 15 | import org.sophie2.base.layout.model.ListPalette; |
| 16 | import org.sophie2.base.model.book.BookH; |
16 | 17 | import org.sophie2.base.model.book.FrameH; |
17 | 18 | import org.sophie2.base.model.book.PageH; |
18 | 19 | import org.sophie2.base.model.book.frame.FrameR4; |
… |
… |
|
26 | 27 | import org.sophie2.base.model.resources.r4.ResourceRefR4; |
27 | 28 | import org.sophie2.base.model.resources.r4.ResourceUtil; |
28 | 29 | import org.sophie2.base.model.resources.r4.access.ResourceAccess; |
| 30 | import org.sophie2.base.model.resources.r4.access.ResourceLocator; |
29 | 31 | import org.sophie2.base.model.resources.r4.changes.AutoAction; |
30 | 32 | import org.sophie2.base.model.resources.r4.changes.ResourceChanger; |
31 | 33 | import org.sophie2.base.model.resources.r4.keys.TemplatedKey; |
| 34 | import org.sophie2.base.model.resources.r4.model.ResourceModel; |
32 | 35 | import org.sophie2.base.model.resources.r4.resources.ResourceH; |
33 | 36 | import org.sophie2.base.model.resources.r4.resources.ResourceR4; |
34 | 37 | import org.sophie2.core.logging.SophieLog; |
… |
… |
|
84 | 87 | SophieLog.debug("This event will not be handled in preview mode!"); |
85 | 88 | return true; |
86 | 89 | } |
87 | | |
| 90 | |
88 | 91 | PageWorkArea pwa = bookDocView.workArea().get(); |
89 | 92 | FrameView currentFrameView = pwa.getSel().getSingleSelected(FrameView.class); |
90 | 93 | |
… |
… |
|
100 | 103 | FrameH template = ((FrameTemplateItem)source.firstSelectedItem().get()).frame().get(); |
101 | 104 | |
102 | 105 | assert template.getRef().isAbsolute(); |
103 | | |
| 106 | |
104 | 107 | final ResourceRefR4 templateRef = ResourceRefR4.getRelativeRef(frameAccess.getRef(), |
105 | 108 | template.getRef()); |
106 | 109 | final String templateKind = frameAccess.open(templateRef, null).getRaw(ResourceR4.KEY_KIND); |
… |
… |
|
117 | 120 | } |
118 | 121 | |
119 | 122 | }.register(frameAccess); |
120 | | |
| 123 | |
121 | 124 | bookDocView.workArea().get().getSel().getEditScope().selectLastElement(); |
122 | | |
| 125 | |
123 | 126 | return true; |
124 | 127 | } |
125 | 128 | |
126 | 129 | }, |
127 | | |
| 130 | |
128 | 131 | /** |
129 | 132 | * Handles a request by the user to delete the selected frame template. |
130 | 133 | */ |
… |
… |
|
147 | 150 | SophieLog.debug("This event will not be handled in preview mode!"); |
148 | 151 | return true; |
149 | 152 | } |
150 | | |
| 153 | |
151 | 154 | assert source.firstSelectedItem().get() instanceof FrameTemplateItem; |
152 | 155 | assert source.firstSelectedItem().get() != null; |
153 | 156 | FrameTemplateItem firstItem = (FrameTemplateItem)source.firstSelectedItem().get(); |
… |
… |
|
159 | 162 | String frameTitle = ResourceR4.KEY_TITLE.get(bookDocView.getAccess().open(template, null)); |
160 | 163 | if (confirmDeletion(frameTitle, bookDocView.swingComponent().get())) { |
161 | 164 | new AutoAction("Delete frame template.", true) { |
162 | | |
| 165 | |
163 | 166 | @Override |
164 | 167 | public void performAuto() { |
165 | 168 | ResourceRefList templates = getChanger().getRaw(BookR4.KEY_FRAME_TEMPLATES); |
… |
… |
|
211 | 214 | |
212 | 215 | public boolean handle(EventR3 event) { |
213 | 216 | DndImport dndImport = event |
214 | | .getEventParam(SophieDragDropHandler.TransferEventIds.TRANSACTION_PARAM_INDEX, |
215 | | DndImport.class); |
| 217 | .getEventParam(SophieDragDropHandler.TransferEventIds.TRANSACTION_PARAM_INDEX, |
| 218 | DndImport.class); |
216 | 219 | DndTransferable transferable = dndImport.getTransferable(); |
217 | 220 | |
218 | 221 | PageWorkArea source = event.getSource(PageWorkArea.class); |
… |
… |
|
222 | 225 | |
223 | 226 | if (transferable.getDndData(ResourceRefData.class) != null) { |
224 | 227 | ResourceRefR4 templateRef = transferable.getDndData(ResourceRefData.class) |
225 | | .getResourceRef(); |
| 228 | .getResourceRef(); |
226 | 229 | assert templateRef.isAbsolute(); |
227 | 230 | if (templateRef.getLocation().startsWith(bookAccess.getRef().getLocation())) { |
228 | 231 | ResourceRefR4 bookToTemplate = ResourceRefR4.getRelativeRef( |
… |
… |
|
232 | 235 | ResourceAccess templateAccess = bookAccess.open(templateRef, null); |
233 | 236 | |
234 | 237 | final ResourceRefR4 frameRef = ResourceRefR4 |
235 | | .generateRandomSub(FrameH.NAME_PREFIX); |
| 238 | .generateRandomSub(FrameH.NAME_PREFIX); |
236 | 239 | final ResourceRefR4 frameToTemplate = ResourceRefR4.getRelativeRef(page |
237 | 240 | .getAccess().getRef().sub(frameRef), templateRef); |
238 | 241 | final String frameTitle = ResourceUtil.getNextTitle(bookAccess.getRef(), |
239 | 242 | FrameR4.DEFAULT_TITLE); |
240 | 243 | final ImmList<ActivationChannel> elements = CompositeElement.KEY_SUB_ELEMENTS |
241 | | .get(page.getAccess()); |
| 244 | .get(page.getAccess()); |
242 | 245 | final String kind = ResourceR4.KEY_KIND.get(templateAccess); |
243 | 246 | final ImmPoint pos = event.getEventParam( |
244 | 247 | SophieDragDropHandler.TransferEventIds.POINT_PARAM_INDEX, |
… |
… |
|
286 | 289 | BookDocView bookDocView = AppViewUtil.getCurrentBookDocView(source); |
287 | 290 | assert bookDocView != null : |
288 | 291 | "There is no current book on which to apply the page template."; |
289 | | |
| 292 | |
290 | 293 | // Disables template logic in preview mode. |
291 | 294 | if (bookDocView.bookView().get().getViewOptions().isPreviewMode()) { |
292 | 295 | SophieLog.debug("This event will not be handled in preview mode!"); |
293 | 296 | return true; |
294 | 297 | } |
295 | | |
| 298 | |
296 | 299 | if (bookDocView.workArea().get().getRootPageView() != null) { |
297 | 300 | ResourceAccess pageAccess = bookDocView.workArea().get().getRootPageView().getAccess(); |
298 | 301 | assert source.firstSelectedItem().get() instanceof PageTemplateItem; |
… |
… |
|
337 | 340 | SophieLog.debug("This event will not be handled in preview mode!"); |
338 | 341 | return true; |
339 | 342 | } |
340 | | |
| 343 | |
341 | 344 | assert source.firstSelectedItem().get() instanceof PageTemplateItem; |
342 | 345 | assert source.firstSelectedItem().get() != null; |
343 | 346 | PageTemplateItem firstItem = (PageTemplateItem)source.firstSelectedItem().get(); |
… |
… |
|
347 | 350 | SophieLog.debug("Delete template " + template.getLocation()); |
348 | 351 | |
349 | 352 | String pageTitle = ResourceR4.KEY_TITLE.get(bookDocView.getAccess().open(template, null)); |
350 | | |
| 353 | |
351 | 354 | if (confirmDeletion(pageTitle, bookDocView.swingComponent().get())) { |
352 | 355 | new AutoAction("Delete page template", true) { |
353 | | |
| 356 | |
354 | 357 | @Override |
355 | 358 | public void performAuto() { |
356 | 359 | ResourceRefList templates = getChanger().getRaw(BookR4.KEY_PAGE_TEMPLATES); |
… |
… |
|
418 | 421 | public boolean handle(EventR3 event) { |
419 | 422 | BookTemplatesPalette source = event.getSource(BookTemplatesPalette.class); |
420 | 423 | AppMainWindow mainWindow = AppViewUtil.findMainWindow(source); |
421 | | |
| 424 | ResourceLocator locator = mainWindow.locator().get(); |
| 425 | |
422 | 426 | assert source.firstSelectedItem().get() instanceof BookTemplateItem; |
423 | 427 | assert source.firstSelectedItem().get() != null; |
424 | 428 | BookTemplateItem firstItem = (BookTemplateItem)source.firstSelectedItem().get(); |
425 | 429 | |
426 | | BookDocView bookView = AppViewUtil.getView(mainWindow, firstItem.bookTemplate().get().book().get(), BookDocView.class); |
427 | | if (mainWindow.documents().get().contains(bookView)) { |
428 | | LogicR3.fire(bookView, null, null, null, DefaultDocView.EventIds.SELECT); |
429 | | } else { |
430 | | mainWindow.documents().add(bookView); |
431 | | } |
432 | | |
| 430 | //Always make a new book. Do not give the access used in the book template items. |
| 431 | //Otherwise someone can close it. |
| 432 | ResourceModel model = firstItem.bookTemplate().get().book().get().getHead().getModel(); |
| 433 | ResourceAccess newBook = BookH.createBookAccess(locator, model); |
| 434 | |
| 435 | BookDocView bookView = AppViewUtil.getView(mainWindow, newBook, BookDocView.class); |
| 436 | mainWindow.documents().add(bookView); |
| 437 | |
433 | 438 | return true; |
434 | 439 | } |
435 | 440 | |
… |
… |
|
457 | 462 | return true; |
458 | 463 | } |
459 | 464 | }, |
460 | | |
| 465 | |
461 | 466 | /** |
462 | 467 | * Handles the dragging a book template in the work area. Creates a new book |
463 | 468 | * from that template if the drag is on the book desktop. Embeds the |
… |
… |
|
473 | 478 | |
474 | 479 | public boolean handle(EventR3 event) { |
475 | 480 | DndImport dndImport = event |
476 | | .getEventParam(SophieDragDropHandler.TransferEventIds.TRANSACTION_PARAM_INDEX, |
477 | | DndImport.class); |
| 481 | .getEventParam(SophieDragDropHandler.TransferEventIds.TRANSACTION_PARAM_INDEX, |
| 482 | DndImport.class); |
478 | 483 | DndTransferable transferable = dndImport.getTransferable(); |
479 | 484 | |
480 | 485 | PageWorkArea source = event.getSource(PageWorkArea.class); |
… |
… |
|
483 | 488 | |
484 | 489 | if (transferable.getDndData(ResourceRefData.class) != null) { |
485 | 490 | final ResourceRefR4 templateRef = transferable.getDndData(ResourceRefData.class) |
486 | | .getResourceRef(); |
| 491 | .getResourceRef(); |
487 | 492 | assert templateRef.isAbsolute(); |
488 | 493 | if (templateRef.getLocation().startsWith( |
489 | 494 | bookDocView.model().get().getRef().getLocation())) { |
… |
… |
|
504 | 509 | templateRef, null); |
505 | 510 | |
506 | 511 | final ImmList<ResourceRefR4> templatePages = BookR4.KEY_PAGES |
507 | | .get(templateAccess); |
| 512 | .get(templateAccess); |
508 | 513 | |
509 | 514 | // transforming the list of ResourceRefs to absolute |
510 | 515 | // refs |
… |
… |
|
524 | 529 | ResourceRefList curPages = ResourceRefList.EMPTY; |
525 | 530 | for (ResourceRefR4 ref : finalAbsTemplatePages) { |
526 | 531 | ResourceRefR4 pageRef = ResourceRefR4 |
527 | | .generateRandomSub(PageH.NAME_PREFIX); |
| 532 | .generateRandomSub(PageH.NAME_PREFIX); |
528 | 533 | String pageTitle = ResourceUtil.getNextTitle(bookRef, |
529 | 534 | PageR4.DEFAULT_TITLE); |
530 | 535 | getChanger().makeResource(pageRef); |
… |
… |
|
619 | 624 | } |
620 | 625 | } |
621 | 626 | } |
622 | | |
| 627 | |
623 | 628 | /** |
624 | 629 | * Shows a confirmation dialog if a template should be deleted. |
625 | 630 | * |
… |
… |
|
635 | 640 | "Confirm removal", false); |
636 | 641 | return DialogManager.get().showDialog(cdi) == ConfirmDialogInput.Response.YES; |
637 | 642 | } |
638 | | |
| 643 | |
639 | 644 | /** |
640 | 645 | * Ids for events for this tab. |
641 | 646 | * |
… |
… |
|
648 | 653 | @EventParams({DndImport.class, ImmPoint.class}) |
649 | 654 | EMBED_BOOK_TEMPLATE, |
650 | 655 | } |
651 | | |
652 | | |
| 656 | |
| 657 | |
653 | 658 | /** |
654 | 659 | * The parameter index of the DND import. |
655 | 660 | */ |
656 | 661 | public static final int DND_IMPORT_PARAM_INDEX = 0; |
657 | | |
| 662 | |
658 | 663 | /** |
659 | 664 | * The parameter index of the point. |
660 | 665 | */ |