Add multi-add of icons.

This commit is contained in:
Paulo Gustavo Veiga 2023-01-13 23:30:41 -08:00
parent 86536ac8d2
commit ad30a9dd94
5 changed files with 24 additions and 28 deletions

View File

@ -84,7 +84,7 @@ abstract class ActionDispatcher extends Events {
abstract shrinkBranch(topicsIds: number[], collapse: boolean): void;
abstract addFeatureToTopic(topicId: number, type: string, attributes: object): void;
abstract addFeatureToTopic(topicIds: number[], type: string, attributes: object): void;
abstract changeFeatureToTopic(topicId: number, featureId: number, attributes: object): void;

View File

@ -853,11 +853,9 @@ class Designer extends Events {
const topicsIds = this.getModel().filterTopicsIds();
const featureType: FeatureType = type === 'emoji' ? 'eicon' : 'icon';
if (topicsIds.length > 0) {
this._actionDispatcher.addFeatureToTopic(topicsIds[0], featureType, {
id: iconType,
});
}
this._actionDispatcher.addFeatureToTopic(topicsIds, featureType, {
id: iconType,
});
}
addLink(): void {

View File

@ -263,7 +263,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
this.execute(command);
}
addFeatureToTopic(topicId: number, featureType: FeatureType, attributes) {
addFeatureToTopic(topicId: number[], featureType: FeatureType, attributes) {
const command = new AddFeatureToTopicCommand(topicId, featureType, attributes);
this.execute(command);
}

View File

@ -721,7 +721,7 @@ abstract class Topic extends NodeGraph {
text: value,
});
} else {
dispatcher.addFeatureToTopic(topicId, 'note', {
dispatcher.addFeatureToTopic([topicId], 'note', {
text: value,
});
}
@ -753,7 +753,7 @@ abstract class Topic extends NodeGraph {
url: value,
});
} else {
dispatcher.addFeatureToTopic(topicId, 'link', {
dispatcher.addFeatureToTopic([topicId], 'link', {
url: value,
});
}

View File

@ -15,14 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { $assert, $defined } from '@wisemapping/core-js';
import Command from '../Command';
import CommandContext from '../CommandContext';
import FeatureModel from '../model/FeatureModel';
import FeatureType from '../model/FeatureType';
class AddFeatureToTopicCommand extends Command {
private _topicId: number;
private _topicIds: number[];
private _featureType: FeatureType;
@ -40,32 +39,31 @@ class AddFeatureToTopicCommand extends Command {
* @extends mindplot.Command
* @see mindplot.model.FeatureModel and subclasses
*/
constructor(topicId: number, featureType: FeatureType, attributes: object) {
$assert($defined(topicId), 'topicId can not be null');
$assert(featureType, 'featureType can not be null');
$assert(attributes, 'attributes can not be null');
constructor(topicIds: number[], featureType: FeatureType, attributes: object) {
super();
this._topicId = topicId;
this._topicIds = topicIds;
this._featureType = featureType;
this._attributes = attributes;
this._featureModel = null;
}
execute(commandContext: CommandContext) {
const topic = commandContext.findTopics([this._topicId])[0];
// Feature must be created only one time.
if (!this._featureModel) {
const model = topic.getModel();
this._featureModel = model.createFeature(this._featureType, this._attributes);
}
topic.addFeature(this._featureModel);
execute(commandContext: CommandContext): void {
const topics = commandContext.findTopics(this._topicIds);
topics.forEach((topic) => {
// Feature must be created only one time.
if (!this._featureModel) {
const model = topic.getModel();
this._featureModel = model.createFeature(this._featureType, this._attributes);
}
topic.addFeature(this._featureModel);
});
}
undoExecute(commandContext: CommandContext) {
const topic = commandContext.findTopics([this._topicId])[0];
topic.removeFeature(this._featureModel!);
const topics = commandContext.findTopics(this._topicIds);
topics.forEach((topic) => {
topic.removeFeature(this._featureModel!);
});
}
}