Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
(click)="DecreaseFont()"><i>A-</i></button>
<button class="btn btn-light btn-sm mb-1 mt-2 mr-1 " matTooltip="Download ino file" style="font-size: 16px; max-height:30px;background: transparent;"
(click)="DownloadCode()"><i class="fa fa-download"></i></button>
<button class="btn btn-light btn-sm mb-1 mt-2 mr-1 " matTooltip="Upload ino file" style="font-size: 16px; max-height:30px;background: transparent;"
(click)="uploadInput.click()"><i class="fa fa-upload"></i></button>
<input id = "UploadCodeBTN" type="file" accept=".ino" #uploadInput style="display: none;" (change)="UploadCode($event)">


<button class="btn btn-light btn-sm mb-1 mt-2 mr-1 " matTooltip="Include Library" style="font-size:16px; max-height:30px;background: transparent;"
(click)="openFolder()"><i class="fas fa-box"></i></button>
<form>
Expand Down
17 changes: 17 additions & 0 deletions ArduinoFrontend/src/app/code-editor/code-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ export class CodeEditorComponent {
type: 'text/ino;charset=utf-8;'
});
}
/**
* Upload the code to the code editor
* @param event Event object containing the file input
*/
UploadCode(event) {
const file: File = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.readAsText(file);

reader.onload = () => {
const fileData = reader.result as string; // file content as string
this.editor.setValue(fileData); // Load content into the editor
document.getElementById('UploadCodeBTN')['value'] = null; // Reset input field
};
}
}
/**
* Include the header to the code
* @param i Index of the Library that needs to be included
Expand Down