[javascript] how to use the second parameter of app.execDialog(monitor, inheritDialog)

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

User avatar
Mathew
User
Posts: 958
Joined: Thu Jun 19, 2014 7:30 pm

[javascript] how to use the second parameter of app.execDialog(monitor, inheritDialog)

Post by Mathew »

image.png
I imagine the second parameter of app.execDialog() is supposed to be a way to have the same dialog be redrawn with a new description, without it closing and re-opening. But I've never been able to get it to work.

I don't understand how the inheritDialog parameter could be passed to app.execDialog() except as a call from one of the dialog box handlers (?) I've tried putting app.execDialog() before dialog.end(), or after dialog.end() and passing the dialog object; in both cases it generates a new dialog, just the same as if I'd not included the parameter. It also builds up the stack because the previous dialog is still there.

I've also tried passing the dialog variable to a global variable, and running app.execDialog(monitor, passedDialog) but that obviously doesn't work because the dialog has already been destroyed by the time it gets there, and it does exactly the same as without the second parameter (destroys the first dialog, then shows the second call).

If anyone has used it, or knows how, please: I'd like to know.
Thanks.

FWIW this is my test script:

Code: Select all

// test of changing dialog with call from within the handler


function randDia(newSnips,insideHandler=true) {
  let lastDia;
  const dia = {
    toLoad: {}, // scripts to load
    initialize(dialog) {
      const stack = new Error("message").stack;
      console.println(stack);
      this.toLoad.info = "Select 'random' to redraw - stack length: " + stack.split('\n').length;
      dialog.load(this.toLoad);
    },
    other(dialog) {
      if (insideHandler) {
        dia.description = addRows(parseInt(Math.random()*9+1));
        
        dialog.end(app.execDialog(dia, dialog));
      } else {
        lastDia = dialog;
        dialog.end('other');
      }
    },
    commit(dialog) {
      const dVals = dialog.store();
      this.toLoad = dVals;
    },

  };
  
  function addRows(numRows) {
    const description = { name: "Add rows", elements: [
        { type: 'static_text', item_id: 'info', width: 300, bold: true},
        { type: 'ok_cancel_other', other_name: 'random'},
      ]};
    // add rows of checkboxes
    newSnips.forEach ((s,i) => {
      if (i<numRows) {
      description.elements.splice(i+1, 0, {type: 'view', align_children: 'align_row', elements:[
        {type: 'check_box', item_id: 'scr'+i.toString(36)},
        {type: 'static_text', name: s.labl || 'script ' + (i+1), width: 280, alignment: 'align_fill'}
      ]});
      dia.toLoad['scr'+i.toString(36)] = true;
      }
    });
    
    return description;
  }
  
  let res = 'other';
  if (insideHandler) {
    dia.description = addRows(parseInt(Math.random()*9+1));
    res = app.execDialog(dia);
  } else {
    while ('other' === res) {
      dia.description = addRows(parseInt(Math.random()*9+1));
      res = app.execDialog(dia, lastDia);
    }  
  }

  if ('ok' !== res) return; // cancelled
  
  // something else
}

// run it inside the dialog
randDia([{labl:"inside 1"}, {labl:"inside 2"}, {labl:"inside 3"}, {labl:"inside 4"}, {labl:"inside 5"}, {labl:"inside 6"}, {labl:"inside 7"}, {labl:"inside 8"}, {labl:"inside 9"}]);
// outside the dialog
randDia([{labl:"outside 1"}, {labl:"outside 2"}, {labl:"outside 3"}, {labl:"outside 4"}, {labl:"outside 5"}, {labl:"outside 6"}, {labl:"outside 7"}, {labl:"outside 8"}, {labl:"outside 9"}], false);
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13323
Joined: Wed Jan 03, 2018 6:52 pm

Re: [javascript] how to use the second parameter of app.execDialog(monitor, inheritDialog)

Post by Daniel - PDF-XChange »

Hello, Mathew

Thank you for the post, I have raised this with the Dev team for review and comment. I will let you know once I hear back from them.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]