Changeset f5456c54572e967281cbc0c449855854cd046885
- Timestamp:
- 01/06/07 23:36:19 (6 years ago)
- Parents:
- e608789f1c38925d706e1b53f791db7997b99c22
- Children:
- 810831841edb9a9fea83b0eba21d712ec4d2ae2a
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:36:19Z+0000
- Files:
-
- 9 modified
-
TODO (modified) (3 diffs)
-
inc/document.hpp (modified) (6 diffs)
-
inc/folder.hpp (modified) (2 diffs)
-
inc/statusbar.hpp (modified) (3 diffs)
-
inc/window.hpp (modified) (3 diffs)
-
src/document.cpp (modified) (10 diffs)
-
src/folder.cpp (modified) (4 diffs)
-
src/statusbar.cpp (modified) (6 diffs)
-
src/window.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
TODO
r1434d77 rf5456c54 4 4 Serious: 5 5 * Opening large documents is _really_ slow on win32's timer implementation 6 * On connection loss: give a chance to save everything7 * Chat messages could be faked by using newline characters (split them into8 multiple single line messages)9 6 10 7 Important: … … 15 12 Normal: 16 13 * Menu to switch the syntax colouring scheme. 17 * Initialise size of paned widgets18 14 * Prompt before overwriting existing files when explicitly choosing path 19 15 * Chat command infrastructure (/me, /ignore) … … 30 26 * Default to save files to the location they were loaded from 31 27 (or save the directory of the last save) 32 -
inc/document.hpp
r3033eda rf5456c54 38 38 { 39 39 public: 40 typedef sigc::signal<void> signal_update_type; 40 typedef sigc::signal<void> signal_cursor_moved_type; 41 typedef sigc::signal<void> signal_changed_type; 41 42 42 43 Document(obby::document& doc, const Folder& folder); … … 54 55 unsigned int get_unsynced_changes_count() const; 55 56 57 /** Returns the current document revision. 58 */ 59 unsigned int get_revision() const; 60 56 61 /** Returns the currently selected Gtk::SourceLanguage. 57 62 */ … … 67 72 Glib::ustring get_content(); 68 73 69 /** Signal which will be emitted if the document gets updated in a way70 * that is interesting for the status bar.74 /** Signal which will be emitted if the document gets changed by a 75 * network event. 71 76 */ 72 signal_update_type update_event() const; 77 signal_changed_type changed_event() const; 78 79 /** Signal which will be emitted if the cursor's position changed. 80 */ 81 signal_cursor_moved_type cursor_moved_event() const; 73 82 74 83 /** Calls from the folder. … … 82 91 void on_obby_insert(const obby::insert_record& record); 83 92 void on_obby_delete(const obby::delete_record& record); 93 void on_obby_change(); 84 94 85 95 /** TextBuffer signal handlers. … … 97 107 const Gtk::TextBuffer::iterator& end); 98 108 99 /** Cursor position changed signal hanlder.109 /** Signal handler for the mark_set event to detect cursor movements. 100 110 */ 101 void on_ cursor_changed(const Gtk::TextBuffer::iterator& location,102 const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark);111 void on_mark_set(const Gtk::TextBuffer::iterator& location, 112 const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark); 103 113 104 114 /** Marks the given part of the text as written by <em>user</em>. … … 125 135 bool m_editing; 126 136 127 signal_update_type m_signal_update; 137 signal_cursor_moved_type m_signal_cursor_moved; 138 signal_changed_type m_signal_changed; 128 139 private: 129 140 /** Handler for update_user_colour(): It removes the given tag in -
inc/folder.hpp
rd4fb979 rf5456c54 42 42 { 43 43 public: 44 typedef sigc::signal<void, Document&> signal_document_update_type; 44 typedef sigc::signal<void, Document&> signal_document_cursor_moved_type; 45 typedef sigc::signal<void, Document&> signal_document_changed_type; 46 typedef sigc::signal<void, Document&> signal_tab_switched_type; 45 47 46 48 Folder(); … … 62 64 void obby_document_remove(obby::document& document); 63 65 64 signal_document_update_type document_update_event() const; 66 signal_document_cursor_moved_type document_cursor_moved_event() const; 67 signal_document_changed_type document_changed_event() const; 68 signal_tab_switched_type tab_switched_event() const; 65 69 66 70 protected: 67 71 // Signal handlers 68 72 virtual void on_switch_page(GtkNotebookPage* page, guint page_num); 69 virtual void on_document_update(Document& document);70 73 71 signal_document_update_type m_signal_document_update; 74 void on_document_cursor_moved(Document& document); 75 void on_document_changed(Document& document); 76 77 signal_document_cursor_moved_type m_signal_document_cursor_moved; 78 signal_document_changed_type m_signal_document_changed; 79 signal_tab_switched_type m_signal_tab_switched; 72 80 73 81 /** Signals whether the obby session is running. -
inc/statusbar.hpp
re51abc7 rf5456c54 26 26 #include <obby/document.hpp> 27 27 #include "document.hpp" 28 #include "folder.hpp" 28 29 29 30 namespace Gobby … … 33 34 { 34 35 public: 35 StatusBar( );36 StatusBar(const Folder& folder); 36 37 virtual ~StatusBar(); 37 38 38 void update(Document& document); 39 #ifdef WITH_GTKSOURCEVIEW 40 void update_language(Document& document); 41 #endif 42 void update_sync(Document& document); 43 void update_revision(Document& document); 44 void update_cursor(Document& document); 45 46 void update_all(Document& document); 39 47 40 48 // Calls from the window … … 50 58 Gtk::Label m_language; 51 59 Gtk::Label m_sync; 60 Gtk::Label m_revision; 52 61 Gtk::Label m_position; 53 62 }; -
inc/window.hpp
reaf8ea6 rf5456c54 58 58 59 59 void on_chat(const Glib::ustring& message); 60 void on_document_update(Document& document);61 60 62 61 // Obby signal handlers … … 82 81 Gtk::VBox m_mainbox; 83 82 Header m_header; 84 StatusBar m_statusbar;85 83 86 84 Gtk::VPaned m_mainpaned; … … 94 92 UserList m_userlist; 95 93 Chat m_chat; 94 StatusBar m_statusbar; 96 95 97 96 // obby -
src/document.cpp
re608789 rf5456c54 93 93 sigc::mem_fun(*this, &Document::on_erase_after), true); 94 94 buf->signal_mark_set().connect( 95 sigc::mem_fun(*this, &Document::on_ cursor_changed) );95 sigc::mem_fun(*this, &Document::on_mark_set) ); 96 96 97 97 // Obby signal handlers … … 100 100 doc.delete_event().before().connect( 101 101 sigc::mem_fun(*this, &Document::on_obby_delete) ); 102 doc.change_event().after().connect( 103 sigc::mem_fun(*this, &Document::on_obby_change) ); 102 104 103 105 // Set initial text … … 164 166 } 165 167 166 Gobby::Document::signal_update_type Gobby::Document::update_event() const 168 Gobby::Document::signal_cursor_moved_type 169 Gobby::Document::cursor_moved_event() const 170 { 171 return m_signal_cursor_moved; 172 } 173 174 Gobby::Document::signal_changed_type Gobby::Document::changed_event() const 175 { 176 return m_signal_changed; 177 } 178 179 /*Gobby::Document::signal_update_type Gobby::Document::update_event() const 167 180 { 168 181 return m_signal_update; 169 182 } 170 183 */ 171 184 void Gobby::Document::get_cursor_position(unsigned int& row, 172 185 unsigned int& col) 173 186 { 174 187 // Get insert mark 175 // TODO: buffer provides a method that returns the insert mark176 // directly.177 188 Glib::RefPtr<Gtk::TextBuffer::Mark> mark = 178 m_view.get_buffer()->get_ mark("insert");189 m_view.get_buffer()->get_insert(); 179 190 180 191 // Get corresponding iterator … … 199 210 // Return amount reported by document otherwise 200 211 return doc->unsynced_count(); 212 } 213 214 unsigned int Gobby::Document::get_revision() const 215 { 216 // Get revision from obby document 217 return m_doc.get_revision(); 201 218 } 202 219 … … 242 259 } 243 260 261 void Gobby::Document::on_obby_insert(const obby::insert_record& record) 262 { 263 if(m_editing) return; 264 m_editing = true; 265 266 // Get textbuffer 267 Glib::RefPtr<Gtk::TextBuffer> buffer = m_view.get_buffer(); 268 269 // Translate position to row/column 270 unsigned int row, col; 271 m_doc.position_to_coord(record.get_position(), row, col); 272 273 // Find obby::user that inserted the text 274 obby::user* user = m_doc.get_buffer().find_user(record.get_from() ); 275 assert(user != NULL); 276 277 // Insert text 278 Gtk::TextBuffer::iterator end = buffer->insert( 279 buffer->get_iter_at_line_index(row, col), 280 record.get_text() 281 ); 282 283 // Colourize new text 284 Gtk::TextBuffer::iterator begin = end; 285 begin.backward_chars(record.get_text().length() ); 286 update_user_colour(begin, end, *user); 287 288 m_view.queue_draw(); 289 m_editing = false; 290 } 291 292 void Gobby::Document::on_obby_delete(const obby::delete_record& record) 293 { 294 if(m_editing) return; 295 m_editing = true; 296 297 Glib::RefPtr<Gtk::TextBuffer> buffer = m_view.get_buffer(); 298 299 unsigned int brow, bcol, erow, ecol; 300 m_doc.position_to_coord(record.get_begin(), brow, bcol); 301 m_doc.position_to_coord(record.get_end(), erow, ecol); 302 303 buffer->erase( 304 buffer->get_iter_at_line_index(brow, bcol), 305 buffer->get_iter_at_line_index(erow, ecol) 306 ); 307 m_editing = false; 308 } 309 310 void Gobby::Document::on_obby_change() 311 { 312 // Document changed 313 m_signal_changed.emit(); 314 } 315 244 316 void Gobby::Document::on_insert_before(const Gtk::TextBuffer::iterator& begin, 245 317 const Glib::ustring& text, … … 248 320 if(m_editing) return; 249 321 m_editing = true; 250 322 251 323 m_doc.insert( 252 324 m_doc.coord_to_position( … … 280 352 } 281 353 282 void Gobby::Document::on_obby_insert(const obby::insert_record& record)283 {284 if(m_editing) return;285 m_editing = true;286 287 // Get textbuffer288 Glib::RefPtr<Gtk::TextBuffer> buffer = m_view.get_buffer();289 290 // Translate position to row/column291 unsigned int row, col;292 m_doc.position_to_coord(record.get_position(), row, col);293 294 // Find obby::user that inserted the text295 obby::user* user = m_doc.get_buffer().find_user(record.get_from() );296 assert(user != NULL);297 298 // Insert text299 Gtk::TextBuffer::iterator end = buffer->insert(300 buffer->get_iter_at_line_index(row, col),301 record.get_text()302 );303 304 // Colourize new text305 Gtk::TextBuffer::iterator begin = end;306 begin.backward_chars(record.get_text().length() );307 update_user_colour(begin, end, *user);308 309 m_view.queue_draw();310 m_editing = false;311 }312 313 void Gobby::Document::on_obby_delete(const obby::delete_record& record)314 {315 if(m_editing) return;316 m_editing = true;317 318 Glib::RefPtr<Gtk::TextBuffer> buffer = m_view.get_buffer();319 320 unsigned int brow, bcol, erow, ecol;321 m_doc.position_to_coord(record.get_begin(), brow, bcol);322 m_doc.position_to_coord(record.get_end(), erow, ecol);323 324 buffer->erase(325 buffer->get_iter_at_line_index(brow, bcol),326 buffer->get_iter_at_line_index(erow, ecol)327 );328 m_editing = false;329 }330 331 354 void Gobby::Document::on_insert_after(const Gtk::TextBuffer::iterator& end, 332 355 const Glib::ustring& text, … … 336 359 if(!m_editing) 337 360 { 338 // TODO: Find a better solution to access the local user object. 339 /*obby::client_document* client_doc = 340 dynamic_cast<obby::client_document*>(&m_doc); 341 obby::host_document* host_doc = 342 dynamic_cast<obby::host_document*>(&m_doc); 343 344 const obby::user* user = NULL; 345 if(client_doc != NULL) 346 user = &client_doc->get_buffer().get_self(); 347 if(host_doc != NULL) 348 user = &host_doc->get_buffer().get_self();*/ 349 // const obby::user& user = reinterpret_cast<const obby::local_buffer&>(m_doc.get_buffer() ).get_self(); 350 // dynamic_cast suckt 361 // Find the user that has written this text 351 362 const obby::user& user = 352 363 dynamic_cast<const obby::local_buffer&>( … … 362 373 } 363 374 364 // Document changed: Update statusbar365 m_signal_ update.emit();375 // Cursor position has changed 376 m_signal_cursor_moved.emit(); 366 377 } 367 378 … … 369 380 const Gtk::TextBuffer::iterator& end) 370 381 { 371 // Document changed: Update statusbar372 m_signal_ update.emit();373 } 374 375 void Gobby::Document::on_ cursor_changed(382 // Cursor position may have changed 383 m_signal_cursor_moved.emit(); 384 } 385 386 void Gobby::Document::on_mark_set( 376 387 const Gtk::TextBuffer::iterator& location, 377 388 const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark 378 389 ) 379 390 { 380 // Insert mark changed position: Update status bar 381 // TODO: Build separate cursor changed signal? 382 if(mark->get_name() == "insert") 383 m_signal_update.emit(); 391 // Insert mark changed position: Cursor position change 392 if(mark == m_view.get_buffer()->get_insert() )//->get_name() == "insert") 393 m_signal_cursor_moved.emit(); 384 394 } 385 395 -
src/folder.cpp
r3033eda rf5456c54 94 94 // Watch update signal to emit document_updated signal if a document 95 95 // has been updated. 96 new_doc-> update_event().connect(96 new_doc->cursor_moved_event().connect( 97 97 sigc::bind( 98 sigc::mem_fun(*this, &Folder::on_document_update), 98 sigc::mem_fun(*this, &Folder::on_document_cursor_moved), 99 sigc::ref(*new_doc) 100 ) 101 ); 102 103 new_doc->changed_event().connect( 104 sigc::bind( 105 sigc::mem_fun(*this, &Folder::on_document_changed), 99 106 sigc::ref(*new_doc) 100 107 ) … … 124 131 } 125 132 126 Gobby::Folder::signal_document_update_type 127 Gobby::Folder::document_update_event() const 133 // Signals 134 Gobby::Folder::signal_document_cursor_moved_type 135 Gobby::Folder::document_cursor_moved_event() const 128 136 { 129 return m_signal_document_update; 137 return m_signal_document_cursor_moved; 138 } 139 140 Gobby::Folder::signal_document_changed_type 141 Gobby::Folder::document_changed_event() const 142 { 143 return m_signal_document_changed; 144 } 145 146 Gobby::Folder::signal_tab_switched_type 147 Gobby::Folder::tab_switched_event() const 148 { 149 return m_signal_tab_switched; 130 150 } 131 151 … … 143 163 { 144 164 // Another document has been selected: Update statusbar 145 m_signal_ document_update.emit(146 *static_cast<Document*>(get_nth_page(page_num) )165 m_signal_tab_switched.emit( 166 *static_cast<Document*>(get_nth_page(page_num) ) 147 167 ); 148 168 } … … 151 171 } 152 172 153 void Gobby::Folder::on_document_ update(Document& document)173 void Gobby::Folder::on_document_cursor_moved(Document& document) 154 174 { 155 175 // Update in the currently visible document? Update statusbar. 156 176 if(get_current_page() == page_num(document) ) 157 m_signal_document_ update.emit(document);177 m_signal_document_cursor_moved.emit(document); 158 178 } 159 179 180 void Gobby::Folder::on_document_changed(Document& document) 181 { 182 // Update in the currently visible document? Update statusbar. 183 if(get_current_page() == page_num(document) ) 184 m_signal_document_changed.emit(document); 185 } 186 -
src/statusbar.cpp
re51abc7 rf5456c54 18 18 19 19 #include <sstream> 20 #include <obby/buffer.hpp> 20 21 #include "common.hpp" 21 22 #include "statusbar.hpp" 22 23 23 Gobby::StatusBar::StatusBar( )24 Gobby::StatusBar::StatusBar(const Folder& folder) 24 25 : Frame(), 25 26 m_language("", Gtk::ALIGN_LEFT), 26 27 m_sync("", Gtk::ALIGN_LEFT), 28 m_revision("", Gtk::ALIGN_LEFT), 27 29 m_position("", Gtk::ALIGN_LEFT) 28 30 { 29 31 m_box.pack_start(m_language); 30 32 m_box.pack_start(m_sync); 33 m_box.pack_start(m_revision); 31 34 m_box.pack_start(m_position); 32 35 m_box.set_homogeneous(true); … … 34 37 add(m_box); 35 38 set_shadow_type(Gtk::SHADOW_OUT); 39 40 folder.document_cursor_moved_event().connect( 41 sigc::mem_fun(*this, &StatusBar::update_cursor) ); 42 folder.document_changed_event().connect( 43 sigc::mem_fun(*this, &StatusBar::update_all) ); 44 folder.tab_switched_event().connect( 45 sigc::mem_fun(*this, &StatusBar::update_all) ); 36 46 } 37 47 … … 40 50 } 41 51 42 void Gobby::StatusBar::update(Document& document) 52 #ifdef WITH_GTKSOURCEVIEW 53 void Gobby::StatusBar::update_language(Document& document) 43 54 { 44 // Unsynced changes45 unsigned int unsynced_count = document.get_unsynced_changes_count();46 47 /* std::stringstream sync_str;48 if(!unsynced_count)49 sync_str << _("In sync");50 else51 sync_str << unsynced_count << _(" unsynced change(s)");*/52 53 // Position54 unsigned int row, col;55 document.get_cursor_position(row, col);56 ++ row; ++ col;57 58 std::stringstream pos_str;59 pos_str << _("Line: ") << row << _(" Column: ") << col;60 61 #ifdef WITH_GTKSOURCEVIEW62 55 // Selected language 63 56 if(document.get_language() ) … … 68 61 else 69 62 m_language.set_text(_("No language selected") ); 63 } 70 64 #endif 71 // m_sync.set_text(sync_str.str() ); 65 66 void Gobby::StatusBar::update_sync(Document& document) 67 { 68 unsigned int unsynced_count = document.get_unsynced_changes_count(); 69 if(unsynced_count) 70 { 71 std::stringstream sync_str; 72 sync_str << unsynced_count << _(" unsynced change(s)"); 73 m_sync.set_text(sync_str.str() ); 74 } 75 else 76 { 77 m_sync.set_text(_("In sync") ); 78 } 79 } 80 81 void Gobby::StatusBar::update_revision(Document& document) 82 { 83 std::stringstream rev_str; 84 rev_str << _("Revision: ") << document.get_revision(); 85 m_revision.set_text(rev_str.str() ); 86 } 87 88 void Gobby::StatusBar::update_cursor(Document& document) 89 { 90 unsigned int row, col; 91 document.get_cursor_position(row, col); 92 ++ row; ++ col; 93 94 std::stringstream pos_str; 95 pos_str << _("Line: ") << row << _(" Column: ") << col; 72 96 m_position.set_text(pos_str.str() ); 97 } 98 99 void Gobby::StatusBar::update_all(Document& document) 100 { 101 #ifdef WITH_GTKSOURCEVIEW 102 update_language(document); 103 #endif 104 update_sync(document); 105 update_revision(document); 106 update_cursor(document); 73 107 } 74 108 … … 80 114 { 81 115 m_language.set_text(""); 116 m_sync.set_text(""); 117 m_revision.set_text(""); 82 118 m_position.set_text(""); 83 m_sync.set_text("");84 119 } 85 120 … … 98 133 void Gobby::StatusBar::obby_document_remove(obby::document& document) 99 134 { 135 // Last document that is closed? 136 if(document.get_buffer().document_count() == 1) 137 { 138 // Clear statusbar 139 obby_end(); 140 } 100 141 } 101 142 -
src/window.cpp
re608789 rf5456c54 43 43 : Gtk::Window(Gtk::WINDOW_TOPLEVEL), 44 44 m_config(Glib::get_home_dir() + "/.gobby/config.xml"), m_buffer(NULL), 45 m_running(false) 45 m_running(false), m_statusbar(m_folder) 46 46 { 47 47 m_header.session_create_event().connect( … … 70 70 m_chat.chat_event().connect( 71 71 sigc::mem_fun(*this, &Window::on_chat) ); 72 m_folder.document_update_event().connect(73 sigc::mem_fun(*this, &Window::on_document_update) );74 72 75 73 m_frame_chat.set_shadow_type(Gtk::SHADOW_IN); … … 403 401 } 404 402 405 void Gobby::Window::on_document_update(Document& document)403 /*void Gobby::Window::on_document_update(Document& document) 406 404 { 407 405 // Update statusbar 408 406 m_statusbar.update(document); 409 } 407 }*/ 410 408 411 409 void Gobby::Window::on_obby_login_failed(const std::string& reason)
