-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context-menu): add linux webview context menu (#237)
* feat(context-menu): create webview on wayland * dynamic generate menu items on html * add context_menu.html * add check mouse hit on context-menu webview * fix: context menu prompt back to verso * feat(context-menu): on linux, handle selection * fix: disble right click on context menu * organize code * adding cfg target linux * fix(linux): shift context menu to avoid overflow, best effort * fix: not append context_menu to dialog webviews * Update src/window.rs Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <[email protected]> Signed-off-by: Jason Tsai <[email protected]> * Update src/window.rs Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <[email protected]> Signed-off-by: Jason Tsai <[email protected]> * move webview id on position to compositor * create Menu newtype * chore: remove unused import * fix: add target_os condition on context_menu --------- Signed-off-by: Jason Tsai <[email protected]> Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <[email protected]>
- Loading branch information
Showing
8 changed files
with
575 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<html> | ||
<head> | ||
<style> | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
background: #dfdfdf; | ||
width: 184px; | ||
} | ||
.menu { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: start; | ||
} | ||
.menu-item { | ||
cursor: pointer; | ||
display: inline-block; | ||
height: 30px; | ||
width: 100%; | ||
line-height: 30px; | ||
padding-left: 5px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
.menu-item:hover { | ||
background: #cecece; | ||
border-radius: 5px; | ||
} | ||
.menu-item.disabled { | ||
cursor: default; | ||
background: #dfdfdf; | ||
color: #505050; | ||
cursor: pointer; | ||
} | ||
.menu-item:hover.disabled { | ||
background: #dfdfdf; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="menu" class="menu"></div> | ||
</body> | ||
<script> | ||
const menuEl = document.getElementById('menu'); | ||
|
||
let url = URL.parse(window.location.href); | ||
let params = url.searchParams; | ||
|
||
const options = JSON.parse(params.get('items')); | ||
for (option of options) { | ||
createMenuItem(option.id, option.label, option.enabled); | ||
} | ||
|
||
function createMenuItem(id, label, enabled) { | ||
const menuItem = document.createElement('div'); | ||
menuItem.classList.add('menu-item'); | ||
menuItem.id = id; | ||
menuItem.innerText = label; | ||
|
||
if (!enabled) { | ||
menuItem.classList.add('disabled'); | ||
} else { | ||
menuItem.onclick = (ev) => { | ||
// accept left click only | ||
if (ev.buttons !== 1) { | ||
return; | ||
} | ||
const msg = JSON.stringify({ | ||
id, | ||
close: true, | ||
}); | ||
console.log(`CONTEXT_MENU:${msg}`); | ||
window.prompt(`CONTEXT_MENU:${msg}`); | ||
}; | ||
} | ||
|
||
menuEl.appendChild(menuItem); | ||
} | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.