Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

UsingDialogs

Minkyu Lee edited this page Jan 19, 2015 · 12 revisions

Using Dialogs

In this chapter, we're going to learn how to use dialogs. StarUML provides the following Dialogs:

File Dialogs

  • Open Dialog
  • Save Dialog

Message Dialogs

  • Error Dialog
  • Alert Dialog
  • Info Dialog

Input Dialogs

  • Input Dialog (single line text)
  • Text Dialog (multi line text)
  • Confirm Dialog
  • Select Radio Dialog
  • Select Dropdown Dialog
  • Color Dialog
  • Font Dialog

Element Dialogs

  • Element Picker Dialog
  • Element List Picker Dialog
  • Element List Editor Dialog

Toast

  • info
  • warning
  • error

File Dialogs

You can use Open Dialog and Save Dialog to allow users to choose files or directories. File-related Dialogs are defined in FileSystem module. Please refer to API Docs for full specification of API.

Following is an example of Open Dialog for choosing a text *.txt file.

var FileSystem = require("filesystem/FileSystem");

FileSystem.showOpenDialog(false, false, "Select a text file...", null, ["txt"], function (err, files) {
    if (!err) {
        if (files.length > 0) {
            // User selected one or more files
        } else {
            // User canceled
        }
    } else {
        // Handle error
    }
});

Following is an example of Save Dialog for getting a file name.

var FileSystem = require("filesystem/FileSystem");

FileSystem.showSaveDialog("Save text as...", null, "Untitled.txt", function (err, filename) {
    if (!err) {
        if (filename) {
            // User selected a file name
        } else {
            // User canceled
        }
    } else {
        // Handle error
    }
});

Message Dialogs

To show message Dialogs, use Dialogs module.

var Dialogs = app.getModule('dialogs/Dialogs');

There are three types of message Dialogs to show error, alert, and info.

// Error Dialog
Dialogs.showErrorDialog("This is error message.");

// Alert Dialog
Dialogs.showAlertDialog("This is alert message.");

// Info Dialog
Dialogs.showInfoDialog("This is info message.");

All showing Dialogs are not synchronous call. So if you want to do something when user press OK button, you need to use callback function.

var dlg = Dialogs.showInfoDialog("This is info message.");
dlg.done(function () {
    console.log("done.");
});

Input Dialogs

var dlg = Dialogs.showInputDialog("Enter your name.");
dlg.done(function (buttonId, text) {
    if (buttonId === Dialogs.DIALOG_BTN_OK) {
        console.log("Your name is", text);
    } else {
        // User canceled
    }
});
var dlg = Dialogs.showTextDialog("Enter your biography.", "Edit here...");
dlg.done(function (buttonId, text) {
    if (buttonId === Dialogs.DIALOG_BTN_OK) {
        console.log("Your bio is", text);
    } else {
        // User canceled
    }
});
var options = [
    { text: "First", value: 1 },
    { text: "Second", value: 2 },
    { text: "Third", value: 3 }
];
var dlg = Dialogs.showSelectRadioDialog("Select one of the following items.", options);
dlg.done(function (buttonId, selected) {
    if (buttonId === Dialogs.DIALOG_BTN_OK) {
        console.log(selected);
    } else {
        // User canceled
    }
});
var options = [
    { text: "First", value: 1 },
    { text: "Second", value: 2 },
    { text: "Third", value: 3 }
];
var dlg = Dialogs.showSelectDropdownDialog("Select one of the following items.", options);
dlg.done(function (buttonId, selected) {
    if (buttonId === Dialogs.DIALOG_BTN_OK) {
        console.log(selected);
    } else {
        // User canceled
    }
});
Clone this wiki locally