Skip to main content
K.Daube
Community Expert
Community Expert
May 3, 2021
Answered

Strange behaviour of dialog

  • May 3, 2021
  • 4 replies
  • 733 views

I have a menu item "SetMsgDisplay" which invokes a simple dialogue. For test purpose it contains only a static text.

Invoking this for the first time after FM-15 start works OK

Invoking it the second to nth time creates an empty window of 2540 x 1020 pix size with not title.

The behaviour can not be repeated in debug mode - because no menu is possible in this mode. Directly invoking the dialogue does not show this strange behaviour.

Changing the window type to palette: this works correctly.

The window ID for the dialog/palette is global (no var declaration for it).

Any ideas what is going on here?

This topic has been closed for replies.
Correct answer ReedError

Hi,

I changed the code to this and it works correctly.

Can't tell you why exactly, but I think it is to do with the dialog being global.

 

// BareBone.jsx ====== UTF-8 =======================================================================

// --- Globals -----------------------------------
if (typeof KLD_G == "undefined") {
	KLD_G = {};                                     // Global script object for this suite
}
KLD_G.msgInfo = true;                          // Informative messages
KLD_G.msgWarn = true;                          // Warnings
KLD_G.msgError = true;                          // Error messages

KLD_G.Main = function () { // =====================================================================
	KLD_G.SetUpMenus();
}; // -- end  Main -------------------------------------------------------------------------------

KLD_G.SetUpMenus = function () { // ===============================================================
	var docFMgraphMenu, menuLocation, oMenus = {}, oCmd = {};

	// --- Menu entries (could be integrated in to command definitions as strings)
	oMenus.MenuMain = "BareBone Graphic Library";
	oMenus.SetMessages = "Re/Set messages";
	// --- Command definition for documents
	oCmd.MsetMessages = DefineCommand(5, "FMgraph_SetMessages", oMenus.SetMessages, "\!qgmo");
	// --- Shortcut labels
	oCmd.MsetMessages.KeyboardShortcutLabel = "ESC q g m";
	// --- Assign commands to menus
	menuLocation = app.GetNamedMenu("GraphicsMenu");     // look up name in the menus.cfg files
	docFMgraphMenu = menuLocation.DefineAndAddMenu("!FMgraphMain", oMenus.MenuMain); // ! required
	docFMgraphMenu.AddCommandToMenu(oCmd.MsetMessages);
	//
	UpdateMenus();                                  // refresh and actually make the new menu appear
}; //-- end  SetUpMenus  ---------------------------------------------------------------------------

function Command(cmd) { // =======================================================================
	switch (cmd) {
		case 5:
			KLD_G.SetMessages();
			break;
	}
} //-- end  Command  ------------------------------------------------------------------------------

KLD_G.SetMessages = function () { // ==============================================================
	KLD_G.DlgSetMessages();
}; //-- end DlgSetMessages  ------------------------------------------------------------------------

KLD_G.DlgSetMessages = function () { // ============================================================
	var wDlgM = new Window("dialog", undefined, undefined);  // title set in DlgM

	// This does not work as dialog, only as palette - see development log.
	wDlgM.text = "BareBone version of FMgraph to demonstrate the dialog problem";

	wDlgM.preferredSize.width = 250;
	wDlgM.orientation = "column";
	wDlgM.alignChildren = ["left", "top"];
	wDlgM.spacing = 10;
	wDlgM.margins = 5;

	wDlgM.chkI = wDlgM.add("checkbox", undefined, "I: Information messages ");
	wDlgM.chkW = wDlgM.add("checkbox", undefined, "W: Warning messages");
	wDlgM.chkE = wDlgM.add("checkbox", undefined, "E: Error messages");
	wDlgM.btnSet = wDlgM.add("button", undefined, "Set messag display");
	// ---------------------------------------------------- behaviour of the buttons ------------------
	wDlgM.btnSet.onClick = function () {
		KLD_G.msgInfo = wDlgM.chkI.value;
		KLD_G.msgWarn = wDlgM.chkW.value;
		KLD_G.msgError = wDlgM.chkE.value;
		wDlgM.close();
	};
	// ---------------------------------------------------- Final work in dialogue --------------------
	wDlgM.chkI.value = KLD_G.msgInfo;               // Informative messages
	wDlgM.chkW.value = KLD_G.msgWarn;               // Warnings
	wDlgM.chkE.value = KLD_G.msgError;              // Error messages
	wDlgM.show();
}; //=== end DlgSetMessages <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
KLD_G.Main(); // === follow the standard

4 replies

ReedErrorCorrect answer
Inspiring
May 4, 2021

Hi,

