OpMenuImport Class Reference

#include <impexpop.h>

Inheritance diagram for OpMenuImport:

SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject OpBevel OpSlice OpURLImport OpURLImport List of all members.

Public Member Functions

 OpMenuImport ()
 Constructor for OpMenuImport operation.
void Do (OpDescriptor *)
 Imports a file into the current document.
void DoImport (PathName Path, Filter *pFilter, String_256 *URL, ImportPosition *pImportPosition=NULL)
 import function
void EndImport ()
 End the operation. It's called by GenericDownloadOp::OnDownloadFail().
virtual BOOL OnDocChangingMsg (Document *pChangingDoc, DocChangingMsg::DocState State)
 End (abort) the operation when for instance the current document has been destroyed while downloading.
virtual BOOL MayChangeNodeBounds () const

Static Public Member Functions

static BOOL Init ()
 Declares op descriptors for Acorn Draw file reading.
static OpState GetState (String_256 *, OpDescriptor *)
 This item is always available, so long as a document is visible.

Static Public Attributes

static String_256 DefaultImportFilterPath

Private Attributes

TCHARFilterString

Static Private Attributes

static UINT32 SelectedFilterID = FILTERID_GENERIC
 The unique ID of the filter to default to when importing files. The path to default to when opening the Import File dialog. The unique ID of the filter to default to when exporting files. The path to default to when opening the Export File dialog.
static INT32 SelectedFilter = -1

Detailed Description

Definition at line 132 of file impexpop.h.


Constructor & Destructor Documentation

OpMenuImport::OpMenuImport  ) 
 

Constructor for OpMenuImport operation.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/02/94

Definition at line 628 of file impexpop.cpp.

00629 {
00630     OpFlags.HasOwnTimeIndicator = TRUE; // The OpMenuImport op has its own time indicator
00631 }


Member Function Documentation

void OpMenuImport::Do OpDescriptor  )  [virtual]
 

Imports a file into the current document.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/02/94
Returns:
Errors: Various. Get reported to the user.

Reimplemented from Operation.

Reimplemented in OpBevel, OpURLImport, OpSlice, and OpURLImport.

Definition at line 294 of file impexpop.cpp.

