• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dialog scroolbar

Explorer ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi all, I have this code, which allows me to select open documents individually and selectively close them, it works well, but when I have many documents open, the selection window it creates is too long and exits the screen, how can I add a scroll setting Is the height of the window fixed? Thank you

 

var openDocs = app.documents.everyItem().getElements()
var selectedDocs = [];
showDialog()
function showDialog(){
    var dialog = new Window("dialog", "Seleziona il file");
    var checkGroup = dialog.add("group");
    checkGroup.orientation = "column";
    checkGroup.alignment = "left";
    var checkboxes = [];
    for (var i = 0; i < openDocs.length; i++) {
      checkboxes[i] = checkGroup.add("checkbox", undefined, openDocs[i].name);
      checkboxes[i].value = false;
    }
    var buttonGroup = dialog.add("group");
    buttonGroup.orientation = "row";
    buttonGroup.alignment = "center";
    var selectAllButton = buttonGroup.add("button", undefined, "Seleziona tutto");
    selectAllButton.onClick = function() {
      for (var i = 0; i < checkboxes.length; i++) {
        checkboxes[i].value = true;
      }
    }
    var deselectAllButton = buttonGroup.add("button", undefined, "Deseleziona tutto");
    deselectAllButton.onClick = function() {
      for (var i = 0; i < checkboxes.length; i++) {
        checkboxes[i].value = false;
      }
    }
    //Button named "cancel" doesn’t need a close function
    var cancelButton = buttonGroup.add("button", undefined, undefined, {name: "cancel"}); 
    cancelButton.text = "Annulla"; 
    var okButton = buttonGroup.add("button", undefined, "OK");
    okButton.onClick = function() {
      for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].value == true) {
            $.writeln(checkboxes[i].text)
            //returns the checkboxes text which can be used to get the document by name:
            selectedDocs.push(app.documents.itemByName(checkboxes[i].text));
        }
      }
      if (selectedDocs.length == 0) {
        alert("Nessun documento selezionato.");
      }
      dialog.close();
    }
    dialog.show()
    //after the dialog is closed run closeSelected function
    closeSelected()
}


function closeSelected(){
    for (var i = 0; i < selectedDocs.length; i++){
        selectedDocs[i].close(SaveOptions.YES)
    };
}
TOPICS
Scripting

Views

497

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Explorer , May 10, 2023 May 10, 2023

Hi m1b, thanks for the answer, I hadn't thought about it, but it was what I needed, I modified the script and now it works as I want, thanks for the suggestion

 

var openDocs = app.documents.everyItem().getElements()
var selectedDocs = [];
showDialog()

function showDialog(){
    var dialog = new Window("dialog", "Seleziona il file");
    var listBox = dialog.add("listbox", [0, 0, 500, 500], undefined, {multiselect: true});
    listBox.maximumSize.width = 600;
    listBox.maximumSize.height = 600;
...

Votes

Translate

Translate
Community Expert , May 10, 2023 May 10, 2023

Excellent work! Here is a quick version with a few tweaks. You may see a few little things that can help. Keep up the great work! 🙂

- Mark

 

var openDocs = app.documents.everyItem().getElements();
openDocs.sort(function (a, b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; });

var selectedDocs = [];
showDialog()

function showDialog() {
    var dialog = new Window("dialog", "Seleziona il file");

    var listBox = dialog.add('listBox', undefined, '', { numberOfColum
...

Votes

Translate

Translate
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi @Samuel22307458169h, I don't think you can scroll a group of checkboxes. It seems to me that a better control for your script would be a ListBox. You can multi-select quite naturally and probably wouldn't need select all and select none buttons. Also handles scrolling for you. What do you think?

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Hi m1b, thanks for the answer, I hadn't thought about it, but it was what I needed, I modified the script and now it works as I want, thanks for the suggestion

 

var openDocs = app.documents.everyItem().getElements()
var selectedDocs = [];
showDialog()

function showDialog(){
    var dialog = new Window("dialog", "Seleziona il file");
    var listBox = dialog.add("listbox", [0, 0, 500, 500], undefined, {multiselect: true});
    listBox.maximumSize.width = 600;
    listBox.maximumSize.height = 600;
    

    for (var i = 0; i < openDocs.length; i++) {
        listBox.add("item", openDocs[i].name);
    }

    var buttonGroup = dialog.add("group");
    buttonGroup.orientation = "row";
    buttonGroup.alignment = "center";

    var cancelButton = buttonGroup.add("button", undefined, undefined, {name: "cancel"}); 
    cancelButton.text = "Annulla"; 

    var okButton = buttonGroup.add("button", undefined, "OK");
    okButton.onClick = function() {
        for (var i = 0; i < listBox.items.length; i++) {
            if (listBox.items[i].selected == true) {
                selectedDocs.push(app.documents.itemByName(listBox.items[i].text));
            }
        }

        if (selectedDocs.length == 0) {
            alert("Nessun documento selezionato.");
        }

        dialog.close();
    }

    dialog.show();
    closeSelected();
}

function closeSelected(){
    for (var i = 0; i < selectedDocs.length; i++){
        selectedDocs[i].close(SaveOptions.YES)
    };
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Excellent work! Here is a quick version with a few tweaks. You may see a few little things that can help. Keep up the great work! 🙂

- Mark

 

var openDocs = app.documents.everyItem().getElements();
openDocs.sort(function (a, b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; });

var selectedDocs = [];
showDialog()

function showDialog() {
    var dialog = new Window("dialog", "Seleziona il file");

    var listBox = dialog.add('listBox', undefined, '', { numberOfColumns: 1, multiselect: true });

    for (var i = 0; i < openDocs.length; i++) {
        var item = listBox.add('item', openDocs[i].name);
    }

    listBox.maximumSize.height = getScreenDimensions()[1] - 200;
    listBox.preferredSize = [350, -1];
    var buttonGroup = dialog.add("group");
    buttonGroup.orientation = "row";
    //Button named "cancel" doesn’t need a close function
    var cancelButton = buttonGroup.add("button", undefined, undefined, { name: "cancel" });
    cancelButton.text = "Annulla";
    var okButton = buttonGroup.add("button", undefined, "OK");
    okButton.onClick = function () {
        for (var i = 0; i < listBox.selection.length; i++) {
            selectedDocs.push(openDocs[listBox.selection[i].index]);
        }
        if (selectedDocs.length == 0) {
            alert("Nessun documento selezionato.");
        }
        dialog.close(1);
    };

    var result = dialog.show();

    if (result === 1) {
        // ok button
        closeSelected(selectedDocs)
    }
    else if (result === 2) {
        // user cancelled
        return;
    }


};

function closeSelected(docs) {
    for (var i = docs.length - 1; i >= 0; i--) {
        try {
            docs[i].close(SaveOptions.YES)
        } catch (error) {
            // user cancelled dialog
        }
    };
};

function getScreenDimensions(index) {
    var screen = $.screens[Math.min(index || 0, $.screens.length - 1)];
    return [screen.right - screen.left, screen.bottom - screen.top];
};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

Thank you very much!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

LATEST

You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines