overhaul selectively showing context menu items

This commit is contained in:
joshuaboud 2021-06-10 11:21:49 -03:00
parent 0c76889ec6
commit 150ed28c5d
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E

View File

@ -247,6 +247,10 @@ class NavEntry {
owner.title = owner.innerText = this.stat["owner"]; owner.title = owner.innerText = this.stat["owner"];
group.title = group.innerText = this.stat["group"]; group.title = group.innerText = this.stat["group"];
size.title = size.innerText = format_bytes(this.stat["size"]); size.title = size.innerText = format_bytes(this.stat["size"]);
mode.classList.add("nav-item-title", "no-select");
owner.classList.add("nav-item-title", "no-select");
group.classList.add("nav-item-title", "no-select");
size.classList.add("nav-item-title", "no-select");
this.dom_element.appendChild(mode); this.dom_element.appendChild(mode);
this.dom_element.appendChild(owner); this.dom_element.appendChild(owner);
this.dom_element.appendChild(group); this.dom_element.appendChild(group);
@ -934,7 +938,6 @@ class NavContextMenu {
this.dom_element.appendChild(elem); this.dom_element.appendChild(elem);
this.menu_options[func[0]] = elem; this.menu_options[func[0]] = elem;
} }
this.menu_options["paste"].style.display = "none";
} }
new_dir() { new_dir() {
@ -1036,29 +1039,30 @@ class NavContextMenu {
* @param {NavEntry} target * @param {NavEntry} target
*/ */
show(event, target) { show(event, target) {
if (this.nav_window_ref.selected_entries.size > 1) { if (!this.nav_window_ref.none_selected()) {
if (event.shiftKey || event.ctrlKey) if (event.shiftKey || event.ctrlKey)
this.nav_window_ref.set_selected(target, event.shiftKey, event.ctrlKey); this.nav_window_ref.set_selected(target, event.shiftKey, event.ctrlKey);
} else { } else {
this.nav_window_ref.set_selected(target, false, false); this.nav_window_ref.set_selected(target, false, false);
} }
this.menu_options["download"].style.display = "flex"; for (let option of Object.keys(this.menu_options)) {
if (target === this.nav_window_ref.pwd()) { this.menu_options[option].style.display = "flex"; // show all
}
// selectively hide options based on context
if (this.nav_window_ref.none_selected()) {
this.menu_options["copy"].style.display = "none"; this.menu_options["copy"].style.display = "none";
this.menu_options["cut"].style.display = "none"; this.menu_options["cut"].style.display = "none";
this.menu_options["delete"].style.display = "none"; this.menu_options["delete"].style.display = "none";
} else { this.menu_options["download"].style.display = "none";
this.menu_options["copy"].style.display = "flex";
this.menu_options["cut"].style.display = "flex";
this.menu_options["delete"].style.display = "flex";
} }
if (this.nav_window_ref.selected_entries.size > 1) { if (this.nav_window_ref.selected_entries.size > 1) {
this.menu_options["rename"].style.display = "none"; this.menu_options["rename"].style.display = "none";
} else { } else {
this.menu_options["rename"].style.display = "flex"; if (target instanceof NavDirLink || target instanceof NavFileLink)
if (target instanceof NavFileLink)
this.menu_options["download"].style.display = "none"; this.menu_options["download"].style.display = "none";
} }
if (!this.nav_window_ref.clip_board.length)
this.menu_options["paste"].style.display = "none";
this.target = target; this.target = target;
this.dom_element.style.display = "inline"; this.dom_element.style.display = "inline";
this.dom_element.style.left = event.clientX + "px"; this.dom_element.style.left = event.clientX + "px";
@ -1583,6 +1587,10 @@ class NavWindow {
return [...this.selected_entries][this.selected_entries.size - 1]; return [...this.selected_entries][this.selected_entries.size - 1];
} }
none_selected() {
return this.selected_entries.length === 1 && this.selected_entry() === this.pwd();
}
show_selected_properties() { show_selected_properties() {
this.selected_entry().show_properties(); this.selected_entry().show_properties();
} }
@ -1855,7 +1863,6 @@ class NavWindow {
async paste_clipboard() { async paste_clipboard() {
this.start_load(); this.start_load();
this.context_menu.hide_paste();
var cmd = ["/usr/share/cockpit/navigator/scripts/paste.py"]; var cmd = ["/usr/share/cockpit/navigator/scripts/paste.py"];
var dest = this.pwd().path_str(); var dest = this.pwd().path_str();
if (this.copy_or_move === "move") { if (this.copy_or_move === "move") {
@ -1866,6 +1873,7 @@ class NavWindow {
cmd.push(item.path_str()); cmd.push(item.path_str());
} }
cmd.push(dest); cmd.push(dest);
this.clip_board.length = 0; // clear clipboard
var promise = new Promise((resolve, reject) => { var promise = new Promise((resolve, reject) => {
var proc = cockpit.spawn( var proc = cockpit.spawn(
cmd, cmd,