1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Adding EXPERIMENTAL_KEY_VIEW that provides a new keyboard binding view.

This commit is contained in:
lllucius 2013-10-01 06:00:13 +00:00
parent aad9d12c39
commit b0e65b57c2
10 changed files with 2791 additions and 68 deletions

View File

@ -554,6 +554,7 @@
284249EE10D337CE004330A6 /* GetProjectInfoCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 284249EA10D337CE004330A6 /* GetProjectInfoCommand.cpp */; };
284249EF10D337CE004330A6 /* SetProjectInfoCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 284249EC10D337CE004330A6 /* SetProjectInfoCommand.cpp */; };
28456AC20A2C180E00C23C1E /* ThemePrefs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28456AC00A2C180E00C23C1E /* ThemePrefs.cpp */; };
2849A42017F8BEC2005C653F /* KeyView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2849A41E17F8BEC2005C653F /* KeyView.cpp */; };
2849B4620A7444BE00ECF12D /* Dependencies.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2849B4600A7444BE00ECF12D /* Dependencies.cpp */; };
284A7B920F31571C001D7A67 /* nyx.c in Sources */ = {isa = PBXBuildFile; fileRef = 284A7B8F0F31571B001D7A67 /* nyx.c */; };
284A7B930F31571C001D7A67 /* nyx.h in Headers */ = {isa = PBXBuildFile; fileRef = 284A7B900F31571B001D7A67 /* nyx.h */; };
@ -3195,6 +3196,8 @@
284249ED10D337CE004330A6 /* SetProjectInfoCommand.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = SetProjectInfoCommand.h; sourceTree = "<group>"; tabWidth = 3; };
28456AC00A2C180E00C23C1E /* ThemePrefs.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = ThemePrefs.cpp; sourceTree = "<group>"; tabWidth = 3; };
28456AC10A2C180E00C23C1E /* ThemePrefs.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = ThemePrefs.h; sourceTree = "<group>"; tabWidth = 3; };
2849A41E17F8BEC2005C653F /* KeyView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyView.cpp; sourceTree = "<group>"; };
2849A41F17F8BEC2005C653F /* KeyView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyView.h; sourceTree = "<group>"; };
2849B4600A7444BE00ECF12D /* Dependencies.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = Dependencies.cpp; sourceTree = "<group>"; tabWidth = 3; };
2849B4610A7444BE00ECF12D /* Dependencies.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Dependencies.h; sourceTree = "<group>"; tabWidth = 3; };
284A7B8F0F31571B001D7A67 /* nyx.c */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.c; path = nyx.c; sourceTree = "<group>"; tabWidth = 3; };
@ -5305,6 +5308,8 @@
28530C490DF2105200555C94 /* HtmlWindow.h */,
28F1D81B0A2D0019005506A7 /* ImageRoll.cpp */,
28F1D81C0A2D0019005506A7 /* ImageRoll.h */,
2849A41E17F8BEC2005C653F /* KeyView.cpp */,
2849A41F17F8BEC2005C653F /* KeyView.h */,
2816372C0BAE3B6C0079C746 /* LinkingHtmlWindow.cpp */,
2816372D0BAE3B6C0079C746 /* LinkingHtmlWindow.h */,
1790B10309883BFD008A330A /* Meter.cpp */,
@ -8800,6 +8805,7 @@
ED920CAF15B19F61008CA12C /* ModulePrefs.cpp in Sources */,
EDD2431416934A6100D9DEC2 /* BassTreble.cpp in Sources */,
ED19449A1733F92800F4F5CA /* Reverb.cpp in Sources */,
2849A42017F8BEC2005C653F /* KeyView.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -30,6 +30,10 @@
#ifndef __EXPERIMENTAL__
#define __EXPERIMENTAL__
// LLL, 22.Nov 2007:
// new key assignment view for preferences
// #define EXPERIMENTAL_KEY_VIEW
// feature to link audio tracks to a label track
#define EXPERIMENTAL_SYNC_LOCK

View File

@ -246,6 +246,7 @@ OBJS = \
widgets/Grid.o \
widgets/HtmlWindow.o \
widgets/ImageRoll.o \
widgets/KeyView.o \
widgets/LinkingHtmlWindow.o \
widgets/Meter.o \
widgets/MultiDialog.o \

View File

@ -1155,7 +1155,9 @@ void CommandManager::GetAllCommandData(
wxArrayString &default_keys,
wxArrayString &labels,
wxArrayString &categories,
#if defined(EXPERIMENTAL_KEY_VIEW)
wxArrayString &prefixes,
#endif
bool includeMultis)
{
unsigned int i;
@ -1168,7 +1170,9 @@ void CommandManager::GetAllCommandData(
default_keys.Add( mCommandList[i]->defaultKey);
labels.Add(mCommandList[i]->label);
categories.Add(mCommandList[i]->labelTop);
#if defined(EXPERIMENTAL_KEY_VIEW)
prefixes.Add(mCommandList[i]->labelPrefix);
#endif
}
else if( includeMultis )
{
@ -1177,7 +1181,9 @@ void CommandManager::GetAllCommandData(
default_keys.Add( mCommandList[i]->defaultKey);
labels.Add(mCommandList[i]->label);
categories.Add(mCommandList[i]->labelTop);
#if defined(EXPERIMENTAL_KEY_VIEW)
prefixes.Add(mCommandList[i]->labelPrefix);
#endif
}
}
}

View File

@ -195,7 +195,10 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
void GetAllCommandLabels(wxArrayString &labels, bool includeMultis);
void GetAllCommandData(
wxArrayString &names, wxArrayString &keys, wxArrayString &default_keys,
wxArrayString &labels, wxArrayString &categories, wxArrayString &prefixes,
wxArrayString &labels, wxArrayString &categories,
#if defined(EXPERIMENTAL_KEY_VIEW)
wxArrayString &prefixes,
#endif
bool includeMultis);
wxString GetLabelFromName(wxString name);

View File

@ -38,6 +38,539 @@ KeyConfigPrefs and MousePrefs use.
#include "FileDialog.h"
#if defined(EXPERIMENTAL_KEY_VIEW)
#include "../widgets/KeyView.h"
//
// KeyConfigPrefs
//
#define AssignDefaultsButtonID 17001
#define CurrentComboID 17002
#define SetButtonID 17003
#define ClearButtonID 17004
#define CommandsListID 17005
#define ExportButtonID 17006
#define ImportButtonID 17007
#define FilterID 17008
#define ViewByTreeID 17009
#define ViewByNameID 17010
#define ViewByKeyID 17011
BEGIN_EVENT_TABLE(KeyConfigPrefs, PrefsPanel)
EVT_BUTTON(AssignDefaultsButtonID, KeyConfigPrefs::OnDefaults)
EVT_BUTTON(SetButtonID, KeyConfigPrefs::OnSet)
EVT_BUTTON(ClearButtonID, KeyConfigPrefs::OnClear)
EVT_BUTTON(ExportButtonID, KeyConfigPrefs::OnExport)
EVT_BUTTON(ImportButtonID, KeyConfigPrefs::OnImport)
EVT_LISTBOX(CommandsListID, KeyConfigPrefs::OnSelected)
EVT_RADIOBUTTON(ViewByTreeID, KeyConfigPrefs::OnViewBy)
EVT_RADIOBUTTON(ViewByNameID, KeyConfigPrefs::OnViewBy)
EVT_RADIOBUTTON(ViewByKeyID, KeyConfigPrefs::OnViewBy)
END_EVENT_TABLE()
KeyConfigPrefs::KeyConfigPrefs(wxWindow * parent)
: PrefsPanel(parent, _("Keyboard")),
mView(NULL),
mFilter(NULL),
mKey(NULL)
{
Populate();
}
KeyConfigPrefs::~KeyConfigPrefs()
{
if (mKey)
{
mKey->Disconnect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyKeyDown),
NULL,
this);
mKey->Disconnect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyChar),
NULL,
this);
mKey->Disconnect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(KeyConfigPrefs::OnHotkeyKillFocus),
NULL,
this);
}
if (mFilter)
{
mKey->Disconnect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnFilterKeyDown),
NULL,
this);
mKey->Disconnect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnFilterChar),
NULL,
this);
}
}
void KeyConfigPrefs::Populate()
{
ShuttleGui S(this, eIsCreatingFromPrefs);
AudacityProject *project = GetActiveProject();
if (!project) {
S.StartVerticalLay(true);
{
S.StartStatic(wxEmptyString, true);
{
S.AddTitle(_("Keyboard preferences currently unavailable."));
S.AddTitle(_("Open a new project to modify keyboard shortcuts."));
}
S.EndStatic();
}
S.EndVerticalLay();
return;
}
PopulateOrExchange(S);
mCommandSelected = -1;
mManager = project->GetCommandManager();
RefreshBindings();
}
/// Normally in classes derived from PrefsPanel this function
/// is used both to populate the panel and to exchange data with it.
/// With KeyConfigPrefs all the exchanges are handled specially,
/// so this is only used in populating the panel.
void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(2);
S.StartStatic(_("Key Bindings"), 1);
{
S.StartMultiColumn(3, wxEXPAND);
{
S.SetStretchyCol(1);
S.StartHorizontalLay(wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
{
S.AddTitle(_("View by:"));
S.StartRadioButtonGroup(wxT("/Prefs/KeyConfig/ViewBy"), wxT("tree"));
{
S.Id(ViewByTreeID).TieRadioButton(_("Tree"), wxT("tree"));
S.Id(ViewByNameID).TieRadioButton(_("Name"), wxT("name"));
S.Id(ViewByKeyID).TieRadioButton(_("Key"), wxT("key"));
}
S.EndRadioButtonGroup();
}
S.EndHorizontalLay();
S.StartHorizontalLay(wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL, 0);
{
// just a spacer
}
S.EndHorizontalLay();
S.StartHorizontalLay(wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0);
{
S.AddTitle(_("Filter:"));
if (!mFilter) {
mFilter = new wxTextCtrl(this,
FilterID,
wxT(""),
wxDefaultPosition,
#if defined(__WXMAC__)
wxSize(300, -1),
#else
wxSize(210, -1),
#endif
wxTE_PROCESS_ENTER);
mFilter->SetName(_("Filter"));
mFilter->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnFilterKeyDown),
NULL,
this);
mFilter->Connect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnFilterChar),
NULL,
this);
}
S.AddWindow(mFilter, wxALIGN_RIGHT);
}
S.EndHorizontalLay();
}
S.EndThreeColumn();
S.AddSpace(-1, 2);
S.StartHorizontalLay(wxEXPAND, 1);
{
if (!mView) {
mView = new KeyView(S.GetParent(), CommandsListID);
mView->SetName(_("Bindings"));
}
S.Prop(true);
S.AddWindow(mView, wxEXPAND);
}
S.EndHorizontalLay();
S.StartThreeColumn();
{
if (!mKey) {
mKey = new wxTextCtrl(this,
CurrentComboID,
wxT(""),
wxDefaultPosition,
#if defined(__WXMAC__)
wxSize(300, -1));
#else
wxSize(210, -1));
#endif
mKey->SetName(_("Hotkey"));
mKey->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyKeyDown),
NULL,
this);
mKey->Connect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyChar),
NULL,
this);
mKey->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(KeyConfigPrefs::OnHotkeyKillFocus),
NULL,
this);
}
S.AddWindow(mKey);
/* i18n-hint: (verb)*/
S.Id(SetButtonID).AddButton(_("Set"));
S.Id(ClearButtonID).AddButton(_("Cl&ear"));
}
S.EndThreeColumn();
#if defined(__WXMAC__)
S.AddFixedText(_("Note: Pressing Cmd+Q will quit. All other keys are valid."));
#endif
S.StartThreeColumn();
{
S.Id(ImportButtonID).AddButton(_("&Import..."));
S.Id(ExportButtonID).AddButton(_("&Export..."));
S.Id(AssignDefaultsButtonID).AddButton(_("&Defaults"));
}
S.EndThreeColumn();
}
S.EndStatic();
}
void KeyConfigPrefs::RefreshBindings()
{
wxArrayString Labels;
wxArrayString Categories;
wxArrayString Prefixes;
mManager->GetAllCommandData(
mNames,
mKeys,
mDefaultKeys,
Labels,
Categories,
Prefixes,
true); // True to include effects (list items), false otherwise.
mView->RefreshBindings(mNames,
Categories,
Prefixes,
Labels,
mKeys);
mNewKeys = mKeys;
}
void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event))
{
wxString file = wxT("Audacity-keys.xml");
wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),
::wxGetCwd());
file = FileSelector(_("Select an XML file containing Audacity keyboard shortcuts..."),
path,
file,
wxT(""),
_("XML files (*.xml)|*.xml|All files (*.*)|*.*"),
wxRESIZE_BORDER,
this);
if (!file) {
return;
}
path = wxPathOnly(file);
gPrefs->Write(wxT("/DefaultOpenPath"), path);
gPrefs->Flush();
XMLFileReader reader;
if (!reader.Parse(mManager, file)) {
wxMessageBox(reader.GetErrorStr(),
_("Error Importing Keyboard Shortcuts"),
wxOK | wxCENTRE, this);
}
RefreshBindings();
}
void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
{
wxString file = wxT("Audacity-keys.xml");
wxString path = gPrefs->Read(wxT("/DefaultExportPath"),
::wxGetCwd());
file = FileSelector(_("Export Keyboard Shortcuts As:"),
path,
file,
wxT("xml"),
_("XML files (*.xml)|*.xml|All files (*.*)|*.*"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
this);
if (!file) {
return;
}
path = wxPathOnly(file);
gPrefs->Write(wxT("/DefaultExportPath"), path);
gPrefs->Flush();
XMLFileWriter prefFile;
try
{
prefFile.Open(file, wxT("wb"));
mManager->WriteXML(prefFile);
prefFile.Close();
}
catch (XMLFileWriterException* pException)
{
wxMessageBox(_("Couldn't write to file: ") + file,
_("Error Exporting Keyboard Shortcuts"),
wxOK | wxCENTRE, this);
delete pException;
}
}
void KeyConfigPrefs::OnDefaults(wxCommandEvent & WXUNUSED(event))
{
mNewKeys = mDefaultKeys;
for (size_t i = 0; i < mNewKeys.GetCount(); i++) {
mManager->SetKeyFromIndex(i, mNewKeys[i]);
}
RefreshBindings();
}
void KeyConfigPrefs::OnHotkeyKeyDown(wxKeyEvent & e)
{
wxTextCtrl *t = (wxTextCtrl *)e.GetEventObject();
// Make sure we can navigate away from the hotkey textctrl.
// On Linux and OSX, it an get stuck, but it doesn't hurt
// to do it for Windows as well.
//
// Mac note: Don't waste time trying to figure out why the
// focus goes back to the prefs tree. Unless Voiceover is
// active, buttons on the Mac do not accept focus and all the
// controls between this one and the tree control are buttons.
if (e.GetKeyCode() == WXK_TAB) {
wxNavigationKeyEvent nevent;
nevent.SetWindowChange(e.ControlDown());
nevent.SetDirection(!e.ShiftDown());
nevent.SetEventObject(t);
nevent.SetCurrentFocus(t);
t->GetParent()->ProcessEvent(nevent);
return;
}
t->SetValue(KeyStringDisplay(KeyEventToKeyString(e)));
}
void KeyConfigPrefs::OnHotkeyChar(wxKeyEvent & WXUNUSED(e))
{
// event.Skip() not performed, so event will not be processed further.
}
void KeyConfigPrefs::OnHotkeyKillFocus(wxFocusEvent & e)
{
if (mKey->GetValue().IsEmpty() && mCommandSelected != wxNOT_FOUND) {
mKey->AppendText(mView->GetKey(mCommandSelected));
}
e.Skip();
}
void KeyConfigPrefs::OnFilterKeyDown(wxKeyEvent & e)
{
wxTextCtrl *t = (wxTextCtrl *)e.GetEventObject();
int keycode = e.GetKeyCode();
// Make sure we can navigate away from the hotkey textctrl.
// On Linux and OSX, it an get stuck, but it doesn't hurt
// to do it for Windows as well.
if (keycode == WXK_TAB) {
wxNavigationKeyEvent nevent;
nevent.SetWindowChange(e.ControlDown());
nevent.SetDirection(!e.ShiftDown());
nevent.SetEventObject(t);
nevent.SetCurrentFocus(t);
t->GetParent()->ProcessEvent(nevent);
return;
}
if (mViewType == ViewByKey) {
wxString key = KeyStringDisplay(KeyEventToKeyString(e));
t->SetValue(key);
if (key != wxEmptyString) {
mView->SetFilter(t->GetValue());
}
}
else
{
if (keycode == WXK_RETURN) {
mView->SetFilter(t->GetValue());
}
else {
e.Skip();
}
}
}
void KeyConfigPrefs::OnFilterChar(wxKeyEvent & e)
{
if (mViewType != ViewByKey)
{
e.Skip();
}
}
// Given a hotkey combination, returns the name (description) of the
// corresponding command, or the empty string if none is found.
wxString KeyConfigPrefs::NameFromKey(const wxString & key)
{
int i = mNewKeys.Index(key);
if (i == wxNOT_FOUND) {
return wxEmptyString;
}
return mNames[i];
}
// Sets the selected command to have this key
// This is not yet a committed change, which will happen on a save.
void KeyConfigPrefs::SetKeyForSelected(const wxString & key)
{
int index = mView->GetIndex(mCommandSelected);
mView->SetKey(mCommandSelected, key);
mManager->SetKeyFromIndex(index, key);
mNewKeys[index] = key;
}
void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
{
wxString newKey = mKey->GetValue();
wxString alreadyAssignedName = NameFromKey(newKey);
// Prevent same hotkey combination being used twice.
if (!alreadyAssignedName.IsEmpty()) {
wxMessageBox(
wxString::Format(
_("The keyboard shortcut '%s' is already assigned to:\n\n'%s'"),
newKey.c_str(),
alreadyAssignedName.c_str()),
_("Error"), wxICON_STOP | wxCENTRE, this);
return;
}
SetKeyForSelected(newKey);
}
void KeyConfigPrefs::OnClear(wxCommandEvent& WXUNUSED(event))
{
mKey->Clear();
SetKeyForSelected(wxEmptyString);
}
void KeyConfigPrefs::OnSelected(wxCommandEvent & e)
{
mCommandSelected = e.GetInt();
mKey->Clear();
mKey->AppendText(mView->GetKey(mCommandSelected));
}
void KeyConfigPrefs::OnViewBy(wxCommandEvent & e)
{
switch (e.GetId())
{
case ViewByTreeID:
mViewType = ViewByTree;
break;
case ViewByNameID:
mViewType = ViewByName;
break;
case ViewByKeyID:
mViewType = ViewByKey;
break;
}
mView->SetView(mViewType);
}
bool KeyConfigPrefs::Apply()
{
for (size_t i = 0; i < mNames.GetCount(); i++) {
wxString dkey = KeyStringNormalize(mDefaultKeys[i]);
wxString name = wxT("/NewKeys/") + mNames[i];
wxString key = KeyStringNormalize(mNewKeys[i]);
if (gPrefs->HasEntry(name)) {
if (key != KeyStringNormalize(gPrefs->Read(name, key))) {
gPrefs->Write(name, key);
}
if (key == dkey) {
gPrefs->DeleteEntry(name);
}
}
else {
if (key != dkey) {
gPrefs->Write(name, key);
}
}
}
return gPrefs->Flush();
}
void KeyConfigPrefs::Cancel()
{
// Restore original key values
for (size_t i = 0; i < mNames.GetCount(); i++) {
mManager->SetKeyFromIndex(i, mKeys[i]);
}
return;
}
#else
//
// KeyConfigPrefs
//
@ -64,7 +597,6 @@ BEGIN_EVENT_TABLE(KeyConfigPrefs, PrefsPanel)
EVT_BUTTON(ExportButtonID, KeyConfigPrefs::OnExport)
EVT_BUTTON(ImportButtonID, KeyConfigPrefs::OnImport)
EVT_CHOICE(CategoryID, KeyConfigPrefs::OnCategory)
EVT_LIST_COL_CLICK(CommandsListID, KeyConfigPrefs::OnSort)
EVT_LIST_ITEM_SELECTED(CommandsListID, KeyConfigPrefs::OnItemSelected)
EVT_LIST_KEY_DOWN(CommandsListID, KeyConfigPrefs::OnKeyDown)
END_EVENT_TABLE()
@ -184,54 +716,27 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
void KeyConfigPrefs::CreateList()
{
mList->InsertColumn(CommandColumn, _("Command"), wxLIST_FORMAT_LEFT);
mList->InsertColumn(KeyComboColumn, _("Combination"), wxLIST_FORMAT_LEFT);
mList->InsertColumn(KeyComboColumn, _("Key Combination"), wxLIST_FORMAT_LEFT);
RepopulateBindingsList();
mList->SetColumnWidth(CommandColumn, wxLIST_AUTOSIZE);
mList->SetColumnWidth(KeyComboColumn, wxLIST_AUTOSIZE);
}
int KeyConfigPrefs::SortItems(long item1, long item2)
{
if (mSortCol->Item(item1) < mSortCol->Item(item2)) {
return -1 * mSortDir;
}
if (mSortCol->Item(item1) > mSortCol->Item(item2)) {
return 1 * mSortDir;
}
return 0;
mList->SetColumnWidth(KeyComboColumn, 250);
}
static int wxCALLBACK SortCallback(long item1, long item2, long sortData)
{
return ((KeyConfigPrefs *)sortData)->SortItems(item1, item2);
}
wxArrayString *names = (wxArrayString *) sortData;
void KeyConfigPrefs::Sort(int column)
{
wxArrayString *data = NULL;
switch(column)
{
case CommandColumn:
data = &mLabels;
break;
case KeyComboColumn:
data = &mKeys;
break;
if (names->Item(item1) < names->Item(item2)) {
return -1;
}
mSortDir = -mSortDir;
if (mSortCol != data) {
mSortDir = 1;
if (names->Item(item1) > names->Item(item2)) {
return 1;
}
mSortCol = data;
mList->SortItems(SortCallback, (long) this);
return 0;
}
void KeyConfigPrefs::RepopulateBindingsList()
@ -240,9 +745,8 @@ void KeyConfigPrefs::RepopulateBindingsList()
mList->DeleteAllItems(); // Delete contents, but not the column headers.
mNames.Clear();
mLabels.Clear();
mDefaultKeys.Clear();
wxArrayString Keys,Labels,Categories,Prefixes;
wxArrayString Keys,Labels,Categories;
mManager->GetAllCommandData(
mNames,
@ -250,7 +754,6 @@ void KeyConfigPrefs::RepopulateBindingsList()
mDefaultKeys,
Labels,
Categories,
Prefixes,
// True to include effects (list items), false otherwise.
true
);
@ -272,6 +775,10 @@ void KeyConfigPrefs::RepopulateBindingsList()
else
mNewKeys[i] = key; // Make sure mNewKeys is updated.
// if (cat != _("All") && ! Categories[i].StartsWith(cat)) {
if (cat != _("All") && ! (Categories[i]== cat)) {
continue;
}
wxString label;
// Labels for undo and redo change according to the last command
@ -288,18 +795,7 @@ void KeyConfigPrefs::RepopulateBindingsList()
}
label = wxMenuItem::GetLabelFromText(label.BeforeFirst(wxT('\t')));
if (!Prefixes[i].IsEmpty()) {
label = wxMenuItem::GetLabelFromText(Prefixes[i]) + wxT(" - ") + label;
}
if (cat == _("All")) {
label = Categories[i] + wxT(" - ") + label;
}
mLabels.Add(label);
// if (cat != _("All") && ! Categories[i].StartsWith(cat)) {
if (cat != _("All") && ! (Categories[i] == cat)) {
continue;
}
mList->InsertItem(ndx, label);
mList->SetItem(ndx, KeyComboColumn, key);
mList->SetItemData(ndx, i);
@ -309,9 +805,7 @@ void KeyConfigPrefs::RepopulateBindingsList()
ndx++;
}
mSortDir = 1;
mSortCol = NULL;
Sort(CommandColumn);
// mList->SortItems(SortCallback, (long) &mNames);
}
void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event))
@ -561,11 +1055,6 @@ void KeyConfigPrefs::OnCategory(wxCommandEvent & WXUNUSED(event))
RepopulateBindingsList();
}
void KeyConfigPrefs::OnSort(wxListEvent & event)
{
Sort(event.GetColumn());
}
void KeyConfigPrefs::OnItemSelected(wxListEvent & e)
{
mCommandSelected = e.GetIndex();
@ -622,3 +1111,5 @@ void KeyConfigPrefs::Cancel()
return;
}
#endif

