Changeset 56383089e5ae1d12c04e5c0b67699e31eae062e0
- Timestamp:
- 01/06/07 23:40:57 (6 years ago)
- Author:
- Philipp Kern <phil@…>
- Parents:
- 9c8b8080dc4d007fd27de778666221b86fe62b54
- Children:
- 21d9a4d072dc4144bb9ee6e07f436fd8fa290adb
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:40:57Z+0000
- Message:
-
[project @ Close icons in tab labels [ref #32]]
Original author: Armin Burgmeier <armin@…>
Date: 2005-07-20 13:55:50+00:00
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rf0556c4
|
r5638308
|
|
| 21 | 21 | |
| 22 | 22 | #include <sigc++/signal.h> |
| | 23 | #include <gtkmm/box.h> |
| | 24 | #include <gtkmm/image.h> |
| | 25 | #include <gtkmm/label.h> |
| | 26 | #include <gtkmm/button.h> |
| 23 | 27 | #include <gtkmm/notebook.h> |
| 24 | 28 | #include <obby/user.hpp> |
| … |
… |
|
| 43 | 47 | { |
| 44 | 48 | public: |
| | 49 | class TabLabel : public Gtk::HBox |
| | 50 | { |
| | 51 | public: |
| | 52 | typedef Glib::SignalProxy0<void> close_signal_type; |
| | 53 | |
| | 54 | TabLabel(const Glib::ustring& label); |
| | 55 | ~TabLabel(); |
| | 56 | |
| | 57 | close_signal_type close_event(); |
| | 58 | protected: |
| | 59 | Gtk::Image m_image; |
| | 60 | Gtk::Label m_label; |
| | 61 | Gtk::Button m_button; |
| | 62 | Gtk::HBox m_box; |
| | 63 | }; |
| | 64 | |
| | 65 | typedef sigc::signal<void, Document&> signal_document_close_type; |
| 45 | 66 | typedef sigc::signal<void, Document&> signal_document_cursor_moved_type; |
| 46 | 67 | typedef sigc::signal<void, Document&> |
| … |
… |
|
| 70 | 91 | void obby_document_remove(obby::local_document_info& document); |
| 71 | 92 | |
| | 93 | signal_document_close_type document_close_event() const; |
| 72 | 94 | signal_document_cursor_moved_type document_cursor_moved_event() const; |
| 73 | 95 | signal_document_content_changed_type |
| … |
… |
|
| 80 | 102 | |
| 81 | 103 | protected: |
| | 104 | // Overrides |
| | 105 | virtual void on_switch_page(GtkNotebookPage* page, guint page_num); |
| | 106 | |
| 82 | 107 | // Signal handlers |
| 83 | | virtual void on_switch_page(GtkNotebookPage* page, guint page_num); |
| | 108 | void on_document_close(Document& document); |
| 84 | 109 | |
| 85 | 110 | void on_document_cursor_moved(Document& document); |
| … |
… |
|
| 89 | 114 | #endif |
| 90 | 115 | |
| | 116 | signal_document_close_type m_signal_document_close; |
| 91 | 117 | signal_document_cursor_moved_type m_signal_document_cursor_moved; |
| 92 | 118 | signal_document_content_changed_type m_signal_document_content_changed; |
-
|
r9c8b808
|
r5638308
|
|
| 27 | 27 | #include "config.hpp" |
| 28 | 28 | #include "header.hpp" |
| | 29 | #include "docwindow.hpp" |
| 29 | 30 | #include "folder.hpp" |
| 30 | 31 | #include "userlist.hpp" |
| … |
… |
|
| 53 | 54 | void obby_end(); |
| 54 | 55 | |
| 55 | | // UI handler |
| | 56 | // Header UI handler |
| 56 | 57 | void on_session_create(); |
| 57 | 58 | void on_session_join(); |
| … |
… |
|
| 73 | 74 | #endif |
| 74 | 75 | |
| | 76 | // Folder UI handler |
| | 77 | void on_folder_document_close(Document& document); |
| 75 | 78 | void on_folder_tab_switched(Document& document); |
| 76 | 79 | |
| … |
… |
|
| 92 | 95 | |
| 93 | 96 | // Helper functions |
| | 97 | void close_document(DocWindow& doc); |
| 94 | 98 | void display_error(const Glib::ustring& message); |
| 95 | 99 | |
| … |
… |
|
| 120 | 124 | #endif |
| 121 | 125 | sigc::connection m_timer_conn; |
| 122 | | bool m_running; // m_running is set if the obby connection has been |
| 123 | | // established successfully. |
| 124 | 126 | }; |
| 125 | 127 | |
-
|
rf0556c4
|
r5638308
|
|
| 17 | 17 | */ |
| 18 | 18 | |
| | 19 | #include <gtkmm/box.h> |
| | 20 | #include <gtkmm/stock.h> |
| | 21 | |
| 19 | 22 | #include "document.hpp" |
| 20 | 23 | #include "docwindow.hpp" |
| 21 | 24 | #include "folder.hpp" |
| 22 | 25 | |
| | 26 | Gobby::Folder::TabLabel::TabLabel(const Glib::ustring& label) |
| | 27 | : m_image(Gtk::Stock::CLOSE, Gtk::ICON_SIZE_MENU), m_label(label) |
| | 28 | { |
| | 29 | // Lookup icon size |
| | 30 | int width, height; |
| | 31 | Gtk::IconSize::lookup(Gtk::ICON_SIZE_MENU, width, height); |
| | 32 | |
| | 33 | // Resize button to image's size |
| | 34 | m_button.set_size_request(width + 4, height); |
| | 35 | m_button.add(m_image); |
| | 36 | m_button.set_relief(Gtk::RELIEF_NONE); |
| | 37 | |
| | 38 | // Add box |
| | 39 | set_spacing(5); |
| | 40 | pack_start(m_label, Gtk::PACK_SHRINK); |
| | 41 | pack_start(m_button, Gtk::PACK_SHRINK); |
| | 42 | show_all(); |
| | 43 | } |
| | 44 | |
| | 45 | Gobby::Folder::TabLabel::~TabLabel() |
| | 46 | { |
| | 47 | } |
| | 48 | |
| 23 | 49 | Gobby::Folder::Folder() |
| 24 | 50 | : Gtk::Notebook(), m_running(false) |
| … |
… |
|
| 33 | 59 | // Delete documents |
| 34 | 60 | for(int i = 0; i < get_n_pages(); ++ i) |
| | 61 | { |
| | 62 | delete get_tab_label(*get_nth_page(i) ); |
| 35 | 63 | delete get_nth_page(i); |
| | 64 | } |
| | 65 | } |
| | 66 | |
| | 67 | Gobby::Folder::TabLabel::close_signal_type |
| | 68 | Gobby::Folder::TabLabel::close_event() |
| | 69 | { |
| | 70 | return m_button.signal_clicked(); |
| 36 | 71 | } |
| 37 | 72 | |
| … |
… |
|
| 125 | 160 | #endif |
| 126 | 161 | |
| | 162 | // Create label for the tab |
| | 163 | TabLabel* label = new TabLabel(document.get_title() ); |
| | 164 | |
| | 165 | // Connect close event |
| | 166 | label->close_event().connect( |
| | 167 | sigc::bind( |
| | 168 | sigc::mem_fun(*this, &Folder::on_document_close), |
| | 169 | sigc::ref(new_doc) |
| | 170 | ) |
| | 171 | ); |
| | 172 | |
| 127 | 173 | // Append document's title as new page to the notebook |
| 128 | | append_page(*new_wnd, document.get_title() ); |
| | 174 | append_page(*new_wnd, *label); |
| 129 | 175 | |
| 130 | 176 | // Show child |
| … |
… |
|
| 143 | 189 | if(&obdoc == &document) |
| 144 | 190 | { |
| 145 | | // Delete it. |
| 146 | | remove_page(i); |
| | 191 | // Remove page |
| | 192 | remove_page(*doc); |
| | 193 | |
| | 194 | // Delete tab label assigned to the document |
| | 195 | delete get_tab_label(*doc); |
| | 196 | |
| | 197 | // Delete document itself |
| 147 | 198 | delete doc; |
| | 199 | |
| 148 | 200 | break; |
| 149 | 201 | } |
| … |
… |
|
| 152 | 204 | |
| 153 | 205 | // Signals |
| | 206 | Gobby::Folder::signal_document_close_type |
| | 207 | Gobby::Folder::document_close_event() const |
| | 208 | { |
| | 209 | return m_signal_document_close; |
| | 210 | } |
| | 211 | |
| 154 | 212 | Gobby::Folder::signal_document_cursor_moved_type |
| 155 | 213 | Gobby::Folder::document_cursor_moved_event() const |
| … |
… |
|
| 176 | 234 | { |
| 177 | 235 | return m_signal_tab_switched; |
| | 236 | } |
| | 237 | |
| | 238 | void Gobby::Folder::on_document_close(Document& document) |
| | 239 | { |
| | 240 | m_signal_document_close.emit(document); |
| 178 | 241 | } |
| 179 | 242 | |
-
|
r9c8b808
|
r5638308
|
|
| 48 | 48 | m_zeroconf(NULL), |
| 49 | 49 | #endif |
| 50 | | m_running(false), m_header(m_folder), m_statusbar(m_folder) |
| 51 | | { |
| 52 | | // Connect UI signals |
| | 50 | m_header(m_folder), m_statusbar(m_folder) |
| | 51 | { |
| | 52 | // Header |
| 53 | 53 | m_header.session_create_event().connect( |
| 54 | 54 | sigc::mem_fun(*this, &Window::on_session_create) ); |
| … |
… |
|
| 84 | 84 | sigc::mem_fun(*this, &Window::on_quit) ); |
| 85 | 85 | |
| | 86 | // Folder |
| | 87 | m_folder.document_close_event().connect( |
| | 88 | sigc::mem_fun(*this, &Window::on_folder_document_close) ); |
| 86 | 89 | m_folder.tab_switched_event().connect( |
| 87 | 90 | sigc::mem_fun(*this, &Window::on_folder_tab_switched) ); |
| … |
… |
|
| 319 | 322 | } |
| 320 | 323 | |
| | 324 | void Gobby::Window::on_folder_document_close(Document& document) |
| | 325 | { |
| | 326 | for(int i = 0; i < m_folder.get_n_pages(); ++ i) |
| | 327 | { |
| | 328 | Gtk::Widget* doc = m_folder.get_nth_page(i); |
| | 329 | if(&static_cast<DocWindow*>(doc)->get_document() == &document) |
| | 330 | { |
| | 331 | close_document(*static_cast<DocWindow*>(doc)); |
| | 332 | break; |
| | 333 | } |
| | 334 | } |
| | 335 | } |
| | 336 | |
| 321 | 337 | void Gobby::Window::on_folder_tab_switched(Document& document) |
| 322 | 338 | { |
| … |
… |
|
| 371 | 387 | void Gobby::Window::on_document_save() |
| 372 | 388 | { |
| | 389 | // Get page |
| 373 | 390 | Widget* page = m_folder.get_nth_page(m_folder.get_current_page() ); |
| 374 | 391 | DocWindow& doc = *static_cast<DocWindow*>(page); |
| 375 | 392 | |
| | 393 | // Show dialog |
| 376 | 394 | Gtk::FileChooserDialog dlg(*this, _("Save current document"), |
| 377 | 395 | Gtk::FILE_CHOOSER_ACTION_SAVE); |
| … |
… |
|
| 382 | 400 | if(dlg.run() == Gtk::RESPONSE_OK) |
| 383 | 401 | { |
| | 402 | // Build ofstream |
| 384 | 403 | std::ofstream stream(dlg.get_filename().c_str() ); |
| 385 | 404 | |
| 386 | 405 | if(stream) |
| 387 | 406 | { |
| | 407 | // Save content into file |
| 388 | 408 | stream << doc.get_document().get_content() << std::endl; |
| 389 | 409 | doc.get_document().set_path(dlg.get_filename() ); |
| … |
… |
|
| 392 | 412 | else |
| 393 | 413 | { |
| | 414 | // File could not be opened |
| 394 | 415 | obby::format_string str("Could not open file " |
| 395 | 416 | "%0 for writing"); |
| … |
… |
|
| 402 | 423 | void Gobby::Window::on_document_close() |
| 403 | 424 | { |
| 404 | | if(m_buffer.get() != NULL) |
| 405 | | { |
| 406 | | // Get current page |
| 407 | | Widget* page = m_folder.get_nth_page( |
| 408 | | m_folder.get_current_page() |
| 409 | | ); |
| 410 | | |
| 411 | | // Send remove document request |
| 412 | | m_buffer->remove_document( |
| 413 | | static_cast<DocWindow*>( |
| 414 | | page |
| 415 | | )->get_document().get_document() |
| 416 | | ); |
| 417 | | } |
| 418 | | else |
| 419 | | { |
| 420 | | // Buffer does not exist: Maybe the connection has been lost |
| 421 | | // or something: Just remove the document from the folder. |
| 422 | | Gtk::Widget* doc_wnd = m_folder.get_nth_page( |
| 423 | | m_folder.get_current_page() |
| 424 | | ); |
| 425 | | |
| 426 | | m_folder.remove_page(m_folder.get_current_page() ); |
| 427 | | delete doc_wnd; |
| 428 | | |
| 429 | | // If there are no more documents disable |
| 430 | | // save and close buttons in header |
| 431 | | if(!m_folder.get_n_pages() ) |
| 432 | | m_header.disable_document_actions(); |
| 433 | | } |
| | 425 | Widget* page = m_folder.get_nth_page(m_folder.get_current_page() ); |
| | 426 | close_document(*static_cast<DocWindow*>(page) ); |
| 434 | 427 | } |
| 435 | 428 | |
| … |
… |
|
| 447 | 440 | if(dlg.run() == Gtk::RESPONSE_OK) |
| 448 | 441 | { |
| 449 | | dynamic_cast<obby::client_buffer*>(m_buffer.get() )->set_password( |
| 450 | | dlg.get_text() ); |
| | 442 | dynamic_cast<obby::client_buffer*>( |
| | 443 | m_buffer.get() )->set_password(dlg.get_text() ); |
| 451 | 444 | } |
| 452 | 445 | } |
| … |
… |
|
| 504 | 497 | } |
| 505 | 498 | |
| 506 | | /* |
| 507 | | void Gobby::Window::on_obby_login_failed(obby::login::error error) |
| 508 | | { |
| 509 | | display_error(obby::login::errstring(error) ); |
| 510 | | on_session_join(); |
| 511 | | } |
| 512 | | |
| 513 | | bool Gobby::Window::on_obby_global_password(std::string& password) |
| 514 | | { |
| 515 | | // Prompt for password |
| 516 | | EntryDialog dlg( |
| 517 | | *this, |
| 518 | | _("Password required"), |
| 519 | | _("Enter session password") |
| 520 | | ); |
| 521 | | |
| 522 | | // Disable view of typed characters (password input) |
| 523 | | dlg.get_entry().set_visibility(false); |
| 524 | | if(dlg.run() == Gtk::RESPONSE_OK) |
| 525 | | { |
| 526 | | // Use given text as password |
| 527 | | password = dlg.get_text(); |
| 528 | | return true; |
| 529 | | } |
| 530 | | else |
| 531 | | { |
| 532 | | // Close connection otherwise |
| 533 | | on_session_quit(); |
| 534 | | return false; |
| 535 | | } |
| 536 | | } |
| 537 | | |
| 538 | | bool Gobby::Window::on_obby_user_password(std::string& password) |
| 539 | | { |
| 540 | | obby::format_string str(_("Enter user password for user %0") ); |
| 541 | | str << m_buffer->get_name(); |
| 542 | | |
| 543 | | // Prompt for password |
| 544 | | EntryDialog dlg( |
| 545 | | *this, |
| 546 | | _("Password required"), |
| 547 | | str.str() |
| 548 | | ); |
| 549 | | |
| 550 | | // Disable view of typed characters (password input) |
| 551 | | dlg.get_entry().set_visibility(false); |
| 552 | | if(dlg.run() == Gtk::RESPONSE_OK) |
| 553 | | { |
| 554 | | // Use given text as password |
| 555 | | password = dlg.get_text(); |
| 556 | | return true; |
| 557 | | } |
| 558 | | else |
| 559 | | { |
| 560 | | // Close connection otherwise |
| 561 | | on_session_quit(); |
| 562 | | return false; |
| 563 | | } |
| 564 | | }*/ |
| 565 | | |
| 566 | 499 | void Gobby::Window::on_obby_close() |
| 567 | 500 | { |
| … |
… |
|
| 569 | 502 | on_session_quit(); |
| 570 | 503 | } |
| 571 | | |
| 572 | | /*void Gobby::Window::on_obby_sync() |
| 573 | | { |
| 574 | | // Send documents to components |
| 575 | | obby::buffer::document_iterator iter = m_buffer->document_begin(); |
| 576 | | for(; iter != m_buffer->document_end(); ++ iter) |
| 577 | | on_obby_document_insert(*iter); |
| 578 | | |
| 579 | | // Set last page as active one because it is currently shown anyway. |
| 580 | | if(m_buffer->document_count() > 0) |
| 581 | | m_folder.set_current_page(m_buffer->document_count() - 1); |
| 582 | | }*/ |
| 583 | 504 | |
| 584 | 505 | void Gobby::Window::on_obby_chat(obby::user& user, const Glib::ustring& message) |
| … |
… |
|
| 647 | 568 | } |
| 648 | 569 | |
| | 570 | void Gobby::Window::close_document(DocWindow& document) |
| | 571 | { |
| | 572 | if(m_buffer.get() != NULL) |
| | 573 | { |
| | 574 | // Send remove document request |
| | 575 | m_buffer->remove_document( |
| | 576 | document.get_document().get_document() |
| | 577 | ); |
| | 578 | } |
| | 579 | else |
| | 580 | { |
| | 581 | // Buffer does not exist: Maybe the connection has been lost |
| | 582 | // or something: Just remove the document from the folder. |
| | 583 | m_folder.remove_page(document); |
| | 584 | delete m_folder.get_tab_label(document); |
| | 585 | delete &document; |
| | 586 | |
| | 587 | // If there are no more documents, disable |
| | 588 | // save and close buttons in header |
| | 589 | if(!m_folder.get_n_pages() ) |
| | 590 | m_header.disable_document_actions(); |
| | 591 | } |
| | 592 | } |
| | 593 | |