Changeset 25

Show
Ignore:
Timestamp:
04/11/06 11:16:59 (2 years ago)
Author:
jordi
Message:

It's now possible to cancel the open file dialog :-)

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/MainPter.cxx

    r24 r25  
    142142    IMainView &view = getView (); 
    143143    gchar *fileName = view.openFileDialog (); 
    144     GError *error; 
    145     if ( m_Document->loadFile (fileName, NULL, &error) ) 
     144    // if openFileDialog returns NULL, then the user cancelled the operation. 
     145    // I don't need to do anything in this case. I'm only interested when 
     146    // the user tried to open a file. 
     147    if ( NULL != fileName ) 
    146148    { 
    147         // Now that the document has been loaded, just reset the initial 
    148         // state. 
    149         setInitialState (); 
    150         g_free (fileName); 
     149        GError *error; 
     150        if ( m_Document->loadFile (fileName, NULL, &error) ) 
     151        { 
     152            // Now that the document has been loaded, just reset the initial 
     153            // state. 
     154            setInitialState (); 
     155            g_free (fileName); 
     156        } 
    151157    } 
    152158} 
  • trunk/tests/DumbMainView.cxx

    r24 r25  
    209209{ 
    210210    g_free (m_OpenFileName); 
    211     m_OpenFileName = g_strdup (fileName); 
    212 } 
     211    m_OpenFileName = NULL; 
     212    if ( NULL != fileName ) 
     213    { 
     214        m_OpenFileName = g_strdup (fileName); 
     215    } 
     216} 
  • trunk/tests/MainPterTest.cxx

    r24 r25  
    117117    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    118118} 
     119 
     120/// 
     121/// @brief Tests a cancelled open file. 
     122/// 
     123/// When the user cancels the open dialog, then nothing should change. 
     124/// 
     125void 
     126MainPterTest::loadCancelled () 
     127{ 
     128    // returning a NULL file name is what will happen when cancel. 
     129    m_View->setOpenFileName (NULL); 
     130    m_MainPter->openFileActivated (); 
     131    CPPUNIT_ASSERT_EQUAL (0,  
     132            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     133    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     134    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     135    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     136    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); 
     137    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     138    CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); 
     139    CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 
     140    CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); 
     141    CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 
     142    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     143} 
  • trunk/tests/MainPterTest.h

    r24 r25  
    2828        CPPUNIT_TEST (initialStatus); 
    2929        CPPUNIT_TEST (loadDocument); 
     30        CPPUNIT_TEST (loadCancelled); 
    3031        CPPUNIT_TEST_SUITE_END(); 
    3132 
     
    3637            void initialStatus (void); 
    3738            void loadDocument (void); 
     39            void loadCancelled (void); 
    3840 
    3941        private: