Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1007474 // swingExportConcepts

JavaX fragment (include)

sS exportSnippetID;

svoid swingExportConcepts(fS desc) {
  thread "Exporting" {
    pcall-messagebox {
      loading {
        try {
          swingExportConcepts_impl(desc);
        } catch e {
          if (containsIC(str(e), "Not your snippet")) {
            if (!confirmOKCancel("Snippet " + exportSnippetID + " does not seem to belong to you. Maybe you're not logged in. Do you want to export to a new snippet?")) ret;
            exportSnippetID = null;
            save("exportSnippetID");
            swingExportConcepts_impl(desc);
          } else rethrow(e);
        }
      }
    }
  }
}

svoid swingExportConcepts_impl(S desc) {
  if (mainConcepts.countConcepts() == 0) fail("Nothing to export (concepts not loaded?)");
  S text = mainConcepts.xfullgrab();
  if (match("exportable=f", text)) fail("Non-exportable concepts found");
  //print(javaTokWordWrap(text));
  print("Size: " + l(utf8(text)));
  print();
  load("exportSnippetID");
  if (empty(exportSnippetID)) {
    infoBox("Creating a snippet for you...");
    exportSnippetID = createSnippet(text, desc + " from " + computerID(), 53);
    infoBox("Your snippet ID: " + exportSnippetID);
    save("exportSnippetID");
  } else {
    S oldMD5 = getSnippetMD5(exportSnippetID);
    S newMD5 = md5(text);
    if (eq(oldMD5, newMD5))
      infoBox("Snippet " + exportSnippetID + " already up to date!");
    else {
      infoBox("Updating snippet: " + exportSnippetID);
      editSnippet(exportSnippetID, text);
      S actualMD5 = getSnippetMD5(exportSnippetID);
      if (eq(actualMD5, newMD5))
        infoBox("Export to " + exportSnippetID + " complete (" + n(lUtf8(text), "bytes") + ").");
      else if (eq(actualMD5, oldMD5))
        infoBox("Export failed for unknown reason");
      else
        infoBox("Hm. Export did something, but MD5 mismatch occurred.");
    }
  }
}

Author comment

Began life as a copy of #1007207

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007474
Snippet name: swingExportConcepts
Eternal ID of this version: #1007474/7
Text MD5: 8e887ddb769523da815ec44d83b9e0fb
Author: stefan
Category: javax / a.i. / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-06 14:46:43
Source code size: 1901 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 375 / 398
Version history: 6 change(s)
Referenced in: [show references]