Skip to content

Commit

Permalink
Merge pull request #72 from alvi-khan/open-file
Browse files Browse the repository at this point in the history
Added option to open a new file.
  • Loading branch information
alvi-khan authored Mar 7, 2023
2 parents d41f972 + 8723e70 commit 1602e8e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/components/menubar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@
</div>
-->

<div class="q-ml-md cursor-pointer non-selectable">
<span>
File
</span>
<q-menu>
<q-list dense style="min-width: 100px">
<q-item clickable v-close-popup @click="$refs.file.click()">
<q-item-section>Open File</q-item-section>
<input
@change="openFile"
type="file"
ref="file"
accept=".txt"
style="display: none"
/>
</q-item>
</q-list>
</q-menu>
</div>

<div class="q-ml-md cursor-pointer non-selectable">
<span>
Annotations
Expand Down Expand Up @@ -183,7 +203,7 @@ export default {
...mapState(["annotations", "classes"]),
},
methods: {
...mapMutations(["loadClasses", "loadAnnotations"]),
...mapMutations(["loadClasses", "loadAnnotations", "setInputSentences", "clearAllAnnotations", "resetIndex"]),
// Funtion that exports the tags to a JSON file
exportTags: async function() {
await exportFile(JSON.stringify(this.classes), "tags.json");
Expand All @@ -205,6 +225,16 @@ export default {
};
filereader.readAsText(file);
},
openFile: function(e) {
let file = e.target.files[0];
let filereader = new FileReader();
filereader.onload = (ev) => {
this.setInputSentences(ev.target.result);
this.clearAllAnnotations();
};
filereader.readAsText(file);
this.resetIndex();
},
importAnnotations: function(e) {
let file = e.target.files[0];
let filereader = new FileReader();
Expand Down
4 changes: 4 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const mutations = {
state.annotations[state.currentIndex] = payload;
state.currentAnnotation = payload;
},
clearAllAnnotations(state) {
state.annotations = [];
state.currentAnnotation = {};
},
setSeparator(state, payload) {
state.separator = payload;
const sentences = state.originalText.split(state.separator);
Expand Down

0 comments on commit 1602e8e

Please sign in to comment.