Ignore:
Timestamp:
2017-08-29T00:16:25+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - refactor PlatformHookOsx so that all GUI actions are performed in MainApplication and only macOS-specific stuff remains in platform hook

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12691 r12695  
    3838import java.util.concurrent.Callable;
    3939import java.util.concurrent.ExecutorService;
     40import java.util.concurrent.Executors;
    4041import java.util.concurrent.Future;
    4142import java.util.logging.Level;
     
    6061import org.openstreetmap.josm.actions.JosmAction;
    6162import org.openstreetmap.josm.actions.OpenFileAction;
     63import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
    6264import org.openstreetmap.josm.actions.PreferencesAction;
    6365import org.openstreetmap.josm.actions.RestartAction;
     
    103105import org.openstreetmap.josm.io.OsmApiInitializationException;
    104106import org.openstreetmap.josm.io.OsmTransferCanceledException;
     107import org.openstreetmap.josm.io.OsmTransferException;
    105108import org.openstreetmap.josm.io.auth.CredentialsManager;
    106109import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
     
    117120import org.openstreetmap.josm.tools.OsmUrlToBounds;
    118121import org.openstreetmap.josm.tools.OverpassTurboQueryWizard;
     122import org.openstreetmap.josm.tools.PlatformHook.NativeOsCallback;
    119123import org.openstreetmap.josm.tools.PlatformHookWindows;
    120124import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
     
    124128import org.openstreetmap.josm.tools.bugreport.BugReport;
    125129import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
     130import org.xml.sax.SAXException;
    126131
    127132/**
     
    725730        // initialize the platform hook, and
    726731        Main.determinePlatformHook();
     732        Main.platform.setNativeOsCallback(new DefaultNativeOsCallback());
    727733        // call the really early hook before we do anything else
    728734        Main.platform.preStartupHook();
     
    11881194        }
    11891195    }
     1196
     1197    private static class DefaultNativeOsCallback implements NativeOsCallback {
     1198        @Override
     1199        public void openFiles(List<File> files) {
     1200            Executors.newSingleThreadExecutor(Utils.newThreadFactory("openFiles-%d", Thread.NORM_PRIORITY)).submit(
     1201                    new OpenFileTask(files, null) {
     1202                @Override
     1203                protected void realRun() throws SAXException, IOException, OsmTransferException {
     1204                    // Wait for JOSM startup is advanced enough to load a file
     1205                    while (Main.parent == null || !Main.parent.isVisible()) {
     1206                        try {
     1207                            Thread.sleep(25);
     1208                        } catch (InterruptedException e) {
     1209                            Logging.warn(e);
     1210                            Thread.currentThread().interrupt();
     1211                        }
     1212                    }
     1213                    super.realRun();
     1214                }
     1215            });
     1216        }
     1217
     1218        @Override
     1219        public boolean handleQuitRequest() {
     1220            return MainApplication.exitJosm(false, 0, null);
     1221        }
     1222
     1223        @Override
     1224        public void handleAbout() {
     1225            MainApplication.getMenu().about.actionPerformed(null);
     1226        }
     1227
     1228        @Override
     1229        public void handlePreferences() {
     1230            MainApplication.getMenu().preferences.actionPerformed(null);
     1231        }
     1232    }
    11901233}
Note: See TracChangeset for help on using the changeset viewer.