Skip to content

Commit

Permalink
v1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhekur committed Mar 10, 2019
1 parent 2fb008d commit c038ec6
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 122 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
- Fixed: Colon only able to remember one unsaved file
- Add: Colon remember you last working project
- Fixed: Auto close when all tabs are closed
- Fixed: Editor will auto focus when you create a new file
- Fixed: Editor will auto focus when you create a new file
- Fixed: Can share unsaved file as well
- Improvement: UI
1 change: 1 addition & 0 deletions assets/css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ input, button, textarea, :focus {
}

.btn{
min-width: 146px;
border:2px solid #ff3939;
outline: none;
background: none;
Expand Down
95 changes: 82 additions & 13 deletions assets/js/code_sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ var localtunnel = require('localtunnel');
const io_client = require('socket.io-client');
var socket;
var clients = [];
var remoteFile;
var remote_mode = false;

function shareCode(){
if(isCurrentFileSaved()){
function shareCode(file, project_path){
// if(isCurrentFileSaved()){
$('#code-sharing-box').html('<h5>Waiting...</h5>');
server.listen(4000, function(){
// console.log('listening at 4000');
Expand All @@ -31,17 +33,38 @@ function shareCode(){
// console.log(file);
io.on('connection', function (socket) {
clients.push(socket);
socket.emit('file', { id: file.id, name:file.name, remote_path:file.path, data:file.editor.getValue() });
socket.on('commit-changes', function (data) {
// console.log('hello');
if(file.id == data.id && file.path == data.path){
file.editor.setValue(data.data);
editor.setValue(data.data);
if(file){
socket.emit('file', { id: file.id, name:file.name, remote_path:file.path, data:file.editor.getValue() });
}else{
socket.emit('project', {path: project_path, name : path.basename(project_path)});
}
files['#' + data.id].editor.setValue(data.data);
});
socket.on('commit-changes', function (data) {
// console.log('hello');
if(file.id == data.id && file.path == data.path){
file.editor.setValue(data.data);
editor.setValue(data.data);
}
files['#' + data.id].editor.setValue(data.data);
});
socket.on('getRemoteDirectoryForSpecificDirpath', function(folder_path){
// console.log(folder_path);
let dir_structure = createDirectoryForSpecificDirpath(folder_path, true);
// console.log(dir_structure);
this.emit('directoryStructureForSpecificRemoteDirpath', dir_structure);
});
socket.on('getContentOfRemoteFile', function(filepath){
console.log('filepath')
let temp_file = openFileFromSidebar(filepath, true);
console.log(temp_file);
this.emit('openFile', temp_file);
});

socket.on('saveRemoteFile', function(data, remote_path){
let status = saveFile(data, remote_path, true);
console.log(status);
});
});
}
// }
}

function connect(flag){
Expand All @@ -61,6 +84,24 @@ function connect(flag){
$('#code-sharing-box').html('<button class = "btn" id = "commit_changes" onclick="code_sharing.commitChanges()">Commit Changes</button><br><br>');
$('#code-sharing-box').append('<button class = "btn" id = "close_socket" onclick="code_sharing.closeSocket()">Close Connection</button>');
});

socket.on('project', function(data){
code_sharing.remote_mode = true;
// console.log(data);
openFolder(data);
// $('#code-sharing-box').html('<button class = "btn" id = "commit_changes" onclick="code_sharing.commitChanges()">Commit Changes</button><br><br>');
$('#code-sharing-box').html('<button class = "btn" id = "close_socket" onclick="code_sharing.closeSocket()">Close Connection</button>');
});

socket.on('directoryStructureForSpecificRemoteDirpath', function(dir_structure){
console.log(dir_structure);
openSpecificDirectory(dir_structure);
});

socket.on('openFile', function(temp_file){
openFile(temp_file.data, undefined, temp_file.name, temp_file.filepath);
});

socket.on('commit-changes', function(data){
// console.log('data recieved');
// console.log(file.remote_path, remoteFile.remote_path);
Expand Down Expand Up @@ -94,10 +135,11 @@ function commitChanges(){
}

function backAllButtons(){
$('#code-sharing-box').html('<button class = "btn" id = "share-code" onclick="code_sharing.shareCode()">Share Code</button><br><br><button class = "btn" id = "connect" onclick="code_sharing.connect(false)">Connect</button>');
$('#code-sharing-box').html('<button class = "btn" id = "share-code" onclick="code_sharing.shareProject()">Share Project</button><br><br><button class = "btn" id = "share-code" onclick="code_sharing.shareCode()">Share Code</button><br><br><button class = "btn" id = "connect" onclick="code_sharing.connect(false)">Connect</button>');
}

function closeSocket(){
code_sharing.remote_mode = false;
socket.destroy();
backAllButtons();
}
Expand All @@ -107,12 +149,39 @@ function disconnect(){
backAllButtons();
}

function shareProject(){
let project_path = ipc.sendSync('getProjectPath');
// console.log(project_path);
if(project_path != null){
shareCode(false, project_path[0]);
}else{
code_sharing.remote_mode = false;
}
// console.log(code_sharing.remote_mode);
}

function getRemoteDirectoryForSpecificDirpath(folder_path){
console.log(folder_path);
socket.emit('getRemoteDirectoryForSpecificDirpath', folder_path);
}

function openRemoteFile(filepath){
socket.emit('getContentOfRemoteFile', filepath);
}

function saveRemoteFile(data, remote_path){
socket.emit('saveRemoteFile', data, remote_path);
}

module.exports = {
shareCode : shareCode,
connect : connect,
commitChangesSender : commitChangesSender,
commitChanges : commitChanges,
backAllButtons : backAllButtons,
closeSocket : closeSocket,
disconnect : disconnect
disconnect : disconnect,
shareProject : shareProject,
getRemoteDirectoryForSpecificDirpath,
openRemoteFile : openRemoteFile
}
142 changes: 48 additions & 94 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const fs = require('fs');
const markdown_converter = new showdown.Converter();
const path = require('path');
var files = {};
var remoteFile;
var newFileCount = 1;
var download_progress;
var userDataPath;
Expand Down Expand Up @@ -336,38 +335,39 @@ function openFolder(structure){
openProjectStructure(true);

last_session.openLastSessionFolders();
last_session.newLastSessionForProject(structure.path);
if(!code_sharing.remote_mode)
last_session.newLastSessionForProject(structure.path);
}

ipc.on('openFolder', function(event,structure){
code_sharing.remote_mode = false;
openFolder(structure);
});

// create directory for specific Dirpath

function createDirectoryForSpecificDirpath(folder){
// console.log(folder.getAttribute('data-path'));
// console.log($('#' + pathToId(folder.getAttribute('data-path'))).length);
// console.log($('#' + pathToId(folder.getAttribute('data-path'))).children());

if($('#' + pathToId(folder.getAttribute('data-path'))).children().length == 0){
ipc.send('createDirectoryForSpecificDirpath', folder.getAttribute('data-path'));

function createDirectoryForSpecificDirpath(folder, remote){
if(remote){
return ipc.sendSync('getRemoteDirectoryForSpecificDirpath', folder);
}else{
if(code_sharing.remote_mode){
code_sharing.getRemoteDirectoryForSpecificDirpath(folder.getAttribute('data-path'));
}else{
ipc.send('createDirectoryForSpecificDirpath', folder.getAttribute('data-path'));
}
}
}

ipc.on('getDirectroyForSpecificDirpath', function(event, structure){
console.log('open')
// console.log(structure);
// console.log(structure.path);
// console.log(makeDirectoryTree(structure.children));
// console.log($('#' + structure.path.replace(/ /g, '_')));
// console.log($('#askdfhkjashdfkjasdf'))

$('#' + pathToId(structure.path)).html(makeDirectoryTree(structure.children));
$('#' + pathToId(structure.path)).filetree();
last_session.updateOpenFolderInProjectInfo(pathToId(structure.path));

openSpecificDirectory(structure);
});

function openSpecificDirectory(dir_structure){
$('#' + pathToId(dir_structure.path)).html(makeDirectoryTree(dir_structure.children));
$('#' + pathToId(dir_structure.path)).filetree();
last_session.updateOpenFolderInProjectInfo(pathToId(dir_structure.path));
}
// create tree structure for opened folder

function makeDirectoryTree(structure){
Expand All @@ -384,10 +384,18 @@ function makeDirectoryTree(structure){
}


function openFileFromSidebar(file){
// console.log(file.getAttribute('data-path'));
let filepath = file.getAttribute('data-path');
ipc.send('openFileFromSidebar', filepath);
function openFileFromSidebar(file, remote){
if(remote){
console.log(file);
return ipc.sendSync('openRemoteFile', file);
}else{
let filepath = file.getAttribute('data-path');
if(code_sharing.remote_mode){
code_sharing.openRemoteFile(filepath);
}else{
ipc.send('openFileFromSidebar', filepath);
}
}
}

// // copy template to new opened file
Expand Down Expand Up @@ -430,18 +438,25 @@ ipc.on('saveAs', function(event){
}
})

ipc.on('save', function(event){
if(editor != undefined){
var data = editor.getValue();
// console.log(data);

// update file in last session
function saveFile(data, filepath, remote){
//update file in last session end here
if(remote){
return ipc.sendSync('saveRemoteFile', data, filepath);
}else{
ipc.send('save-data', data, filepath);
}
}

ipc.on('save', function(event){
if(editor != undefined){
let data = editor.getValue();
last_session.changeLastSessionFilesContent(file.id, data);

//update file in last session end here

ipc.send('save-data', data, file.path);
if(file.remote_path){
code_sharing.saveRemoteFile(data, file.remote_path);
}else{
saveFile(data, file.path);
}
}
});

Expand Down Expand Up @@ -1111,64 +1126,3 @@ function openSettingsRightPanel(menu){
}

// end here



// Tabs

// (function($){
// function initSecondaryCodeEditor(){
// var $active = $('#code_mirror_editors > .active > a');
// var $sec_tab = $($active.data('target'));
// // --> 1. & 2. & 3.: try to find an already existing CodeMirror instance (https://github.com/codemirror/CodeMirror/issues/1413)
// // if found, simply refresh it!
// var codeMirrorContainer = $sec_tab.find(".CodeMirror")[0];
// if (codeMirrorContainer && codeMirrorContainer.CodeMirror) {
// // console.log('hello');
// codeMirrorContainer.CodeMirror.refresh();
// } else {
// console.log('Hello');
// initEditor($sec_tab.find('textarea')[0]);
// // CodeMirror.fromTextArea($sec_tab.find('textarea')[0], {
// // lineNumbers: true
// // });
// }
// // <--
// }

// $(document).ready(function(){

// $('#code_mirror_editors > li > a[data-toggle="tab"]').on('shown.bs.tab', function(e){
// // --> 1.: this might be called while the element is still invisible which breaks some CodeMirror calculations
// if ($(e.target).is(":visible")) {
// initSecondaryCodeEditor();
// }
// // <--
// });

// // Remember tabs
// var json, tabsState;
// $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
// tabsState = localStorage.getItem("tabs-state");
// json = JSON.parse(tabsState || "{}");
// json[$(e.target).parents("ul.nav.nav-pills, ul.nav.nav-tabs").attr("id")] = $(e.target).data('target');

// localStorage.setItem("tabs-state", JSON.stringify(json));
// });

// tabsState = localStorage.getItem("tabs-state");

// json = JSON.parse(tabsState || "{}");
// $.each(json, function(containerId, target) {
// return $("#" + containerId + " a[data-target=" + target + "]").tab('show');
// });

// $("ul.nav.nav-pills, ul.nav.nav-tabs").each(function() {
// var $this = $(this);
// if (!json[$this.attr("id")]) {
// return $this.find("a[data-toggle=tab]:first, a[data-toggle=pill]:first").tab("show");
// }
// });

// });// doc.ready
// })(jQuery);
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function createWindow () {
slashes: true
}))
// Open the DevTools.
mainWindow.webContents.openDevTools()
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
Expand Down
Loading

0 comments on commit c038ec6

Please sign in to comment.