Changeset 9a8cd27d463ae24ca3b212a3d0be3bef9bea422a
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r215618c
|
r9a8cd27
|
|
| | 1 | 2008-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 | |
| 1 | 21 | 2008-12-30 Armin Burgmeier <armin@arbur.net> |
| 2 | 22 | |
-
|
r4d4ee96
|
r9a8cd27
|
|
| 60 | 60 | m_name, error->message), 5); |
| 61 | 61 | |
| 62 | | remove(); |
| | 62 | fail(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | void Gobby::OperationDelete::on_request_finished(InfcBrowserIter* iter) |
| 66 | 66 | { |
| 67 | | remove(); |
| | 67 | finish(); |
| 68 | 68 | } |
-
|
r4d4ee96
|
r9a8cd27
|
|
| 77 | 77 | m_name, error->message), 5); |
| 78 | 78 | |
| 79 | | remove(); |
| | 79 | fail(); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | void Gobby::OperationNew::on_request_finished(InfcBrowserIter* iter) |
| 83 | 83 | { |
| 84 | | remove(); |
| | 84 | finish(); |
| 85 | 85 | } |
-
|
rcfae6a6
|
r9a8cd27
|
|
| 437 | 437 | get_info_storage().set_info(m_browser, iter, info); |
| 438 | 438 | |
| 439 | | remove(); |
| | 439 | finish(); |
| 440 | 440 | } |
| 441 | 441 | |
| … |
… |
|
| 447 | 447 | m_file->get_uri(), message), 5); |
| 448 | 448 | |
| 449 | | remove(); |
| 450 | | } |
| | 449 | fail(); |
| | 450 | } |
-
|
r4d4ee96
|
r9a8cd27
|
|
| 29 | 29 | { |
| 30 | 30 | |
| 31 | | class OperationOpen: public Operations::Operation |
| | 31 | class OperationOpen: public Operations::Operation, public sigc::trackable |
| 32 | 32 | { |
| 33 | 33 | public: |
-
|
r215618c
|
r9a8cd27
|
|
| 29 | 29 | const std::string& encoding, |
| 30 | 30 | 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), |
| 32 | 33 | m_iconv(encoding.c_str(), "UTF-8"), m_encoding(encoding), |
| 33 | 34 | m_eol_style(eol_style), |
| … |
… |
|
| 158 | 159 | } |
| 159 | 160 | |
| 160 | | remove(); |
| | 161 | finish(); |
| 161 | 162 | } |
| 162 | 163 | else |
| … |
… |
|
| 283 | 284 | m_file->get_uri(), message), 5); |
| 284 | 285 | |
| 285 | | remove(); |
| 286 | | } |
| | 286 | fail(); |
| | 287 | } |
-
|
r4d4ee96
|
r9a8cd27
|
|
| 26 | 26 | #include <giomm/outputstream.h> |
| 27 | 27 | |
| | 28 | #include <ctime> |
| | 29 | |
| 28 | 30 | namespace Gobby |
| 29 | 31 | { |
| 30 | 32 | |
| 31 | | class OperationSave: public Operations::Operation |
| | 33 | class OperationSave: public Operations::Operation, public sigc::trackable |
| 32 | 34 | { |
| 33 | 35 | public: |
| … |
… |
|
| 38 | 40 | |
| 39 | 41 | 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; } |
| 40 | 49 | |
| 41 | 50 | protected: |
| … |
… |
|
| 49 | 58 | protected: |
| 50 | 59 | DocWindow* m_document; |
| | 60 | std::time_t m_start_time; |
| 51 | 61 | |
| 52 | 62 | typedef std::pair<gchar*, std::size_t> Line; |
-
|
r215618c
|
r9a8cd27
|
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | | Gobby::Operations::Operation* |
| | 46 | Gobby::OperationNew* |
| 47 | 47 | Gobby::Operations::create_directory(InfcBrowser* browser, |
| 48 | 48 | InfcBrowserIter* parent, |
| … |
… |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | | Gobby::Operations::Operation* |
| | 58 | Gobby::OperationNew* |
| 59 | 59 | Gobby::Operations::create_document(InfcBrowser* browser, |
| 60 | 60 | InfcBrowserIter* parent, |
| … |
… |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | | Gobby::Operations::Operation* |
| | 70 | Gobby::OperationOpen* |
| 71 | 71 | Gobby::Operations::create_document(InfcBrowser* browser, |
| 72 | 72 | InfcBrowserIter* parent, |
| … |
… |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | | Gobby::Operations::Operation* |
| | 86 | Gobby::OperationSave* |
| 87 | 87 | Gobby::Operations::save_document(DocWindow& document, |
| 88 | 88 | Folder& folder, |
| … |
… |
|
| 91 | 91 | DocumentInfoStorage::EolStyle eol_style) |
| 92 | 92 | { |
| | 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 | |
| 93 | 99 | OperationSave* op = new OperationSave(*this, document, folder, uri, |
| 94 | 100 | encoding, eol_style); |
| 95 | 101 | |
| 96 | 102 | m_operations.insert(op); |
| | 103 | m_signal_begin_save_operation.emit(op); |
| 97 | 104 | return op; |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | | Gobby::Operations::Operation* |
| | 107 | Gobby::OperationDelete* |
| 101 | 108 | Gobby::Operations::delete_node(InfcBrowser* browser, |
| 102 | 109 | InfcBrowserIter* iter) |
| … |
… |
|
| 107 | 114 | } |
| 108 | 115 | |
| 109 | | void Gobby::Operations::remove_operation(Operation* operation) |
| | 116 | Gobby::OperationSave* |
| | 117 | Gobby::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 | |
| | 134 | void Gobby::Operations::finish_operation(Operation* operation) |
| 110 | 135 | { |
| 111 | 136 | m_operations.erase(operation); |
| | 137 | operation->signal_finished().emit(true); |
| 112 | 138 | delete operation; |
| 113 | 139 | } |
| | 140 | |
| | 141 | void Gobby::Operations::fail_operation(Operation* operation) |
| | 142 | { |
| | 143 | m_operations.erase(operation); |
| | 144 | operation->signal_finished().emit(false); |
| | 145 | delete operation; |
| | 146 | } |
-
|
r215618c
|
r9a8cd27
|
|
| 33 | 33 | { |
| 34 | 34 | |
| | 35 | class OperationNew; |
| | 36 | class OperationOpen; |
| | 37 | class OperationSave; |
| | 38 | class OperationDelete; |
| | 39 | |
| 35 | 40 | class Operations: public sigc::trackable |
| 36 | 41 | { |
| … |
… |
|
| 39 | 44 | { |
| 40 | 45 | public: |
| 41 | | typedef sigc::signal<void> SignalFinished; |
| | 46 | typedef sigc::signal<void, bool> SignalFinished; |
| 42 | 47 | |
| 43 | 48 | Operation(Operations& operations): |
| … |
… |
|
| 55 | 60 | } |
| 56 | 61 | |
| 57 | | void remove() |
| 58 | | { |
| 59 | | m_signal_finished.emit(); |
| 60 | | m_operations.remove_operation(this); |
| 61 | | } |
| 62 | | |
| 63 | 62 | SignalFinished signal_finished() const |
| 64 | 63 | { |
| 65 | 64 | return m_signal_finished; |
| 66 | 65 | } |
| | 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 | |
| 67 | 78 | private: |
| 68 | 79 | SignalFinished m_signal_finished; |
| … |
… |
|
| 70 | 81 | }; |
| 71 | 82 | |
| | 83 | typedef sigc::signal<void, OperationSave*> SignalBeginSaveOperation; |
| | 84 | |
| 72 | 85 | Operations(DocumentInfoStorage& info_storage, StatusBar& status_bar); |
| 73 | 86 | ~Operations(); |
| 74 | 87 | |
| 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); |
| 78 | 91 | |
| 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); |
| 82 | 95 | |
| 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); |
| 89 | 102 | |
| 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); |
| 95 | 108 | |
| 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 | } |
| 98 | 118 | |
| 99 | 119 | protected: |
| 100 | | void remove_operation(Operation* operation); |
| | 120 | void fail_operation(Operation* operation); |
| | 121 | void finish_operation(Operation* operation); |
| 101 | 122 | |
| 102 | 123 | DocumentInfoStorage& m_info_storage; |
| … |
… |
|
| 105 | 126 | typedef std::set<Operation*> OperationSet; |
| 106 | 127 | OperationSet m_operations; |
| | 128 | |
| | 129 | SignalBeginSaveOperation m_signal_begin_save_operation; |
| 107 | 130 | }; |
| 108 | 131 | |