增加 sidebar + signal view tree 新功能:shift + 鼠标左击连续选择

This commit is contained in:
锦恢 2024-09-02 20:49:53 +08:00
parent 0e21f5c4f8
commit ce90f9df4b
5 changed files with 126 additions and 32 deletions

View File

@ -23,7 +23,7 @@
<SignalItem <SignalItem
v-show="view.renderType === 0" v-show="view.renderType === 0"
:view="view" :view="view"
@click.stop="handleItemClick(view.signalInfo.link)" @click.stop="handleItemClick($event, view.signalInfo.link)"
@contextmenu.prevent="handleContextmenu($event, view, index)" @contextmenu.prevent="handleContextmenu($event, view, index)"
/> />
@ -76,6 +76,7 @@ import SignalItem from './signal-item.vue';
import GroupItem from './group-item.vue'; import GroupItem from './group-item.vue';
import GroupContextMenu from './group-context-menu.vue'; import GroupContextMenu from './group-context-menu.vue';
import { sidebarSelectedWires } from '@/hook/sidebar-select-wire'; import { sidebarSelectedWires } from '@/hook/sidebar-select-wire';
import { genOrderedLinks } from '@/hook/wave-container-view';
const { t } = useI18n(); const { t } = useI18n();
defineComponent({ name: 'side-bar' }); defineComponent({ name: 'side-bar' });
@ -102,18 +103,37 @@ function addSignal() {
} }
function handleItemClick(link) { function handleItemClick(event, link) {
contextmenu.show = false; contextmenu.show = false;
groupcontextmenu.show = false; groupcontextmenu.show = false;
const lastLink = sidebarSelectedWires.lastLink;
if (sidebarSelectedWires.has(link)) { if (event.shiftKey && lastLink !== undefined) {
sidebarSelectedWires.delete(link); // shift link link
let addBegin = false;
const links = [];
for (const currentLink of genOrderedLinks({returnGroup: false})) {
if (currentLink === link || currentLink === lastLink) {
links.push(currentLink);
addBegin = !addBegin;
} else if (addBegin) {
links.push(currentLink);
}
}
sidebarSelectedWires.addLinks(links);
} else { } else {
sidebarSelectedWires.add(link); //
if (sidebarSelectedWires.has(link)) {
sidebarSelectedWires.delete(link);
} else {
sidebarSelectedWires.add(link);
}
} }
} }
function handleSidebarGlobalClick() { function handleSidebarGlobalClick() {
contextmenu.show = false; contextmenu.show = false;
groupcontextmenu.show = false; groupcontextmenu.show = false;

View File

@ -70,6 +70,7 @@ export default {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
transition: height .5s ease-in-out; transition: height .5s ease-in-out;
user-select: none;
} }
.vcd-module-wrapper { .vcd-module-wrapper {

View File

@ -4,7 +4,7 @@
<hr> <hr>
<el-scrollbar height="86vh" class="vcd-signal-signals-display"> <el-scrollbar height="86vh" class="vcd-signal-signals-display">
<div v-for="(signal, index) in signals.content" :key="index" <div v-for="(signal, index) in signals.content" :key="index"
@click="toggleRender(signal)" @click="toggleRender($event, signal)"
class="vcd-signal-signal-item" class="vcd-signal-signal-item"
:class="globalLookup.currentWires.has(signal) ? 'vcd-treeview-selected' : ''" :class="globalLookup.currentWires.has(signal) ? 'vcd-treeview-selected' : ''"
> >
@ -19,42 +19,73 @@
</div> </div>
</template> </template>
<script> <script setup>
import { reactive } from 'vue'; import { defineComponent, reactive } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { emitter, globalLookup } from '@/hook/global'; import { emitter, globalLookup } from '@/hook/global';
import { makeIconClass } from '@/hook/utils'; import { makeIconClass } from '@/hook/utils';
import { toggleRender } from '@/hook/render'; import { WaveContainerView } from '@/hook/wave-container-view';
/* eslint-disable */ defineComponent({ name: 'signals' });
export default {
name: 'signals',
props: {},
setup() {
const { t } = useI18n();
// signal : link, name, size, type const { t } = useI18n();
const signals = reactive({
content: []
});
emitter.on('tree-view', sendWires => { // signal : link, name, size, type
signals.content = []; const signals = reactive({
signals.content = sendWires; /**
}); * @type {WireItem[]}
*/
content: []
});
function makeSignalCaption(signal) { emitter.on('tree-view', sendWires => {
return signal.size === 1 ? '' : `${signal.size - 1}:0`; signals.content = sendWires;
});
function makeSignalCaption(signal) {
return signal.size === 1 ? '' : `${signal.size - 1}:0`;
}
const controller = {
lastSignal: undefined
};
/**
* @description 用于点击波形后触发的逻辑如果波形已经在列表中则去除否则加入
* NOTE该函数需要同时操作所有的波形容器视图
* @param {MouseEvent} event
* @param {WireItem} signal
*/
function toggleRender(event, signal) {
const lastSignal = controller.lastSignal;
if (event.shiftKey && lastSignal !== undefined) {
const renderSignals = [];
let addBegin = false;
for (const currentSignal of signals.content) {
if (currentSignal === signal || lastSignal === currentSignal) {
renderSignals.push(currentSignal);
addBegin = !addBegin;
} else if (addBegin) {
renderSignals.push(currentSignal);
}
} }
return { for (const renderSignal of renderSignals) {
signals, WaveContainerView.add(renderSignal);
toggleRender, controller.lastSignal = renderSignal;
globalLookup, }
makeSignalCaption, globalLookup.render();
t,
makeIconClass } else {
if (WaveContainerView.has(signal)) {
WaveContainerView.delete(signal);
controller.lastSignal = undefined;
globalLookup.render();
} else {
WaveContainerView.add(signal);
controller.lastSignal = signal;
globalLookup.render();
} }
} }
} }

View File

@ -31,6 +31,21 @@ export const sidebarSelectedWires = {
this.togglePipe(); this.togglePipe();
}, },
/**
* @description 批量加入 link
* @param {string[]} links
*/
addLinks(links) {
for (const link of links) {
globalLookup.sidebarSelectedWireLinks.add(link);
globalLookup.setRenderOption(link, 'highlight', 1);
this.lastLink = link;
}
globalLookup.render({ type: 'wave-only' });
this.togglePipe();
},
delete(link) { delete(link) {
globalLookup.sidebarSelectedWireLinks.delete(link); globalLookup.sidebarSelectedWireLinks.delete(link);
if (this.lastLink === link) { if (this.lastLink === link) {

View File

@ -7,6 +7,11 @@ import { globalLookup } from "./global";
import { getSmartCurrentSignalValue } from "./utils"; import { getSmartCurrentSignalValue } from "./utils";
/**
* @typedef {Object} ViewIterConfig
* @property {boolean} returnGroup
*/
/** /**
* @namespace WaveContainerView * @namespace WaveContainerView
*/ */
@ -115,3 +120,25 @@ function makeFullSignalNameDeps(signal) {
htmlString = '<div class="signal-info-tooltip-wrapper">' + htmlString + '</div>'; htmlString = '<div class="signal-info-tooltip-wrapper">' + htmlString + '</div>';
return htmlString; return htmlString;
} }
/**
*
* @param {ViewIterConfig} iterConfig
* @returns {Generator<string>}
*/
export function* genOrderedLinks(iterConfig) {
const iterGroup = (iterConfig || {}).iterGroup || false;
for (const view of globalLookup.currentWiresRenderView) {
if (view.renderType === 0) {
yield view.signalInfo.link;
} else {
if (iterGroup) {
// groupLink 都会以 -group 结尾
yield view.signalInfo.link;
}
for (const child of view.children) {
yield child.signalInfo.link;
}
}
}
}