Page 1 of 1

Detection transaction operation

Posted: Tue Jan 09, 2018 8:22 pm
by caramel
Hi,

I'm using transaction listener for change detection :

Code: Select all

TransactionListener.init = function (basePath) {

  var adapter = new RTransactionListenerAdapter();
  var appWin = EAction.getMainWindow();
  appWin.addTransactionListener(adapter);

  adapter.transactionUpdated.connect(function (document, transaction) {
    if (isNull(document) || isNull(transaction)) {
      return;
    }
    
    var doc = EAction.getDocument();
    var objIds = transaction.getAffectedObjects();

    for (var i = 0; i < objIds.length; i++) {
      var objId = objIds[i];     

      var obj = doc.queryObjectDirect(objIds[i]);

      if (isLineEntity(obj)) {
        if (transaction.getText().toLowerCase() == "supprimer") {
          qDebug("line deleted");
          //mycode...
        }

        else if (transaction.getText().toLowerCase().indexOf("déplacer") != -1) {          
          qDebug("line moved");   
          //mycode...    
        }

      }
    }

  });

  EAction.handleUserMessage("Mod_TransactionListener.js: Transaction listener installed.");

};
And as you can see I'm temporarily basing on transaction.getText() to detect operation type, but I know that isn't the appropriate way, could you tell me the rightr way to detect it ?

Thanks a lot !
Caramel

Re: Detection transaction operation

Posted: Mon Mar 12, 2018 12:53 pm
by andrew
There is no transaction type as such. A transaction encapsulates a change in the drawing (changing objects, adding objects, removing objects). Transactions are unaware of the particular tool that was used to cause that change (apart from the transaction text which can be optionally set by the tool responsible for the transaction).

transaction.getAffectedObjects() returns a list of object IDs of objects that were changed / added/ deleted by a transaction.
transaction.getStatusChanges() returns a list of object IDs of objects that were either created or deleted (check undo status of object)
transaction.getPropertyChanges() returns a list of exact property changes per object as shown in ExTransactionListener.