Skip to content

Commit

Permalink
Add new button for open with code
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsseTheWolf committed Jan 8, 2024
1 parent ba2dec7 commit 09de659
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
1 change: 1 addition & 0 deletions assets/add-bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/minus-bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/vscode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 31 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<div class="menu">
<div class="menu-group">
<div id="pathDisplay"></div>
<div id="pathDisplay" style="margin-left: 5px;"></div>
<div id="saveStatus">Unsaved changes</div>
</div>
<div class="menu-group">
Expand All @@ -28,20 +28,32 @@
<img src="assets/rename-file.svg" width="16px" height="16px" style="margin-right: 5px;"/>
<div class="button-hover-content">Rename File</div>
</div>
<div class="button" id="openWithCode">
<img src="assets/vscode.svg" width="16px" height="16px" style="margin-right: 5px;" />
</div>
</div>
</div>
<div id="container"></div>
<div class="menu">
<select id="language">
<option value="javascript">JavaScript</option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="python">Python</option>
<option value="cpp">C++</option>
<option value="java">Java</option>
<option value="json">JSON</option>
<option value="txt">Plain text</option>
</select>
<div class="menu" id="footerMenu">
<div class="menu-group">
<select id="language">
<option value="javascript">JavaScript</option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="python">Python</option>
<option value="cpp">C++</option>
<option value="java">Java</option>
<option value="json">JSON</option>
<option value="txt">Plain text</option>
</select>
<div class="button" id="increaseFontSizeButton">
<img src="assets/add-bold.svg" width="16px" height="16px"/>
</div>
<div class="button" id="textSize">-</div>
<div class="button" id="decreaseFontSizeButton">
<img src="assets/minus-bold.svg" width="16px" height="16px"/>
</div>
</div>
<div id="cursorPosition" style="font-size: small;">Row: 0, Column: 0</div>
</div>
<script src="renderer.js"></script>
Expand All @@ -64,6 +76,11 @@
flex-direction: column;
user-select: none;
}
#footerMenu {
background-color: rgba(0,0,0,0);
margin: 0px;
padding: 5px;
}
#container {
flex: auto;
width: 100%;
Expand Down Expand Up @@ -109,12 +126,12 @@
.button:hover {
background-color: rgba(255, 255, 255, 0.2);
}
.button-hover-content {
/* .button-hover-content {
display: none;
}
.button:hover .button-hover-content {
display: block;
}
} */

select {
font-family: var(--default-font-family);
Expand Down
11 changes: 11 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const { app, BrowserWindow, ipcMain, dialog, globalShortcut, Tray, Menu } = require('electron');
const fs = require('fs');
const path = require('path');
const {exec} = require('child_process');
const homedirHandler = require('./homedirHandler');
const moment = require('moment');
const themes = require("./styles/stylesManager.js");
Expand Down Expand Up @@ -115,6 +116,16 @@ app.on('ready', () => {
event.reply("got-style", themes)
});

// open with code
ipcMain.on("open-with-code", (event, filePath) => {
console.log(filePath);
exec(`code "${filePath}"`, (err, stdout, stderr) => {
if (err) {
console.log(err);
}
});
})

});

app.on('window-all-closed', function () {
Expand Down
27 changes: 27 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let editor;
let currentFilePath;
let client;
let isSaved = false;
let currentTextSize = 16;

const defaultTheme = {
base: "vs-dark",
Expand Down Expand Up @@ -360,6 +361,7 @@ require(['vs/editor/editor.main'], function() {
value: '',
language: 'javascript',
theme: 'currentTheme',
fontSize: currentTextSize,
});

editor.onDidChangeCursorPosition(function (e) {
Expand Down Expand Up @@ -405,6 +407,8 @@ require(['vs/editor/editor.main'], function() {
currentFilePath = filePath;
document.getElementById("pathDisplay").innerText = fileName;
});

document.getElementById('textSize').textContent = currentTextSize;
});

function openFile() {
Expand Down Expand Up @@ -448,12 +452,35 @@ async function handleRenameFile() {
console.log(filePath);
}

function increaseTextSize() {
currentTextSize += 1;
editor.updateOptions({
fontSize: currentTextSize
});
document.getElementById('textSize').textContent = currentTextSize;
}

function decreaseTextSize() {
currentTextSize -= 1;
editor.updateOptions({
fontSize: currentTextSize
});
document.getElementById('textSize').textContent = currentTextSize;
}

function openWithCode() {
window.ipcRenderer.send("open-with-code", currentFilePath);
}


document.getElementById("pathDisplay").innerText = currentFilePath;
document.getElementById('openFileButton').addEventListener('click', openFile);
document.getElementById('newFileButton').addEventListener('click', createNewFile);
document.getElementById('saveFileButton').addEventListener('click', saveFile);
document.getElementById('renameFileButton').addEventListener('click', renameFile);
document.getElementById('increaseFontSizeButton').addEventListener('click', increaseTextSize);
document.getElementById('decreaseFontSizeButton').addEventListener('click', decreaseTextSize);
document.getElementById('openWithCode').addEventListener('click', openWithCode);

window.addEventListener('resize', function () {
editor.layout();
Expand Down

0 comments on commit 09de659

Please sign in to comment.