Changeset 97

Show
Ignore:
Timestamp:
04/20/06 10:08:49 (2 years ago)
Author:
jordi
Message:

The Main presenter now pass the last folder used to open a file to the view, so it can change the shown folder on the open dialog. Also, the main presenter saves the last folder to the configuration class.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r67 r97  
    4949            /// the toolkit's specific open dialog. 
    5050            /// 
     51            /// @param folder The last folder used to open a file. This is 
     52            ///               used to show this folder when the open dialog 
     53            ///               appears. 
     54            /// 
    5155            /// @return A copy of the file name that the user will try to open 
    5256            ///         or NULL if the user cancelled the operation. 
    5357            ///         This string will be freed by the presenter. 
    5458            /// 
    55             virtual gchar *openFileDialog (void) = 0; 
     59            virtual gchar *openFileDialog (const gchar *lastFolder) = 0; 
    5660 
    5761            /// 
  • trunk/src/MainPter.cxx

    r67 r97  
    253253{ 
    254254    IMainView &view = getView (); 
    255     gchar *fileName = view.openFileDialog (); 
     255    Config &config = Config::getConfig (); 
     256     
     257    gchar *lastFolder = config.getOpenFileFolder (); 
     258    gchar *fileName = view.openFileDialog (lastFolder); 
     259    g_free (lastFolder); 
     260     
    256261    openDocument (fileName, NULL, TRUE); 
    257     g_free (fileName); 
     262    if ( NULL != fileName ) 
     263    { 
     264        gchar *dirName = g_path_get_dirname (fileName); 
     265        g_free (fileName); 
     266         
     267        config.setOpenFileFolder (dirName); 
     268        g_free (dirName); 
     269    } 
     270     
    258271} 
    259272 
  • trunk/src/gtk/MainView.cxx

    r95 r97  
    192192 
    193193gchar * 
    194 MainView::openFileDialog () 
     194MainView::openFileDialog (const gchar *lastFolder) 
    195195{ 
    196196    GtkWidget *openDialog = gtk_file_chooser_dialog_new (_("Open PDF File"), 
     
    200200            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 
    201201            NULL); 
     202     
     203    if ( NULL != lastFolder ) 
     204    { 
     205        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (openDialog), 
     206                                             lastFolder); 
     207    } 
     208     
    202209    if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (openDialog)) ) 
    203210    { 
  • trunk/src/gtk/MainView.h

    r70 r97  
    3232            ~MainView (); 
    3333             
    34             gchar *openFileDialog (); 
    35             gchar *promptPasswordDialog (); 
     34            gchar *openFileDialog (const gchar *lastFolder); 
     35            gchar *promptPasswordDialog (void); 
    3636            void sensitiveGoToFirstPage (gboolean sensitive); 
    3737            void sensitiveGoToLastPage (gboolean sensitive); 
  • trunk/tests/DumbMainView.cxx

    r73 r97  
    3232    m_GoToPageText = g_strdup (""); 
    3333    m_OpenFileName = g_strdup (""); 
     34    m_LastOpenFileFolder = NULL; 
    3435    m_Outline = NULL; 
    3536    m_Password = NULL; 
     
    5758{ 
    5859    g_free (m_GoToPageText); 
     60    g_free (m_LastOpenFileFolder); 
    5961    g_free (m_OpenFileName); 
    6062    g_free (m_Password); 
     
    6365             
    6466gchar * 
    65 DumbMainView::openFileDialog (void) 
    66 { 
     67DumbMainView::openFileDialog (const gchar *lastFolder) 
     68{ 
     69    g_free (m_LastOpenFileFolder); 
     70    m_LastOpenFileFolder = g_strdup (lastFolder); 
    6771    return g_strdup (m_OpenFileName); 
    6872} 
     
    226230    return m_CurrentPage; 
    227231} 
     232 
     233const gchar * 
     234DumbMainView::getLastOpenFileFolder () 
     235{ 
     236    return m_LastOpenFileFolder; 
     237} 
     238 
    228239 
    229240DocumentOutline * 
  • trunk/tests/DumbMainView.h

    r66 r97  
    2828            ~DumbMainView (); 
    2929 
    30             gchar *openFileDialog (void); 
     30            gchar *openFileDialog (const gchar *lastFolder); 
    3131            gchar *promptPasswordDialog (void); 
    3232            void sensitiveGoToFirstPage (gboolean sensitive); 
     
    5656            gint countTimesShownPasswordPrompt (void); 
    5757            gint getCurrentPage (void); 
     58            const gchar *getLastOpenFileFolder (void); 
    5859            DocumentOutline *getOutline (void); 
    5960            const gchar *getTitle (void); 
     
    8283            DocumentPage *m_DocumentPage; 
    8384            gchar *m_GoToPageText; 
     85            gchar *m_LastOpenFileFolder; 
    8486            gchar *m_OpenFileName; 
    8587            DocumentOutline *m_Outline; 
  • trunk/tests/MainPterTest.cxx

    r80 r97  
    3636    m_View = new DumbMainView (m_MainPter); 
    3737    m_MainPter->setView (m_View); 
     38    Config::loadFile (FALSE); 
    3839} 
    3940 
     
    4748    // classes are deleted by it. 
    4849    delete m_MainPter; 
     50    // Drop the current configuration. 
     51    Config::destroy (); 
    4952} 
    5053 
     
    292295} 
    293296 
     297/// 
     298/// @brief Test the last folder used to open a file. 
     299/// 
     300/// When the presenter wants to open a file, it should pass to the 
     301/// view the last folder that was used to open a file, so the 
     302/// view can show it up when opening the dialog. 
     303/// 
     304void 
     305MainPterTest::lastFolder () 
     306{ 
     307    m_View->setOpenFileName ("/tmp/test.pdf"); 
     308    m_MainPter->openFileActivated (); 
     309    CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); 
     310 
     311 
     312    m_View->setOpenFileName ("/usr/test.pdf"); 
     313    m_MainPter->openFileActivated (); 
     314    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp",  
     315                                             m_View->getLastOpenFileFolder ())); 
     316     
     317    m_MainPter->openFileActivated (); 
     318    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr",  
     319                                             m_View->getLastOpenFileFolder ())); 
     320} 
    294321 
    295322/// 
  • trunk/tests/MainPterTest.h

    r66 r97  
    3333        CPPUNIT_TEST (badPassword); 
    3434        CPPUNIT_TEST (goodPassword); 
     35        CPPUNIT_TEST (lastFolder); 
    3536        CPPUNIT_TEST (pageNavigation); 
    3637        CPPUNIT_TEST (pageNavigationEntry); 
     
    5455            void badPassword (void); 
    5556            void goodPassword (void); 
     57            void lastFolder (void); 
    5658            void pageNavigation (void); 
    5759            void pageNavigationEntry (void);