Changeset 0c6e731fde2f0fa4c225215371d356fed6d6f6f3
- Timestamp:
- 01/06/07 23:57:58 (6 years ago)
- Parents:
- ba89078f762f9261827bc9091e642ac272644d35
- Children:
- 1662ea7cb97e74c04650ddda1130c2ea7a4d07ce
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:57:58Z+0000
- Files:
-
- 2 added
- 7 modified
-
Makefile.am (modified) (2 diffs)
-
inc/application_state.hpp (added)
-
inc/folder.hpp (modified) (4 diffs)
-
inc/header.hpp (modified) (6 diffs)
-
inc/window.hpp (modified) (2 diffs)
-
src/application_state.cpp (added)
-
src/folder.cpp (modified) (6 diffs)
-
src/header.cpp (modified) (4 diffs)
-
src/window.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
rba89078 r0c6e731 23 23 noinst_HEADERS += inc/mimemap.hpp 24 24 noinst_HEADERS += inc/regex.hpp 25 noinst_HEADERS += inc/application_state.hpp 25 26 noinst_HEADERS += inc/encoding_selector.hpp 26 27 noinst_HEADERS += inc/defaultdialog.hpp … … 77 78 gobby_SOURCES += src/mimemap.cpp 78 79 gobby_SOURCES += src/regex.cpp 80 gobby_SOURCES += src/application_state.cpp 79 81 gobby_SOURCES += src/encoding_selector.cpp 80 82 gobby_SOURCES += src/defaultdialog.cpp -
inc/folder.hpp
r2aa10af r0c6e731 130 130 tab_switched_event() const; 131 131 protected: 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 the140 * 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 = 2147 };148 149 132 // Overrides 150 133 virtual void on_switch_page(GtkNotebookPage* page, guint page_num); … … 154 137 // Internals 155 138 void set_tab_colour(DocWindow& win, const Glib::ustring& colour); 156 void enable_document_items(DocumentItems which);157 139 158 140 // Signal handlers … … 180 162 signal_document_remove_type 181 163 m_signal_document_remove; 164 182 165 signal_document_close_request_type 183 166 m_signal_document_close_request; … … 188 171 signal_document_language_changed_type 189 172 m_signal_document_language_changed; 173 190 174 signal_tab_switched_type 191 175 m_signal_tab_switched; -
inc/header.hpp
r5843bef r0c6e731 20 20 #define _GOBBY_HEADER_HPP_ 21 21 22 #include <list> 23 22 24 #include <gtkmm/box.h> 23 25 #include <gtkmm/uimanager.h> … … 26 28 #include <gtkmm/toolbar.h> 27 29 30 #include "application_state.hpp" 28 31 #include "sourceview/sourcelanguage.hpp" 29 32 #include "sourceview/sourcelanguagesmanager.hpp" … … 47 50 }; 48 51 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 49 99 class LanguageWrapper 50 100 { 51 101 public: 102 //typedef AutoAction<Gtk::RadioAction> Action; 52 103 typedef Glib::RefPtr<Gtk::RadioAction> Action; 53 104 typedef Glib::RefPtr<Gtk::SourceLanguage> Language; … … 63 114 }; 64 115 65 Header( );116 Header(const ApplicationState& state); 66 117 67 118 // Access to accelerator groups of the ui manager … … 123 174 124 175 protected: 176 void set_action_auto(const Glib::RefPtr<Gtk::Action>& action, 177 const ApplicationState& state, 178 ApplicationFlags inc_flags, 179 ApplicationFlags exc_flags); 180 125 181 const Glib::RefPtr<Gtk::UIManager> m_ui_manager; 126 182 Glib::RefPtr<Gtk::SourceLanguagesManager> m_lang_manager; … … 130 186 131 187 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; 132 193 }; 133 194 -
inc/window.hpp
r1ae339e r0c6e731 24 24 #include <gtkmm/frame.h> 25 25 #include <gtkmm/messagedialog.h> 26 26 27 #include "features.hpp" 27 28 #include "icon.hpp" 28 29 #include "config.hpp" 30 #include "application_state.hpp" 29 31 #include "header.hpp" 30 32 #include "docwindow.hpp" … … 148 150 Gtk::Frame m_frame_text; 149 151 152 ApplicationState m_application_state; 150 153 DocumentSettings m_document_settings; 151 154 -
src/folder.cpp
r2aa10af r0c6e731 116 116 const Preferences& preferences): 117 117 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) 119 120 { 120 121 set_scrollable(true); … … 156 157 remove_page(0); 157 158 158 // Disable all document items, there are no documents upon start159 enable_document_items(DOCUMENT_ITEMS_DISABLE_ALL);160 161 159 set_sensitive(true); 162 160 m_buffer = &buf; … … 170 168 // the documents 171 169 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(); 178 171 } 179 172 180 173 void Gobby::Folder::obby_user_join(const obby::user& user) 181 174 { 182 // Pass user join event to documents183 //for(unsigned int i = 0; i < get_n_pages(); ++ i)184 // static_cast<DocWindow*>(get_nth_page(i) )->obby_user_join(user);185 175 } 186 176 187 177 void Gobby::Folder::obby_user_part(const obby::user& user) 188 178 { 189 // Pass user part event to documents190 //for(unsigned int i = 0; i < get_n_pages(); ++ i)191 // static_cast<DocWindow*>(get_nth_page(i) )->obby_user_part(user);192 179 } 193 180 194 181 void Gobby::Folder::obby_user_colour(const obby::user& user) 195 182 { 196 // Pass user colour event to documents197 //for(unsigned int i = 0; i < get_n_pages(); ++ i)198 // static_cast<DocWindow*>(199 // get_nth_page(i) )->obby_user_colour(user);200 183 } 201 184 … … 303 286 } 304 287 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 319 288 void Gobby::Folder::on_language_changed(const Glib::RefPtr<Gtk::SourceLanguage>& language) 320 289 { … … 421 390 new_wnd->show_all(); 422 391 423 // Enable document items as there is at least one document we are424 // subscribed to.425 enable_document_items(DOCUMENT_ITEMS_ENABLE_ALL);426 427 392 // Emit add_document signal 428 393 m_signal_document_add.emit(*new_wnd); … … 457 422 // is Gtk::managed 458 423 m_signal_document_remove.emit(*wnd); 459 460 if(get_n_pages() == 0)461 {462 // Disable document items if there are no more documents left463 enable_document_items(DOCUMENT_ITEMS_DISABLE_ALL);464 }465 424 466 425 // The next time the user subscribes the DocWindow will be -
src/header.cpp
r5843bef r0c6e731 150 150 } 151 151 152 Gobby::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 171 void 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 176 void 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 184 Gobby::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 152 194 Gobby::Header::Error::Error(Code error_code, const Glib::ustring& error_message) 153 195 : Glib::Error(g_quark_from_static_string("GOBBY_HEADER_ERROR"), … … 161 203 } 162 204 163 Gobby::Header::Header( ):205 Gobby::Header::Header(const ApplicationState& state): 164 206 group_app(Gtk::ActionGroup::create() ), 165 207 group_session(Gtk::ActionGroup::create() ), … … 370 412 m_lang_manager(Gtk::SourceLanguagesManager::create() ) 371 413 { 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 372 555 // Add basic menu 373 556 m_ui_manager->add_ui_from_string(ui_desc); … … 545 728 return *m_toolbar; 546 729 } 730 731 void 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 55 55 m_zeroconf(NULL), 56 56 #endif 57 m_document_settings(*this), m_header(), 57 m_application_state(APPLICATION_NONE), 58 m_document_settings(*this), m_header(m_application_state), 58 59 m_userlist(*this, m_header, m_preferences, config["windows"]), 59 60 m_documentlist( … … 127 128 add_accel_group(m_header.get_accel_group() ); 128 129 129 // Initialise header sensitivity130 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 136 130 m_frame_chat.set_shadow_type(Gtk::SHADOW_IN); 137 131 m_frame_text.set_shadow_type(Gtk::SHADOW_IN); … … 155 149 set_title("Gobby"); 156 150 set_default_size(640, 480); 151 152 m_application_state.modify(APPLICATION_INITIAL, APPLICATION_NONE); 157 153 158 154 #ifdef WITH_HOWL … … 232 228 { 233 229 if(m_buffer.get() == NULL) return false; 230 if(!m_buffer->is_open() ) return false; 234 231 235 232 Gtk::MessageDialog dlg( … … 272 269 m_dnd.reset(new DragDrop(*this) ); 273 270 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()) != NULL287 );288 289 271 // Delegate start of obby session 290 272 m_folder.obby_start(*m_buffer); … … 311 293 312 294 // 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); 315 297 316 298 // Clear location of previous session file, this is a new session … … 326 308 m_documentlist.grab_focus(); 327 309 } 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); 328 320 } 329 321 … … 338 330 ); 339 331 } 332 333 m_application_state.modify(APPLICATION_NONE, APPLICATION_SESSION); 340 334 341 335 if(m_buffer->is_open() ) … … 361 355 m_chat.obby_end(); 362 356 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);372 357 373 358 #ifdef WITH_HOWL … … 604 589 // Select newly created page 605 590 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 } 607 601 } 608 602 … … 615 609 update_title_bar(); 616 610 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 ); 624 615 } 625 616 } … … 1307 1298 } 1308 1299 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(); 1321 1301 } 1322 1302 … … 1328 1308 dlg.run(); 1329 1309 } 1330
