Changeset 332744111f03bec9a9f87d1cdd4ee32e3b8808ed
- Timestamp:
- 10/08/08 21:20:36 (5 years ago)
- Author:
- Armin Burgmeier <armin@…>
- Parents:
- 927cc449d112ac085e67682a6f7de8434861026c
- Children:
- 5f4fbabbd782af175903825bb04c5e9056b9ba0b
- git-committer:
- Armin Burgmeier <armin@arbur.net> / 2008-10-08T21:20:36Z+0200
- Message:
-
Disable "New" and "Open" actions when there is no document in the browser
2008-10-08 Armin Burgmeier <armin@…>
- src/core/folder.cpp: Emit document_changed with NULL document after
the last document has been removed, not before, so
get_current_document() yields the correct result.
- inc/commands/edit-commands.hpp:
- src/commands/edit-commands.cpp: Don't rely on m_current_document
being valid until on_document_changed() was called.
- inc/commands/file-commands.hpp:
- src/commands/file-commands.cpp: Make "New" and "Open" actions
insensitive when there is no entry in the Document Browser.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r927cc44
|
r3327441
|
|
| | 1 | 2008-10-08 Armin Burgmeier <armin@arbur.net> |
| | 2 | |
| | 3 | * src/core/folder.cpp: Emit document_changed with NULL document after |
| | 4 | the last document has been removed, not before, so |
| | 5 | get_current_document() yields the correct result. |
| | 6 | |
| | 7 | * inc/commands/edit-commands.hpp: |
| | 8 | * src/commands/edit-commands.cpp: Don't rely on m_current_document |
| | 9 | being valid until on_document_changed() was called. |
| | 10 | |
| | 11 | * inc/commands/file-commands.hpp: |
| | 12 | * src/commands/file-commands.cpp: Make "New" and "Open" actions |
| | 13 | insensitive when there is no entry in the Document Browser. |
| | 14 | |
| 1 | 15 | 2008-10-08 Armin Burgmeier <armin@arbur.net> |
| 2 | 16 | |
-
|
r8d53871
|
r3327441
|
|
| 44 | 44 | |
| 45 | 45 | protected: |
| | 46 | void on_document_removed(DocWindow& document); |
| 46 | 47 | void on_document_changed(DocWindow* document); |
| 47 | 48 | |
-
|
r91b91f6
|
r3327441
|
|
| 37 | 37 | public: |
| 38 | 38 | FileCommands(Gtk::Window& parent, Header& header, |
| 39 | | const Browser& browser, Folder& folder, |
| | 39 | Browser& browser, Folder& folder, |
| 40 | 40 | FileChooser& file_chooser, Operations& operations, |
| 41 | 41 | const DocumentInfoStorage& info_storage, |
| 42 | 42 | Preferences& preferences); |
| | 43 | ~FileCommands(); |
| 43 | 44 | |
| 44 | 45 | class Task: public sigc::trackable |
| … |
… |
|
| 70 | 71 | protected: |
| 71 | 72 | void set_task(Task* task); |
| | 73 | |
| | 74 | static void on_row_inserted_static(GtkTreeModel* model, |
| | 75 | GtkTreePath* path, |
| | 76 | GtkTreeIter* iter, |
| | 77 | gpointer user_data) |
| | 78 | { |
| | 79 | static_cast<FileCommands*>(user_data)->on_row_inserted(); |
| | 80 | } |
| | 81 | |
| | 82 | static void on_row_deleted_static(GtkTreeModel* model, |
| | 83 | GtkTreePath* path, |
| | 84 | gpointer user_data) |
| | 85 | { |
| | 86 | static_cast<FileCommands*>(user_data)->on_row_deleted(); |
| | 87 | } |
| | 88 | |
| 72 | 89 | void on_document_changed(DocWindow* document); |
| | 90 | void on_row_inserted(); |
| | 91 | void on_row_deleted(); |
| 73 | 92 | void on_task_finished(); |
| 74 | 93 | |
| … |
… |
|
| 82 | 101 | void on_quit(); |
| 83 | 102 | |
| 84 | | void set_sensitivity(bool sensitivity); |
| | 103 | void update_sensitivity(); |
| 85 | 104 | |
| 86 | 105 | Gtk::Window& m_parent; |
| 87 | 106 | Header& m_header; |
| 88 | | const Browser& m_browser; |
| | 107 | Browser& m_browser; |
| 89 | 108 | Folder& m_folder; |
| 90 | 109 | FileChooser& m_file_chooser; |
| … |
… |
|
| 95 | 114 | std::auto_ptr<Task> m_task; |
| 96 | 115 | std::auto_ptr<DocumentLocationDialog> m_location_dialog; |
| | 116 | |
| | 117 | gulong m_row_inserted_handler; |
| | 118 | gulong m_row_deleted_handler; |
| 97 | 119 | }; |
| 98 | 120 | |
-
|
r8d53871
|
r3327441
|
|
| 54 | 54 | m_header.action_edit_preferences->signal_activate().connect( |
| 55 | 55 | sigc::mem_fun(*this, &EditCommands::on_preferences)); |
| | 56 | m_folder.signal_document_removed().connect( |
| | 57 | sigc::mem_fun(*this, &EditCommands::on_document_removed)); |
| 56 | 58 | m_folder.signal_document_changed().connect( |
| 57 | 59 | sigc::mem_fun(*this, &EditCommands::on_document_changed)); |
| … |
… |
|
| 65 | 67 | // Disconnect handlers from current document: |
| 66 | 68 | on_document_changed(NULL); |
| | 69 | } |
| | 70 | |
| | 71 | void Gobby::EditCommands::on_document_removed(DocWindow& document) |
| | 72 | { |
| | 73 | if(&document == m_current_document) |
| | 74 | on_document_changed(NULL); |
| 67 | 75 | } |
| 68 | 76 | |
-
|
rff49ce1
|
r3327441
|
|
| 377 | 377 | |
| 378 | 378 | Gobby::FileCommands::FileCommands(Gtk::Window& parent, Header& header, |
| 379 | | const Browser& browser, Folder& folder, |
| | 379 | Browser& browser, Folder& folder, |
| 380 | 380 | FileChooser& file_chooser, |
| 381 | 381 | Operations& operations, |
| … |
… |
|
| 401 | 401 | header.action_file_quit->signal_activate().connect( |
| 402 | 402 | sigc::mem_fun(*this, &FileCommands::on_quit)); |
| | 403 | |
| 403 | 404 | folder.signal_document_changed().connect( |
| 404 | 405 | sigc::mem_fun(*this, &FileCommands::on_document_changed)); |
| 405 | 406 | |
| 406 | | set_sensitivity(folder.get_current_document() != NULL); |
| | 407 | InfGtkBrowserStore* store = browser.get_store(); |
| | 408 | m_row_inserted_handler = |
| | 409 | g_signal_connect(G_OBJECT(store), "row-inserted", |
| | 410 | G_CALLBACK(on_row_inserted_static), this); |
| | 411 | m_row_deleted_handler = |
| | 412 | g_signal_connect(G_OBJECT(store), "row-deleted", |
| | 413 | G_CALLBACK(on_row_deleted_static), this); |
| | 414 | |
| | 415 | update_sensitivity(); |
| | 416 | } |
| | 417 | |
| | 418 | Gobby::FileCommands::~FileCommands() |
| | 419 | { |
| | 420 | InfGtkBrowserStore* store = m_browser.get_store(); |
| | 421 | g_signal_handler_disconnect(G_OBJECT(store), m_row_inserted_handler); |
| | 422 | g_signal_handler_disconnect(G_OBJECT(store), m_row_deleted_handler); |
| 407 | 423 | } |
| 408 | 424 | |
| … |
… |
|
| 416 | 432 | void Gobby::FileCommands::on_document_changed(DocWindow* document) |
| 417 | 433 | { |
| 418 | | set_sensitivity(document != NULL); |
| | 434 | update_sensitivity(); |
| | 435 | } |
| | 436 | |
| | 437 | void Gobby::FileCommands::on_row_inserted() |
| | 438 | { |
| | 439 | update_sensitivity(); |
| | 440 | } |
| | 441 | |
| | 442 | void Gobby::FileCommands::on_row_deleted() |
| | 443 | { |
| | 444 | update_sensitivity(); |
| 419 | 445 | } |
| 420 | 446 | |
| … |
… |
|
| 482 | 508 | } |
| 483 | 509 | |
| 484 | | void Gobby::FileCommands::set_sensitivity(bool sensitivity) |
| 485 | | { |
| 486 | | m_header.action_file_save->set_sensitive(sensitivity); |
| 487 | | m_header.action_file_save_as->set_sensitive(sensitivity); |
| 488 | | m_header.action_file_save_all->set_sensitive(sensitivity); |
| 489 | | m_header.action_file_close->set_sensitive(sensitivity); |
| 490 | | } |
| | 510 | void Gobby::FileCommands::update_sensitivity() |
| | 511 | { |
| | 512 | GtkTreeIter dummy_iter; |
| | 513 | bool create_sensitivity = gtk_tree_model_get_iter_first( |
| | 514 | GTK_TREE_MODEL(m_browser.get_store()), &dummy_iter); |
| | 515 | gboolean active_sensitivity = m_folder.get_current_document() != NULL; |
| | 516 | |
| | 517 | m_header.action_file_new->set_sensitive(create_sensitivity); |
| | 518 | m_header.action_file_open->set_sensitive(create_sensitivity); |
| | 519 | |
| | 520 | m_header.action_file_save->set_sensitive(active_sensitivity); |
| | 521 | m_header.action_file_save_as->set_sensitive(active_sensitivity); |
| | 522 | m_header.action_file_save_all->set_sensitive(active_sensitivity); |
| | 523 | m_header.action_file_close->set_sensitive(active_sensitivity); |
| | 524 | } |
-
|
r9a0333e
|
r3327441
|
|
| 274 | 274 | m_signal_document_removed.emit(window); |
| 275 | 275 | |
| 276 | | // TODO: We should actually remove the page here, but destroy the |
| 277 | | // DocWindow after having emitted signal_document_changed. |
| 278 | | if(get_n_pages() == 1) |
| 279 | | m_signal_document_changed.emit(NULL); |
| 280 | | |
| 281 | 276 | // Finish the record |
| 282 | | g_object_set_data(G_OBJECT(window.get_session()), |
| 283 | | "GOBBY_SESSION_RECORD", NULL); |
| 284 | | |
| 285 | 277 | InfTextSession* session = window.get_session(); |
| | 278 | g_object_set_data(G_OBJECT(session), "GOBBY_SESSION_RECORD", NULL); |
| | 279 | |
| 286 | 280 | g_object_ref(session); |
| 287 | | |
| 288 | 281 | inf_session_close(INF_SESSION(session)); |
| 289 | 282 | remove_page(window); |
| 290 | | |
| 291 | 283 | g_object_unref(session); |
| | 284 | |
| | 285 | if(get_n_pages() == 0) |
| | 286 | m_signal_document_changed.emit(NULL); |
| 292 | 287 | } |
| 293 | 288 | |