| 1 |
#pragma once |
| 2 |
#include "util/pool_goto_provider.hpp" |
| 3 |
#include "util/item_set.hpp" |
| 4 |
#include "rules/rules.hpp" |
| 5 |
#include "util/history_manager.hpp" |
| 6 |
#include <gtkmm.h> |
| 7 |
|
| 8 |
namespace horizon { |
| 9 |
class PoolEditorBase : public PoolGotoProvider { |
| 10 |
public: |
| 11 |
PoolEditorBase(const std::string &fn, class IPool &apool); |
| 12 |
|
| 13 |
virtual void reload() |
| 14 |
{ |
| 15 |
} |
| 16 |
bool get_needs_save() const |
| 17 |
{ |
| 18 |
return needs_save; |
| 19 |
} |
| 20 |
virtual void select(const ItemSet &items) |
| 21 |
{ |
| 22 |
} |
| 23 |
|
| 24 |
virtual void save_as(const std::string &fn) = 0; |
| 25 |
virtual std::string get_name() const = 0; |
| 26 |
virtual const UUID &get_uuid() const = 0; |
| 27 |
virtual const class FileVersion &get_version() const = 0; |
| 28 |
virtual unsigned int get_required_version() const; |
| 29 |
virtual ObjectType get_type() const = 0; |
| 30 |
virtual RulesCheckResult run_checks() const = 0; |
| 31 |
|
| 32 |
std::string filename; |
| 33 |
|
| 34 |
void undo(); |
| 35 |
void redo(); |
| 36 |
|
| 37 |
bool can_undo() const; |
| 38 |
bool can_redo() const; |
| 39 |
|
| 40 |
void history_append(const std::string &comment); |
| 41 |
typedef sigc::signal<void> type_signal_needs_save; |
| 42 |
type_signal_needs_save signal_needs_save() |
| 43 |
{ |
| 44 |
return s_signal_needs_save; |
| 45 |
} |
| 46 |
|
| 47 |
typedef sigc::signal<void, std::string> type_signal_extra_file_saved; |
| 48 |
type_signal_extra_file_saved signal_extra_file_saved() |
| 49 |
{ |
| 50 |
return s_signal_extra_file_saved; |
| 51 |
} |
| 52 |
|
| 53 |
type_signal_goto signal_open_item() |
| 54 |
{ |
| 55 |
return s_signal_open_item; |
| 56 |
} |
| 57 |
|
| 58 |
protected: |
| 59 |
IPool &pool; |
| 60 |
|
| 61 |
HistoryManager history_manager; |
| 62 |
|
| 63 |
virtual std::unique_ptr<HistoryManager::HistoryItem> make_history_item(const std::string &comment) = 0; |
| 64 |
virtual void history_load(const HistoryManager::HistoryItem &it) = 0; |
| 65 |
|
| 66 |
void set_needs_save() |
| 67 |
{ |
| 68 |
set_needs_save(false); |
| 69 |
} |
| 70 |
|
| 71 |
void unset_needs_save() |
| 72 |
{ |
| 73 |
needs_save = false; |
| 74 |
s_signal_needs_save.emit(); |
| 75 |
} |
| 76 |
|
| 77 |
class LoadingSetter { |
| 78 |
friend PoolEditorBase; |
| 79 |
LoadingSetter(PoolEditorBase &i) : iface(i) |
| 80 |
{ |
| 81 |
iface.loading = true; |
| 82 |
} |
| 83 |
PoolEditorBase &iface; |
| 84 |
|
| 85 |
public: |
| 86 |
~LoadingSetter() |
| 87 |
{ |
| 88 |
iface.loading = false; |
| 89 |
} |
| 90 |
}; |
| 91 |
friend LoadingSetter; |
| 92 |
|
| 93 |
[[nodiscard]] LoadingSetter set_loading() |
| 94 |
{ |
| 95 |
return LoadingSetter(*this); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
bool is_loading() const |
| 100 |
{ |
| 101 |
return loading; |
| 102 |
} |
| 103 |
|
| 104 |
type_signal_extra_file_saved s_signal_extra_file_saved; |
| 105 |
type_signal_goto s_signal_open_item; |
| 106 |
|
| 107 |
void label_make_item_link(Gtk::Label &la, ObjectType type); |
| 108 |
|
| 109 |
private: |
| 110 |
bool loading = false; |
| 111 |
bool needs_save = false; |
| 112 |
type_signal_needs_save s_signal_needs_save; |
| 113 |
|
| 114 |
void set_needs_save(bool from_undo) |
| 115 |
{ |
| 116 |
if (loading) |
| 117 |
throw std::runtime_error("set_needs_save called while loading"); |
| 118 |
needs_save = true; |
| 119 |
if (!from_undo) |
| 120 |
history_append("edit"); |
| 121 |
s_signal_needs_save.emit(); |
| 122 |
} |
| 123 |
|
| 124 |
void apply_preferences(); |
| 125 |
}; |
| 126 |
} // namespace horizon |