How to prevent opening a Dialog Box if already open?

Greetings,

Does anyone have a script to prevent openinig multiple instances of the same dialog box?
SystemAdmin - Fri Apr 23 07:46:04 EDT 2010

Re: How to prevent opening a Dialog Box if already open?
Mathias Mamsch - Fri Apr 23 12:21:39 EDT 2010

That depends. Do you want to prevent opening the same dialog box twice during your client sessions in the same dxl context (i.e. a dxl program running once) or in different contexts (i.e. a dxl program running twice).

Since you cannot iterate over all open dialog boxes, you need to use some global variable or any object that won't change it's state during two runs of a DXL program. You could use the config area to store a temporary file, install a global variable using evalTop_ , use any COM object which will signal you that your dialog box is already open.

Regards, Mathias

Re: How to prevent opening a Dialog Box if already open?
SystemAdmin - Fri Apr 23 16:42:41 EDT 2010

Mathias Mamsch - Fri Apr 23 12:21:39 EDT 2010
That depends. Do you want to prevent opening the same dialog box twice during your client sessions in the same dxl context (i.e. a dxl program running once) or in different contexts (i.e. a dxl program running twice).

Since you cannot iterate over all open dialog boxes, you need to use some global variable or any object that won't change it's state during two runs of a DXL program. You could use the config area to store a temporary file, install a global variable using evalTop_ , use any COM object which will signal you that your dialog box is already open.

Regards, Mathias

Great Advice, I don't know how the stuff you mentioned work, but it gave me the following IDEA. Please take a look and let me know what do you think, or maybe if you have examples of those API integration, i can figure out something.

I definately can not write in the config area, that's why i'm using the C:/Temp location, because i assume that everyone can access that.
 

AttrDef ad
Module m = current
Skip attrList = createString()
Buffer bAttr = create()
string temp
string attrName
string arr [] = {}
DB dbAttr
DBE lstAttr
int count
int num
 
 
//checkingInstancesofCRTool() function global variables
string location = "c:/Temp/"
string fName = "dbLock.txt"
string path = location fName
string winLock = "CR Tool currently running an instance."
 
void checkingInstancesofCRTool()
{
    
        bool canWriteStream = canOpenFile(path, false)
        
        if(canWriteStream)
        {
                string val = readFile(path)
                if(val == winLock)
                {
                        ack(winLock)
                        if(confirm("Are you running an instance of the CR Tool?"))
                        {
                                halt
                        }
                                else
                                {
                                        deleteFile(path)
                                        Stream out = write(path)
                                        out << winLock
                                        close(out)
                                        flush(out)
                                }
                }
                
        }
                else
                {
                        Stream out = write(path)
                        out << winLock
                        close(out)
                        flush(out)
                }
}
 
void getAttrList (){
if(null m){
infoBox"Program must be run from a module"
} else {
for ad in m do
{
        if ((ad.object) && (!ad.system)) 
        {
                        attrName = ad.name
                        if((attrName == "RTF NonShpPict") || (attrName == "RTF ShpPict"))
                        {
                                attrName = null
                        }
                                else 
                                {
                                put(attrList, attrName, attrName)
                                }
 
        }
}
}
num = 0
        for attrName in attrList do
        {
        insert(lstAttr, num, (string key attrList), iconNone)
        set(lstAttr,num, 1, num"")
        num++
 
        }
 
delete(attrList)
delete(bAttr)
}
 
 
void insLstView (DB Win)
{
attrName = null
int i
bool getAttr
count = 0
 
        for(i = 0; i<noElems(lstAttr); i++)
        {
                        getAttr = getCheck(lstAttr, i)
 
                        if(getAttr)
                        {
                                attrName = get(lstAttr, i)
                                print attrName"\n"
                                
                                col = insert (column count)
                                attribute(col, attrName)
                                width(col, 200)
                                count ++                        
                        }
        }
}
 
void closedbWin(DB Win)
{
        hide(dbAttr)
        destroy(dbAttr)
        deleteFile(path)
}
 
 
void main_form_init()
{
 
        dbAttr = create("Attribute List", styleCentered|styleFixed)
        lstAttr = listView(dbAttr, listViewOptionCheckboxes, 425, 10, arr)
        
        apply(dbAttr, "Insert", insLstView)
        close(dbAttr, true, closedbWin)
        
        realize(dbAttr)
        
        insertColumn(lstAttr, 0, "Select the attributes you want to update", 250, iconNone)   
        insertColumn(lstAttr, 1, "Column Value", 150, iconNone)               
        
        getAttrList()
        
        show (dbAttr)
}
 
checkingInstancesofCRTool()
main_form_init

Re: How to prevent opening a Dialog Box if already open?
Mathias Mamsch - Sat Apr 24 05:47:46 EDT 2010

SystemAdmin - Fri Apr 23 16:42:41 EDT 2010

