Changeset 9a8cd27d463ae24ca3b212a3d0be3bef9bea422a

Show
Ignore:
Timestamp:
12/31/08 18:23:22 (4 years ago)
Author:
Armin Burgmeier <armin@…>
Parents:
215618cb3db4556e21f4040ae192e01f100fde03
Children:
c66abc31de85dace6d89600a4638b1993978f0e4
git-committer:
Armin Burgmeier <armin@arbur.net> / 2008-12-31T18:23:22Z+0100
Message:

Added begin-save-operation signal

2008-12-31 Armin Burgmeier <armin@…>

  • code/operations/operations.hpp:
  • code/operations/operations.cpp: Added a begin_save_operation signal, and added a boolean parameter to base operation's finished signal which indicates whether the operation was performed successfully or not. Removed the remove() function, and added finish() and fail() instead.
  • code/operations/operation-open.hpp: Derive from sigc::trackable.
  • code/operations/operation-save.hpp:
  • code/operations/operation-save.cpp: Added get_document(), get_start_time() and derive from sigc::trackable, adapt to finish() and fail().
  • code/operations/operation-new.cpp:
  • code/operations/operation-open.cpp:
  • code/operations/operation-delete.cpp: Adapt to finish() and fail().
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r215618c r9a8cd27  
     12008-12-31  Armin Burgmeier  <armin@arbur.net> 
     2 
     3        * code/operations/operations.hpp: 
     4        * code/operations/operations.cpp: Added a begin_save_operation signal, 
     5        and added a boolean parameter to base operation's finished signal 
     6        which indicates whether the operation was performed successfully or 
     7        not. Removed the remove() function, and added finish() and fail() 
     8        instead. 
     9 
     10        * code/operations/operation-open.hpp: Derive from sigc::trackable. 
     11 
     12        * code/operations/operation-save.hpp: 
     13        * code/operations/operation-save.cpp: Added get_document(), 
     14        get_start_time() and derive from sigc::trackable, adapt to finish() 
     15        and fail(). 
     16 
     17        * code/operations/operation-new.cpp: 
     18        * code/operations/operation-open.cpp: 
     19        * code/operations/operation-delete.cpp: Adapt to finish() and fail(). 
     20 
    1212008-12-30  Armin Burgmeier  <armin@arbur.net> 
    222 
  • code/operations/operation-delete.cpp

    r4d4ee96 r9a8cd27  
    6060                        m_name, error->message), 5); 
    6161 
    62         remove(); 
     62        fail(); 
    6363} 
    6464 
    6565void Gobby::OperationDelete::on_request_finished(InfcBrowserIter* iter) 
    6666{ 
    67         remove(); 
     67        finish(); 
    6868} 
  • code/operations/operation-new.cpp

    r4d4ee96 r9a8cd27  
    7777                        m_name, error->message), 5); 
    7878 
    79         remove(); 
     79        fail(); 
    8080} 
    8181 
    8282void Gobby::OperationNew::on_request_finished(InfcBrowserIter* iter) 
    8383{ 
    84         remove(); 
     84        finish(); 
    8585} 
  • code/operations/operation-open.cpp

    rcfae6a6 r9a8cd27  
    437437        get_info_storage().set_info(m_browser, iter, info); 
    438438 
    439         remove(); 
     439        finish(); 
    440440} 
    441441 
     
    447447                                         m_file->get_uri(), message), 5); 
    448448 
    449         remove(); 
    450 } 
     449        fail(); 
     450} 
  • code/operations/operation-open.hpp

    r4d4ee96 r9a8cd27  
    2929{ 
    3030 
    31 class OperationOpen: public Operations::Operation 
     31class OperationOpen: public Operations::Operation, public sigc::trackable 
    3232{ 
    3333public: 
  • code/operations/operation-save.cpp

    r215618c r9a8cd27  
    2929                                    const std::string& encoding, 
    3030                                    DocumentInfoStorage::EolStyle eol_style): 
    31         Operation(operations), m_document(&document), m_current_line_index(0), 
     31        Operation(operations), m_document(&document), 
     32        m_start_time(std::time(NULL)), m_current_line_index(0), 
    3233        m_iconv(encoding.c_str(), "UTF-8"), m_encoding(encoding), 
    3334        m_eol_style(eol_style), 
     
    158159                } 
    159160 
    160                 remove(); 
     161                finish(); 
    161162        } 
    162163        else 
     
    283284                                         m_file->get_uri(), message), 5); 
    284285 
    285         remove(); 
    286 } 
     286        fail(); 
     287} 
  • code/operations/operation-save.hpp

    r4d4ee96 r9a8cd27  
    2626#include <giomm/outputstream.h> 
    2727 
     28#include <ctime> 
     29 
    2830namespace Gobby 
    2931{ 
    3032 
    31 class OperationSave: public Operations::Operation 
     33class OperationSave: public Operations::Operation, public sigc::trackable 
    3234{ 
    3335public: 
     
    3840 
    3941        virtual ~OperationSave(); 
     42 
     43        // Note these can return NULL in case the document has been removed 
     44        // in the meanwhile. 
     45        DocWindow* get_document() { return m_document; } 
     46        const DocWindow* get_document() const { return m_document; } 
     47 
     48        std::time_t get_start_time() const { return m_start_time; } 
    4049 
    4150protected: 
     
    4958protected: 
    5059        DocWindow* m_document; 
     60        std::time_t m_start_time; 
    5161 
    5262        typedef std::pair<gchar*, std::size_t> Line; 
  • code/operations/operations.cpp

    r215618c r9a8cd27  
    4444} 
    4545 
    46 Gobby::Operations::Operation* 
     46Gobby::OperationNew* 
    4747Gobby::Operations::create_directory(InfcBrowser* browser, 
    4848                                    InfcBrowserIter* parent, 
     
    5656} 
    5757 
    58 Gobby::Operations::Operation* 
     58Gobby::OperationNew* 
    5959Gobby::Operations::create_document(InfcBrowser* browser, 
    6060                                   InfcBrowserIter* parent, 
     
    6868} 
    6969 
    70 Gobby::Operations::Operation* 
     70Gobby::OperationOpen* 
    7171Gobby::Operations::create_document(InfcBrowser* browser, 
    7272                                   InfcBrowserIter* parent, 
     
    8484} 
    8585 
    86 Gobby::Operations::Operation* 
     86Gobby::OperationSave* 
    8787Gobby::Operations::save_document(DocWindow& document, 
    8888                                 Folder& folder, 
     
    9191                                 DocumentInfoStorage::EolStyle eol_style) 
    9292{ 
     93        OperationSave* prev_op = get_save_operation_for_document(document); 
     94 
     95        // Cancel previous save operation: 
     96        if(prev_op != NULL) 
     97                fail_operation(prev_op); 
     98 
    9399        OperationSave* op = new OperationSave(*this, document, folder, uri, 
    94100                                              encoding, eol_style); 
    95101 
    96102        m_operations.insert(op); 
     103        m_signal_begin_save_operation.emit(op); 
    97104        return op; 
    98105} 
    99106 
    100 Gobby::Operations::Operation* 
     107Gobby::OperationDelete* 
    101108Gobby::Operations::delete_node(InfcBrowser* browser, 
    102109                               InfcBrowserIter* iter) 
     
    107114} 
    108115 
    109 void Gobby::Operations::remove_operation(Operation* operation) 
     116Gobby::OperationSave* 
     117Gobby::Operations::get_save_operation_for_document(DocWindow& document) 
     118{ 
     119        for(OperationSet::iterator iter = m_operations.begin(); 
     120            iter != m_operations.end(); ++ iter) 
     121        { 
     122                Operation* op = *iter; 
     123                OperationSave* save_op = dynamic_cast<OperationSave*>(op); 
     124                if(save_op != NULL) 
     125                { 
     126                        if(save_op->get_document() == &document) 
     127                                return save_op; 
     128                } 
     129        } 
     130 
     131        return NULL; 
     132} 
     133 
     134void Gobby::Operations::finish_operation(Operation* operation) 
    110135{ 
    111136        m_operations.erase(operation); 
     137        operation->signal_finished().emit(true); 
    112138        delete operation; 
    113139} 
     140 
     141void Gobby::Operations::fail_operation(Operation* operation) 
     142{ 
     143        m_operations.erase(operation); 
     144        operation->signal_finished().emit(false); 
     145        delete operation; 
     146} 
  • code/operations/operations.hpp

    r215618c r9a8cd27  
    3333{ 
    3434 
     35class OperationNew; 
     36class OperationOpen; 
     37class OperationSave; 
     38class OperationDelete; 
     39 
    3540class Operations: public sigc::trackable 
    3641{ 
     
    3944        { 
    4045        public: 
    41                 typedef sigc::signal<void> SignalFinished; 
     46                typedef sigc::signal<void, bool> SignalFinished; 
    4247 
    4348                Operation(Operations& operations): 
     
    5560                } 
    5661 
    57                 void remove() 
    58                 { 
    59                         m_signal_finished.emit(); 
    60                         m_operations.remove_operation(this); 
    61                 } 
    62  
    6362                SignalFinished signal_finished() const 
    6463                { 
    6564                        return m_signal_finished; 
    6665                } 
     66 
     67        protected: 
     68                void fail() 
     69                { 
     70                        m_operations.fail_operation(this); 
     71                } 
     72 
     73                void finish() 
     74                { 
     75                        m_operations.finish_operation(this); 
     76                } 
     77 
    6778        private: 
    6879                SignalFinished m_signal_finished; 
     
    7081        }; 
    7182 
     83        typedef sigc::signal<void, OperationSave*> SignalBeginSaveOperation; 
     84 
    7285        Operations(DocumentInfoStorage& info_storage, StatusBar& status_bar); 
    7386        ~Operations(); 
    7487 
    75         Operation* create_directory(InfcBrowser* browser, 
    76                                     InfcBrowserIter* parent, 
    77                                     const Glib::ustring& name); 
     88        OperationNew* create_directory(InfcBrowser* browser, 
     89                                       InfcBrowserIter* parent, 
     90                                       const Glib::ustring& name); 
    7891 
    79         Operation* create_document(InfcBrowser* browser, 
    80                                    InfcBrowserIter* parent, 
    81                                    const Glib::ustring& name); 
     92        OperationNew* create_document(InfcBrowser* browser, 
     93                                      InfcBrowserIter* parent, 
     94                                      const Glib::ustring& name); 
    8295 
    83         Operation* create_document(InfcBrowser* browser, 
    84                                    InfcBrowserIter* parent, 
    85                                    const Glib::ustring& name, 
    86                                    const Preferences& preferences, 
    87                                    const Glib::ustring& from_uri, 
    88                                    const char* encoding); 
     96        OperationOpen* create_document(InfcBrowser* browser, 
     97                                       InfcBrowserIter* parent, 
     98                                       const Glib::ustring& name, 
     99                                       const Preferences& preferences, 
     100                                       const Glib::ustring& from_uri, 
     101                                       const char* encoding); 
    89102 
    90         Operation* save_document(DocWindow& document, 
    91                                  Folder& folder, 
    92                                  const std::string& uri, 
    93                                  const std::string& encoding, 
    94                                  DocumentInfoStorage::EolStyle eol_style); 
     103        OperationSave* save_document(DocWindow& document, 
     104                                     Folder& folder, 
     105                                     const std::string& uri, 
     106                                     const std::string& encoding, 
     107                                     DocumentInfoStorage::EolStyle eol_style); 
    95108 
    96         Operation* delete_node(InfcBrowser* browser, 
    97                                InfcBrowserIter* iter); 
     109        OperationDelete* delete_node(InfcBrowser* browser, 
     110                                     InfcBrowserIter* iter); 
     111 
     112        OperationSave* get_save_operation_for_document(DocWindow& window); 
     113 
     114        SignalBeginSaveOperation signal_begin_save_operation() const 
     115        { 
     116                return m_signal_begin_save_operation; 
     117        } 
    98118 
    99119protected: 
    100         void remove_operation(Operation* operation); 
     120        void fail_operation(Operation* operation); 
     121        void finish_operation(Operation* operation); 
    101122 
    102123        DocumentInfoStorage& m_info_storage; 
     
    105126        typedef std::set<Operation*> OperationSet; 
    106127        OperationSet m_operations; 
     128 
     129        SignalBeginSaveOperation m_signal_begin_save_operation; 
    107130}; 
    108131