Changeset f5456c54572e967281cbc0c449855854cd046885

Show
Ignore:
Timestamp:
01/06/07 23:36:19 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
e608789f1c38925d706e1b53f791db7997b99c22
Children:
810831841edb9a9fea83b0eba21d712ec4d2ae2a
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:36:19Z+0000
Message:

[project @ Show revision and sync state in statusbar [fixes #13]]

Original author: Armin Burgmeier <armin@…>
Date: 2005-06-01 18:25:31+00:00

Files:
9 modified

Legend:

Unmodified
Added
Removed
  • TODO

    r1434d77 rf5456c54  
    44Serious: 
    55 * Opening large documents is _really_ slow on win32's timer implementation 
    6  * On connection loss: give a chance to save everything 
    7  * Chat messages could be faked by using newline characters (split them into 
    8    multiple single line messages) 
    96 
    107Important: 
     
    1512Normal: 
    1613 * Menu to switch the syntax colouring scheme. 
    17  * Initialise size of paned widgets 
    1814 * Prompt before overwriting existing files when explicitly choosing path 
    1915 * Chat command infrastructure (/me, /ignore) 
     
    3026 * Default to save files to the location they were loaded from 
    3127   (or save the directory of the last save) 
    32  
  • inc/document.hpp

    r3033eda rf5456c54  
    3838{ 
    3939public: 
    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; 
    4142 
    4243        Document(obby::document& doc, const Folder& folder); 
     
    5455        unsigned int get_unsynced_changes_count() const; 
    5556 
     57        /** Returns the current document revision. 
     58         */ 
     59        unsigned int get_revision() const; 
     60 
    5661        /** Returns the currently selected Gtk::SourceLanguage. 
    5762         */ 
     
    6772        Glib::ustring get_content(); 
    6873 
    69         /** Signal which will be emitted if the document gets updated in a way 
    70          * that is interesting for the status bar. 
     74        /** Signal which will be emitted if the document gets changed by a 
     75         * network event. 
    7176         */ 
    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; 
    7382 
    7483        /** Calls from the folder. 
     
    8291        void on_obby_insert(const obby::insert_record& record); 
    8392        void on_obby_delete(const obby::delete_record& record); 
     93        void on_obby_change(); 
    8494 
    8595        /** TextBuffer signal handlers. 
     
    97107                            const Gtk::TextBuffer::iterator& end); 
    98108 
    99         /** Cursor position changed signal hanlder. 
     109        /** Signal handler for the mark_set event to detect cursor movements. 
    100110         */ 
    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); 
    103113 
    104114        /** Marks the given part of the text as written by <em>user</em>. 
     
    125135        bool m_editing; 
    126136         
    127         signal_update_type m_signal_update; 
     137        signal_cursor_moved_type m_signal_cursor_moved; 
     138        signal_changed_type m_signal_changed; 
    128139private: 
    129140        /** Handler for update_user_colour(): It removes the given tag in 
  • inc/folder.hpp

    rd4fb979 rf5456c54  
    4242{ 
    4343public: 
    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; 
    4547 
    4648        Folder(); 
     
    6264        void obby_document_remove(obby::document& document); 
    6365 
    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; 
    6569 
    6670protected: 
    6771        // Signal handlers 
    6872        virtual void on_switch_page(GtkNotebookPage* page, guint page_num); 
    69         virtual void on_document_update(Document& document); 
    7073 
    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; 
    7280 
    7381        /** Signals whether the obby session is running. 
  • inc/statusbar.hpp

    re51abc7 rf5456c54  
    2626#include <obby/document.hpp> 
    2727#include "document.hpp" 
     28#include "folder.hpp" 
    2829 
    2930namespace Gobby 
     
    3334{ 
    3435public: 
    35         StatusBar(); 
     36        StatusBar(const Folder& folder); 
    3637        virtual ~StatusBar(); 
    3738 
    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); 
    3947 
    4048        // Calls from the window 
     
    5058        Gtk::Label m_language; 
    5159        Gtk::Label m_sync; 
     60        Gtk::Label m_revision; 
    5261        Gtk::Label m_position; 
    5362}; 
  • inc/window.hpp

    reaf8ea6 rf5456c54  
    5858 
    5959        void on_chat(const Glib::ustring& message); 
    60         void on_document_update(Document& document); 
    6160 
    6261        // Obby signal handlers 
     
    8281        Gtk::VBox m_mainbox; 
    8382        Header m_header; 
    84         StatusBar m_statusbar; 
    8583 
    8684        Gtk::VPaned m_mainpaned; 
     
    9492        UserList m_userlist; 
    9593        Chat m_chat; 
     94        StatusBar m_statusbar; 
    9695 
    9796        // obby 
  • src/document.cpp

    re608789 rf5456c54  
    9393                sigc::mem_fun(*this, &Document::on_erase_after), true); 
    9494        buf->signal_mark_set().connect( 
    95                 sigc::mem_fun(*this, &Document::on_cursor_changed) ); 
     95                sigc::mem_fun(*this, &Document::on_mark_set) ); 
    9696 
    9797        // Obby signal handlers 
     
    100100        doc.delete_event().before().connect( 
    101101                sigc::mem_fun(*this, &Document::on_obby_delete) ); 
     102        doc.change_event().after().connect( 
     103                sigc::mem_fun(*this, &Document::on_obby_change) ); 
    102104 
    103105        // Set initial text 
     
    164166} 
    165167 
    166 Gobby::Document::signal_update_type Gobby::Document::update_event() const 
     168Gobby::Document::signal_cursor_moved_type 
     169Gobby::Document::cursor_moved_event() const 
     170{ 
     171        return m_signal_cursor_moved; 
     172} 
     173 
     174Gobby::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 
    167180{ 
    168181        return m_signal_update; 
    169182} 
    170          
     183*/ 
    171184void Gobby::Document::get_cursor_position(unsigned int& row, 
    172185                                          unsigned int& col) 
    173186{ 
    174187        // Get insert mark 
    175         // TODO: buffer provides a method that returns the insert mark 
    176         // directly. 
    177188        Glib::RefPtr<Gtk::TextBuffer::Mark> mark = 
    178                 m_view.get_buffer()->get_mark("insert"); 
     189                m_view.get_buffer()->get_insert(); 
    179190 
    180191        // Get corresponding iterator 
     
    199210        // Return amount reported by document otherwise 
    200211        return doc->unsynced_count(); 
     212} 
     213 
     214unsigned int Gobby::Document::get_revision() const 
     215{ 
     216        // Get revision from obby document 
     217        return m_doc.get_revision(); 
    201218} 
    202219 
     
    242259} 
    243260 
     261void 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 
     292void 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 
     310void Gobby::Document::on_obby_change() 
     311{ 
     312        // Document changed 
     313        m_signal_changed.emit(); 
     314} 
     315 
    244316void Gobby::Document::on_insert_before(const Gtk::TextBuffer::iterator& begin, 
    245317                                       const Glib::ustring& text, 
     
    248320        if(m_editing) return; 
    249321        m_editing = true; 
    250          
     322 
    251323        m_doc.insert( 
    252324                m_doc.coord_to_position( 
     
    280352} 
    281353 
    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 textbuffer 
    288         Glib::RefPtr<Gtk::TextBuffer> buffer = m_view.get_buffer(); 
    289  
    290         // Translate position to row/column 
    291         unsigned int row, col; 
    292         m_doc.position_to_coord(record.get_position(), row, col); 
    293  
    294         // Find obby::user that inserted the text 
    295         obby::user* user = m_doc.get_buffer().find_user(record.get_from() ); 
    296         assert(user != NULL); 
    297  
    298         // Insert text 
    299         Gtk::TextBuffer::iterator end = buffer->insert( 
    300                 buffer->get_iter_at_line_index(row, col), 
    301                 record.get_text() 
    302         ); 
    303  
    304         // Colourize new text 
    305         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  
    331354void Gobby::Document::on_insert_after(const Gtk::TextBuffer::iterator& end, 
    332355                                      const Glib::ustring& text, 
     
    336359        if(!m_editing) 
    337360        { 
    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 
    351362                const obby::user& user = 
    352363                        dynamic_cast<const obby::local_buffer&>( 
     
    362373        } 
    363374 
    364         // Document changed: Update statusbar 
    365         m_signal_update.emit(); 
     375        // Cursor position has changed 
     376        m_signal_cursor_moved.emit(); 
    366377} 
    367378 
     
    369380                                     const Gtk::TextBuffer::iterator& end) 
    370381{ 
    371         // Document changed: Update statusbar 
    372         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 
     386void Gobby::Document::on_mark_set( 
    376387        const Gtk::TextBuffer::iterator& location, 
    377388        const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark 
    378389) 
    379390{ 
    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(); 
    384394} 
    385395 
  • src/folder.cpp

    r3033eda rf5456c54  
    9494        // Watch update signal to emit document_updated signal if a document 
    9595        // has been updated. 
    96         new_doc->update_event().connect( 
     96        new_doc->cursor_moved_event().connect( 
    9797                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), 
    99106                        sigc::ref(*new_doc) 
    100107                ) 
     
    124131} 
    125132 
    126 Gobby::Folder::signal_document_update_type 
    127 Gobby::Folder::document_update_event() const 
     133// Signals 
     134Gobby::Folder::signal_document_cursor_moved_type 
     135Gobby::Folder::document_cursor_moved_event() const 
    128136{ 
    129         return m_signal_document_update; 
     137        return m_signal_document_cursor_moved; 
     138} 
     139 
     140Gobby::Folder::signal_document_changed_type 
     141Gobby::Folder::document_changed_event() const 
     142{ 
     143        return m_signal_document_changed; 
     144} 
     145 
     146Gobby::Folder::signal_tab_switched_type 
     147Gobby::Folder::tab_switched_event() const 
     148{ 
     149        return m_signal_tab_switched; 
    130150} 
    131151 
     
    143163        { 
    144164                // 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) ) 
    147167                ); 
    148168        } 
     
    151171} 
    152172 
    153 void Gobby::Folder::on_document_update(Document& document) 
     173void Gobby::Folder::on_document_cursor_moved(Document& document) 
    154174{ 
    155175        // Update in the currently visible document? Update statusbar. 
    156176        if(get_current_page() == page_num(document) ) 
    157                 m_signal_document_update.emit(document); 
     177                m_signal_document_cursor_moved.emit(document); 
    158178} 
    159179 
     180void 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  
    1818 
    1919#include <sstream> 
     20#include <obby/buffer.hpp> 
    2021#include "common.hpp" 
    2122#include "statusbar.hpp" 
    2223 
    23 Gobby::StatusBar::StatusBar() 
     24Gobby::StatusBar::StatusBar(const Folder& folder) 
    2425 : Frame(),  
    2526   m_language("", Gtk::ALIGN_LEFT), 
    2627   m_sync("", Gtk::ALIGN_LEFT), 
     28   m_revision("", Gtk::ALIGN_LEFT), 
    2729   m_position("", Gtk::ALIGN_LEFT) 
    2830{ 
    2931        m_box.pack_start(m_language); 
    3032        m_box.pack_start(m_sync); 
     33        m_box.pack_start(m_revision); 
    3134        m_box.pack_start(m_position); 
    3235        m_box.set_homogeneous(true); 
     
    3437        add(m_box); 
    3538        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) ); 
    3646} 
    3747 
     
    4050} 
    4151 
    42 void Gobby::StatusBar::update(Document& document) 
     52#ifdef WITH_GTKSOURCEVIEW 
     53void Gobby::StatusBar::update_language(Document& document) 
    4354{ 
    44         // Unsynced changes 
    45         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         else 
    51                 sync_str << unsynced_count << _(" unsynced change(s)");*/ 
    52          
    53         // Position 
    54         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_GTKSOURCEVIEW 
    6255        // Selected language 
    6356        if(document.get_language() ) 
     
    6861        else 
    6962                m_language.set_text(_("No language selected") ); 
     63} 
    7064#endif 
    71 //      m_sync.set_text(sync_str.str() ); 
     65 
     66void 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 
     81void 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 
     88void 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; 
    7296        m_position.set_text(pos_str.str() ); 
     97} 
     98 
     99void 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); 
    73107} 
    74108 
     
    80114{ 
    81115        m_language.set_text(""); 
     116        m_sync.set_text(""); 
     117        m_revision.set_text(""); 
    82118        m_position.set_text(""); 
    83         m_sync.set_text(""); 
    84119} 
    85120 
     
    98133void Gobby::StatusBar::obby_document_remove(obby::document& document) 
    99134{ 
     135        // Last document that is closed? 
     136        if(document.get_buffer().document_count() == 1) 
     137        { 
     138                // Clear statusbar 
     139                obby_end(); 
     140        } 
    100141} 
    101142 
  • src/window.cpp

    re608789 rf5456c54  
    4343 : Gtk::Window(Gtk::WINDOW_TOPLEVEL),  
    4444   m_config(Glib::get_home_dir() + "/.gobby/config.xml"), m_buffer(NULL), 
    45    m_running(false) 
     45   m_running(false), m_statusbar(m_folder) 
    4646{ 
    4747        m_header.session_create_event().connect( 
     
    7070        m_chat.chat_event().connect( 
    7171                sigc::mem_fun(*this, &Window::on_chat) ); 
    72         m_folder.document_update_event().connect( 
    73                 sigc::mem_fun(*this, &Window::on_document_update) ); 
    7472 
    7573        m_frame_chat.set_shadow_type(Gtk::SHADOW_IN); 
     
    403401} 
    404402 
    405 void Gobby::Window::on_document_update(Document& document) 
     403/*void Gobby::Window::on_document_update(Document& document) 
    406404{ 
    407405        // Update statusbar 
    408406        m_statusbar.update(document); 
    409 } 
     407}*/ 
    410408 
    411409void Gobby::Window::on_obby_login_failed(const std::string& reason)