//************************************************************************************** // Filename: NibPrefsDialog.cp // Copyright © 2003 _tk_. All rights reserved. // // Description: // //************************************************************************************** // Revision History: // Sunday, August 24, 2003 - Original //************************************************************************************** #include "NibPrefsDialog.h" #include "ATabControl.h" #include "AControls.h" #include "ACFString.h" #include "CFObjDel.h" NibPrefsDialog::NibPrefsDialog(CFStringRef inNibName, CFStringRef inDlogWindowName) : NibModalDialog(inNibName, inDlogWindowName), mTabContol(NULL) { } NibPrefsDialog::NibPrefsDialog(CFBundleRef inBundleRef, CFStringRef inNibName, CFStringRef inDlogWindowName) : NibModalDialog(inBundleRef, inNibName, inDlogWindowName), mTabContol(NULL) { } NibPrefsDialog::~NibPrefsDialog(void) { delete mTabContol; } void NibPrefsDialog::Initialize() { if(mWindow == NULL) return; const ControlID tabsControlID = { 'tabs', 100 }; mTabContol = new ATabControl(mWindow, tabsControlID, 1); } //returns noErr if command handled otherwise should return eventNotHandledErr OSStatus NibPrefsDialog::ProcessCommand() { OSStatus outErr = eventNotHandledErr; switch (mCommand.commandID) { case 'Choo': ChooseCreator(); break; case 'CrCh': CreatorSettingsChanged(); break; } return outErr; } void NibPrefsDialog::SetInitialDialogOptions(const CyclonePrefs &inPrefs) { //General tab if(true) {//remember last encoding const ControlID checkID = {'Pref', 101}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kSaveLastEncodings) != 0) ? 1 : 0); } if(true) {//keep partial const ControlID checkID = {'Pref', 102}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kKeepPartialFiles) != 0) ? 1 : 0); } //Input tab if(true) {//ask at startup const ControlID checkID = {'Pref', 201}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kAskAtStartup) != 0) ? 1 : 0); } if(true) {//use sniffers const ControlID checkID = {'Pref', 202}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kUseSniffers) != 0) ? 1 : 0); } //Output tab if(true) {//dont ask for output name const ControlID checkID = {'Pref', 301}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kSaveDontAsk) != 0) ? 1 : 0); } if(true) {//use custom creator const ControlID checkID = {'Pref', 304}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kUseCustomSignature) != 0) ? 1 : 0); } if(true) {//line breaks radio group const ControlID radioID = {'Pref', 303}; AControl theRadio(mWindow, radioID); if((inPrefs.flags & kExplicitLineBreakChange) != 0) theRadio.SetValue(3); else if((inPrefs.flags & kAutoChangeLineBreaks) != 0) theRadio.SetValue(2); else theRadio.SetValue(1); } if(true) {//custom creator const ControlID editFieldID = {'Pref', 305}; ACFString theCreator(inPrefs.theSignature); AEditText editField(mWindow, editFieldID); editField.SetCFText((CFStringRef)theCreator); } //Multiple Files tab if(true) {//ask for each const ControlID checkID = {'Pref', 401}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kAskEncForEachFile) != 0) ? 1 : 0); } if(true) {//suppress error messages and generate log const ControlID checkID = {'Pref', 402}; AControl theCheck(mWindow, checkID); theCheck.SetValue(((inPrefs.flags & kSuppressMsgGenLog) != 0) ? 1 : 0); } CreatorSettingsChanged(); } void NibPrefsDialog::GetClosingDialogOptions(CyclonePrefs &outPrefs) { //General tab if(true) {//remember last encoding const ControlID checkID = {'Pref', 101}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kSaveLastEncodings; else outPrefs.flags &= ~kSaveLastEncodings; } if(true) {//keep partial const ControlID checkID = {'Pref', 102}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kKeepPartialFiles; else outPrefs.flags &= ~kKeepPartialFiles; } //Input tab if(true) {//ask at startup const ControlID checkID = {'Pref', 201}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kAskAtStartup; else outPrefs.flags &= ~kAskAtStartup; } if(true) {//use sniffers const ControlID checkID = {'Pref', 202}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kUseSniffers; else outPrefs.flags &= ~kUseSniffers; } //Output tab if(true) {//dont ask for output name const ControlID checkID = {'Pref', 301}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kSaveDontAsk; else outPrefs.flags &= ~kSaveDontAsk; } if(true) {//use custom creator const ControlID checkID = {'Pref', 304}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kUseCustomSignature; else outPrefs.flags &= ~kUseCustomSignature; } if(true) {//line breaks radio group const ControlID radioID = {'Pref', 303}; AControl theRadio(mWindow, radioID); switch(theRadio.Value()) { case 3://manual change outPrefs.flags |= kExplicitLineBreakChange; outPrefs.flags &= ~kAutoChangeLineBreaks; break; case 2://auto change outPrefs.flags |= kAutoChangeLineBreaks; outPrefs.flags &= ~kExplicitLineBreakChange; break; default://no change outPrefs.flags &= ~kAutoChangeLineBreaks; outPrefs.flags &= ~kExplicitLineBreakChange; break; } } if(true) {//custom creator const ControlID editFieldID = {'Pref', 305}; ACFString theCreator(outPrefs.theSignature); AEditText editField(mWindow, editFieldID); CFStringRef creatorText = editField.CopyCFText(); CFObjDel theDel(creatorText); outPrefs.theSignature = PlistPreferences::CFStringToFourCharCode((CFStringRef)creatorText); } //Multiple Files tab if(true) {//ask for each const ControlID checkID = {'Pref', 401}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kAskEncForEachFile; else outPrefs.flags &= ~kAskEncForEachFile; } if(true) {//suppress error messages and generate log const ControlID checkID = {'Pref', 402}; AControl theCheck(mWindow, checkID); if(theCheck.Value()) outPrefs.flags |= kSuppressMsgGenLog; else outPrefs.flags &= ~kSuppressMsgGenLog; } } void NibPrefsDialog::ChooseCreator() { FSRef objRef; Boolean isOK = ChooseFileDialog(objRef, CFSTR("Choose application or file to pick creator signature from:"), CFSTR("Choose")); if(isOK) { OSType creator = GetCreator(objRef); const ControlID editFieldID = {'Pref', 305}; ACFString theCreator(creator); AEditText editField(mWindow, editFieldID); editField.SetCFText((CFStringRef)theCreator); } } void NibPrefsDialog::CreatorSettingsChanged() { const ControlID creatorCheckID = {'Pref', 304};//master checkbox AControl creatorCheck(mWindow, creatorCheckID); const ControlID editFieldID = {'Pref', 305};//edit field AControl editField(mWindow, editFieldID); const ControlID buttonID = {'Pref', 306};//button AControl chooseButton(mWindow, buttonID); if( creatorCheck.Value() != 0) { editField.Enable(); chooseButton.Enable(); } else { editField.Disable(); chooseButton.Disable(); } } Boolean NibPrefsDialog::ChooseFileDialog(FSRef &outRef, CFStringRef inMessage, CFStringRef inActionButtLabel) { NavDialogCreationOptions dialogOptions; OSStatus err = ::NavGetDefaultDialogCreationOptions( &dialogOptions ); if( err != noErr) return false; dialogOptions.optionFlags = kNavNoTypePopup + kNavSupportPackages; dialogOptions.modality = kWindowModalityWindowModal; dialogOptions.parentWindow = mWindow; dialogOptions.clientName = CFSTR("Cyclone"); dialogOptions.message = inMessage; dialogOptions.actionButtonLabel = inActionButtLabel; dialogOptions.preferenceKey = 'Crea'; Boolean outOK = false; NavDialogRef dialogRef = NULL; err = ::NavCreateChooseFileDialog( &dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialogRef); if( (err == noErr) && (dialogRef != NULL) ) { err = ::NavDialogRun( dialogRef ); if( err == noErr ) { NavUserAction theAction = ::NavDialogGetUserAction( dialogRef ); if( (theAction != kNavUserActionCancel) && (theAction != kNavUserActionNone) ) { NavReplyRecord reply; err = ::NavDialogGetReply(dialogRef, &reply); if(err == noErr) { AEKeyword theAEKeyword; DescType typeCode; Size actualSize; err = ::AEGetNthPtr( &(reply.selection), 1, typeFSRef, &theAEKeyword, &typeCode, &outRef, sizeof(FSRef), &actualSize); ::NavDisposeReply( &reply ); outOK = (err == noErr); } } } ::NavDialogDispose( dialogRef ); } return outOK; } OSType NibPrefsDialog::GetCreator(FSRef &inRef) { FSCatalogInfo theInfo; ::BlockZero(&theInfo, sizeof(theInfo)); OSErr err = ::FSGetCatalogInfo(&inRef, kFSCatInfoNodeFlags, &theInfo, NULL, NULL, NULL); if ( err == noErr ) {//it is a file or folder. we can safely proceed LSItemInfoRecord itemInfo; ::BlockZero(&itemInfo, sizeof(itemInfo)); LSRequestedInfo whichInfo = kLSRequestTypeCreator; err = ::LSCopyItemInfoForRef( &inRef, whichInfo, &itemInfo); if( err == noErr ) { return itemInfo.creator; } } return '????'; }