Changeset 0c6e731fde2f0fa4c225215371d356fed6d6f6f3

Show
Ignore:
Timestamp:
01/06/07 23:57:58 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
ba89078f762f9261827bc9091e642ac272644d35
Children:
1662ea7cb97e74c04650ddda1130c2ea7a4d07ce
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:57:58Z+0000
Message:

[project @ Added application state frags controlling header sensitivity]

Original author: Armin Burgmeier <armin@…>
Date: 2006-03-07 17:22:46+00:00

Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rba89078 r0c6e731  
    2323noinst_HEADERS += inc/mimemap.hpp 
    2424noinst_HEADERS += inc/regex.hpp 
     25noinst_HEADERS += inc/application_state.hpp 
    2526noinst_HEADERS += inc/encoding_selector.hpp 
    2627noinst_HEADERS += inc/defaultdialog.hpp 
     
    7778gobby_SOURCES += src/mimemap.cpp 
    7879gobby_SOURCES += src/regex.cpp 
     80gobby_SOURCES += src/application_state.cpp 
    7981gobby_SOURCES += src/encoding_selector.cpp 
    8082gobby_SOURCES += src/defaultdialog.cpp 
  • inc/folder.hpp

    r2aa10af r0c6e731  
    130130                tab_switched_event() const; 
    131131protected: 
    132         /** Parameter type for the internal enable_document_items function. 
    133          */ 
    134         enum DocumentItems { 
    135                 /** Disable all document items. 
    136                  */ 
    137                 DOCUMENT_ITEMS_DISABLE_ALL = 0, 
    138  
    139                 /** Enable only document items which are useful even if the 
    140                  * user is not subscribed to the document, disable others. 
    141                  */ 
    142                 DOCUMENT_ITEMS_ENABLE_DISCONN = 1, 
    143  
    144                 /** Enable all document items. 
    145                  */ 
    146                 DOCUMENT_ITEMS_ENABLE_ALL = 2 
    147         }; 
    148  
    149132        // Overrides 
    150133        virtual void on_switch_page(GtkNotebookPage* page, guint page_num); 
     
    154137        // Internals 
    155138        void set_tab_colour(DocWindow& win, const Glib::ustring& colour); 
    156         void enable_document_items(DocumentItems which); 
    157139 
    158140        // Signal handlers 
     
    180162        signal_document_remove_type 
    181163                m_signal_document_remove; 
     164 
    182165        signal_document_close_request_type 
    183166                m_signal_document_close_request; 
     
    188171        signal_document_language_changed_type 
    189172                m_signal_document_language_changed; 
     173 
    190174        signal_tab_switched_type 
    191175                m_signal_tab_switched; 
  • inc/header.hpp

    r5843bef r0c6e731  
    2020#define _GOBBY_HEADER_HPP_ 
    2121 
     22#include <list> 
     23 
    2224#include <gtkmm/box.h> 
    2325#include <gtkmm/uimanager.h> 
     
    2628#include <gtkmm/toolbar.h> 
    2729 
     30#include "application_state.hpp" 
    2831#include "sourceview/sourcelanguage.hpp" 
    2932#include "sourceview/sourcelanguagesmanager.hpp" 
     
    4750        }; 
    4851 
     52        /** @brief Action that automatically chances sensitivity depending 
     53         * on application state. 
     54         */ 
     55        class AutoAction 
     56        { 
     57        public: 
     58                typedef Glib::RefPtr<Gtk::Action> action_type; 
     59 
     60                AutoAction(action_type action, 
     61                           const ApplicationState& state, 
     62                           ApplicationFlags inc_flags, 
     63                           ApplicationFlags exc_flags); 
     64 
     65        protected: 
     66                void on_state_change(const ApplicationState& state); 
     67 
     68                action_type m_action; 
     69                ApplicationFlags m_inc_flags; 
     70                ApplicationFlags m_exc_flags; 
     71        }; 
     72 
     73        /** @brief Class that stores multiple AutoActions. 
     74         * 
     75         * Once an AutoAction has been created, it works without any further 
     76         * need to access the AutoAction object again, one just needs to 
     77         * keep the AutoAction somewhere and release it when the application 
     78         * exits. 
     79         * 
     80         * So this class does just keep auto actions without providing access 
     81         * to them. 
     82         */ 
     83        class AutoList 
     84        { 
     85        public: 
     86                typedef AutoAction::action_type action_type; 
     87 
     88                void add(action_type action, 
     89                         const ApplicationState& state, 
     90                         ApplicationFlags inc_flags, 
     91                         ApplicationFlags exc_flags); 
     92 
     93                ~AutoList(); 
     94 
     95        protected: 
     96                std::list<AutoAction*> m_list; 
     97        }; 
     98 
    4999        class LanguageWrapper 
    50100        { 
    51101        public: 
     102                //typedef AutoAction<Gtk::RadioAction> Action; 
    52103                typedef Glib::RefPtr<Gtk::RadioAction> Action; 
    53104                typedef Glib::RefPtr<Gtk::SourceLanguage> Language; 
     
    63114        }; 
    64115 
    65         Header(); 
     116        Header(const ApplicationState& state); 
    66117 
    67118        // Access to accelerator groups of the ui manager 
     
    123174 
    124175protected: 
     176        void set_action_auto(const Glib::RefPtr<Gtk::Action>& action, 
     177                             const ApplicationState& state, 
     178                             ApplicationFlags inc_flags, 
     179                             ApplicationFlags exc_flags); 
     180 
    125181        const Glib::RefPtr<Gtk::UIManager> m_ui_manager; 
    126182        Glib::RefPtr<Gtk::SourceLanguagesManager> m_lang_manager; 
     
    130186 
    131187        Gtk::RadioButtonGroup m_lang_group; 
     188 
     189        /** @brief List that just stores internally the auto actions to have 
     190         * the actions change sensitivity automatically. 
     191         */ 
     192        AutoList m_auto_actions; 
    132193}; 
    133194 
  • inc/window.hpp

    r1ae339e r0c6e731  
    2424#include <gtkmm/frame.h> 
    2525#include <gtkmm/messagedialog.h> 
     26 
    2627#include "features.hpp" 
    2728#include "icon.hpp" 
    2829#include "config.hpp" 
     30#include "application_state.hpp" 
    2931#include "header.hpp" 
    3032#include "docwindow.hpp" 
     
    148150        Gtk::Frame m_frame_text; 
    149151 
     152        ApplicationState m_application_state; 
    150153        DocumentSettings m_document_settings; 
    151154 
  • src/folder.cpp

    r2aa10af r0c6e731  
    116116                      const Preferences& preferences): 
    117117        Gtk::Notebook(), 
    118         m_block_language(false), m_header(header), m_preferences(preferences), m_buffer(NULL) 
     118        m_block_language(false), m_header(header), m_preferences(preferences), 
     119        m_buffer(NULL) 
    119120{ 
    120121        set_scrollable(true); 
     
    156157                remove_page(0); 
    157158 
    158         // Disable all document items, there are no documents upon start 
    159         enable_document_items(DOCUMENT_ITEMS_DISABLE_ALL); 
    160  
    161159        set_sensitive(true); 
    162160        m_buffer = &buf; 
     
    170168        // the documents 
    171169        for(int i = 0; i < get_n_pages(); ++ i) 
    172                 static_cast<DocWindow*>(get_nth_page(i) )->disable(); //get_document().set_sensitive(false); 
    173  
    174         // Disable some items, but let save and close still active. 
    175         // Disable all if the last document has been closed. 
    176         if(get_n_pages() > 0) 
    177                 enable_document_items(DOCUMENT_ITEMS_ENABLE_DISCONN); 
     170                static_cast<DocWindow*>(get_nth_page(i) )->disable(); 
    178171} 
    179172 
    180173void Gobby::Folder::obby_user_join(const obby::user& user) 
    181174{ 
    182         // Pass user join event to documents 
    183         //for(unsigned int i = 0; i < get_n_pages(); ++ i) 
    184         //      static_cast<DocWindow*>(get_nth_page(i) )->obby_user_join(user); 
    185175} 
    186176 
    187177void Gobby::Folder::obby_user_part(const obby::user& user) 
    188178{ 
    189         // Pass user part event to documents 
    190         //for(unsigned int i = 0; i < get_n_pages(); ++ i) 
    191         //      static_cast<DocWindow*>(get_nth_page(i) )->obby_user_part(user); 
    192179} 
    193180 
    194181void Gobby::Folder::obby_user_colour(const obby::user& user) 
    195182{ 
    196         // Pass user colour event to documents 
    197         //for(unsigned int i = 0; i < get_n_pages(); ++ i) 
    198         //      static_cast<DocWindow*>( 
    199         //              get_nth_page(i) )->obby_user_colour(user); 
    200183} 
    201184 
     
    303286} 
    304287 
    305 void Gobby::Folder::enable_document_items(DocumentItems which) 
    306 { 
    307         m_header.action_session_document_save-> 
    308                 set_sensitive(which >= DOCUMENT_ITEMS_ENABLE_DISCONN); 
    309         m_header.action_session_document_save_as-> 
    310                 set_sensitive(which >= DOCUMENT_ITEMS_ENABLE_DISCONN); 
    311         m_header.action_session_document_close-> 
    312                 set_sensitive(which >= DOCUMENT_ITEMS_ENABLE_DISCONN); 
    313         m_header.action_view_preferences-> 
    314                 set_sensitive(which >= DOCUMENT_ITEMS_ENABLE_DISCONN); 
    315         m_header.action_view_syntax-> 
    316                 set_sensitive(which >= DOCUMENT_ITEMS_ENABLE_DISCONN); 
    317 } 
    318  
    319288void Gobby::Folder::on_language_changed(const Glib::RefPtr<Gtk::SourceLanguage>& language) 
    320289{ 
     
    421390        new_wnd->show_all(); 
    422391 
    423         // Enable document items as there is at least one document we are 
    424         // subscribed to. 
    425         enable_document_items(DOCUMENT_ITEMS_ENABLE_ALL); 
    426  
    427392        // Emit add_document signal 
    428393        m_signal_document_add.emit(*new_wnd); 
     
    457422        // is Gtk::managed 
    458423        m_signal_document_remove.emit(*wnd); 
    459  
    460         if(get_n_pages() == 0) 
    461         { 
    462                 // Disable document items if there are no more documents left 
    463                 enable_document_items(DOCUMENT_ITEMS_DISABLE_ALL); 
    464         } 
    465424 
    466425        // The next time the user subscribes the DocWindow will be 
  • src/header.cpp

    r5843bef r0c6e731  
    150150} 
    151151 
     152Gobby::Header::AutoAction::AutoAction(action_type action, 
     153                                      const ApplicationState& state, 
     154                                      ApplicationFlags inc_flags, 
     155                                      ApplicationFlags exc_flags): 
     156        m_action(action), m_inc_flags(inc_flags), m_exc_flags(exc_flags) 
     157{ 
     158        state.state_changed_event().connect( 
     159                sigc::bind( 
     160                        sigc::hide( 
     161                                sigc::mem_fun( 
     162                                        *this, 
     163                                        &AutoAction::on_state_change 
     164                                ) 
     165                        ), 
     166                        sigc::ref(state) 
     167                ) 
     168        ); 
     169} 
     170 
     171void Gobby::Header::AutoAction::on_state_change(const ApplicationState& state) 
     172{ 
     173        m_action->set_sensitive(state.query(m_inc_flags, m_exc_flags) ); 
     174} 
     175 
     176void Gobby::Header::AutoList::add(action_type action, 
     177                                  const ApplicationState& state, 
     178                                  ApplicationFlags inc_flags, 
     179                                  ApplicationFlags exc_flags) 
     180{ 
     181        m_list.push_back(new AutoAction(action, state, inc_flags, exc_flags) ); 
     182} 
     183 
     184Gobby::Header::AutoList::~AutoList() 
     185{ 
     186        for(std::list<AutoAction*>::iterator iter = m_list.begin(); 
     187            iter != m_list.end(); 
     188            ++ iter) 
     189        { 
     190                delete *iter; 
     191        } 
     192} 
     193 
    152194Gobby::Header::Error::Error(Code error_code, const Glib::ustring& error_message) 
    153195 : Glib::Error(g_quark_from_static_string("GOBBY_HEADER_ERROR"), 
     
    161203} 
    162204 
    163 Gobby::Header::Header(): 
     205Gobby::Header::Header(const ApplicationState& state): 
    164206        group_app(Gtk::ActionGroup::create() ), 
    165207        group_session(Gtk::ActionGroup::create() ), 
     
    370412        m_lang_manager(Gtk::SourceLanguagesManager::create() ) 
    371413{ 
     414        // Assign auto actions 
     415        set_action_auto( 
     416                action_app, state, 
     417                APPLICATION_NONE, APPLICATION_NONE 
     418        ); 
     419 
     420        set_action_auto( 
     421                action_app_session_create, state, 
     422                APPLICATION_NONE, APPLICATION_SESSION 
     423        ); 
     424 
     425        set_action_auto( 
     426                action_app_session_join, state, 
     427                APPLICATION_NONE, APPLICATION_SESSION 
     428        ); 
     429 
     430        set_action_auto( 
     431                action_app_session_save, state, 
     432                APPLICATION_NONE, APPLICATION_INITIAL 
     433        ); 
     434 
     435        set_action_auto( 
     436                action_app_session_quit, state, 
     437                APPLICATION_SESSION, APPLICATION_NONE 
     438        ); 
     439 
     440        set_action_auto( 
     441                action_app_quit, state, 
     442                APPLICATION_NONE, APPLICATION_NONE 
     443        ); 
     444 
     445        set_action_auto( 
     446                action_session, state, 
     447                APPLICATION_NONE, APPLICATION_INITIAL 
     448        ); 
     449 
     450        set_action_auto( 
     451                action_session_document_create, state, 
     452                APPLICATION_SESSION, APPLICATION_NONE 
     453        ); 
     454 
     455        set_action_auto( 
     456                action_session_document_open, state, 
     457                APPLICATION_SESSION, APPLICATION_NONE 
     458        ); 
     459 
     460        set_action_auto( 
     461                action_session_document_save, state, 
     462                APPLICATION_DOCUMENT, APPLICATION_NONE 
     463        ); 
     464 
     465        set_action_auto( 
     466                action_session_document_save_as, state, 
     467                APPLICATION_DOCUMENT, APPLICATION_NONE 
     468        ); 
     469 
     470        set_action_auto( 
     471                action_session_document_close, state, 
     472                APPLICATION_DOCUMENT, APPLICATION_NONE 
     473        ); 
     474 
     475        set_action_auto( 
     476                action_edit, state, 
     477                APPLICATION_NONE, APPLICATION_NONE 
     478        ); 
     479 
     480        set_action_auto( 
     481                action_edit_search, state, 
     482                APPLICATION_NONE, APPLICATION_NONE 
     483        ); 
     484 
     485        set_action_auto( 
     486                action_edit_search_replace, state, 
     487                APPLICATION_NONE, APPLICATION_NONE 
     488        ); 
     489 
     490        set_action_auto( 
     491                action_edit_goto_line, state, 
     492                APPLICATION_NONE, APPLICATION_NONE 
     493        ); 
     494 
     495        set_action_auto( 
     496                action_edit_preferences, state, 
     497                APPLICATION_NONE, APPLICATION_NONE 
     498        ); 
     499 
     500        set_action_auto( 
     501                action_user, state, 
     502                APPLICATION_SESSION, APPLICATION_NONE 
     503        ); 
     504 
     505        set_action_auto( 
     506                action_user_set_password, state, 
     507                APPLICATION_SESSION, APPLICATION_HOST 
     508        ); 
     509 
     510        set_action_auto( 
     511                action_user_set_colour, state, 
     512                APPLICATION_SESSION, APPLICATION_NONE 
     513        ); 
     514 
     515        set_action_auto( 
     516                action_view, state, 
     517                APPLICATION_DOCUMENT, APPLICATION_NONE 
     518        ); 
     519 
     520        set_action_auto( 
     521                action_view_preferences, state, 
     522                APPLICATION_DOCUMENT, APPLICATION_NONE 
     523        ); 
     524 
     525        set_action_auto( 
     526                action_view_syntax, state, 
     527                APPLICATION_DOCUMENT, APPLICATION_NONE 
     528        ); 
     529 
     530        set_action_auto( 
     531                action_window, state, 
     532                APPLICATION_NONE, APPLICATION_NONE 
     533        ); 
     534 
     535        set_action_auto( 
     536                action_window_userlist, state, 
     537                APPLICATION_NONE, APPLICATION_NONE 
     538        ); 
     539 
     540        set_action_auto( 
     541                action_window_documentlist, state, 
     542                APPLICATION_NONE, APPLICATION_NONE 
     543        ); 
     544 
     545        set_action_auto( 
     546                action_help, state, 
     547                APPLICATION_NONE, APPLICATION_NONE 
     548        ); 
     549 
     550        set_action_auto( 
     551                action_help_about, state, 
     552                APPLICATION_NONE, APPLICATION_NONE 
     553        ); 
     554 
    372555        // Add basic menu 
    373556        m_ui_manager->add_ui_from_string(ui_desc); 
     
    545728        return *m_toolbar; 
    546729} 
     730 
     731void Gobby::Header::set_action_auto(const Glib::RefPtr<Gtk::Action>& action, 
     732                                    const ApplicationState& state, 
     733                                    ApplicationFlags inc_flags, 
     734                                    ApplicationFlags exc_flags) 
     735{ 
     736        m_auto_actions.add(action, state, inc_flags, exc_flags); 
     737} 
     738 
  • src/window.cpp

    rba89078 r0c6e731  
    5555        m_zeroconf(NULL), 
    5656#endif 
    57         m_document_settings(*this), m_header(), 
     57        m_application_state(APPLICATION_NONE), 
     58        m_document_settings(*this), m_header(m_application_state), 
    5859        m_userlist(*this, m_header, m_preferences, config["windows"]), 
    5960        m_documentlist( 
     
    127128        add_accel_group(m_header.get_accel_group() ); 
    128129 
    129         // Initialise header sensitivity 
    130         m_header.group_session->set_sensitive(false); 
    131         m_header.group_user->set_sensitive(false); 
    132         m_header.group_view->set_sensitive(false); 
    133         m_header.action_app_session_save->set_sensitive(false); 
    134         m_header.action_app_session_quit->set_sensitive(false); 
    135  
    136130        m_frame_chat.set_shadow_type(Gtk::SHADOW_IN); 
    137131        m_frame_text.set_shadow_type(Gtk::SHADOW_IN); 
     
    155149        set_title("Gobby"); 
    156150        set_default_size(640, 480); 
     151 
     152        m_application_state.modify(APPLICATION_INITIAL, APPLICATION_NONE); 
    157153 
    158154#ifdef WITH_HOWL 
     
    232228{ 
    233229        if(m_buffer.get() == NULL) return false; 
     230        if(!m_buffer->is_open() ) return false; 
    234231 
    235232        Gtk::MessageDialog dlg( 
     
    272269        m_dnd.reset(new DragDrop(*this) ); 
    273270 
    274         m_header.group_session->set_sensitive(true); 
    275         m_header.action_session_document_create->set_sensitive(true); 
    276         m_header.action_session_document_open->set_sensitive(true); 
    277         m_header.group_user->set_sensitive(true); 
    278         m_header.group_view->set_sensitive(true); 
    279         m_header.action_app_session_save->set_sensitive(true); 
    280         m_header.action_app_session_quit->set_sensitive(true); 
    281  
    282         m_header.action_app_session_create->set_sensitive(false); 
    283         m_header.action_app_session_join->set_sensitive(false); 
    284  
    285         m_header.action_user_set_password->set_sensitive( 
    286                 dynamic_cast<ClientBuffer*>(m_buffer.get()) != NULL 
    287         ); 
    288  
    289271        // Delegate start of obby session 
    290272        m_folder.obby_start(*m_buffer); 
     
    311293 
    312294        // Set last page as active one because it is currently shown anyway. 
    313         if(m_buffer->document_count() > 0) 
    314                 m_folder.set_current_page(m_buffer->document_count() - 1); 
     295        //if(m_buffer->document_count() > 0) 
     296        //      m_folder.set_current_page(m_buffer->document_count() - 1); 
    315297 
    316298        // Clear location of previous session file, this is a new session 
     
    326308                m_documentlist.grab_focus(); 
    327309        } 
     310 
     311        ApplicationFlags inc_flags = APPLICATION_SESSION; 
     312        ApplicationFlags exc_flags = APPLICATION_INITIAL | APPLICATION_DOCUMENT; 
     313 
     314        if(dynamic_cast<ClientBuffer*>(m_buffer.get()) != NULL) 
     315                exc_flags |= APPLICATION_HOST; 
     316        else 
     317                inc_flags |= APPLICATION_HOST; 
     318 
     319        m_application_state.modify(inc_flags, exc_flags); 
    328320} 
    329321 
     
    338330                ); 
    339331        } 
     332 
     333        m_application_state.modify(APPLICATION_NONE, APPLICATION_SESSION); 
    340334 
    341335        if(m_buffer->is_open() ) 
     
    361355        m_chat.obby_end(); 
    362356        m_statusbar.obby_end(); 
    363  
    364         m_header.action_session_document_create->set_sensitive(false); 
    365         m_header.action_session_document_open->set_sensitive(false); 
    366         m_header.group_user->set_sensitive(false); 
    367         //m_header.action_app_session_save->set_sensitive(false); 
    368         m_header.action_app_session_quit->set_sensitive(false); 
    369  
    370         m_header.action_app_session_create->set_sensitive(true); 
    371         m_header.action_app_session_join->set_sensitive(true); 
    372357 
    373358#ifdef WITH_HOWL 
     
    604589        // Select newly created page 
    605590        m_folder.set_current_page(m_folder.page_num(window) ); 
    606         window.grab_focus(); // TODO: Grab focus to sourceview... 
     591        window.grab_focus(); 
     592 
     593        if(m_folder.get_n_pages() == 1) 
     594        { 
     595                // There have not been any documents before 
     596                m_application_state.modify( 
     597                        APPLICATION_DOCUMENT, 
     598                        APPLICATION_NONE 
     599                ); 
     600        } 
    607601} 
    608602 
     
    615609                update_title_bar(); 
    616610 
    617                 // TODO: This should be done automatically with flags for the 
    618                 // menu items which specify when the entry is visible 
    619                 if(m_buffer.get() == NULL || !m_buffer->is_open()) 
    620                 { 
    621                         m_header.group_session->set_sensitive(false); 
    622                         m_header.group_view->set_sensitive(false); 
    623                 } 
     611                m_application_state.modify( 
     612                        APPLICATION_NONE, 
     613                        APPLICATION_DOCUMENT 
     614                ); 
    624615        } 
    625616} 
     
    13071298        } 
    13081299 
    1309 //      if(m_buffer.get() != NULL) 
    1310 //      { 
    1311                 // Unsubscribe from document 
    1312                 window.get_info().unsubscribe(); 
    1313 //      } 
    1314 //      else 
    1315 //      { 
    1316                 // Buffer does not exist: Maybe the connection has been lost 
    1317                 // or something: Just remove the document from the folder. 
    1318 //              m_folder.remove_page(window); 
    1319 //              on_folder_document_remove(window); 
    1320 //      } 
     1300        window.get_info().unsubscribe(); 
    13211301} 
    13221302 
     
    13281308        dlg.run(); 
    13291309} 
    1330