00295 {
00296     // zero is a bad state for this to be in so ensure its not in that state
00297     if (SelectedFilter == 0)
00298         SelectedFilter = -1;
00299 
00300     // Get the list of import filters
00301     FilterString = BaseFileDialog::BuildFilterString(TRUE, SelectedFilterID, &SelectedFilter);
00302     if (FilterString == 0)
00303     {
00304         // Unable to build filter string - report error and finish operation.
00305         InformError();
00306         FailAndExecute();
00307         // Finished the operation
00308         End();
00309         return;
00310     }
00311 
00312     // Create the dialog box
00313     ImportFileDialog FDialog(FilterString);
00314     
00315     FDialog.SetTitle(_R(IDT_IMPORT_TITLE));
00316 
00317     // Select the desired filter, if the default i.e. -1 then set 1 as this is the first valid index.
00318     if (SelectedFilter != -1)
00319         FDialog.SetSelectedFilterIndex(SelectedFilter);
00320     else
00321         FDialog.SetSelectedFilterIndex(1);
00322 
00323     // Select the desired path
00324     if (DefaultImportFilterPath.Length() > 0)
00325         FDialog.SetInitialDirectory(DefaultImportFilterPath);
00326 
00327     BOOL LayersImport = Filter::ImportWithLayers;
00328 
00329     // 'Do' the dialog and get that path/filename that we so desire
00330     BOOL DlgResult = FDialog.OpenAndGetFileName();
00331 
00332     // Check if the import with layers button has been changed and if so send a message
00333     // to warn other users e.g. options dialog box
00334     if (LayersImport != Filter::ImportWithLayers)
00335         BROADCAST_TO_ALL(OptionsChangingMsg(OptionsChangingMsg::IMPORTWITHLAYERS)); 
00336 
00337     if (!DlgResult)
00338     {
00339         // Get rid of the filter string buffer
00340         CCFree(FilterString);
00341         FilterString = 0;
00342 
00343         // User aborted - exit operation quietly.
00344         FailAndExecute();
00345         End();
00346         return;
00347     }
00348 
00349     // Remember the filter for next time.
00350     SelectedFilter = FDialog.GetSelectedFilterIndex();
00351     TRACEUSER( "luke", _T("Looking for ordinal %d"), SelectedFilter );
00352 
00353     // Get the filename, ensuring that the path is valid
00354     PathName Path;
00355     if (!FDialog.GetChosenFileName(&Path))
00356     {
00357         InformError();
00358         // Get rid of the filter string buffer
00359         CCFree(FilterString);
00360         FilterString = 0;
00361         FailAndExecute(); 
00362         End();
00363         return;
00364     }
00365 
00366     // Extract directory name (minus terminating backslash) and remember for next time.
00367     DefaultImportFilterPath = Path.GetLocation(FALSE);
00368             
00369     // Find the filter that the user chose
00370     Filter *pFilter = Filter::GetFirst();
00371     while (pFilter != 0)
00372     {
00373         if( NULL != pFilter->pOILFilter )
00374         {
00375             if( ( pFilter->GetFlags().CanImport && !IS_A( pFilter, CamelotEPSFilter ) ) &&
00376                 pFilter->pOILFilter->Position == SelectedFilter )
00377             {
00378                 TRACEUSER( "luke", _T("%s is THE filter (%d)"),
00379                     (TCHAR*)pFilter->FilterName, pFilter->pOILFilter->Position );
00380 
00381                 // This is the filter!
00382                 break;
00383             }
00384 
00385             TRACEUSER( "luke", _T("%s is not selected (ord=%d)"),
00386                 (TCHAR*)pFilter->FilterName, pFilter->pOILFilter->Position );
00387         }
00388         else
00389             TRACEUSER( "luke", _T("Can't handle NULL pFilter->pOILFilter for %s"),
00390                 (TCHAR*)pFilter->FilterName );
00391         
00392         // Try the next filter
00393         pFilter = Filter::GetNext(pFilter);
00394     }
00395     
00396     // Get rid of the filter string buffer
00397     CCFree(FilterString);
00398     FilterString = 0;
00399 
00400     if (pFilter == 0)
00401     {
00402         InformError(_R(IDT_CANT_FIND_FILTER));
00403         FailAndExecute(); 
00404     }
00405     else
00406     {
00407         SelectedFilterID = pFilter->FilterID;
00408 
00409         String_256 URL = Path.GetPath();
00410         
00411         TRACEUSER( "luke", _T("Path = %s\n"), (TCHAR*)URL );
00412 
00413         //Graham 14/7/97: Get the current view
00414         DocView* pDocView=DocView::GetCurrent();
00415 
00416         //And find its centre import position
00417         ImportPosition posToUse=pDocView->GetCentreImportPosition();
00418             
00419         // call the Import function
00420         DoImport(Path, pFilter, &URL, &posToUse);
00421     }
00422 }

void OpMenuImport::DoImport PathName  Path,
Filter pFilter,
String_256 URL,
ImportPosition pImportPosition = NULL
 

import function

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com> gascoin
Date:
07/05/97
Parameters:
Path - local file [INPUTS] pFilter - pointer to a filter URL - original URL of the imported file pImportPosition - position to import to (added by Graham 14/7/97)

Definition at line 440 of file impexpop.cpp.