I changed the code to this and it works correctly.

Can't tell you why exactly, but I think it is to do with the dialog being global.

 

// BareBone.jsx ====== UTF-8 =======================================================================

// --- Globals -----------------------------------
if (typeof KLD_G == "undefined") {
	KLD_G = {};                                     // Global script object for this suite
}
KLD_G.msgInfo = true;                          // Informative messages
KLD_G.msgWarn = true;                          // Warnings
KLD_G.msgError = true;                          // Error messages

KLD_G.Main = function () { // =====================================================================
	KLD_G.SetUpMenus();
}; // -- end  Main -------------------------------------------------------------------------------

KLD_G.SetUpMenus = function () { // ===============================================================
	var docFMgraphMenu, menuLocation, oMenus = {}, oCmd = {};

	// --- Menu entries (could be integrated in to command definitions as strings)
	oMenus.MenuMain = "BareBone Graphic Library";
	oMenus.SetMessages = "Re/Set messages";
	// --- Command definition for documents
	oCmd.MsetMessages = DefineCommand(5, "FMgraph_SetMessages", oMenus.SetMessages, "\!qgmo");
	// --- Shortcut labels
	oCmd.MsetMessages.KeyboardShortcutLabel = "ESC q g m";
	// --- Assign commands to menus
	menuLocation = app.GetNamedMenu("GraphicsMenu");     // look up name in the menus.cfg files
	docFMgraphMenu = menuLocation.DefineAndAddMenu("!FMgraphMain", oMenus.MenuMain); // ! required
	docFMgraphMenu.AddCommandToMenu(oCmd.MsetMessages);
	//
	UpdateMenus();                                  // refresh and actually make the new menu appear
}; //-- end  SetUpMenus  ---------------------------------------------------------------------------

function Command(cmd) { // =======================================================================
	switch (cmd) {
		case 5:
			KLD_G.SetMessages();
			break;
	}
} //-- end  Command  ------------------------------------------------------------------------------

KLD_G.SetMessages = function () { // ==============================================================
	KLD_G.DlgSetMessages();
}; //-- end DlgSetMessages  ------------------------------------------------------------------------

KLD_G.DlgSetMessages = function () { // ============================================================
	var wDlgM = new Window("dialog", undefined, undefined);  // title set in DlgM

	// This does not work as dialog, only as palette - see development log.
	wDlgM.text = "BareBone version of FMgraph to demonstrate the dialog problem";

	wDlgM.preferredSize.width = 250;
	wDlgM.orientation = "column";
	wDlgM.alignChildren = ["left", "top"];
	wDlgM.spacing = 10;
	wDlgM.margins = 5;

	wDlgM.chkI = wDlgM.add("checkbox", undefined, "I: Information messages ");
	wDlgM.chkW = wDlgM.add("checkbox", undefined, "W: Warning messages");
	wDlgM.chkE = wDlgM.add("checkbox", undefined, "E: Error messages");
	wDlgM.btnSet = wDlgM.add("button", undefined, "Set messag display");
	// ---------------------------------------------------- behaviour of the buttons ------------------
	wDlgM.btnSet.onClick = function () {
		KLD_G.msgInfo = wDlgM.chkI.value;
		KLD_G.msgWarn = wDlgM.chkW.value;
		KLD_G.msgError = wDlgM.chkE.value;
		wDlgM.close();
	};
	// ---------------------------------------------------- Final work in dialogue --------------------
	wDlgM.chkI.value = KLD_G.msgInfo;               // Informative messages
	wDlgM.chkW.value = KLD_G.msgWarn;               // Warnings
	wDlgM.chkE.value = KLD_G.msgError;              // Error messages
	wDlgM.show();
}; //=== end DlgSetMessages <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
KLD_G.Main(); // === follow the standard
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
May 5, 2021

Thank You very much, ReedError!

Looking back into my previous projects, I see that I started with this method for both dialog and palette windows. Later I decided to declare the window ID for palettes globally - I did not have the need for a dialog in recent projects. The palettes work fine with a global ID - hence the knowledge about the dialog requirements disappeared ...

frameexpert
Community Expert
Community Expert
May 3, 2021

Do you have the static text as a direct child of the window object? If so, put a group or panel object in the window first, then add the static text. I am pretty sure this is a known issue with the ScriptUI object.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
May 3, 2021

Rick,

Putting all the contents of the dialog into a group does not solve the problem here ...

As far as I know the group is necessary for list boxes and drop-down lists.

Klaus Göbel
Legend
May 3, 2021

Hi Klaus,

could you please post some code, so I can check it?

thanks

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
May 3, 2021

Hello Klaus,

