Dialog questions

I have a script that pops up a dialog. I haven't managed to get the title to be set dynamically at run time. I can set static text in the dialog editor but haven't worked out how to change it at run time. I'd also like to select by default the text I set in an edit box using the select property but again, I can't quite get the magic right. Any hints appreciated. Thank you.

I tested that the window title cannot be modified at runtime, but the content of the control can be modified.

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
    var dlg = clickData.func.Dlg();
    
    dlg.title = "Directory Opus";                                              // Title
    dlg.template = "dlgCombox";
	dlg.detach = true;
    dlg.Create();
	dlg.Control("static").style = "b";
	dlg.Control("static").label = "Move Here to New Subfolder";                // Topic
	dlg.Control("static2").label = "Select or enter folder name or subpath";   // Notes
	dlg.Control("static3").label = "D:\\Icons\\MOVE.png";                      // Icon
	
	dlg.Control("combo").label = tab.selected(0).name_stem;                    // Defalut value
	dlg.Control("combo").SelectRange(0, -1);                                   // Select defalut value
	
    for(var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
	    dlg.Control("combo").AddItem(e.item().name_stem_m);                    //Add each item to drop-down list
    }
    
    dlg.Show();

// msg loop	
	do
	{
		msg = dlg.GetMsg();
/*
        // Selection
		if(msg == true && dlg.Control("combo").focus == true) {
		   DOpus.Output(dlg.Control("combo").label);
		}
*/
        // Result, perform the move operation
		if (dlg.result == 1) {

		}
/*		
		// If the button 3 is pressed
		if(dlg.result == 2) {
		DOpus.Output("Button 3 is pressed");
		}
		
		// If the button 4 is pressed
		if(dlg.result == 3) {
		DOpus.Output("Button 4 is pressed");
		}
*/
	} while (msg == true);
}



==SCRIPT RESOURCES
<resources>
	<resource name="dlgCombox" type="dialog">
		<dialog fontsize="8" height="78" lang="english" resize="yes" title="Directory Opus" width="322">
			<control edit="yes" height="40" name="combo" type="combo" width="306" x="8" y="40" />
			<control close="3" enable="no" height="14" name="btn4" resize="xy" title="&amp;4" type="button" visible="no" width="50" x="101" y="57" />
			<control close="2" enable="no" height="14" name="btn3" resize="xy" title="&amp;3" type="button" visible="no" width="50" x="155" y="57" />
			<control halign="left" height="8" name="static" title="Topic" type="static" valign="top" width="280" x="30" y="10" />
			<control halign="left" height="16" name="static2" title="Notes" type="static" valign="top" width="280" x="30" y="22" />
			<control halign="center" height="14" image="yes" name="static3" title="Icon" type="static" valign="top" width="14" x="8" y="7" />
			<control close="1" default="yes" height="14" name="btnOK" resize="xy" title="&amp;OK" type="button" width="50" x="209" y="57" />
			<control close="0" height="14" name="btnCancel" resize="xy" title="&amp;Cancel" type="button" width="50" x="263" y="57" />
		</dialog>
	</resource>
</resources>

Changing the title before the dialog is displayed works. The dlg.title = ... line you have there will change the dialog's title (if it's set to something different to the title in the resource).

Thanks Wken and Leo., Changing title now works. I am still trying to get the selection of the text to work. I have a dialog that pops up and there is a text entry box that is initialised with some value, and I think it's possible to have the text preselected so that starting typing will overwrite the selected text?

dlg.Control("combo").SelectRange(0, -1); // Select defalut value

Thank you Wken, but that's not what I mean. This is an edit box where text can be typed and according to https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Dialog.htm setting 'select' to true should select the text when the dialog appears. Unless I am misunderstanding what that page is telling me.

I also can't make it preselect as the documentation says.
SelectRange(0, -1) does work.

But only for combo boxes ? Not text entry boxes?

