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 167 168 169 170 171 172 173 174 175 176 177
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright : (C) 2015 Eran Ifrah
// File name : clKeyboardManager.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 KEYBOARDMANAGER_H
#define KEYBOARDMANAGER_H
#include "codelite_exports.h"
#include <list>
#include <wx/frame.h>
#include <wx/accel.h>
#include <vector>
#include <map>
#include <wx/menu.h>
#include <wx/event.h>
#include "macros.h"
#include "wxStringHash.h"
struct WXDLLIMPEXP_SDK MenuItemData {
wxString resourceID;
wxString accel;
wxString action;
wxString parentMenu; // For display purposes
struct ClearParentMenu {
void operator()(std::pair<const int, MenuItemData>& iter) { iter.second.parentMenu.Clear(); }
};
struct PrependPrefix {
wxString m_prefix;
PrependPrefix(const wxString& prefix)
: m_prefix(prefix)
{
}
void operator()(std::pair<const int, MenuItemData>& iter) { iter.second.action.Prepend(m_prefix); }
};
};
typedef std::unordered_map<wxString, MenuItemData> MenuItemDataMap_t;
typedef std::unordered_map<int, MenuItemData> MenuItemDataIntMap_t;
struct WXDLLIMPEXP_SDK clKeyboardShortcut {
bool m_ctrl;
bool m_alt;
bool m_shift;
wxString m_keyCode;
clKeyboardShortcut()
: m_ctrl(false)
, m_alt(false)
, m_shift(false)
{
}
/**
* @brief clear this accelerator
*/
void Clear();
/**
* @brief construct this object from string representation
* e.g.: Ctrl-Alt-1
*/
void FromString(const wxString& accelString);
/**
* @brief return a string representation of this accelerator
*/
wxString ToString() const;
typedef std::vector<clKeyboardShortcut> Vec_t;
};
class WXDLLIMPEXP_SDK clKeyboardManager : public wxEvtHandler
{
private:
typedef std::list<wxFrame*> FrameList_t;
MenuItemDataMap_t m_menuTable;
MenuItemDataMap_t m_globalTable;
wxStringSet_t m_keyCodes;
wxStringSet_t m_allShorcuts;
protected:
/**
* @brief return list of frames
*/
void DoGetFrames(wxFrame* parent, clKeyboardManager::FrameList_t& frames);
void DoUpdateMenu(wxMenu* menu, MenuItemDataIntMap_t& accels, std::vector<wxAcceleratorEntry>& table);
void DoUpdateFrame(wxFrame* frame, MenuItemDataIntMap_t& accels);
void DoConvertToIntMap(const MenuItemDataMap_t& strMap, MenuItemDataIntMap_t& intMap);
MenuItemDataMap_t DoLoadDefaultAccelerators();
clKeyboardManager();
virtual ~clKeyboardManager();
protected:
void OnStartupCompleted(wxCommandEvent& event);
public:
static void Release();
static clKeyboardManager* Get();
/**
* @brief return an array of all unassigned keyboard shortcuts
*/
wxArrayString GetAllUnasignedKeyboardShortcuts() const;
/**
* @brief show a 'Add keyboard shortcut' dialog
*/
int PopupNewKeyboardShortcutDlg(wxWindow* parent, MenuItemData& menuItemData);
/**
* @brief return true if the accelerator is already assigned
*/
bool Exists(const wxString& accel) const;
/**
* @brief save the bindings to disk
*/
void Save();
/**
* @brief load bindings from the file system
*/
void Initialize();
/**
* @brief add keyboard shortcut by specifying the action ID + the shortcut combination
* For example: AddAccelerator("wxID_COPY", "Ctrl-Shift-C", "Copy the current selection");
* @return true if the action succeeded, false otherwise
*/
void AddGlobalAccelerator(
const wxString& resourceID, const wxString& keyboardShortcut, const wxString& description);
/**
* @brief replace all acceleratos with 'accels'
*/
void SetAccelerators(const MenuItemDataMap_t& accels);
/**
* @brief return all accelerators known to CodeLite
*/
void GetAllAccelerators(MenuItemDataMap_t& accels) const;
/**
* @brief update accelerators
*/
void Update(wxFrame* frame = NULL);
/**
* @brief restore keyboard shortcuts to defaults
*/
void RestoreDefaults();
};
#endif // KEYBOARDMANAGER_H
|