Skip to content

Commit

Permalink
adding save functionality; bumping ove version to get multiple fixes-…
Browse files Browse the repository at this point in the history
…- drag fix -- window resize fix
  • Loading branch information
tnrich committed Dec 18, 2019
1 parent 8d278a8 commit 367ff69
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 736 deletions.
8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ app.on("open-file", async (event, path) => {
event.preventDefault();
try {
const initialSeqJson = await getSeqJsonFromPath(path);
console.log(`initialSeqJson:`, initialSeqJson);
createWindow({ initialSeqJson });
createWindow({ initialSeqJson, filePath: path });
} catch (e) {
console.error(`e73562891230:`, e);
}
Expand Down Expand Up @@ -230,5 +229,10 @@ ipcMain.on("restart_app", () => {
autoUpdater.quitAndInstall();
});
});

ipcMain.on("ove_onSave", (event, opts) => {
const { formattedSeqString, filePath } = opts;
fs.writeFileSync(filePath, formattedSeqString);
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ove-electron",
"version": "0.1.5",
"version": "0.1.6",
"description": "An open source vector/plasmid editor",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -70,18 +70,18 @@
"author": "tnrich",
"license": "MIT",
"devDependencies": {
"electron": "^6.0.9",
"electron": "^7.1.6",
"electron-builder": "^21.2.0",
"env-cmd": "^10.0.1",
"eslint": "^6.4.0",
"eslint": "^6.7.2",
"eslint-config-teselagen": "^5.0.5"
},
"dependencies": {
"bio-parsers": "5.6.1",
"electron-updater": "^4.1.2",
"bio-parsers": "6.0.0",
"electron-updater": "^4.2.0",
"electron-window-state": "^5.0.3",
"open-vector-editor": "^10.1.8",
"ve-range-utils": "^2.5.5",
"ve-sequence-utils": "^3.3.50"
"open-vector-editor": "^10.1.35",
"ve-range-utils": "^2.5.7",
"ve-sequence-utils": "^3.3.53"
}
}
8 changes: 6 additions & 2 deletions src/preload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const electron = require("electron");
const {jsonToGenbank} = require("bio-parsers");
const { dialog } = require('electron').remote

const currentWindow = electron.remote.getCurrentWindow();
const { ipcRenderer } = require("electron");
Object.assign(window, {
currentWindow,
ipcRenderer
});
ipcRenderer,
jsonToGenbank,
dialog
});
84 changes: 63 additions & 21 deletions src/renderer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@

const { currentWindow } = window;
const seqDataToUse = currentWindow.initialSeqJson || { circular: true };
// export default generateSequenceData()
const originalTitle = document.title;

setNewTitle(seqDataToUse.name);

function setNewTitle(name) {
document.title = originalTitle + " -- " + (name || "Untitled Sequence");
}

const handleSave = isSaveAs => (
event,
sequenceDataToSave,
editorProps,
onSuccessCallback
) => {
let newFilePath;
if (isSaveAs || !window.filePath) {
//we need to get the newFilePath
const filename = `${sequenceDataToSave.name || "Untitled_Sequence"}.gb`;
newFilePath = window.dialog.showSaveDialogSync({
title: filename,
defaultPath:
(window.filePath
? window.filePath.slice(0, window.filePath.lastIndexOf("/") + 1)
: "~/Downloads/") + filename,
buttonLabel: "Save file"
});
if (!newFilePath) {
return; //cancel the save!
}
if (
!sequenceDataToSave.name ||
sequenceDataToSave.name === "Untitled_Sequence" ||
sequenceDataToSave.name === "Untitled Sequence"
) {
sequenceDataToSave.name = newFilePath
.slice(newFilePath.lastIndexOf("/") + 1)
.replace(".gb", "");

setNewTitle(sequenceDataToSave.name);
}
editor.updateEditor({
//update the name of the seq without triggering the undo/redo stack tracking
sequenceData: sequenceDataToSave
});

window.filePath = newFilePath;

} else {
//normal save
newFilePath = window.filePath;
}
const formattedSeqString = window.jsonToGenbank(sequenceDataToSave);
window.ipcRenderer.send("ove_onSave", {
filePath: newFilePath,
formattedSeqString
});
onSuccessCallback();
window.toastr.success(`Sequence Saved to ${newFilePath}`)
};

document.title =
originalTitle + " -- " + (seqDataToUse.name || "Untitled Sequence");
const editor = window.createVectorEditor("createDomNodeForMe", {
isFullscreen: true,
// or you can pass "createDomNodeForMe" but make sure to use editor.close() to clean up the dom node!

//you can also pass a DOM node as the first arg here
// showReadOnly: false,
// disableSetReadOnly: true,
shouldAutosave: true,
shouldAutosave: false,
alwaysAllowSave: true,
// rightClickOverrides: {
// selectionLayerRightClicked: (items /* { annotation }, props */) => {
// return [
Expand All @@ -30,25 +85,12 @@ const editor = window.createVectorEditor("createDomNodeForMe", {
// editor.close() //this calls reactDom.unmountComponent at the node you passed as the first arg
// },
onRename: newName => {
document.title = originalTitle + " -- " + newName;
setNewTitle(newName);
}, //this option should be shown by default
// onNew: () => {}, //unless this callback is defined, don't show the option to create a new seq
// onDuplicate: () => {}, //unless this callback is defined, don't show the option to create a new seq
// onSave: function(
// event,
// sequenceDataToSave,
// editorState,
// onSuccessCallback
// ) {
// console.info("event:", event);
// console.info("sequenceData:", sequenceDataToSave);
// console.info("editorState:", editorState);
// // To disable the save button after successful saving
// // either call the onSuccessCallback or return a successful promise :)
// onSuccessCallback();
// //or
// // return myPromiseBasedApiCall()
// },
onSaveAs: handleSave(true),
onSave: handleSave(),
// onDelete: data => {
// console.warn("would delete", data);
// },
Expand Down Expand Up @@ -149,7 +191,7 @@ const editor = window.createVectorEditor("createDomNodeForMe", {
}
}); /* createDomNodeForMe will make a dom node for you and append it to the document.body*/

const isCircular = seqDataToUse && seqDataToUse.circular
const isCircular = seqDataToUse && seqDataToUse.circular;
editor.updateEditor({
sequenceData: seqDataToUse,
sequenceDataHistory: {}, //clear the sequenceDataHistory if there is any left over from a previous sequence
Expand Down
3 changes: 3 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
top: 5px;
right: 5px;
}
.bp3-toast-container {
z-index: 100000000;
}
Loading

0 comments on commit 367ff69

Please sign in to comment.