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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : unredobase.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef UNREDOBASE_H
#define UNREDOBASE_H
#include "clToolBar.h"
#include "codelite_exports.h"
#include <vector>
#include <wx/aui/auibar.h>
#include <wx/bitmap.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/sharedptr.h>
enum CLC_types { CLC_insert, CLC_delete, CLC_unknown };
class WXDLLIMPEXP_SDK CLCommand
{
public:
typedef wxSharedPtr<CLCommand> Ptr_t;
typedef std::vector<CLCommand::Ptr_t> Vec_t;
CLCommand(CLC_types type = CLC_unknown, const wxString& name = "")
: m_commandType(type)
, m_commandName(name)
, m_isOpen(true)
{
}
virtual ~CLCommand() {}
int GetCommandType() const { return m_commandType; }
wxString GetName() const { return m_commandName; }
void SetName(const wxString& name) { m_commandName = name; }
const wxString& GetText() const { return m_text; }
void SetText(const wxString& text) { m_text = text; }
bool IsOpen() const { return m_isOpen; }
void Close() { m_isOpen = false; }
wxString GetUserLabel() const { return m_userLabel; }
void SetUserLabel(const wxString& label) { m_userLabel = label; }
void AppendText(const wxString& text, int position) { m_text << text; }
virtual bool GetIsAppendable() const = 0;
virtual bool Do() { return true; }
virtual bool Undo() { return true; }
protected:
const int m_commandType;
wxString m_commandName;
wxString m_text;
wxString m_userLabel;
bool m_isOpen;
};
class WXDLLIMPEXP_SDK CommandProcessorBase : public wxEvtHandler
{
public:
CommandProcessorBase();
virtual ~CommandProcessorBase();
bool CanAppend(CLC_types type)
{
return GetOpenCommand()->GetIsAppendable() && GetOpenCommand()->GetCommandType() == type;
}
virtual void ProcessOpenCommand();
void PopulateUnRedoMenu(clToolBar* tb, wxWindowID toolId);
virtual void DoPopulateUnRedoMenu(wxMenu& menu, bool undoing);
void PrepareLabelledStatesMenu(wxMenu* menu);
void PopulateLabelledStatesMenu(wxMenu* menu);
void UnBindLabelledStatesMenu(wxMenu* menu);
void DoUnBindLabelledStatesMenu(wxMenu* menu);
CLCommand::Ptr_t GetInitialCommand() const { return m_initialCommand; }
int GetCurrentCommand() const { return m_currentCommand; }
void IncrementCurrentCommand();
void DecrementCurrentCommand();
int GetNextUndoCommand() const { return GetCommands().size() - m_currentCommand - 1; }
void Add(CLCommand::Ptr_t command)
{
m_commands.push_back(command);
m_currentCommand = m_commands.size() - 1;
}
CLCommand::Ptr_t GetOpenCommand();
bool HasOpenCommand() { return (GetOpenCommand() != NULL); }
virtual void CloseOpenCommand();
CLCommand::Vec_t& GetCommands() { return m_commands; }
const CLCommand::Vec_t& GetCommands() const { return m_commands; }
void OnTBUnRedo(wxCommandEvent& event);
virtual bool DoUndo() = 0;
virtual bool DoRedo() = 0;
bool CanUndo() const { return (GetCurrentCommand() > -1); }
bool CanRedo() const
{
return (GetCommands().size() > 0) && (GetCurrentCommand() < (int)(GetCommands().size() - 1));
}
void ClearRedos()
{ // Remove any redos invalidated by a new addition
while(GetCurrentCommand() < (int)(GetCommands().size() - 1)) {
GetCommands().pop_back();
}
}
void SetUserLabel(const wxString& label);
CLCommand::Ptr_t GetActiveCommand() const; // The command indexed by m_currentCommand
virtual void OnUndoDropdownItem(wxCommandEvent& event);
virtual void OnRedoDropdownItem(wxCommandEvent& event);
void Clear()
{
m_commands.clear();
m_initialCommand = NULL;
}
protected:
virtual void OnLabelledStatesMenuItem(wxCommandEvent& event);
CLCommand::Ptr_t m_initialCommand; // A command to hold any initial-state user-label, and to store any initial state
// if we're state-storing
CLCommand::Vec_t m_commands;
int m_currentCommand; // The next one to be undone
};
#endif // UNREDOBASE_H
|