How to show selected file name in a dialog?

I created a dialog which ask if the selected file shall be deleted (after extracting the file - so the idea is to have the deletion in one button).
Better would be if the name of the file would be displayed. Similar to the standard delete dialog from Opus.

Is this possible?

ok, one sultion seems to be to use the command

cmd.RunCommand('Delete FILE="' + item + '"');

instead of an own dialog. Then Opus ask if it shall delete the file and afterwards the script continues.
(I have to check if the syntax is right. In the first step I simpy removed the QUIET' from cmd.RunCommand('Delete FILE="' + item + '" QUIET');

But anyway it would nice to now if it is possible to show a file name in a dialog.

What kind of dialog are we talking about? What is creating it?

You can usually put whatever text you want in a dialog.

Not sure what is meant with "type of dialog".

It is related to the extract button script. There is e.g. the dialog which ask if the archive shall be extracted to source or destination.

I added a similar dialog with the question "shall Opus delete the archive".
Better would be "shall Opus delete ?"

What is the code or command which opens the dialog?

Dlg.window = tab;
Dlg.icon = "question";
Dlg.top = true;
Dlg.template = "delete";

If necessary I can choose another code/command. At the moment I copied the existing one and created a new template.

That’s a custom script dialog. You can make it display anything you want. Everything it displays is determined by your script.

Can you give a hint? Perhaps a reference or example in the help?

In the manual, Scripting > Script Dialogs has a whole section on this.

ok. Also with the help of some other topics in the forum I did it. Problem was somehow that the script is jscript and the help examples show VBScript.

That is my code (snippet). The dialog is defined in the Ressources and has a static text with the name "archname".

				Dlg.window = tab;
				Dlg.icon = "question";
				Dlg.top = true;
				Dlg.template = "delete";
				Dlg.detach = true;
				Dlg.Create();
				Dlg.Control("archname").label = "<" + item.name + ">";				
				var retVal2 = Dlg.RunDlg();

I recognized that the Dlg.RunDlg seems to "break" the Dlg.Show command for the subsequent script. I have to use now for all following dialogs also

Dlg.Create();
Dlg.RunDlg();

instead of Dlg.Show() to show a dialog.

What is the explanation for this? I want to understand the code... :slight_smile:

Hard to say without seeing the code.

If you're reusing the same Dlg object then it might be better to create a new one each time.

The manual describes what Dlg.RunDlg and Dlg.Show both do and how they differ from each other.

Its related to this button: Smart archive extraction - #10 by Mosed

There is first the above mentioned dialog which ask for deletion and later after extract and deletion is done there is a warning dialog, which informs the user, when also non-archive-files were selected.

v2022.02.12a is with Dlg.Show for the warning dialog at the end, which does not show up (or is closed immediately without user input)

	if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Show();
}

v2022.02.13 is with Dlg.RunDlg instead Dlg.Show and now the warning shows up again.

	if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.Create();
				Dlg.RunDlg;
}

So it is not the same Dlg object as far as I understand it. And it is not detached (or is the setting from previous dialog global?) - then the dialog would close immediatly acc. to the manual when using Dlg.Show.

EDIT: Ah, the detach topic seems to be relevant.
When I set detach to false for this dialog it works with show.

			if (selWarning) {
				Dlg.window = tab;
				Dlg.icon = "warning";
				Dlg.top = true;
				Dlg.template = "warning";
				Dlg.detach = false;
				Dlg.Show;
			}

It is the same Dlg object, assuming Dlg is the same variable in both cases.

Ah, so the Dlg is not a command, but the variable which is set in the very beginning of the script with

var Dlg = DOpus.Dlg;

And if I want to create a second Dlg object I would have to add e.g.

var Dlg2 = DOpus.Dlg;

And then for a dialog e.g.

if (selWarning) {
				Dlg2.window = tab;
				Dlg2.icon = "warning";
				Dlg2.top = true;
				Dlg2.template = "warning";
				Dlg2.Show;
			}

Short test: works. ok. thank you.

1 Like

If you weren't aware, this is Objected-Oriented Programming (OOP) you've just discovered. It's beyond the scope of this forum to discuss how it works in detail. In short, objects (what you referred to as a variable) can have properties and methods. Properties are generally things you can look at or change and methods are things you do to that object. Dlg2 in your last code sample is an object. Dlg2.Show is a method.

If you (or anybody else reading this) have not experienced OOP, I'd suggest reading up on it.

Here is one page explaining OOP: What is object-oriented programming? OOP explained in depth (educative.io)

2 Likes