function OnClick(clickData)
{

    var dlgEdit = clickData.func.Dlg();
    var tab = clickData.func.sourcetab;

    dlgEdit.title = "Directory Opus";
    dlgEdit.template = "dlgEditTags";
    dlgEdit.detach = true;
    dlgEdit.Create();

	dlgEdit.Control("static").style = "b";
	dlgEdit.Control("static").label = 'Edit Tags';                              // Topic
	dlgEdit.Control("static2").label = 'One tag per line, or enter new tags separated by commas.';   // Notes
	//dlgEdit.Control("static3").label = Script.LoadImage("Edit.png");            // Icon

	//var editTag = tab.vars.Get('editTag', editTag);
	var editTag = "Test"
	dlgEdit.Control("editTags").value = editTag;                                // Default value
	dlgEdit.Control("editTags").SelectRange(0, -1);                             // Select defalut value

    dlgEdit.Show();

    DOpus.ClearOutput;
	var newTag, tagsTMP = "|", dlgValueOld, dlgValue = "";

// msg loop
	do
	{
	   dlgValueOld = dlgEdit.Control("editTags").value;
	   msg = dlgEdit.GetMsg();

	   if (msg == true) {dlgValue = dlgEdit.Control("editTags").value};

	   if (msg.qualifiers == "none") {tagsTMP = dlgEdit.Control("editTags").value};

	   var dlgValueArray = dlgValue.split("\r");
	   var newDlgValue = "";
	   for (i = 0; dlgValueArray[i]; i++)
	   {
		   newDlgValue += dlgValueArray[i].trim();
	   }

	   var OldArray = dlgValueOld.split("\r");
	   var dlgValueOld2 = "";
	   for (i = 0;OldArray[i]; i++)
	   {
		   dlgValueOld2 += OldArray[i].trim()
	   }

       // Result
	   if (dlgEdit.result == 1 || msg.qualifiers == "ctrl" && msg.event == "editchange" && newDlgValue == dlgValueOld2 && dlgValue != DOpus.GetClip || msg.qualifiers == "ctrl" && msg.event == "editchange" && dlgValue.trim() == tagsTMP.trim() || msg.qualifiers == "ctrl" && msg.event == "editchange" && dlgValueArray[0].trim() == "" && dlgValue.trim() != "")
	   {
		   if (msg.qualifiers == "ctrl" && msg.event == "editchange" && dlgValueArray[0].trim() == "" && dlgValue.trim() != "")
		   {
			   dlgEdit.EndDlg;
			   //DOpus.Output("0")
			   newTag = dlgValue
		   }
		   else
		   if (msg.qualifiers == "ctrl" && msg.event == "editchange" && dlgValue.trim() == tagsTMP.trim())
		   {
			   dlgEdit.EndDlg;
			   //DOpus.Output("1")
			   newTag = dlgValue
		   }
		   else
		   if (msg.qualifiers == "ctrl" && msg.event == "editchange" && newDlgValue == dlgValueOld2 && dlgValue != DOpus.GetClip)
		   {
			   dlgEdit.EndDlg;
			   //DOpus.Output("2")
			   newTag = dlgValueOld
		   }
		   else
		   {
			   newTag = dlgEdit.Control("editTags").value
			   //DOpus.Output("3")
		   }

		   if (newTag.trim() == "") {return;}
           newTag = format_tags(newTag);
		   newTag = remove_duplicate(newTag);

		   var tags = tab.vars.Get('DOpusTag');

		   // Remove duplicate
	       var tags = tab.vars.Get('DOpusTag');
		   var tagsArray = newTag.split(", ");
		   var tagsArray2 = tags.split(", ");                            // Seprator

		   var tagCase, newTags = "";
		   for (i = 0; tagsArray2[i]; i++)
		   {
			    tagCase = "";
			    for (ii = 0; tagsArray[ii]; ii++)
				{
				     if (tagsArray2[i] == tagsArray[ii])
					 {
						 tagCase = 1;
					 }
				}
				if (tagCase != 1 && tagsArray2[i] != editTag)
				{
					newTags += tagsArray2[i] + ", ";
				}
		   }

           if (newTags == "") return;
		   newTags = newTag + ", " + newTags;
		   newTags = newTags.substr(0, newTags.length-2);
           tab.vars.Set('DOpusTag', newTags);

           // Write new tags to DOpusTag.dat
		   var tagFile = "%appdata%\\GPSoftware\\Directory Opus\\Scripts\\INI\\DOpusTag.dat";   // File path
		   var oFileWrite = fsu.OpenFile(tagFile, "wa");
           var utf8bom = ST.Encode(newTags, "utf-8 bom");   // Decode as UTF-8 with BOM
           if (oFileWrite.error == 0)
           {
               oFileWrite.Write(utf8bom)
           }
              oFileWrite.Close()
	   }
	} while (msg == true)
}




==SCRIPT RESOURCES
<resources>
	<resource name="dlgEditTags" type="dialog">
		<dialog fontsize="8" height="120" lang="english" resize="yes" title="Edit Tags" width="522">
			<control halign="left" height="62" multiline="yes" name="editTags" resize="wh" type="edit" width="506" x="8" y="32" />
			<control close="1" default="yes" height="14" name="btnApply" resize="xy" title="&amp;Apply" type="button" width="50" x="409" y="99" />
			<control close="0" height="14" name="btnCancel" resize="xy" title="&amp;Cancel" type="button" width="50" x="462" y="99" />
			<control halign="left" height="8" name="static" title="Edit Tags" type="static" valign="top" width="472" x="39" y="7" />
			<control halign="left" height="20" image="yes" name="static3" title="Static" type="static" valign="top" width="20" x="10" y="4" />
			<control halign="left" height="8" name="static2" title="Notes" type="static" valign="top" width="472" x="39" y="17" />
		</dialog>
	</resource>
</resources>

Edit controls need to have focus to show a selection.

dlg.Control("edit1").focus = True or similar after showing the dialog should give the control focus (if it is named “edit1”), based on a another discussion I found.

The magic seems to be

Dlg.Control("edit1").SelectRange(0, -1);

Nothing else I tried worked. Thanks for the help, WKen and Leo. Much appreciated.

The point of this is that I've been writing a script to work around what I think is DOpus' somewhat broken handling of comments in mp4 files. I do hope that a future version of DOpus will honour the 'use descript.ion for comments and not NTFS' setting for all files and not silently ignore it for certain filetypes, eg mp4. Other than that I love DOpus. That really is the only issue I have with it.

Nothing broken about how it works; it's entirely by design and what a lot of people explicitly want/expect, although we're not opposed to adding an option for other people.

But it's already been discussed in the thread about it, and this thread is about a different question. Let's stick to one thing at a time, please.

An option would be good. We'll agree to disagree on it being broken, Leo.