View File

@ -12,6 +12,70 @@
#ifndef __AUDACITY_KEY_CONFIG_PREFS__
#define __AUDACITY_KEY_CONFIG_PREFS__
#if defined(EXPERIMENTAL_KEY_VIEW)
#include <wx/defs.h>
#include <wx/imaglist.h>
#include <wx/listctrl.h>
#include <wx/srchctrl.h>
#include <wx/textctrl.h>
#include <wx/string.h>
#include "../ShuttleGui.h"
#include "../commands/CommandManager.h"
#include "../widgets/KeyView.h"
#include "PrefsPanel.h"
class KeyConfigPrefs:public PrefsPanel
{
public:
KeyConfigPrefs(wxWindow * parent);
~KeyConfigPrefs();
virtual bool Apply();
virtual void Cancel();
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);
void RefreshBindings();
wxString NameFromKey(const wxString & key);
void SetKeyForSelected(const wxString & key);
void OnViewBy(wxCommandEvent & e);
void OnDefaults(wxCommandEvent & e);
void OnImport(wxCommandEvent & e);
void OnExport(wxCommandEvent & e);
void OnSet(wxCommandEvent & e);
void OnClear(wxCommandEvent & e);
void OnSelected(wxCommandEvent & e);
void OnHotkeyKeyDown(wxKeyEvent & e);
void OnHotkeyChar(wxKeyEvent & e);
void OnHotkeyKillFocus(wxFocusEvent & e);
void OnFilterKeyDown(wxKeyEvent & e);
void OnFilterChar(wxKeyEvent & e);
KeyView *mView;
wxTextCtrl *mFilter;
wxTextCtrl *mKey;
ViewByType mViewType;
CommandManager *mManager;
int mCommandSelected;
wxArrayString mNames;
wxArrayString mDefaultKeys;
wxArrayString mKeys;
wxArrayString mNewKeys; // Used for work in progress.
DECLARE_EVENT_TABLE();
};
#else
#include <wx/defs.h>
#include <wx/listctrl.h>
#include <wx/textctrl.h>
@ -30,16 +94,13 @@ class KeyConfigPrefs:public PrefsPanel
virtual bool Apply();
virtual void Cancel();
int SortItems(long item1, long item2);
private:
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);
void CreateList();
void RepopulateBindingsList();
wxString NameFromKey( const wxString & key );
void SetKeyForSelected( const wxString & key );
void Sort(int column);
void OnDefaults(wxCommandEvent & e);
void OnImport(wxCommandEvent & e);
@ -47,7 +108,6 @@ private:
void OnSet(wxCommandEvent & e);
void OnClear(wxCommandEvent & e);
void OnCategory(wxCommandEvent & e);
void OnSort(wxListEvent & e);
void OnItemSelected(wxListEvent & e);
void OnKeyDown(wxListEvent & e);
@ -63,14 +123,12 @@ private:
wxArrayString mCats;
wxArrayString mNames;
wxArrayString mLabels;
wxArrayString mDefaultKeys;
wxArrayString mKeys;
wxArrayString mNewKeys; // Used for work in progress.
wxArrayString *mSortCol;
int mSortDir;
DECLARE_EVENT_TABLE();
};
#endif#endif
#endif

