Changeset 3033edac03b725f01854e3161ac09682e771a063
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r59d5565
|
r3033eda
|
|
| 59 | 59 | Glib::RefPtr<Gtk::SourceLanguage> get_language() const; |
| 60 | 60 | #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(); |
| 61 | 68 | |
| 62 | 69 | /** Signal which will be emitted if the document gets updated in a way |
-
|
ra70a4d0
|
r3033eda
|
|
| 62 | 62 | Glib::RefPtr<const Gtk::AccelGroup> get_accel_group() const; |
| 63 | 63 | |
| | 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 | |
| 64 | 68 | signal_session_create_type session_create_event() const; |
| 65 | 69 | signal_session_join_type session_join_event() const; |
-
|
r6ac8196
|
r3033eda
|
|
| 205 | 205 | #endif |
| 206 | 206 | |
| | 207 | Glib::ustring Gobby::Document::get_content() |
| | 208 | { |
| | 209 | return m_view.get_buffer()->get_text(); |
| | 210 | } |
| | 211 | |
| 207 | 212 | void Gobby::Document::obby_user_join(obby::user& user) |
| 208 | 213 | { |
-
|
rd4fb979
|
r3033eda
|
|
| 63 | 63 | void Gobby::Folder::obby_end() |
| 64 | 64 | { |
| 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 | |
| 68 | 72 | m_running = false; |
| 69 | 73 | } |
| … |
… |
|
| 109 | 113 | for(int i = 0; i < get_n_pages(); ++ i) |
| 110 | 114 | { |
| 111 | | Widget* doc = get_nth_page(i); |
| | 115 | Gtk::Widget* doc = get_nth_page(i); |
| 112 | 116 | if(&static_cast<Document*>(doc)->get_document() == &document) |
| 113 | 117 | { |
-
|
r930225e
|
r3033eda
|
|
| 249 | 249 | } |
| 250 | 250 | |
| | 251 | void 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 | |
| 251 | 257 | Gobby::Header::signal_session_create_type |
| 252 | 258 | Gobby::Header::session_create_event() const |
| … |
… |
|
| 330 | 336 | m_group_app->get_action("CreateDocument")->set_sensitive(false); |
| 331 | 337 | 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. |
| 334 | 341 | } |
| 335 | 342 | |
-
|
racd944b
|
r3033eda
|
|
| 313 | 313 | { |
| 314 | 314 | 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); |
| 316 | 316 | |
| 317 | 317 | Gtk::FileChooserDialog dlg(*this, _("Save current document"), |
| 318 | 318 | 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) ); |
| 320 | 320 | dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
| 321 | 321 | dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); |
| … |
… |
|
| 324 | 324 | { |
| 325 | 325 | 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 | } |
| 327 | 339 | } |
| 328 | 340 | } |
| … |
… |
|
| 330 | 342 | void Gobby::Window::on_document_close() |
| 331 | 343 | { |
| 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 | } |
| 335 | 372 | } |
| 336 | 373 | |