예제 #1
0
파일: Shortcut.java 프로젝트: uazure/josm
 private static Shortcut reassignShortcut(
     String shortText,
     String longText,
     int requestedKey,
     Shortcut conflict,
     int m,
     int k,
     int newmodifier) {
   Shortcut newsc =
       new Shortcut(shortText, longText, requestedKey, m, k, newmodifier, false, false);
   Main.info(
       tr(
           "Silent shortcut conflict: ''{0}'' moved by ''{1}'' to ''{2}''.",
           shortText, conflict.getShortText(), newsc.getKeyText()));
   newsc.saveDefault();
   shortcuts.put(shortText, newsc);
   return newsc;
 }
예제 #2
0
파일: Shortcut.java 프로젝트: uazure/josm
  // and now the workhorse. same parameters as above, just one more
  private static Shortcut registerShortcut(
      String shortText, String longText, int requestedKey, int requestedGroup, Integer modifier) {
    doInit();
    if (shortcuts.containsKey(
        shortText)) { // a re-register? maybe a sc already read from the preferences?
      Shortcut sc = shortcuts.get(shortText);
      sc.setLongText(
          longText); // or set by the platformHook, in this case the original longText doesn't match
      // the real action
      sc.saveDefault();
      return sc;
    }
    Integer defaultModifier = findModifier(requestedGroup, modifier);
    Shortcut conflict = findShortcut(requestedKey, defaultModifier);
    if (conflict != null) {
      if (Main.isPlatformOsx()) {
        // Try to reassign Meta to Ctrl
        int newmodifier = findNewOsxModifier(requestedGroup);
        if (findShortcut(requestedKey, newmodifier) == null) {
          Main.info(
              "Reassigning OSX shortcut '"
                  + shortText
                  + "' from Meta to Ctrl because of conflict with "
                  + conflict);
          return reassignShortcut(
              shortText,
              longText,
              requestedKey,
              conflict,
              requestedGroup,
              requestedKey,
              newmodifier);
        }
      }
      for (int m : mods) {
        for (int k : keys) {
          int newmodifier = getGroupModifier(m);
          if (findShortcut(k, newmodifier) == null) {
            Main.info(
                "Reassigning shortcut '"
                    + shortText
                    + "' from "
                    + modifier
                    + " to "
                    + newmodifier
                    + " because of conflict with "
                    + conflict);
            return reassignShortcut(shortText, longText, requestedKey, conflict, m, k, newmodifier);
          }
        }
      }
    } else {
      Shortcut newsc =
          new Shortcut(
              shortText,
              longText,
              requestedKey,
              requestedGroup,
              requestedKey,
              defaultModifier,
              true,
              false);
      newsc.saveDefault();
      shortcuts.put(shortText, newsc);
      return newsc;
    }

    return null;
  }