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 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; abstract changeFeatureToTopic(topicId: number, featureId: number, attributes: object): void;

View File

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

View File

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

View File

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

View File

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