//**************************************************************************/ // Copyright (c) 2008 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. // //**************************************************************************/ // DESCRIPTION: // CREATED: October 2008 //**************************************************************************/ #include "FileEventHandler.h" // This line provides some information about the plugin to Mudbox. This can be used to // specify a function which will be called once all the plugins are loaded. MB_PLUGIN( "FileEventHandler", "Sample file event handler", "Autodesk", "http://www.mudbox3d.com", FileEventHandler::Initializer ); // There will be one global instance of our class, which supposed to catch all the file events. FileEventHandler g_cHandler; // One time initialization. This function will simply connect the attribute in the FileEventHandler class to the original attribute in the Kernel. // So if the kernel attribute changes it's value (i.e. a file event happened) the one in our class will also change its value, and we can catch the event. void FileEventHandler::Initializer( void ) { g_cHandler.m_pEvent.Connect( Kernel()->FileEvent ); }; // This function will be called when an event occurs. void FileEventHandler::OnNodeEvent( const Attribute &cAttribute, NodeEventType eType ) { // Once the plug-in is installed, this method will get called for every file event // that occurs. The different file events are defined in Kernel.h (FileEvent class) // // There are many different event types (see NodeEventType in node.h), but here we're // interested in the event being 'triggered'. (This is the same as a value change in // this case) // // We also check cAttribute to make sure it's the right event we're getting a message from // (and that the event is not NULL) if ( cAttribute == m_pEvent && eType == etEventTriggered && m_pEvent ) { // A file event happened. // // Take appropriate action, depending on the event type. For example, you // could log every single event the log file like this next line: Kernel()->Log( NTRQ("FILEEVENT - type: %1, name: %2\n").arg(m_pEvent->m_eType).arg(m_pEvent->m_sFileName) ); // Chech the type of the file event. switch ( m_pEvent->m_eType ) { case FileEventNotifier::typeBrowseForRead: // This is called after the user chooses file>open, but before the file browswer opens. // The variable m_pEvent->m_sFileName contains the path that the browswer will open // to. You can change that string to make the browser open elsewhere, as shown here: m_pEvent->m_sFileName = "c:\\"; break; case FileEventNotifier::typeBrowseForWrite: // This is called after the user chooses file>save as, but before the file browswer opens. break; case FileEventNotifier::typePreRead: // This is call just before the file is read in. The file name is in m_pEvent->m_sFileName. break; case FileEventNotifier::typePostWrite: // This is call just before after the file is written out. The file name is in m_pEvent->m_sFileName. break; }; }; };