aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/CurrentUserUtils.ts2
-rw-r--r--src/client/util/SelectionManager.ts59
2 files changed, 19 insertions, 42 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 87ee1b252..ba3c26b42 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -339,7 +339,7 @@ export class CurrentUserUtils {
/// returns descriptions needed to buttons for the left sidebar to open up panes displaying different collections of documents
static leftSidebarMenuBtnDescriptions(doc: Doc):{title:string, target:Doc, icon:string, toolTip: string, scripts:{[key:string]:any}, funcs?:{[key:string]:any}, hidden?: boolean}[] {
- const badgeValue = "((len) => len && len !== '0' ? len: undefined)(docList(self.target.data).filter(doc => !docList(self.target.viewed).includes(doc)).length.toString())";
+ const badgeValue = "((len) => len && len !== '0' ? len: undefined)(docList(self.target?.data).filter(doc => !docList(self.target.viewed).includes(doc)).length.toString())";
const getActiveDashTrails = "Doc.ActiveDashboard?.myTrails";
return [
{ title: "Dashboards", toolTip: "Dashboards", target: this.setupDashboards(doc, "myDashboards"), ignoreClick: true, icon: "desktop", funcs: {hidden: "IsNoviceMode()"} },
diff --git a/src/client/util/SelectionManager.ts b/src/client/util/SelectionManager.ts
index d0f66d124..fcf705ac0 100644
--- a/src/client/util/SelectionManager.ts
+++ b/src/client/util/SelectionManager.ts
@@ -1,6 +1,6 @@
-import { action, observable, ObservableMap } from 'mobx';
-import { computedFn } from 'mobx-utils';
+import { action, observable } from 'mobx';
import { Doc, Opt } from '../../fields/Doc';
+import { DocViews } from '../../fields/DocSymbols';
import { List } from '../../fields/List';
import { listSpec } from '../../fields/Schema';
import { Cast, DocCast } from '../../fields/Types';
@@ -12,9 +12,8 @@ import { UndoManager } from './UndoManager';
export namespace SelectionManager {
class Manager {
- @observable IsDragging: boolean = false;
- SelectedViewsMap: ObservableMap<DocumentView, Doc> = new ObservableMap();
@observable SelectedViews: DocumentView[] = [];
+ @observable IsDragging: boolean = false;
@observable SelectedSchemaDocument: Doc | undefined;
@action
@@ -24,27 +23,21 @@ export namespace SelectionManager {
@action
SelectView(docView: DocumentView, ctrlPressed: boolean): void {
// if doc is not in SelectedDocuments, add it
- if (!manager.SelectedViewsMap.get(docView)) {
- if (!ctrlPressed) {
- this.DeselectAll();
- }
-
+ if (!docView.SELECTED) {
+ if (!ctrlPressed) this.DeselectAll();
manager.SelectedViews.push(docView);
- manager.SelectedViewsMap.set(docView, docView.rootDoc);
- docView.props.whenChildContentsActiveChanged(true);
- } else if (!ctrlPressed && (Array.from(manager.SelectedViewsMap.entries()).length > 1 || manager.SelectedSchemaDocument)) {
- Array.from(manager.SelectedViewsMap.keys()).map(dv => dv !== docView && dv.props.whenChildContentsActiveChanged(false));
+ } else if (!ctrlPressed && (manager.SelectedViews.length > 1 || manager.SelectedSchemaDocument)) {
+ manager.SelectedViews.filter(dv => dv !== docView).forEach(dv => dv.props.whenChildContentsActiveChanged(false));
manager.SelectedSchemaDocument = undefined;
manager.SelectedViews.length = 0;
- manager.SelectedViewsMap.clear();
- manager.SelectedViews.push(docView);
- manager.SelectedViewsMap.set(docView, docView.rootDoc);
}
+ docView.SELECTED = true;
+ docView.props.whenChildContentsActiveChanged(true);
}
@action
DeselectView(docView?: DocumentView): void {
- if (docView && manager.SelectedViewsMap.get(docView)) {
- manager.SelectedViewsMap.delete(docView);
+ if (docView && manager.SelectedViews.includes(docView)) {
+ docView.SELECTED = false;
manager.SelectedViews.splice(manager.SelectedViews.indexOf(docView), 1);
docView.props.whenChildContentsActiveChanged(false);
}
@@ -54,8 +47,10 @@ export namespace SelectionManager {
LinkManager.currentLink = undefined;
LinkManager.currentLinkAnchor = undefined;
manager.SelectedSchemaDocument = undefined;
- Array.from(manager.SelectedViewsMap.keys()).forEach(dv => dv.props.whenChildContentsActiveChanged(false));
- manager.SelectedViewsMap.clear();
+ manager.SelectedViews.forEach(dv => {
+ dv.SELECTED = false;
+ dv.props.whenChildContentsActiveChanged(false);
+ });
manager.SelectedViews.length = 0;
}
}
@@ -74,45 +69,27 @@ export namespace SelectionManager {
manager.SelectSchemaViewDoc(document);
}
- const IsSelectedCache = computedFn(function isSelected(doc: DocumentView) {
- // wrapping get() in a computedFn only generates mobx() invalidations when the return value of the function for the specific get parameters has changed
- return manager.SelectedViewsMap.get(doc) ? true : false;
- });
// computed functions, such as used in IsSelected generate errors if they're called outside of a
// reaction context. Specifying the context with 'outsideReaction' allows an efficiency feature
// to avoid unnecessary mobx invalidations when running inside a reaction.
- export function IsSelected(doc: DocumentView | undefined, outsideReaction?: boolean): boolean {
- return !doc
- ? false
- : outsideReaction
- ? manager.SelectedViewsMap.get(doc)
- ? true
- : false // get() accesses a hashtable -- setting anything in the hashtable generates a mobx invalidation for every get()
- : IsSelectedCache(doc);
+ export function IsSelected(dv?: DocumentView | Doc): boolean {
+ return (dv instanceof Doc ? Array.from(dv[DocViews]) : dv ? [dv] : []).some(dv => dv?.SELECTED);
}
export function DeselectAll(except?: Doc): void {
- let found: DocumentView | undefined = undefined;
- if (except) {
- for (const view of Array.from(manager.SelectedViewsMap.keys())) {
- if (view.props.Document === except) found = view;
- }
- }
-
+ const found = manager.SelectedViews.find(dv => dv.Document === except);
manager.DeselectAll();
if (found) manager.SelectView(found, false);
}
export function Views(): Array<DocumentView> {
return manager.SelectedViews;
- // Array.from(manager.SelectedViewsMap.keys()); //.filter(dv => manager.SelectedViews.get(dv)?._type_collection !== CollectionViewType.Docking);
}
export function SelectedSchemaDoc(): Doc | undefined {
return manager.SelectedSchemaDocument;
}
export function Docs(): Doc[] {
return manager.SelectedViews.map(dv => dv.rootDoc).filter(doc => doc?._type_collection !== CollectionViewType.Docking);
- // Array.from(manager.SelectedViewsMap.values()).filter(doc => doc?._type_collection !== CollectionViewType.Docking);
}
}
ScriptingGlobals.add(function SelectionManager_selectedDocType(type: string, expertMode: boolean, checkContext?: boolean) {