00441 {
00442     // If this is not a filter family, check for compatibility before asking
00443     // filter to load the file.
00444     // This means the user has chosen an explicit filter to handle the import
00445     if (!pFilter->IS_KIND_OF(FilterFamily))
00446     {
00447         UINT32 Size = 1024;
00448         size_t FileSize;
00449         ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);
00450 
00451         // If there has been a problem in the load initial segment then fail now.
00452         if (FilterBuf == 0)
00453         {
00454             // Tell the user about the problem and get out now while the goings good 
00455             InformError();
00456             FailAndExecute(); 
00457             End();
00458             return;
00459         }
00460 
00461         // Inform any filters that we are about to do a HowCompatible call.
00462         // This would allow a set of filters which have common functionality hidden in a
00463         // filter that cannot import and cannot export handle this call and hence set
00464         // itself up. This would allow it to maybe cache a result which should only be
00465         // checked by the first filter in the group. 
00466         pFilter->PreHowCompatible();
00467             
00468         // Change this to be less than 8 as the filters like the Accusoft forms return
00469         // 8 and 9 to make sure that they are last in the chain.
00470         if (pFilter->HowCompatible(Path, FilterBuf, Size, FileSize) < 8)
00471         {
00472             // Not 100% happy with this file - ask for confirmation.
00473             ErrorInfo Question;
00474             Question.ErrorMsg = _R(IDT_IMPQUERY_NOTSURE);
00475             Question.Button[0] = _R(IDB_IMPQUERY_IMPORT);
00476             Question.Button[1] = _R(IDB_IMPQUERY_DONTIMPORT);
00477 
00478             if (UINT32(AskQuestion(&Question)) != _R(IDB_IMPQUERY_IMPORT))
00479             {
00480                 // User asked for this to be cancelled.
00481                 TRACEUSER( "Tim", _T("Filter compatibility was less than 10\n"));
00482 
00483                 // Close the file, report the abort and finish.
00484                 CCFree(FilterBuf);
00485                 FailAndExecute();
00486                 InformMessage(_R(IDT_IMP_USERABORT));
00487                 End();
00488                 return;
00489             }
00490         }
00491 
00492         // Get rid of initial file header
00493         CCFree(FilterBuf);
00494     }
00495 
00496     // Start the selection operation
00497     if (DoStartSelOp(FALSE)) // We don't want to save the end selection status because 
00498                              // it will be restored automatically when the operation is 
00499                              // redone
00500     {
00501         // First off, we have to try and open the file
00502         CCDiskFile DiskFile(1024, FALSE, TRUE);
00503 
00504         // Get pointer to current doc 'cos we'll need it several times...
00505         Document* pCurDoc = Document::GetCurrent();
00506 
00507         try
00508         {
00509             if (!DiskFile.open(Path, ios::in | ios::binary))
00510             {
00511                 // Failed to open the file...
00512                 TRACEUSER( "Rik", _T("Failed to open file in MenuImport Do"));
00513                 InformError(_R(IDT_IMPORT_NOTFOUND));
00514                 FailAndExecute();
00515                 End();
00516                 return;
00517             }
00518 
00519             // Import the file and see if Something went a bit wrong - tell the user what it was.
00520             if (!pFilter->DoImport(this, &DiskFile, pCurDoc, FALSE, pImportPosition, 0, 0, URL))
00521             {
00522                 // Only tell them if not special user cancelled error message
00523                 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00524                     InformError();
00525                 else
00526                     Error::ClearError();    // otherwise remove the error so it won't get reported
00527                 FailAndExecute();
00528                 End();
00529 
00530                 // Close the file again
00531                 if (DiskFile.isOpen())
00532                     DiskFile.close();
00533 
00534                 return;
00535             }
00536 
00537             // close the file
00538             if (DiskFile.isOpen())
00539                 DiskFile.close();
00540     
00541         }
00542 
00543         // See if there was a file io error
00544         catch(CFileException e)
00545         {
00546             // Report the error if no one else did
00547             if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00548                 InformError();
00549             else
00550                 Error::ClearError();    // otherwise remove the error so it won't get reported
00551 
00552             // Make sure that the file is closed
00553             try
00554             {
00555                 if (DiskFile.isOpen())
00556                     DiskFile.close();
00557             }
00558             catch(CFileException e)
00559             {
00560                 // Failed to close the file - not much we can do about it really
00561             }
00562 
00563             // and fail
00564             FailAndExecute();
00565         }
00566     }
00567 
00568     // grab the focus
00569     GetMainFrame()->SetFocus();
00570     // Finished the operation
00571     End();
00572 }

void OpMenuImport::EndImport  ) 
 

End the operation. It's called by GenericDownloadOp::OnDownloadFail().

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/05/97

Definition at line 585 of file impexpop.cpp.

00586 {
00587     FailAndExecute();
00588     End();
00589 }

OpState OpMenuImport::GetState String_256 ,
OpDescriptor
[static]
 

