Skip to content

Commit

Permalink
Update 1.3.0 and Fixed multiple Instances of same file
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhekur committed Jan 14, 2019
1 parent a306f3b commit 05b6bc8
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 69 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Changelog
- Capable of remembering last session if you forgot to save
- Auto Save
- Button & shorcut added to refresh preview
- Update download progress bar added
- Improved performance
- Themes Implemented
- Template Implemented
- Settings Panel Implemented
- Hint on Sidebar
- Multiple instances of same file has been fixed
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Colon is a flexible text editor, built on [Electron](https://github.com/electron

### macOS

Download the latest [Colon release](https://github.com/Chhekur/colon-ide/releases/download/v1.2.0/Colon-1.2.0.dmg) for mac.
Download the latest [Colon release](https://github.com/Chhekur/colon-ide/releases/download/v1.3.0/Colon-1.3.0.dmg) for mac.

Colon will automatically update when a new release is available.

### Windows

Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.2.0/Colon-Setup-1.2.0.exe) for windows.
Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.3.0/Colon-Setup-1.3.0.exe) for windows.

Colon will automatically update when a new release is available.

### Linux

Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.2.0/Colon-1.2.0-x86_64.AppImage) for linux.
Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.3.0/Colon-1.3.0-x86_64.AppImage) for linux.

## License