Please find hereafter the 'barebone' version demonstrating the problem:

Put the code into the StartUp folder from either FM-15.0.8 or FM-16.0.1

You will find a menu item in Graphics > BareBone Graphics Library > Re/Set Messages

Using this menu item the first time you will get a correct dialog

Using it for the 2nd to nth time you get an empty large window...

If you change "dialog" to "palette" in the Globals section you do not have a problem with 2nd to nth call...

 

// BareBone.jsx ====== UTF-8 =======================================================================

#target framemaker
// --- Globals -----------------------------------
if (typeof KLD_G == "undefined") {
  KLD_G = {};                                     // Global script object for this suite
}
  KLD_G.msgInfo  = true;                          // Informative messages
  KLD_G.msgWarn  = true;                          // Warnings
  KLD_G.msgError = true;                          // Error messages
  wDlgM  = new Window("dialog", undefined, undefined);  // title set in DlgM

KLD_G.Main = function () { // =====================================================================
  KLD_G.SetUpMenus ();
} ; // -- end  Main -------------------------------------------------------------------------------

KLD_G.SetUpMenus = function () { // ===============================================================
var docFMgraphMenu, menuLocation, oMenus = {}, oCmd = {};

// --- Menu entries (could be integrated in to command definitions as strings)
  oMenus.MenuMain   = "BareBone Graphic Library";
  oMenus.SetMessages= "Re/Set messages";
// --- Command definition for documents
  oCmd.MsetMessages = DefineCommand(5,"FMgraph_SetMessages", oMenus.SetMessages, "\!qgmo");
// --- Shortcut labels
  oCmd.MsetMessages.KeyboardShortcutLabel = "ESC q g m";
// --- Assign commands to menus
  menuLocation = app.GetNamedMenu("GraphicsMenu");     // look up name in the menus.cfg files
  docFMgraphMenu  = menuLocation.DefineAndAddMenu("!FMgraphMain", oMenus.MenuMain); // ! required
  docFMgraphMenu.AddCommandToMenu (oCmd.MsetMessages);
//
  UpdateMenus();                                  // refresh and actually make the new menu appear
} //-- end  SetUpMenus  ---------------------------------------------------------------------------

function Command (cmd) { // =======================================================================
  switch (cmd) {
    case 5:
      KLD_G.SetMessages ();
      break;
  }
} //-- end  Command  ------------------------------------------------------------------------------

KLD_G.SetMessages = function () { // ==============================================================
  KLD_G.DlgSetMessages ();
} //-- end DlgSetMessages  ------------------------------------------------------------------------

KLD_G.DlgSetMessages = function (){ // ============================================================
// This does not work as dialog, only as palette - see development log.
  wDlgM.text = "BareBone version of FMgraph to demonstrate the dialog problem";

  wDlgM.preferredSize.width = 250;
  wDlgM.orientation = "column";
  wDlgM.alignChildren = ["left","top"];
  wDlgM.spacing = 10;
  wDlgM.margins = 5;

  wDlgM.chkI = wDlgM.add("checkbox", undefined, "I: Information messages ");
  wDlgM.chkW = wDlgM.add("checkbox", undefined, "W: Warning messages");
  wDlgM.chkE = wDlgM.add("checkbox", undefined, "E: Error messages");
  wDlgM.btnSet = wDlgM.add("button", undefined, "Set messag display");
// ---------------------------------------------------- behaviour of the buttons ------------------
  wDlgM.btnSet.onClick                           = function () {
    KLD_G.ButtonSet ();
  }
// ---------------------------------------------------- Final work in dialogue --------------------
  wDlgM.chkI.value = KLD_G.msgInfo;               // Informative messages
  wDlgM.chkW.value = KLD_G.msgWarn;               // Warnings
  wDlgM.chkE.value = KLD_G.msgError;              // Error messages
  wDlgM.show();
} //=== end DlgSetMessages <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

KLD_G.ButtonSet = function () { // ================================================================
  KLD_G.msgInfo  = wDlgM.chkI.value;
  KLD_G.msgWarn  = wDlgM.chkW.value;
  KLD_G.msgError = wDlgM.chkE.value;
  wDlgM.close();
} //---  end ButtonSet  ---------------------------------------------------------------------------

// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
KLD_G.Main (); // === follow the standard

 

Community Manager
May 3, 2021

What do you mean with "FM-15"? FrameMaker (2015 release, internal 13.x) or FrameMaker (2019 release, internal 15.x)?

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
May 3, 2021

It is 15.0.8.979

BTW have just tested with 16.0.1 - same strange behaviour

@Klaus GöbelI need to cut the menu stuff down to just this item - takes some time.