Allow dialog to change the view/show text
I have a dialog that is created with some text objects attached to its buttons. The user can make some choices for each one, hit OK, and have their choices applied. What I'd like is for the buttons to bring the user to the text, so they can see it in context as they're deciding (that is the only reason these are buttons; otherwise they'd be static text). I know how to manage this with a palette, but I'm wondering if there is any way to do it with a dialog. Using a palette for just this purpose seems wrong to me; I don't really want users to be able to make changes to the document while the palette is open, and I don't want anything to change in the document until the user clicks OK. It's a dialog with one palette-like quirk, really.
The problem is that .showText() and setting the activePage both throw the error "Cannot handle the request because a modal dialog or alert is active." I've tried setting the dialog to .active = false or .visible = false, but it has no effect. Is this just impossible? This functionality, changing the view but not changing the content, seems to live in a grey area between the way dialogs work and the way palettes work, so I'm not sure if I'm just going down a pointless path. Any insight would be appreciated.
Here is some sample code to illustrate what I'm trying to do:
#target indesign
main();
function main(){
if (app.documents.length == 0){createTestDoc();}
runDialog();
}
function createTestDoc(){
//create a test document
var myDocPre = app.documentPresets.add({name: "testPre", createPrimaryTextFrame: true, pagesPerDocument: 5});
var myDoc = app.documents.add(true, myDocPre);
var myPSty = myDoc.paragraphStyles.add({name: "newPageSty", startParagraph: StartParagraph.NEXT_PAGE});
var myCSty = myDoc.characterStyles.add({name: "CSty", underline: true});
myDoc.textFrames[0].contents = "1\r2\r3\r4\r5";
myDoc.textFrames[0].texts.everyItem().appliedParagraphStyle = myPSty;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = "^9";
app.changeTextPreferences.appliedCharacterStyle = myCSty;
myDoc.changeText();
myDocPre.remove();
}
function runDialog(){
//find text with a particular character style and send that text to my dialog creation function.
var myDoc = app.activeDocument;
var myCSty = myDoc.characterStyles.itemByName("CSty");
if (myCSty.isValid){
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.appliedCharacterStyle = myCSty;
var myResults = myDoc.findText();
myDialog(myResults);
}
}
function myDialog(textRngs){
//create the dialog.
var myWin = new Window("dialog", "Test Dialog", undefined);
var mainGroup = myWin.add("group");
mainGroup.orientation = "column";
//each text range gets a row.
for (var i = 0; i < textRngs.length; i++){
var myTextRng = textRngs;
var myRow = mainGroup.add("group");
myRow.orientation = "row";
var myBut = myRow.add("button", undefined, myTextRng.contents);
//attaches the text object to the button.
myBut.targetObject = myTextRng;
//does nothing - just a reminder that the actual dialog will do something at the end based on the info entered.
myRow.add("editText");
myBut.onClick = function(){
//this is what I do when I want this functionality within a palette. Selects the text so that it can be seen in context.
if (!(this.targetObject.hasOwnProperty("select") && this.targetObject.hasOwnProperty("showText"))) {}
else{
this.targetObject.showText();
this.targetObject.select();
//OR
//tried this as an alternative, but setting myWin.visible does nothing.
//myWin.visible = false;
//myDoc.layoutWindows[0].activePage = this.targetObject.parentTextFrames[0].parentPage;
//myWin.visible = true;
}
}
}
var OKGrp = myWin.add("group");
var OKBut = OKGrp.add("button", undefined, "OK");
OKBut.onClick = function(){
//do something
myWin.close();
}
myWin.show();
}
