1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _DB_SQL_EDITOR_HISTORY_BE_H_
#define _DB_SQL_EDITOR_HISTORY_BE_H_
#include "workbench/wb_backend_public_interface.h"
#include "sqlide/var_grid_model_be.h"
#include <boost/shared_ptr.hpp>
#include <time.h>
#include "mforms/menu.h"
class MYSQLWBBACKEND_PUBLIC_FUNC DbSqlEditorHistory
{
public:
typedef boost::shared_ptr<DbSqlEditorHistory> Ref;
static Ref create(bec::GRTManager *grtm) { return Ref(new DbSqlEditorHistory(grtm)); }
virtual ~DbSqlEditorHistory();
protected:
DbSqlEditorHistory(bec::GRTManager *grtm);
bec::GRTManager *_grtm;
public:
void reset();
void add_entry(const std::list<std::string> &statements);
int current_entry() { return _current_entry_index; }
void current_entry(int index);
std::string restore_sql_from_history(int entry_index, std::list<int> &detail_indexes);
protected:
int _current_entry_index;
public:
void load();
public:
class EntriesModel;
class DetailsModel;
public:
class DetailsModel : public VarGridModel
{
public:
friend class DbSqlEditorHistory;
typedef boost::shared_ptr<DetailsModel> Ref;
static Ref create(bec::GRTManager *grtm) { return Ref(new DetailsModel(grtm)); }
protected:
DetailsModel(bec::GRTManager *grtm);
public:
void add_entries(const std::list<std::string> &statements);
virtual void refresh() { refresh_ui(); }
mforms::Menu* get_context_menu() { return &_context_menu; }
virtual void reset();
void save();
void load(const std::string &storage_file_path);
protected:
int _last_loaded_row; // required to skip duplication of existing entries when dumping contents
public:
std::tm datestamp() const { return _datestamp; }
void datestamp(const std::tm &val) { _datestamp= val; }
protected:
std::string storage_file_path() const;
std::tm _datestamp; // raw datestamp for locale independent storage file name
private:
grt::StringRef _last_timestamp;
grt::StringRef _last_statement;
mforms::Menu _context_menu;
};
public:
class EntriesModel : public VarGridModel
{
private:
bool _ui_usage;
public:
friend class DbSqlEditorHistory;
typedef boost::shared_ptr<EntriesModel> Ref;
static Ref create(DbSqlEditorHistory *owner, bec::GRTManager *grtm) { return Ref(new EntriesModel(owner, grtm)); }
protected:
EntriesModel(DbSqlEditorHistory *owner, bec::GRTManager *grtm);
DbSqlEditorHistory *_owner;
void add_statements(const std::list<std::string> &statements);
public:
bool insert_entry(const std::tm &t);
void delete_all_entries();
void delete_entries(const std::vector<size_t> &rows);
void set_ui_usage(bool value) { _ui_usage = value; }
bool get_ui_usage() { return _ui_usage; }
std::string entry_path(size_t index);
std::tm entry_date(size_t index);
virtual void reset();
void load();
virtual bool activate_popup_item_for_nodes(const std::string &action, const std::vector<bec::NodeId> &orig_nodes);
virtual bec::MenuItemList get_popup_items_for_nodes(const std::vector<bec::NodeId> &nodes);
};
public:
EntriesModel::Ref entries_model() { return _entries_model; }
DetailsModel::Ref details_model() { return _details_model; }
DetailsModel::Ref write_only_details_model(){return _write_only_details_model;}
protected:
EntriesModel::Ref _entries_model;
DetailsModel::Ref _details_model;
DetailsModel::Ref _write_only_details_model;
void update_timestamp(std::tm timestamp);
};
#endif /* _DB_SQL_EDITOR_HISTORY_BE_H_ */
|