Changeset 332744111f03bec9a9f87d1cdd4ee32e3b8808ed

Show
Ignore:
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:
6 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r927cc44 r3327441  
     12008-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 
    1152008-10-08  Armin Burgmeier  <armin@arbur.net> 
    216 
  • inc/commands/edit-commands.hpp

    r8d53871 r3327441  
    4444 
    4545protected: 
     46        void on_document_removed(DocWindow& document); 
    4647        void on_document_changed(DocWindow* document); 
    4748 
  • inc/commands/file-commands.hpp

    r91b91f6 r3327441  
    3737public: 
    3838        FileCommands(Gtk::Window& parent, Header& header, 
    39                      const Browser& browser, Folder& folder, 
     39                     Browser& browser, Folder& folder, 
    4040                     FileChooser& file_chooser, Operations& operations, 
    4141                     const DocumentInfoStorage& info_storage, 
    4242                     Preferences& preferences); 
     43        ~FileCommands(); 
    4344 
    4445        class Task: public sigc::trackable 
     
    7071protected: 
    7172        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 
    7289        void on_document_changed(DocWindow* document); 
     90        void on_row_inserted(); 
     91        void on_row_deleted(); 
    7392        void on_task_finished(); 
    7493 
     
    82101        void on_quit(); 
    83102 
    84         void set_sensitivity(bool sensitivity); 
     103        void update_sensitivity(); 
    85104 
    86105        Gtk::Window& m_parent; 
    87106        Header& m_header; 
    88         const Browser& m_browser; 
     107        Browser& m_browser; 
    89108        Folder& m_folder; 
    90109        FileChooser& m_file_chooser; 
     
    95114        std::auto_ptr<Task> m_task; 
    96115        std::auto_ptr<DocumentLocationDialog> m_location_dialog; 
     116 
     117        gulong m_row_inserted_handler; 
     118        gulong m_row_deleted_handler; 
    97119}; 
    98120 
  • src/commands/edit-commands.cpp

    r8d53871 r3327441  
    5454        m_header.action_edit_preferences->signal_activate().connect( 
    5555                sigc::mem_fun(*this, &EditCommands::on_preferences)); 
     56        m_folder.signal_document_removed().connect( 
     57                sigc::mem_fun(*this, &EditCommands::on_document_removed)); 
    5658        m_folder.signal_document_changed().connect( 
    5759                sigc::mem_fun(*this, &EditCommands::on_document_changed)); 
     
    6567        // Disconnect handlers from current document: 
    6668        on_document_changed(NULL); 
     69} 
     70 
     71void Gobby::EditCommands::on_document_removed(DocWindow& document) 
     72{ 
     73        if(&document == m_current_document) 
     74                on_document_changed(NULL); 
    6775} 
    6876 
  • src/commands/file-commands.cpp

    rff49ce1 r3327441  
    377377 
    378378Gobby::FileCommands::FileCommands(Gtk::Window& parent, Header& header, 
    379                                   const Browser& browser, Folder& folder, 
     379                                  Browser& browser, Folder& folder, 
    380380                                  FileChooser& file_chooser, 
    381381                                  Operations& operations, 
     
    401401        header.action_file_quit->signal_activate().connect( 
    402402                sigc::mem_fun(*this, &FileCommands::on_quit)); 
     403 
    403404        folder.signal_document_changed().connect( 
    404405                sigc::mem_fun(*this, &FileCommands::on_document_changed)); 
    405406 
    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 
     418Gobby::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); 
    407423} 
    408424 
     
    416432void Gobby::FileCommands::on_document_changed(DocWindow* document) 
    417433{ 
    418         set_sensitivity(document != NULL); 
     434        update_sensitivity(); 
     435} 
     436 
     437void Gobby::FileCommands::on_row_inserted() 
     438{ 
     439        update_sensitivity(); 
     440} 
     441 
     442void Gobby::FileCommands::on_row_deleted() 
     443{ 
     444        update_sensitivity(); 
    419445} 
    420446 
     
    482508} 
    483509 
    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 } 
     510void 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} 
  • src/core/folder.cpp

    r9a0333e r3327441  
    274274        m_signal_document_removed.emit(window); 
    275275 
    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  
    281276        // Finish the record 
    282         g_object_set_data(G_OBJECT(window.get_session()), 
    283                           "GOBBY_SESSION_RECORD", NULL); 
    284  
    285277        InfTextSession* session = window.get_session(); 
     278        g_object_set_data(G_OBJECT(session), "GOBBY_SESSION_RECORD", NULL); 
     279 
    286280        g_object_ref(session); 
    287  
    288281        inf_session_close(INF_SESSION(session)); 
    289282        remove_page(window); 
    290  
    291283        g_object_unref(session); 
     284 
     285        if(get_n_pages() == 0) 
     286                m_signal_document_changed.emit(NULL); 
    292287} 
    293288