Skip to content

Commit

Permalink
fixed rename
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammed-abuodeh committed Feb 27, 2024
1 parent a36cf43 commit df49474
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 11 deletions.
11 changes: 11 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ li #faq {
font-size: 1.2em;
font-family: 'bebas';
display: none;

display: flex;
justify-content: space-between;
}

#conlluFileName #currentTreeNumber{
Expand Down Expand Up @@ -320,6 +323,7 @@ body.viewtree {
/* toolbar buttons */
.toolbar {
/* display: inline-block; */
flex: 0 0 20%
}

.toolbar input {
Expand Down Expand Up @@ -636,6 +640,13 @@ div.scroll {
row-gap: 0.5vw;
}

.rename-mode-input {
display: inline-block !important;
margin-top: 0px !important;
background: white !important;
color: black !important;
}

/****************************************************************/
/* Server button classes */
/****************************************************************/
Expand Down
92 changes: 81 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,12 @@ function isValidExtension(original_filename) {
}

function addFilenameToHtmlElements(original_filename) {
// display filename on page and when downloading files
document.getElementById("conlluFileName").innerHTML = original_filename;
// // display filename on page and when downloading files
// document.getElementById("conlluFileName").innerHTML = original_filename;
filenameIdx = 0 // the index of the filename in the parent div is always 0 (1 is the tree number)
filenameParent = document.getElementById("conlluFileNameDiv");
const span = renderFilenameInReadMode(original_filename, filenameParent, filenameIdx);
filenameParent.replaceChild(span, filenameParent.children[0]);
}

function LocalFileInputChecker() {
Expand Down Expand Up @@ -1443,16 +1447,82 @@ var goToTreeToggle = function () {
}
};

function addEditListenerToSpan(span, filenameParent, filenameIdx) {
span.addEventListener('dblclick', () => {
filenameParent.replaceChild(
renderRenameMode(span.textContent, filenameParent, filenameIdx),
filenameParent.children[filenameIdx]
)
});
}


function renderFilenameInReadMode(filename, filenameParent, filenameIdx) {
const span = document.createElement('span');
span.textContent = filename;
span.id = "conlluFileName";

addEditListenerToSpan(span, filenameParent, filenameIdx);

return span;
}

function renderRenameMode(oldFilename, filenameParent, filenameIdx) {
const div = document.createElement('div');
div.id = "conlluFileName";

const textInput = document.createElement('input');
textInput.type = 'text';
textInput.value = oldFilename;
textInput.className = "rename-mode-input";

div.appendChild(textInput);

// add save button
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.addEventListener('click', () => {
filenameParent.replaceChild(
renderFilenameInReadMode(textInput.value, filenameParent, filenameIdx),
filenameParent.children[filenameIdx]
);
});
div.appendChild(saveButton);

// add cancel button
const cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
cancelButton.addEventListener('click', () => {
filenameParent.replaceChild(
renderFilenameInReadMode(oldFilename, filenameParent, filenameIdx),
filenameParent.children[filenameIdx]
);
});

div.appendChild(cancelButton);

return div;
}

function renameToggle() {
if (focusWindow !== "saveas") {
hideAllWindows();
$("#rename").show();
$("#rename-section").show();
focusWindow = "rename-section";
$("#filename_remote").val(addFileExtension(document.getElementById("conlluFileName").innerHTML, ".conllu"));
} else {
hideAllWindows();
}
filenameIdx = 0 // the index of the filename in the parent div is always 0 (1 is the tree number)

filenameParent = document.getElementById("conlluFileNameDiv");
oldFilename = filenameParent.children[filenameIdx].textContent;

filenameParent.replaceChild(
renderRenameMode(oldFilename, filenameParent, filenameIdx), // 0 is the index
filenameParent.children[filenameIdx]
)
// if (focusWindow !== "saveas") {
// hideAllWindows();
// $("#rename").show();
// $("#rename-section").show();
// focusWindow = "rename-section";
// $("#filename_remote").val(addFileExtension(document.getElementById("conlluFileName").innerHTML, ".conllu"));
// } else {
// hideAllWindows();
// }
};

// END SETTINGS
Expand Down

0 comments on commit df49474

Please sign in to comment.