Great Advice, I don't know how the stuff you mentioned work, but it gave me the following IDEA. Please take a look and let me know what do you think, or maybe if you have examples of those API integration, i can figure out something.

I definately can not write in the config area, that's why i'm using the C:/Temp location, because i assume that everyone can access that.
 

AttrDef ad
Module m = current
Skip attrList = createString()
Buffer bAttr = create()
string temp
string attrName
string arr [] = {}
DB dbAttr
DBE lstAttr
int count
int num
 
 
//checkingInstancesofCRTool() function global variables
string location = "c:/Temp/"
string fName = "dbLock.txt"
string path = location fName
string winLock = "CR Tool currently running an instance."
 
void checkingInstancesofCRTool()
{
    
        bool canWriteStream = canOpenFile(path, false)
        
        if(canWriteStream)
        {
                string val = readFile(path)
                if(val == winLock)
                {
                        ack(winLock)
                        if(confirm("Are you running an instance of the CR Tool?"))
                        {
                                halt
                        }
                                else
                                {
                                        deleteFile(path)
                                        Stream out = write(path)
                                        out << winLock
                                        close(out)
                                        flush(out)
                                }
                }
                
        }
                else
                {
                        Stream out = write(path)
                        out << winLock
                        close(out)
                        flush(out)
                }
}
 
void getAttrList (){
if(null m){
infoBox"Program must be run from a module"
} else {
for ad in m do
{
        if ((ad.object) && (!ad.system)) 
        {
                        attrName = ad.name
                        if((attrName == "RTF NonShpPict") || (attrName == "RTF ShpPict"))
                        {
                                attrName = null
                        }
                                else 
                                {
                                put(attrList, attrName, attrName)
                                }
 
        }
}
}
num = 0
        for attrName in attrList do
        {
        insert(lstAttr, num, (string key attrList), iconNone)
        set(lstAttr,num, 1, num"")
        num++
 
        }
 
delete(attrList)
delete(bAttr)
}
 
 
void insLstView (DB Win)
{
attrName = null
int i
bool getAttr
count = 0
 
        for(i = 0; i<noElems(lstAttr); i++)
        {
                        getAttr = getCheck(lstAttr, i)
 
                        if(getAttr)
                        {
                                attrName = get(lstAttr, i)
                                print attrName"\n"
                                
                                col = insert (column count)
                                attribute(col, attrName)
                                width(col, 200)
                                count ++                        
                        }
        }
}
 
void closedbWin(DB Win)
{
        hide(dbAttr)
        destroy(dbAttr)
        deleteFile(path)
}
 
 
void main_form_init()
{
 
        dbAttr = create("Attribute List", styleCentered|styleFixed)
        lstAttr = listView(dbAttr, listViewOptionCheckboxes, 425, 10, arr)
        
        apply(dbAttr, "Insert", insLstView)
        close(dbAttr, true, closedbWin)
        
        realize(dbAttr)
        
        insertColumn(lstAttr, 0, "Select the attributes you want to update", 250, iconNone)   
        insertColumn(lstAttr, 1, "Column Value", 150, iconNone)               
        
        getAttrList()
        
        show (dbAttr)
}
 
checkingInstancesofCRTool()
main_form_init

Ok, this seems to be a way to do it. You should maybe not use "c:\temp" as a directory, but instead use tempFile() and cut off the filename. Note: If you want the user to be able to open the tool twice for different modules, append the module id (uniqueID getItem Module) to the filename. Regards, Mathias

Re: How to prevent opening a Dialog Box if already open?
llandale - Wed Jun 09 13:57:17 EDT 2010

So you have a script in a pull-down menu that applies to the current module and displays a dialog, and you want the script to know when the script is already running (for that module) and to not display the GUI a 2nd time. If the dialog is open for some other Module, then OK display it for THIS module.

I'd have the script create a dynamic pre-close module trigger that closes the Dialog when the module closes. I'd have the main script plow though all the triggers in that module looking for this particular dynamic pre-close module trigger, and if it finds it then it ends without displaying the main dialog.

  • Louie

Re: How to prevent opening a Dialog Box if already open?
llandale - Wed Jun 09 13:59:11 EDT 2010

llandale - Wed Jun 09 13:57:17 EDT 2010
So you have a script in a pull-down menu that applies to the current module and displays a dialog, and you want the script to know when the script is already running (for that module) and to not display the GUI a 2nd time. If the dialog is open for some other Module, then OK display it for THIS module.

I'd have the script create a dynamic pre-close module trigger that closes the Dialog when the module closes. I'd have the main script plow though all the triggers in that module looking for this particular dynamic pre-close module trigger, and if it finds it then it ends without displaying the main dialog.

  • Louie

... and the main Dialog overrides its standard 'close' with its own 'close' function, which removes the Trigger then hides and destroys the dialog.

  • Louie