This item is always available, so long as a document is visible.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/02/94

Reimplemented in OpBevel, OpURLImport, OpSlice, and OpURLImport.

Definition at line 645 of file impexpop.cpp.

00646 {
00647     OpState OpSt;
00648 
00649     return OpSt;
00650 }

BOOL OpMenuImport::Init void   )  [static]
 

Declares op descriptors for Acorn Draw file reading.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/02/94
Returns:
TRUE if worked, FALSE if failed (out of memory)

Errors: Returns FALSE on failure.

Reimplemented from SimpleCCObject.

Reimplemented in OpBevel, OpURLImport, OpSlice, and OpURLImport.

Definition at line 246 of file impexpop.cpp.

00247 {
00248     // Derived off SelectionOperation which does not take 15 parameters.
00249     // (Misses out trhe vertical counterpart parameter)
00250     BOOL InitOK;
00251     InitOK = RegisterOpDescriptor(  0,                          // Tool ID
00252                                     _R(IDT_IMPORT),                 // String resource ID
00253                                     CC_RUNTIME_CLASS(OpMenuImport),     // Runtime class
00254                                     OPTOKEN_MENUIMPORT,         // Token string
00255                                     GetState,                   // GetState function
00256                                     0,                          // help ID
00257                                     _R(IDBBL_FILEIMPORT),           // bubble help
00258                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00259                                     _R(IDC_FILEIMPORT),             // control ID
00260                                     SYSTEMBAR_FILE,             // Bar ID
00261                                     TRUE,                       // Recieve system messages
00262                                     FALSE,                      // Smart duplicate operation
00263                                     TRUE,                       // Clean operation
00264                                     _R(IDS_OPMENUIMPORT_ONE),       // String for one copy only error
00265                                     DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC // Auto state flags
00266                                 );
00267     if (!InitOK) return FALSE; 
00268 
00269 
00270     Camelot.DeclareSection(_T("Filters"), 5);
00271     Camelot.DeclarePref(_T("Filters"), _T("DefaultImportFilter"), &SelectedFilterID);
00272     Camelot.DeclarePref(_T("Filters"), _T("DefaultImportFilterPath"), &DefaultImportFilterPath);
00273 
00274 PORTNOTE("other", "Removed OpGenericDownload" )
00275 #if 0
00276     if (!OpGenericDownload::Init())
00277         return FALSE;
00278 #endif
00279     
00280     return TRUE;
00281 }

virtual BOOL OpMenuImport::MayChangeNodeBounds  )  const [inline, virtual]
 

Reimplemented from SelOperation.

Definition at line 149 of file impexpop.h.

00149 { return FALSE; }

BOOL OpMenuImport::OnDocChangingMsg Document pChangingDoc,
DocChangingMsg::DocState  State
[virtual]
 

End (abort) the operation when for instance the current document has been destroyed while downloading.

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/05/97
Parameters:
pChangingDoc - [INPUTS] State -
Returns:

Errors:

Reimplemented from MessageHandler.

Definition at line 607 of file impexpop.cpp.

00608 {
00609     if (State == DocChangingMsg::ABOUTTODIE && pChangingDoc == pOurDoc)
00610     {
00611         EndImport();
00612     }
00613 
00614     return TRUE;
00615 }


Member Data Documentation

String_256 OpMenuImport::DefaultImportFilterPath [static]
 

Definition at line 159 of file impexpop.h.

TCHAR* OpMenuImport::FilterString [private]
 

Definition at line 152 of file impexpop.h.

INT32 OpMenuImport::SelectedFilter = -1 [static, private]
 

Definition at line 154 of file impexpop.h.

UINT32 OpMenuImport::SelectedFilterID = FILTERID_GENERIC [static, private]
 

The unique ID of the filter to default to when importing files. The path to default to when opening the Import File dialog. The unique ID of the filter to default to when exporting files. The path to default to when opening the Export File dialog.

Preference: DefaultExportFilterPath Section: Filters Range: A pathname.

See also:
DefaultExportFilter; DefaultImportFilter; DefaultImportFilterPath

Definition at line 153 of file impexpop.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:58:26 2007 for Camelot by  doxygen 1.4.4