Changeset 3033edac03b725f01854e3161ac09682e771a063

Show
Ignore:
Timestamp:
01/06/07 23:35:59 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
930225ef1e1c135c0f5076cf955ef263ab5be48e
Children:
f9e7e83d1603744ec991482a6817091f55697ba2
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:35:59Z+0000
Message:

[project @ Allow the user to save documents after connection loss [fixes #1]]

Original author: Armin Burgmeier <armin@…>
Date: 2005-05-29 11:40:30+00:00

Files:
6 modified

Legend:

Unmodified
Added
Removed
  • inc/document.hpp

    r59d5565 r3033eda  
    5959        Glib::RefPtr<Gtk::SourceLanguage> get_language() const; 
    6060#endif 
     61 
     62        /** Returns the document content. Equivalent to 
     63         * get_document().get_whole_buffer(), but it may be used even if the 
     64         * obby buffer does not exist anymore (in which case get_document() 
     65         * returns an invalid reference!) 
     66         */ 
     67        Glib::ustring get_content(); 
    6168 
    6269        /** Signal which will be emitted if the document gets updated in a way 
  • inc/header.hpp

    ra70a4d0 r3033eda  
    6262        Glib::RefPtr<const Gtk::AccelGroup> get_accel_group() const; 
    6363 
     64        // Disables close and save buttons. The windows calls this after 
     65        // all remaining documents have been closed after a connection loss. 
     66        void disable_close_save(); 
     67 
    6468        signal_session_create_type session_create_event() const; 
    6569        signal_session_join_type session_join_event() const; 
  • src/document.cpp

    r6ac8196 r3033eda  
    205205#endif 
    206206 
     207Glib::ustring Gobby::Document::get_content() 
     208{ 
     209        return m_view.get_buffer()->get_text(); 
     210} 
     211 
    207212void Gobby::Document::obby_user_join(obby::user& user) 
    208213{ 
  • src/folder.cpp

    rd4fb979 r3033eda  
    6363void Gobby::Folder::obby_end() 
    6464{ 
    65         // TODO: Just remove the editable-attribute to allow the user to still 
    66         // save the documents. 
    67         set_sensitive(false); 
     65        // Insensitive just the text editor to allow to scroll and tab between 
     66        // the documents 
     67        for(unsigned int i = 0; i < get_n_pages(); ++ i) 
     68                static_cast<Document*>( 
     69                        get_nth_page(i) 
     70                )->get_child()->set_sensitive(false); 
     71 
    6872        m_running = false; 
    6973} 
     
    109113        for(int i = 0; i < get_n_pages(); ++ i) 
    110114        { 
    111                 Widget* doc = get_nth_page(i); 
     115                Gtk::Widget* doc = get_nth_page(i); 
    112116                if(&static_cast<Document*>(doc)->get_document() == &document) 
    113117                { 
  • src/header.cpp

    r930225e r3033eda  
    249249} 
    250250 
     251void Gobby::Header::disable_close_save() 
     252{ 
     253        m_group_app->get_action("SaveDocument")->set_sensitive(false); 
     254        m_group_app->get_action("CloseDocument")->set_sensitive(false); 
     255} 
     256 
    251257Gobby::Header::signal_session_create_type 
    252258Gobby::Header::session_create_event() const 
     
    330336        m_group_app->get_action("CreateDocument")->set_sensitive(false); 
    331337        m_group_app->get_action("OpenDocument")->set_sensitive(false); 
    332         m_group_app->get_action("SaveDocument")->set_sensitive(false); 
    333         m_group_app->get_action("CloseDocument")->set_sensitive(false); 
     338 
     339        // Leave SaveDocument and CloseDocument as they were to allow the user 
     340        // to save documents. 
    334341} 
    335342 
  • src/window.cpp

    racd944b r3033eda  
    313313{ 
    314314        Widget* page = m_folder.get_nth_page(m_folder.get_current_page() ); 
    315         obby::document& doc = static_cast<Document*>(page)->get_document(); 
     315        Document& doc = *static_cast<Document*>(page); 
    316316 
    317317        Gtk::FileChooserDialog dlg(*this, _("Save current document"), 
    318318                        Gtk::FILE_CHOOSER_ACTION_SAVE); 
    319         dlg.set_current_name(doc.get_title() ); 
     319        dlg.set_current_name(m_folder.get_tab_label_text(doc) ); 
    320320        dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    321321        dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 
     
    324324        { 
    325325                std::ofstream stream(dlg.get_filename().c_str() ); 
    326                 stream << doc.get_whole_buffer() << std::endl; 
     326 
     327                if(stream) 
     328                { 
     329                        stream << doc.get_content() << std::endl; 
     330                } 
     331                else 
     332                { 
     333                        display_error( 
     334                                "Could not open file " + 
     335                                dlg.get_filename() + 
     336                                " for writing" 
     337                        ); 
     338                } 
    327339        } 
    328340} 
     
    330342void Gobby::Window::on_document_close() 
    331343{ 
    332         Widget* page = m_folder.get_nth_page(m_folder.get_current_page() ); 
    333         m_buffer->remove_document( 
    334                 static_cast<Document*>(page)->get_document() ); 
     344        if(m_buffer) 
     345        { 
     346                // Get current page 
     347                Widget* page = m_folder.get_nth_page( 
     348                        m_folder.get_current_page() 
     349                ); 
     350 
     351                // Send remove document request 
     352                m_buffer->remove_document( 
     353                        static_cast<Document*>(page)->get_document() 
     354                ); 
     355        } 
     356        else 
     357        { 
     358                // Buffer does not exist: Maybe the connection has been lost 
     359                // or something: Just remove the document from the folder. 
     360                Gtk::Widget* doc = m_folder.get_nth_page( 
     361                        m_folder.get_current_page() 
     362                ); 
     363 
     364                m_folder.remove_page(m_folder.get_current_page() ); 
     365                delete doc; 
     366 
     367                // If there are no more documents disable 
     368                // save and close buttons in header 
     369                if(!m_folder.get_n_pages() ) 
     370                        m_header.disable_close_save(); 
     371        } 
    335372} 
    336373