コード例 #1
0
  @Override
  public void performPaste(@NotNull DataContext dataContext) {
    TemplateGroup group = myConfigurable.getSingleSelectedGroup();
    assert group != null;

    String buffer = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
    assert buffer != null;

    try {
      for (Element templateElement :
          JDOMUtil.load(new StringReader("<root>" + buffer + "</root>"))
              .getChildren(TemplateSettings.TEMPLATE)) {
        TemplateImpl template =
            TemplateSettings.readTemplateFromElement(
                group.getName(), templateElement, getClass().getClassLoader());
        while (group.containsTemplate(template.getKey(), template.getId())) {
          template.setKey(template.getKey() + "1");
          if (template.getId() != null) {
            template.setId(template.getId() + "1");
          }
        }
        myConfigurable.addTemplate(template);
      }
    } catch (JDOMException ignore) {
    } catch (IOException ignore) {
    }
  }
コード例 #2
0
 private static void checkForUpdates() {
   PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
   long lastUpdate = propertiesComponent.getOrInitLong(KEY, 0);
   if (lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1)) {
     ApplicationManager.getApplication()
         .executeOnPooledThread(
             () -> {
               try {
                 String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                 IdeaPluginDescriptor plugin = getPlugin();
                 String pluginVersion = plugin.getVersion();
                 String pluginId = plugin.getPluginId().getIdString();
                 String os =
                     URLEncoder.encode(
                         SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                 String uid = PermanentInstallationID.get();
                 String url =
                     "https://plugins.jetbrains.com/plugins/list"
                         + "?pluginId="
                         + pluginId
                         + "&build="
                         + buildNumber
                         + "&pluginVersion="
                         + pluginVersion
                         + "&os="
                         + os
                         + "&uuid="
                         + uid;
                 PropertiesComponent.getInstance()
                     .setValue(KEY, String.valueOf(System.currentTimeMillis()));
                 HttpRequests.request(url)
                     .connect(
                         request -> {
                           try {
                             JDOMUtil.load(request.getReader());
                             LOG.info(
                                 (request.isSuccessful() ? "Successful" : "Unsuccessful")
                                     + " update: "
                                     + url);
                           } catch (JDOMException e) {
                             LOG.warn(e);
                           }
                           return null;
                         });
               } catch (UnknownHostException ignored) {
               } catch (IOException e) {
                 LOG.warn(e);
               }
             });
   }
 }