-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make branch actions available via context menu too
- Loading branch information
Showing
17 changed files
with
220 additions
and
65 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
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,95 @@ | ||
import Vue from 'vue' | ||
|
||
``###* @typedef {{label:string,icon?:string,action:()=>any}} ContextMenuEntry ### | ||
``###* @typedef {{ | ||
oncontextmenu: (this: HTMLElement, ev: MouseEvent) => any | ||
onglobalclick: (ev: MouseEvent) => any | ||
onglobalkeyup: (ev: KeyboardEvent) => any | ||
entries: ContextMenuEntry[] | ||
}} ContextMenuData | ||
### | ||
|
||
``###* @type {Map<HTMLElement,ContextMenuData>} ### | ||
context_menu_data_by_el = new Map | ||
|
||
set_context_menu = (###* @type HTMLElement ### el, ###* @type ContextMenuEntry[] ### entries) => | ||
existing_context_menu_data = context_menu_data_by_el.get el | ||
if existing_context_menu_data | ||
existing_context_menu_data.entries = entries | ||
return | ||
|
||
``###* @type {HTMLElement | null} ### | ||
wrapper_el = null | ||
|
||
# The element(s) created by this is quite similar to the template of <git-action-button> | ||
build_context_menu = (###* @type number ### x, ###* @type number ### y) => | ||
wrapper_el = document.createElement('ul') | ||
wrapper_el.setAttribute('aria-label', 'Context menu') | ||
wrapper_el.classList.add 'context-menu-wrapper' | ||
wrapper_el.style.setProperty 'left', x + 'px' | ||
wrapper_el.style.setProperty 'top', y + 'px' | ||
for entry from entries | ||
entry_el = document.createElement('li') | ||
entry_el.setAttribute('role', 'button') | ||
entry_el.classList.add('row', 'gap-5') | ||
icon_el = document.createElement('i') | ||
if entry.icon | ||
icon_el.classList.add "codicon", "codicon-#{entry.icon}" | ||
label_el = document.createElement('span') | ||
label_el.textContent = entry.label | ||
entry_el.appendChild(icon_el) | ||
entry_el.appendChild(label_el) | ||
entry_el.onclick = entry.action | ||
wrapper_el.appendChild(entry_el) | ||
document.body.appendChild(wrapper_el) | ||
destroy_context_menu = => | ||
return if not wrapper_el | ||
document.body.removeChild(wrapper_el) | ||
wrapper_el = null | ||
|
||
``###* @type ContextMenuData ### | ||
context_menu_data = | ||
oncontextmenu: (e) => | ||
e.preventDefault() | ||
e.stopPropagation() | ||
destroy_context_menu() | ||
build_context_menu(e.clientX, e.clientY) | ||
onglobalclick: => | ||
destroy_context_menu() | ||
onglobalkeyup: (e) => | ||
if e.key == "Escape" | ||
destroy_context_menu() | ||
entries: entries | ||
|
||
el.addEventListener 'contextmenu', context_menu_data.oncontextmenu, false | ||
document.addEventListener 'contextmenu', context_menu_data.onglobalclick, false | ||
document.addEventListener 'click', context_menu_data.onglobalclick, false | ||
document.addEventListener 'keyup', context_menu_data.onglobalkeyup, false | ||
|
||
context_menu_data_by_el.set el, context_menu_data | ||
|
||
disable_context_menu = (###* @type {HTMLElement} ### el) => | ||
context_menu_data = context_menu_data_by_el.get el | ||
if not context_menu_data | ||
return | ||
el.removeEventListener 'contextmenu', context_menu_data.oncontextmenu | ||
document.removeEventListener 'contextmenu', context_menu_data.onglobalclick | ||
document.removeEventListener 'click', context_menu_data.onglobalclick | ||
document.removeEventListener 'keyup', context_menu_data.onglobalkeyup | ||
context_menu_data_by_el.delete el | ||
|
||
``###* @type {Vue.Directive} ### | ||
directive = | ||
mounted: (el, { value }) -> | ||
if value | ||
set_context_menu el, value | ||
updated: (el, { value }) -> | ||
value = value or null | ||
if not value | ||
disable_context_menu el | ||
else | ||
set_context_menu el, value | ||
unmounted: (el) -> | ||
disable_context_menu el | ||
|
||
export default directive |
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
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 |
---|---|---|
@@ -1,27 +1,13 @@ | ||
import { ref, defineComponent } from 'vue' | ||
import GitInput from './GitInput.vue' | ||
import { defineComponent } from 'vue' | ||
import { selected_git_action } from './store.coffee' | ||
|
||
###* visual representation of a GitAction, resolving to a Button and onclick a Popup with GitInput inside ### | ||
export default defineComponent | ||
inheritAttrs: false | ||
components: { GitInput } | ||
emits: [ 'change' ] | ||
props: | ||
git_action: | ||
###* @type {() => import('./GitInput.coffee').GitAction} ### | ||
type: Object | ||
required: true | ||
setup: (_, { emit }) -> | ||
show_popup = ref false | ||
keep_open = ref false | ||
|
||
success = => | ||
if not keep_open.value | ||
show_popup.value = false | ||
emit 'change' | ||
|
||
{ | ||
show_popup | ||
keep_open | ||
success | ||
} | ||
setup: -> | ||
{ selected_git_action } |
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 |
---|---|---|
@@ -1,22 +1,12 @@ | ||
<template lang="slm"> | ||
div | ||
button.btn.gap-5 @click="show_popup=true" :title="git_action.description" | ||
.icon.center v-if="git_action.icon" | ||
i.codicon :class="'codicon-'+git_action.icon" | ||
.title v-if="git_action.title" | ||
| {{ git_action.title }} | ||
popup v-if="show_popup" @close="show_popup=false" | ||
.selected-input | ||
p Execute Git command | ||
git-input :git_action="git_action" @success="success()" | ||
label.row.align-center.gap-5 | ||
input type="checkbox" v-model="keep_open" | ||
| Keep window open after success | ||
button.btn.gap-5 @click="selected_git_action=git_action" :title="git_action.description" | ||
.icon.center v-if="git_action.icon" | ||
i.codicon :class="'codicon-'+git_action.icon" | ||
.title v-if="git_action.title" | ||
| {{ git_action.title }} | ||
</template> | ||
|
||
<script lang="coffee" src="./GitActionButton.coffee"></script> | ||
|
||
<style lang="stylus"> | ||
.selected-input | ||
width: clamp(200px, 50vw, 50vw) | ||
</style> |
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
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.