From 135e56bda6dd3b93ba178a8b382b316e3b5d2c5f Mon Sep 17 00:00:00 2001 From: veronie Date: Tue, 16 Feb 2021 15:51:24 +0100 Subject: [PATCH] Import from result.txt done. Added a File menu with save, load, import. --- xyz.veronie.bgg.ui/Application.e4xmi | 15 +++- xyz.veronie.bgg.ui/icons/noun_Save_16x16.png | Bin 0 -> 1414 bytes .../icons/noun_import_16x16.png | Bin 0 -> 1432 bytes .../icons/noun_import_60x60.png | Bin 0 -> 1870 bytes xyz.veronie.bgg.ui/icons/noun_open_16x16.png | Bin 0 -> 1429 bytes xyz.veronie.bgg.ui/plugin.xml | 12 ---- .../veronie/bgg/localdb/SqliteController.java | 2 +- .../src/xyz/veronie/bgg/result/BggApi.java | 4 +- .../xyz/veronie/bgg/result/ThingProvider.java | 3 +- .../bgg/ui/dialogs/LoadGameListDialog.java | 52 +------------- .../ui/handlers/ImportResultTxtHandler.java | 65 ++++++++---------- ...Gamelist.java => LoadGamelistHandler.java} | 4 +- ...Gamelist.java => SaveGamelistHandler.java} | 6 +- .../src/xyz/veronie/bgg/ui/parts/BatMain.java | 1 + 14 files changed, 54 insertions(+), 110 deletions(-) create mode 100644 xyz.veronie.bgg.ui/icons/noun_Save_16x16.png create mode 100644 xyz.veronie.bgg.ui/icons/noun_import_16x16.png create mode 100644 xyz.veronie.bgg.ui/icons/noun_import_60x60.png create mode 100644 xyz.veronie.bgg.ui/icons/noun_open_16x16.png rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/{HandleLoadGamelist.java => LoadGamelistHandler.java} (92%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/{HandleSaveGamelist.java => SaveGamelistHandler.java} (89%) diff --git a/xyz.veronie.bgg.ui/Application.e4xmi b/xyz.veronie.bgg.ui/Application.e4xmi index be08761..002cfe8 100644 --- a/xyz.veronie.bgg.ui/Application.e4xmi +++ b/xyz.veronie.bgg.ui/Application.e4xmi @@ -7,7 +7,13 @@ View - + + + + + + + @@ -15,9 +21,12 @@ - - + + + + + diff --git a/xyz.veronie.bgg.ui/icons/noun_Save_16x16.png b/xyz.veronie.bgg.ui/icons/noun_Save_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..440a12e652370e8342d5ab16b0b82e7bf87e10fd GIT binary patch literal 1414 zcmV;11$p|3P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KZlH525hX3mnIf4Ko&~apaROJSH{JfIgp6;3K zCaK+DTWyssj4)sxtey$uukSN_!$Bo;NNS!-&Jjl{sc?nh@jS}DQcU}L-Nc9Rq7U~1 zLnWByytR7SSLpTQfkzBFUiHDR752*!-H!JmEAo>2bCS^Wsi$-~D&rJ#aeGenxE!_1 zaHn#e=}zmM)_r(U7^>72frNPoN!(XIGmv$X)IC>78FnNJS)_!$kS}K_$jj^91&q%H zdMWZl3ZJWgOP`9*_0r3yTIQ=p5PrHq`bjT$7=8{ccSiiWVDfPFwa9aJpL3jVS5rns z^VLzi*z|A%!viIk{aD5@oC?|YC>S1VY(U;)iw8!dLJTT1P@+ziCXGEeYDh8hV8hJZ z0BY%6j0-neoYERJ*`!Dp2gAlA09_KkbD0@%-L3n zDEeJ1VdF0uDuQ_SZl zM8W#y03||fMKUBH5Hq@;GDTxHBGl0Vs3LQg#0LnFDt9EwN$|AOqUvEIDP(Ia^+vTs5&|YT3-(id7d+uAbf8 zy?8BL1bd*CT&#F0rB)6Vfhv4e*jH!{KIBM;9{I4tk8;$8_GzhU%gvg%(rV`}9ot0D z-MaVE>!2{OQ;alpT=4sPsnf0c2QT;OhfEr!Yc#~Roc2k2km_1z3 z+D>#a12Ikn;=Y&y&b(By&b(By&b(B z{SO>X{PBQ)V#5yv@SS#MHhx0@00D$)LqkwWLqi~Na&Km7Y-Iodc$|HaJxIeq9K~N# zr6TnM>>whNp*mR*6>*d*7QsSkE41oha_JW|X-HCB90k{cgCC1k2N!2u9b5%L@B_rn z%}LQkO8j3^Xc6PVaX;SOd)&PPgnF5&X2%4eYL=0VMa4{Z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X;`dS|Gd|W>_kR-jCsGd%D)f;iW>iVgQ$|a0@2yHoRDy z9{o>vUnsG;RL?W5N-~rX&0)2~+Dfq!P~(Oo!~NAF!J@GaTyy3gWn z9=&&^+oku>8J@^OA27K{n})$M=!cEIy6az{9~f%H^>BH3XBN_{p%z?2&ph8vqpi`x z_rwy1w!wN2=`nm+g8iLJ!={$C8%HXzo4|;qq@<)~PzUyu-P>MrUBI?Q>S(W3xcP>q z?zn#%Z%PLCLwFF`hf`rY9Cnj9j3-zZL&-?o@4>}d25t*4epAd7ZN;aUhW^4-EX_76 z?iduX1;69yQ2aCK3^vB(X1tbxd*i$|UVbd>I%DSZJ{IE7aWtS_gzcvIalYd<9@j%i z?+kBt;cIww8atxxPKDP#M)_H+kGb!=fc+8R=s&-v9sr literal 0 HcmV?d00001 diff --git a/xyz.veronie.bgg.ui/icons/noun_open_16x16.png b/xyz.veronie.bgg.ui/icons/noun_open_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..8b276f12f42eca690148422899b14de46745b094 GIT binary patch literal 1429 zcmV;G1#0? zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KJvfL;Ph2L34mVhLL#Bwk{RoTHTKL>30?Y_A) zNowY0s@jwd7P64fC)3qo{Plf?Z#c+e4oS^($vNUkB^9n1cs!4?uN2e1UN`X`yx2o* z*95~P=;ge%diht__2Yqi4LV-!!LJ$iE6}~<6;Rg7j6r`+5_UfAl&(N!oP%84o>M*e z?AztIQ@KvD9r_Vu-G^sGGN{xQUcx+tB<`!98OSh3E>8Ga;+v51Flx-)?wFR%Ad zHa-jVBJw>7pVhy$|13V&%R@eCnQvj~1Y#orP?Ei8|W_;tc$Lw$Xn>zuRuoa21E znlcp4S4G8etFxYg;{nNKKbFx@u?XwvS1V{9Yixkip}~RHs1Sq743wx-rAcG=jT%x+ zJlN1PH-K6;7vsWB7N@itO*Sdg#lf)g2tb#FAGy$8x9s&AIacljS0)4_Jo2|K{L|#0 zv@quaPPD{qr&h>|SLGs&MQ&Z;1t2spZn_1&+l4p#so4XgUg^OSh)RK!8FQwGVp<2a zxl6}3(Q~)%z4SUL4D1vm4IO#d@KHvcsI@6GO`Un#^jT(oP`jx9)c$}PUDSA!T7LGR z25T_8L(tkzbTI=lP6Xn%2%w;OF^f(q@gldF#lrX~l#!$^HlfoZ283x4>!b&}4|2c7 zEvWw%H~tm5u+aS%%;u;8rbXlQLF#9e+PO8dIx$3 zdI$Qy2b%cRz`vL916xZVNC}9C{r~_0glR)VP)S2WAaHVTW@&6?004NLeUUv#!$2Ix zUsI(b^#kl6B9fsxSr8R*lqwd%LTM|s>R@u|7c^-|Qd}Gb*Mfr|i&X~~XI&j!1wrrw z#Ldk~(M3x9Us7lh)~G4>|q>xny#cz{s(H3RFmrAN&t~cWdUSCf%f9 z6zF`h?T=9)unRP5w*7r<+l>>z{|sDdEq|pB%zlzyYiZ#lpl=(vxNd3k9&ot>3_j_S zAvuztrjXAA?`QN)SzzE6=w5SsYwqLp0Z3C<%QwKmAuv{;>~)WKceVHS@0n(QKdwJ= zzx+Q6tpET324YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G` z2jv0~4ki!zdzaAw005auL_t(2&z;gu3IR|Q#qpn)GQi9tWCv!l2OF>oD^fl=!l?HkU%_7Jm( z%a6Ym>S&-4S%03z2^Tbx6Q@nU4y6Pb`T+yf65unI0b^7X0@gSLEKo@ZnBo?YM=>E_ j^!|e~R=7vNS4`ju@Wd;;or7AJ00000NkvXXu0mjf3mTN6 literal 0 HcmV?d00001 diff --git a/xyz.veronie.bgg.ui/plugin.xml b/xyz.veronie.bgg.ui/plugin.xml index 4a77977..9cf6b9b 100644 --- a/xyz.veronie.bgg.ui/plugin.xml +++ b/xyz.veronie.bgg.ui/plugin.xml @@ -2,18 +2,6 @@ - - - - - - diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java index ad74389..fa2e1a7 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java @@ -173,7 +173,7 @@ public class SqliteController { PreparedStatement thingStatement = connection .prepareStatement("INSERT OR REPLACE INTO Thing VALUES (?, ?, ?, ?, ?, ?);"); PreparedStatement listToThingStatement = connection - .prepareStatement("INSERT INTO ThingListToThing VALUES (?, ?);"); + .prepareStatement("INSERT OR IGNORE INTO ThingListToThing VALUES (?, ?);"); for (Thing thing : things) { ThingMetaData metaData = thing.getMetaData(); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java index 137e7f3..7b0ceef 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java @@ -11,8 +11,8 @@ import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import java.util.Map.Entry; +import java.util.Set; import javax.inject.Inject; import javax.xml.parsers.DocumentBuilder; @@ -63,7 +63,7 @@ public class BggApi { } /// retrieve a list of things from BGG with the given ids - public ArrayList getThings(List ids) { + public ArrayList getThings(Set ids) { StringBuilder urlStr = new StringBuilder(); urlStr.append(BASE_URL + "thing?id="); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java index c7b0da3..c5ae7eb 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java @@ -99,10 +99,9 @@ public class ThingProvider { } /// store things as a new list - public void storeThings(List importThings, String listName) throws SQLException { + public void importList(List importThings, String listName) { if(importThings != null && !importThings.isEmpty()) { this.things = importThings; - localDbAdapterService.storeThingList(importThings, listName); } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java index 0cbe166..74a037b 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java @@ -2,13 +2,6 @@ package xyz.veronie.bgg.ui.dialogs; import java.util.List; -import javax.inject.Inject; - -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.e4.core.commands.ECommandService; -import org.eclipse.e4.core.commands.EHandlerService; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ArrayContentProvider; @@ -24,7 +17,6 @@ import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -33,32 +25,23 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.wb.swt.SWTResourceManager; -import xyz.veronie.bgg.types.EventConstants; import xyz.veronie.bgg.ui.helpers.BatColors; -@SuppressWarnings("restriction") public class LoadGameListDialog extends Dialog { private String selectedName; private List thingLists; - private ECommandService commandService; - - private EHandlerService handlerService; - /** * Create the dialog. * @param parentShell * @param handlerService * @param commandService */ - public LoadGameListDialog(Shell parentShell, List thingLists, - ECommandService commandService, EHandlerService handlerService) + public LoadGameListDialog(Shell parentShell, List thingLists) { super(parentShell); this.thingLists = thingLists; - this.commandService = commandService; - this.handlerService = handlerService; setShellStyle(SWT.BORDER | SWT.RESIZE | SWT.APPLICATION_MODAL); } @@ -137,18 +120,7 @@ public class LoadGameListDialog extends Dialog { Composite otherActionsComposite = new Composite(container, SWT.NONE); otherActionsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); otherActionsComposite.setLayout(new GridLayout(1, false)); - - Button btnImport = new Button(otherActionsComposite, SWT.NONE); - btnImport.addMouseListener(new MouseAdapter() { - @Override - public void mouseUp(MouseEvent e) { - importFromBggTool1Result(); - } - }); - btnImport.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - btnImport.setBounds(0, 0, 75, 25); - btnImport.setText("Import from bgg1tool result.txt..."); - + return container; } @@ -157,15 +129,7 @@ public class LoadGameListDialog extends Dialog { this.setReturnCode(OK); this.close(); } - - private void importFromBggTool1Result() { - ParameterizedCommand cmd = - commandService.createCommand("xyz.veronie.bgg.ui.command.importResultTxt", null); - if (handlerService.canExecute(cmd)){ - handlerService.executeHandler(cmd); - } - closeDialogOk(); - } + /** * Create contents of the button bar. @@ -191,14 +155,4 @@ public class LoadGameListDialog extends Dialog { return selectedName; } - - // TODO: is not called - @Inject - @Optional - private void subscribeTopicThingsSaved - (@UIEventTopic(EventConstants.TOPIC_RESULT_CHANGED) - String listName) { - System.out.println("LoadGameListDialog: TOPIC_RESULT_CHANGED"); - closeDialogOk(); - } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java index 5ca2fe1..f368864 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java @@ -5,14 +5,14 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.sql.SQLException; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.eclipse.core.runtime.Path; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.services.events.IEventBroker; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.MessageBox; @@ -22,7 +22,6 @@ import xyz.veronie.bgg.result.BggApi; import xyz.veronie.bgg.result.Thing; import xyz.veronie.bgg.result.ThingProvider; import xyz.veronie.bgg.types.EventConstants; -import xyz.veronie.bgg.ui.dialogs.SaveGameListDialog; public class ImportResultTxtHandler { @@ -40,51 +39,43 @@ public class ImportResultTxtHandler { String resultPath = dialog.open(); if(resultPath != null && !resultPath.isEmpty()) { - List thingIds = parseResultTxtIds(resultPath); + Set thingIds = parseResultTxtIds(resultPath); if(thingIds != null && !thingIds.isEmpty()) { - SaveGameListDialog saveDialog = new SaveGameListDialog(shell); - saveDialog.open(); - - int returnCode = saveDialog.getReturnCode(); - if(returnCode == Dialog.OK) { - String listName = saveDialog.getEntryText(); - try { - eventBroker.send(EventConstants.TOPIC_STATUS, "Fetching entries from BGG..."); - List things = bggApi.getThings(thingIds); - thingProvider.storeThings(things, listName); - eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, listName); - eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(things.size()) + " things."); - } catch (SQLException e) { - MessageBox msgErrorBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); - msgErrorBox.setMessage("Could not save imported result.txt as game list."); - msgErrorBox.open(); - e.printStackTrace(); - } - } + String listName = new Path(resultPath).lastSegment() + " (unsaved)"; + eventBroker.send(EventConstants.TOPIC_STATUS, "Fetching entries from BGG..."); + List things = bggApi.getThings(thingIds); + thingProvider.importList(things, listName); + eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, listName); + eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(things.size()) + " things."); } } } - private List parseResultTxtIds(String resultPath) { + private Set parseResultTxtIds(String resultPath) { FileReader input = null; String myLine = null; - int lineNo = 0; - int errNo = 0; + int lineNo = 0; // count overall lines + int errNo = 0; // count unparsable lines + int dupNo = 0; // count duplicates try { input = new FileReader(resultPath); BufferedReader bufferedReader = new BufferedReader(input); - List ids = new ArrayList(); + Set ids = new HashSet(); while ( (myLine = bufferedReader.readLine()) != null) { + lineNo++; String[] tokens = myLine.split(","); - if(tokens.length > 1) { + if(tokens.length > 0) { if(tokens[0].equals("id")) continue; // header line try { - ids.add(Integer.parseInt(tokens[0])); - lineNo++; + boolean exists = !ids.add(Integer.parseInt(tokens[0])); + if(exists) { + System.out.println("DEBUG: duplicate id: " + tokens[0]); + dupNo++; + } } catch (NumberFormatException e) { errNo++; @@ -99,13 +90,15 @@ public class ImportResultTxtHandler { if(ids != null) { MessageBox msgBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK); StringBuilder msg = new StringBuilder(); - msg.append("Parsing successful. Found ").append(Integer.toString(lineNo)).append(" things."); + int thingsNo = lineNo - errNo - dupNo - 1; + msg.append("Parsing successful. Found ").append(Integer.toString(thingsNo)).append(" things."); if(errNo > 0) { - msg.append("Skipped ").append(Integer.toString(errNo)).append(" line(s).\n\r"); - } else { - msg.append("\n\r"); + msg.append("\n\rSkipped ").append(Integer.toString(errNo)).append(" line(s)."); + } + if(dupNo > 0) { + msg.append("\n\r").append(Integer.toString(dupNo)).append(" duplicate ids"); } - msg.append("Next, you will be asked to save the imported list as a new game list."); + msg.append("\n\r"); msgBox.setMessage(msg.toString()); msgBox.open(); } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleLoadGamelist.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/LoadGamelistHandler.java similarity index 92% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleLoadGamelist.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/LoadGamelistHandler.java index b5254e5..06249f9 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleLoadGamelist.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/LoadGamelistHandler.java @@ -21,7 +21,7 @@ import xyz.veronie.bgg.types.EventConstants; import xyz.veronie.bgg.ui.dialogs.LoadGameListDialog; @SuppressWarnings("restriction") -public class HandleLoadGamelist { +public class LoadGamelistHandler { @Inject ThingProvider thingProvider; @@ -39,7 +39,7 @@ public class HandleLoadGamelist { return; } - LoadGameListDialog loadDialog = new LoadGameListDialog(shell, thingLists, commandService, handlerService); + LoadGameListDialog loadDialog = new LoadGameListDialog(shell, thingLists); loadDialog.open(); int returnCode = loadDialog.getReturnCode(); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/SaveGamelistHandler.java similarity index 89% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/SaveGamelistHandler.java index 0e4b1aa..bb9abba 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/SaveGamelistHandler.java @@ -15,19 +15,18 @@ import xyz.veronie.bgg.result.ThingProvider; import xyz.veronie.bgg.types.EventConstants; import xyz.veronie.bgg.ui.dialogs.SaveGameListDialog; -public class HandleSaveGamelist { +public class SaveGamelistHandler { @Inject ThingProvider thingProvider; - public HandleSaveGamelist() { + public SaveGamelistHandler() { } @Execute public void execute(Shell shell, IEventBroker eventBroker) { - // TODO: disable save if list is empty if(thingProvider.numberOfThings() == 0) { MessageBox msgBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); msgBox.setMessage("To save an empty game list would be like drawing from an empty deck."); @@ -35,6 +34,7 @@ public class HandleSaveGamelist { return; } + // TODO: handle existing name SaveGameListDialog saveDialog = new SaveGameListDialog(shell); saveDialog.open(); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java index 722f751..cec7827 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java @@ -55,6 +55,7 @@ import xyz.veronie.bgg.ui.helpers.BatLayouts; // TODO: Display selection details on game // TODO: cache family/geeklist descriptions // TODO: allow different screen scalings +// TODO: handle existing name @SuppressWarnings("restriction") public class BatMain {