1898
src/widgets/KeyView.cpp Normal file

File diff suppressed because it is too large Load Diff

248
src/widgets/KeyView.h Normal file
View File

@ -0,0 +1,248 @@
/**********************************************************************
Audacity: A Digital Audio Editor
KeyView.h
**********************************************************************/
#ifndef __AUDACITY_WIDGETS_KEYVIEW__
#define __AUDACITY_WIDGETS_KEYVIEW__
#include "../Audacity.h"
#include <wx/defs.h>
#include <wx/arrstr.h>
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
#include <wx/dynarray.h>
#include <wx/string.h>
#include <wx/vlbox.h>
// Class holding all information about a node. Rather than a real tree
// we store these in an array and simulate a tree.
class KeyNode
{
public:
KeyNode()
{
node = -1;
index = -1;
depth = -1;
line = -1;
iscat = false;
ispfx = false;
isparent = false;
isopen = false;
}
public:
wxString category;
wxString prefix;
wxString label;
wxString key;
int node;
int index;
int depth;
int line;
bool iscat;
bool ispfx;
bool isparent;
bool isopen;
};
// Declare the KeyNode arrays
WX_DECLARE_OBJARRAY(KeyNode, KeyNodeArray);
WX_DECLARE_OBJARRAY(KeyNode *, KeyNodeArrayPtr);
// Types of view currently supported
enum ViewByType
{
ViewByTree,
ViewByName,
ViewByKey
};
#if wxUSE_ACCESSIBILITY
#include <wx/access.h>
// Forward reference accessibility provideer
class KeyViewAx;
#endif
// The KeyView class
class KeyView : public wxVListBox
{
public:
KeyView(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize);
virtual ~KeyView();
void RefreshBindings(const wxArrayString & names,
const wxArrayString & categories,
const wxArrayString & prefixes,
const wxArrayString & labels,
const wxArrayString & keys);
wxString GetLabel(int line);
wxString GetFullLabel(int line);
wxString GetKey(int line);
int GetIndex(int line);
void SetKey(int line, const wxString & key);
void SetView(ViewByType type);
void SetFilter(const wxString & filter);
private:
void OnDrawItem(wxDC & dc, const wxRect & rect, size_t line) const;
void OnDrawBackground(wxDC & dc, const wxRect & rect, size_t line) const;
wxCoord OnMeasureItem(size_t line) const;
void OnLeftDown(wxMouseEvent & event);
void OnKeyDown(wxKeyEvent & event);
void OnSelected(wxCommandEvent & event);
void OnSetFocus(wxFocusEvent & event);
void OnKillFocus(wxFocusEvent & event);
void OnScroll(wxScrollWinEvent & event);
void OnSize(wxSizeEvent & event);
void RecalcExtents();
void RefreshLineCount();
void UpdateHScroll();
void SelectLine(int line);
static int CmpKeyNodeByTree(KeyNode ***n1, KeyNode ***n2);
static int CmpKeyNodeByName(KeyNode ***n1, KeyNode ***n2);
static int CmpKeyNodeByKey(KeyNode ***n1, KeyNode ***n2);
#if wxUSE_ACCESSIBILITY
friend class KeyViewAx;
bool HasChildren(int line);
bool IsExpanded(int line);
wxCoord GetLineHeight(int line);
wxString GetValue(int line);
#endif
private:
wxBitmap *mOpen;
wxBitmap *mClosed;
KeyNodeArray mNodes;
KeyNodeArrayPtr mLines;
ViewByType mViewType;
wxString mFilter;
wxCoord mScrollX;
wxCoord mWidth;
size_t mLineCount;
wxCoord mLineHeight;
wxCoord mKeyX;
int mCommandWidth;
wxCoord mKeyWidth;
#if wxUSE_ACCESSIBILITY
KeyViewAx *mAx;
#endif
DECLARE_EVENT_TABLE();
};
#if wxUSE_ACCESSIBILITY
// ----------------------------------------------------------------------------
// KeyViewAx
//
// wxAccessible object providing information for KeyView.
// ----------------------------------------------------------------------------
class KeyViewAx
: public wxWindowAccessible
{
public:
KeyViewAx(KeyView *view);
void SetCurrentLine(int row);
void ListUpdated();
bool GetLine(int childId, int & line);
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
virtual wxAccStatus GetChild(int childId, wxAccessible **child);
// Gets the number of children.
virtual wxAccStatus GetChildCount(int *childCount);
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
virtual wxAccStatus GetDefaultAction(int childId, wxString *actionName);
// Returns the description for this object or a child.
virtual wxAccStatus GetDescription(int childId, wxString *description);
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
virtual wxAccStatus GetFocus(int *childId, wxAccessible **child);
// Returns help text for this object or a child, similar to tooltip text.
virtual wxAccStatus GetHelpText(int childId, wxString *helpText);
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
virtual wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut);
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
virtual wxAccStatus GetLocation(wxRect & rect, int elementId);
// Gets the name of the specified object.
virtual wxAccStatus GetName(int childId, wxString *name);
// Gets the parent, or NULL.
virtual wxAccStatus GetParent(wxAccessible **parent);
// Returns a role constant.
virtual wxAccStatus GetRole(int childId, wxAccRole *role);
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
virtual wxAccStatus GetSelections(wxVariant *selections);
// Returns a state constant.
virtual wxAccStatus GetState(int childId, long *state);
// Returns a localized string representing the value for the object
// or child.
virtual wxAccStatus GetValue(int childId, wxString *strValue);
#if defined(__WXMAC__)
// Selects the object or child.
virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags);
#endif
private:
KeyView *mView;
int mLastId;
};
#endif
#endif

View File

@ -1855,6 +1855,14 @@
RelativePath="..\..\..\src\widgets\ImageRoll.h"
>
</File>
<File
RelativePath="..\..\..\src\widgets\KeyView.cpp"
>
</File>
<File
RelativePath="..\..\..\src\widgets\KeyView.h"
>
</File>
<File
RelativePath="..\..\..\src\widgets\LinkingHtmlWindow.cpp"
>