Expand Down
131 changes: 84 additions & 47 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,26 @@ let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/i
last_session = JSON.parse(last_session);
// console.log(last_session,Object.keys(last_session).length);
if(Object.keys(last_session).length > 0){
for (i in last_session){
// console.log(i);
fs.writeFileSync(path.join(getUserDataPath() , '/last_session/info.json'), '{}');
for (let i in last_session){
// console.log('i - ', i);
let data = fs.readFileSync(path.join(getUserDataPath(), last_session[i].current_path), 'utf-8');
openFile(data, last_session[i].original_path);

// console.log('file_id - ', '#' + file.id);
// console.log('#' + file.id, i);
if('#' + file.id != i){
fs.unlinkSync(path.join(getUserDataPath(), last_session[i].current_path));
let temp_last_session = fs.readFileSync(path.join(getUserDataPath() , '/last_session/info.json'));
temp_last_session = JSON.parse(temp_last_session);
delete temp_last_session[i];
temp_last_session = JSON.stringify(temp_last_session, null, 2);
fs.writeFileSync(path.join(getUserDataPath() , '/last_session/info.json'),temp_last_session);
// let temp_last_session = fs.readFileSync(path.join(getUserDataPath() , '/last_session/info.json'));
// temp_last_session = JSON.parse(temp_last_session);
// delete temp_last_session[i];
// temp_last_session = JSON.stringify(temp_last_session, null, 2);
}
}

// for(i in last_session){
// let data = fs.readFileSync(path.join(getUserDataPath(), last_session[i].current_path), 'utf-8');
// openFile(data, last_session[i].original_path);
// }
// fs.writeFileSync('last_session/info.json','{}');
}else{
newFile();
Expand Down Expand Up @@ -210,39 +216,66 @@ ipc.on('themeChanged', function(event){
// editor.refresh();
});

// check is file already opened

function isFileAlreadyOpened(filepath){
for(i in files){
if(files[i].path == filepath) return true;
}
return false;
}

// end here

// get File ID from filepath

function getFileID(filepath){
for(i in files){
if(files[i].path == filepath) return files[i].id;
}
return undefined;
}

// end here


// Open File

function openFile(data, filepath){
newFileCount++;
newTab(filepath, newFileCount , (filepath == undefined) ? 'untitled': path.basename(filepath),data);
if(isFileAlreadyOpened(filepath)){
// console.log($('#filename_'+getFileID(filepath)));
$('#filename_'+getFileID(filepath)).click();
}else{
newFileCount++;
newTab(filepath, newFileCount , (filepath == undefined) ? 'untitled': path.basename(filepath),data);

//last session
//last session

let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
last_session = JSON.parse(last_session);
// console.log(last_session);
last_session['#new' + newFileCount] = {
original_path : filepath,
current_path : path.join('last_session','#new' + newFileCount)
}
fs.writeFile(path.join(getUserDataPath(), last_session['#new' + newFileCount].current_path), data, function(error){
if(error) throw error;
});
last_session = JSON.stringify(last_session, null, 2);
fs.writeFileSync(path.join(getUserDataPath(), '/last_session/info.json'),last_session);
let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
last_session = JSON.parse(last_session);
// console.log(last_session);
last_session['#new' + newFileCount] = {
original_path : filepath,
current_path : path.join('last_session','#new' + newFileCount)
}
fs.writeFile(path.join(getUserDataPath(), last_session['#new' + newFileCount].current_path), data, function(error){
if(error) throw error;
});
last_session = JSON.stringify(last_session, null, 2);
fs.writeFileSync(path.join(getUserDataPath(), '/last_session/info.json'),last_session);

// last session end here
// last session end here

$('#filename_new'+newFileCount).click();
// files['#'+filepath] = {
// path: filepath,
// name: path.basename(filepath),
// id: filepath,
// editor: editor
// }
// // console.log('Hello')
// editor.getDoc().setValue(data);
$('#filename_new'+newFileCount).click();
// files['#'+filepath] = {
// path: filepath,
// name: path.basename(filepath),
// id: filepath,
// editor: editor
// }
// // console.log('Hello')
// editor.getDoc().setValue(data);
}
}


Expand Down Expand Up @@ -635,21 +668,25 @@ ipc.on('editorSettingsSaved', function(event){
// open about page

ipc.on('openAbout', function(event){
if(isFileAlreadyOpened(path.join(__dirname, 'about.html'))){
$('#filename_'+getFileID(path.join(__dirname, 'about.html'))).click();
// console.log('jello');
newFileCount++;
let file_id = "new" + newFileCount;
fs.readFile(path.join(__dirname, 'about.html'), function(err,data){
if(err) console.log(err);
$('#code_mirror_editors').append('<li id = "file_tab_'+file_id+'"><a href="" data-target="#' + file_id + '" role="tab" data-toggle="tab"><span id = "filename_'+file_id+'" onclick = "opentab(this)">' + 'About' + '</span><span onclick = "closeAnyFile(this)" class="close black"></span></a></li>');
$('#editors').append('<div class="tab-pane" id = "'+file_id+'">'+data+'</div>');
files['#'+ file_id] = {
path: undefined,
name: undefined,
id: file_id,
editor: undefined
}
$('#filename_new'+newFileCount).click();
});
}else{
newFileCount++;
let file_id = "new" + newFileCount;
fs.readFile(path.join(__dirname, 'about.html'), function(err,data){
if(err) console.log(err);
$('#code_mirror_editors').append('<li id = "file_tab_'+file_id+'"><a href="" data-target="#' + file_id + '" role="tab" data-toggle="tab"><span id = "filename_'+file_id+'" onclick = "opentab(this)">' + 'About' + '</span><span onclick = "closeAnyFile(this)" class="close black"></span></a></li>');
$('#editors').append('<div class="tab-pane" id = "'+file_id+'">'+data+'</div>');
files['#'+ file_id] = {
path: path.join(__dirname, 'about.html'),
name: undefined,
id: file_id,
editor: undefined
}
$('#filename_new'+newFileCount).click();
});
}
});

// open console
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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
12 changes: 6 additions & 6 deletions menu/view_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ module.exports = [
click:function(){
fun.openProjectStructure();
}
},
{
label : 'Change Theme',
click:function(){
fun.changeTheme();
}
}
// {
// label : 'Change Theme',
// click:function(){
// fun.changeTheme();
// }
// }
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Colon",
"version": "1.2.0",
"version": "1.3.0",
"description": "A flexible text editor",
"author": "Harendra Chhekur <[email protected]>",
"main": "main.js",
Expand Down
3 changes: 0 additions & 3 deletions settings.json

This file was deleted.

4 changes: 4 additions & 0 deletions src/editor/theme/ambiance.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/editor/theme/darcula.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@
.theme-container-active{
background-color: #303030;
}
.about-page {
color:#abb2bf;
background-color:#323131;
}
4 changes: 4 additions & 0 deletions src/editor/theme/dracula.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@
.theme-container-active{
background-color: #2d2f3d;
}
.about-page {
color:#abb2bf;
background-color:#282a36;
}
4 changes: 4 additions & 0 deletions src/editor/theme/eclipse.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@
.theme-container-active{
background-color: #c1c1c1;
}
.about-page {
color:#000000;
background-color:#fff;
}
4 changes: 4 additions & 0 deletions src/editor/theme/gruvbox-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@
.theme-container-active{
background-color: #303030;
}
.about-page {
color:#abb2bf;
background-color:#303030;
}
4 changes: 4 additions & 0 deletions src/editor/theme/hopscotch.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@
.theme-container-active{
background-color: #3f313d;
}
.about-page {
color:#abb2bf;
background-color:#322931;
}
4 changes: 4 additions & 0 deletions src/editor/theme/monokai.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@
.theme-container-active{
background-color: #303030;
}
.about-page {
color:#abb2bf;
background-color:#303030;
}
4 changes: 4 additions & 0 deletions src/editor/theme/one-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@
.theme-container-active{
background-color: #2f3640;
}
.about-page {
color:#abb2bf;
background-color:#282c34;;
}
14 changes: 11 additions & 3 deletions views/about.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<style>
.about-page {
margin:0px;
color:#abb2bf;
/*color:#abb2bf;*/
font-family:system-ui;
align-items: center;
display: flex;
justify-content: center;
height: 100%;
width: 100%;
background-color:#282c34;
/*background-color:#282c34;*/
}
</style>

<script>
let fs = require('fs');
let path = require('path');
let version = fs.readFileSync(path.join(__dirname, '..', 'package.json'));
version = JSON.parse(version);
document.getElementById('version').innerHTML = version.version;
</script>
<div class = "about-page">
<center>
<img src = "../assets/icon.png" width = 100px>
<h1>
Colon
Colon <span id = "version"></span>
</h1>
<h4>
A flexible text editor or ide
Expand Down

0 comments on commit 05b6bc8

Please sign in to comment.