* Cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29705 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006 Haiku Inc. All rights reserved.
|
* Copyright 2004-2009 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Sandor Vroemisse
|
* Sandor Vroemisse
|
||||||
* Jérôme Duval
|
* Jérôme Duval
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* A BStringItem modified such that it holds
|
|
||||||
* the BEntry object it corresponds with
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KEYMAP_LIST_ITEM_H
|
#ifndef KEYMAP_LIST_ITEM_H
|
||||||
#define KEYMAP_LIST_ITEM_H
|
#define KEYMAP_LIST_ITEM_H
|
||||||
|
|
||||||
|
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*! A BStringItem modified such that it holds
|
||||||
|
the BEntry object it corresponds with
|
||||||
|
*/
|
||||||
class KeymapListItem : public BStringItem {
|
class KeymapListItem : public BStringItem {
|
||||||
public:
|
public:
|
||||||
KeymapListItem(entry_ref& keymap, const char* name = NULL);
|
KeymapListItem(entry_ref& keymap, const char* name = NULL);
|
||||||
entry_ref & KeymapEntry() { return fKeymap; };
|
|
||||||
|
entry_ref& EntryRef() { return fKeymap; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
entry_ref fKeymap;
|
entry_ref fKeymap;
|
||||||
|
|||||||
@@ -138,10 +138,15 @@ KeymapWindow::KeymapWindow()
|
|||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
// Try and find the current map name in the two list views (if the name
|
// Try and find the current map name in the two list views (if the name
|
||||||
// was read at all) - this will also load the fCurrentMap
|
// was read at all)
|
||||||
if (!_SelectCurrentMap(fSystemListView)
|
_SelectCurrentMap();
|
||||||
&& !_SelectCurrentMap(fUserListView))
|
|
||||||
fUserListView->Select(0L);
|
KeymapListItem* current
|
||||||
|
= static_cast<KeymapListItem*>(fUserListView->FirstItem());
|
||||||
|
|
||||||
|
fCurrentMap.Load(current->EntryRef());
|
||||||
|
fPreviousMap.Load(current->EntryRef());
|
||||||
|
fAppliedMap.Load(current->EntryRef());
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
@@ -208,16 +213,6 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
fSavePanel->Show();
|
fSavePanel->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if 0
|
|
||||||
case kMsgMenuEditUndo:
|
|
||||||
case kMsgMenuEditCut:
|
|
||||||
case kMsgMenuEditCopy:
|
|
||||||
case kMsgMenuEditPaste:
|
|
||||||
case kMsgMenuEditClear:
|
|
||||||
case kMsgMenuEditSelectAll:
|
|
||||||
fMapView->MessageReceived(message);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case kMsgMenuFontChanged:
|
case kMsgMenuFontChanged:
|
||||||
{
|
{
|
||||||
BMenuItem *item = fFontMenu->FindMarked();
|
BMenuItem *item = fFontMenu->FindMarked();
|
||||||
@@ -231,51 +226,41 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case kMsgSystemMapSelected:
|
case kMsgSystemMapSelected:
|
||||||
{
|
|
||||||
KeymapListItem *keymapListItem =
|
|
||||||
static_cast<KeymapListItem*>(fSystemListView->ItemAt(
|
|
||||||
fSystemListView->CurrentSelection()));
|
|
||||||
if (keymapListItem) {
|
|
||||||
fCurrentMap.Load(keymapListItem->KeymapEntry());
|
|
||||||
|
|
||||||
if (fFirstTime) {
|
|
||||||
fPreviousMap.Load(keymapListItem->KeymapEntry());
|
|
||||||
fAppliedMap.Load(keymapListItem->KeymapEntry());
|
|
||||||
fFirstTime = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
|
||||||
|
|
||||||
// Deselect item in other BListView
|
|
||||||
fUserListView->DeselectAll();
|
|
||||||
_UpdateButtons();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case kMsgUserMapSelected:
|
case kMsgUserMapSelected:
|
||||||
{
|
{
|
||||||
int32 index = fUserListView->CurrentSelection();
|
BListView* listView;
|
||||||
if (index == 0) {
|
BListView* otherListView;
|
||||||
|
|
||||||
|
if (message->what == kMsgSystemMapSelected) {
|
||||||
|
fUserListView->DeselectAll();
|
||||||
|
listView = fSystemListView;
|
||||||
|
otherListView = fUserListView;
|
||||||
|
} else {
|
||||||
|
listView = fUserListView;
|
||||||
|
otherListView = fSystemListView;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 index = listView->CurrentSelection();
|
||||||
|
if (index < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Deselect item in other BListView
|
||||||
|
otherListView->DeselectAll();
|
||||||
|
|
||||||
|
if (index == 0 && listView == fUserListView) {
|
||||||
// we can safely ignore the "(Current)" item
|
// we can safely ignore the "(Current)" item
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeymapListItem *keymapListItem =
|
KeymapListItem* item
|
||||||
static_cast<KeymapListItem*>(fUserListView->ItemAt(index));
|
= static_cast<KeymapListItem*>(listView->ItemAt(index));
|
||||||
if (keymapListItem != NULL) {
|
if (item != NULL) {
|
||||||
fCurrentMap.Load(keymapListItem->KeymapEntry());
|
if (!fFirstTime)
|
||||||
|
fCurrentMap.Load(item->EntryRef());
|
||||||
if (fFirstTime) {
|
else
|
||||||
fPreviousMap.Load(keymapListItem->KeymapEntry());
|
|
||||||
fAppliedMap.Load(keymapListItem->KeymapEntry());
|
|
||||||
fFirstTime = false;
|
fFirstTime = false;
|
||||||
}
|
|
||||||
|
|
||||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
||||||
|
|
||||||
// Deselect item in other BListView
|
|
||||||
fSystemListView->DeselectAll();
|
|
||||||
_UpdateButtons();
|
_UpdateButtons();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -428,14 +413,8 @@ KeymapWindow::_UpdateButtons()
|
|||||||
void
|
void
|
||||||
KeymapWindow::_RevertKeymap()
|
KeymapWindow::_RevertKeymap()
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append("Key_map");
|
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
get_ref_for_path(path.Path(), &ref);
|
_GetCurrentKeymap(ref);
|
||||||
|
|
||||||
status_t status = fPreviousMap.Save(ref);
|
status_t status = fPreviousMap.Save(ref);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
@@ -451,30 +430,22 @@ KeymapWindow::_RevertKeymap()
|
|||||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
||||||
|
|
||||||
fCurrentMapName = _GetActiveKeymapName();
|
fCurrentMapName = _GetActiveKeymapName();
|
||||||
|
_SelectCurrentMap();
|
||||||
if (!_SelectCurrentMap(fSystemListView)
|
|
||||||
&& !_SelectCurrentMap(fUserListView))
|
|
||||||
fUserListView->Select(0L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeymapWindow::_UseKeymap()
|
KeymapWindow::_UseKeymap()
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append("Key_map");
|
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
get_ref_for_path(path.Path(), &ref);
|
_GetCurrentKeymap(ref);
|
||||||
|
|
||||||
status_t err;
|
status_t status = fCurrentMap.Save(ref);
|
||||||
if ((err = fCurrentMap.Save(ref)) != B_OK) {
|
if (status != B_OK) {
|
||||||
printf("error when saving : %s", strerror(err));
|
printf("error when saving : %s", strerror(status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fCurrentMap.Use();
|
fCurrentMap.Use();
|
||||||
fAppliedMap.Load(ref);
|
fAppliedMap.Load(ref);
|
||||||
|
|
||||||
@@ -513,19 +484,14 @@ KeymapWindow::_FillUserMaps()
|
|||||||
while ((item = fUserListView->RemoveItem(static_cast<int32>(0))))
|
while ((item = fUserListView->RemoveItem(static_cast<int32>(0))))
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
path.Append("Key_map");
|
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
get_ref_for_path(path.Path(), &ref);
|
_GetCurrentKeymap(ref);
|
||||||
|
|
||||||
fUserListView->AddItem(new KeymapListItem(ref, "(Current)"));
|
fUserListView->AddItem(new KeymapListItem(ref, "(Current)"));
|
||||||
|
|
||||||
fCurrentMapName = _GetActiveKeymapName();
|
fCurrentMapName = _GetActiveKeymapName();
|
||||||
|
|
||||||
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -555,19 +521,27 @@ KeymapWindow::_SetListViewSize(BListView* listView)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeymapWindow::_GetCurrentKeymap(entry_ref& ref)
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
path.Append("Key_map");
|
||||||
|
|
||||||
|
return get_ref_for_path(path.Path(), &ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
KeymapWindow::_GetActiveKeymapName()
|
KeymapWindow::_GetActiveKeymapName()
|
||||||
{
|
{
|
||||||
BString mapName = "(Current)"; // safe default
|
BString mapName = "(Current)"; // safe default
|
||||||
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return mapName;
|
|
||||||
|
|
||||||
path.Append("Key_map");
|
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
get_ref_for_path(path.Path(), &ref);
|
_GetCurrentKeymap(ref);
|
||||||
|
|
||||||
BNode node(&ref);
|
BNode node(&ref);
|
||||||
|
|
||||||
if (node.InitCheck() == B_OK)
|
if (node.InitCheck() == B_OK)
|
||||||
@@ -594,3 +568,15 @@ KeymapWindow::_SelectCurrentMap(BListView* view)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeymapWindow::_SelectCurrentMap()
|
||||||
|
{
|
||||||
|
if (!_SelectCurrentMap(fSystemListView)
|
||||||
|
&& !_SelectCurrentMap(fUserListView)) {
|
||||||
|
// Select the "(Current)" entry if no name matches
|
||||||
|
fUserListView->Select(0L);
|
||||||
|
fFirstTime = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,8 +47,10 @@ protected:
|
|||||||
void _FillUserMaps();
|
void _FillUserMaps();
|
||||||
void _SetListViewSize(BListView* listView);
|
void _SetListViewSize(BListView* listView);
|
||||||
|
|
||||||
bool _SelectCurrentMap(BListView *list);
|
status_t _GetCurrentKeymap(entry_ref& ref);
|
||||||
BString _GetActiveKeymapName();
|
BString _GetActiveKeymapName();
|
||||||
|
bool _SelectCurrentMap(BListView *list);
|
||||||
|
void _SelectCurrentMap();
|
||||||
|
|
||||||
BListView* fSystemListView;
|
BListView* fSystemListView;
|
||||||
BListView* fUserListView;
|
BListView* fUserListView;
|
||||||
|
|||||||
Reference in New Issue
Block a user