// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: Aug 21, 2003 // // Procedure Name: // melFileToSave() // // Description: // Brings up a modal dialog for the user to input the pathname // to which the selected contents of the Script Editor will be // saved. Called from within the Script Editor code. // // Input Value: // None // // Output Value: // Pathname of a valid writable file that the user typed in. // global proc string melFileToSave() // // Purpose: // // Called from the "File->Save Selected" menu item // of the Script Editor under low memory conditions // on Windows, when a standard system dialog would // cause Maya to hang. // // Brings up a simple text box that allows the user // to type in a full path to a MEL script to save to. // Loops until a valid pathname is entered, or // the user cancels the dialog. Also tries to // confirm if a file would be overwritten. // // { string $text = ""; string $ok = (uiRes("m_melFileToSave.kOk")); string $cancel = (uiRes("m_melFileToSave.kCancel")); while( 1 ) { $result = `promptDialog -title (uiRes("m_melFileToSave.kSaveSelected")) -message (uiRes("m_melFileToSave.kEnterFilename")) -button $ok -button $cancel -defaultButton $ok -cancelButton $cancel -dismissString $cancel -tx $text`; if ($result == $ok) { $text = `promptDialog -query -text`; // if file exists already, check to see if // user wants to overwrite it // int $exists = 0; if( `filetest -f $text` ) { $exists = 1; string $msg = (uiRes("m_melFileToSave.kOverwriteMessage")); $msg = `format -s $text $msg`; string $overwrite = `confirmDialog -title (uiRes("m_melFileToSave.kConfirmOverwrite")) -message $msg -button $ok -button $cancel -defaultButton $cancel -cancelButton $cancel`; if( $overwrite == $cancel ) { continue; } } // if file cannot be opened for write, inform user. // File can be opened for write if it exists and is writable, // or if it does not exist but the specified directory exists // and is writable. // string $dir = dirname( $text ); int $canWrite = ($exists && `filetest -w $text`) || (!$exists && size($dir) && `filetest -w $dir`); if( !$canWrite ) { confirmDialog -title (uiRes("m_melFileToSave.kError")) -message (uiRes("m_melFileToSave.kWriteMessage")) -button (uiRes("m_melFileToSave.kTryAgain")); continue; } else { break; } } else { // user cancelled dialog // $text = ""; break; } } return $text; }