Localization of Shortcuts based on a patch by Jorma Karvonen (ticket #5857),

thanks! I've tested the application, and it works (as bad) as before. To note
would be the possibility that custom actions may stop working when switching
the system to another language after configuring them. Don't know if I
concluded this potential problem from the code correctly, or if translated
strings are actually not stored with a KeySet.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36840 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-05-17 12:09:52 +00:00
parent 53d7472637
commit 3672a07ec1
6 changed files with 275 additions and 197 deletions

View File

@ -20,6 +20,16 @@ Preference Shortcuts :
PrefilledBitmap.cpp
ScrollViewCorner.cpp
: be tracker libshortcuts_shared.a $(TARGET_LIBSTDC++)
: be locale tracker libshortcuts_shared.a $(TARGET_LIBSTDC++)
: Shortcuts.rdef
;
DoCatalogs Shortcuts :
x-vnd.Haiku-Shortcuts
:
ShortcutsApp.cpp
ShortcutsWindow.cpp
ShortcutsSpec.cpp
;

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2009 Haiku Inc. All rights reserved.
* Copyright 1999-2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -11,12 +11,17 @@
#include "ShortcutsApp.h"
#include <Alert.h>
#include <Catalog.h>
#include <Locale.h>
#include "ShortcutsWindow.h"
#define APPLICATION_SIGNATURE "application/x-vnd.Haiku-Shortcuts"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsApp"
ShortcutsApp::ShortcutsApp()
:
@ -41,9 +46,10 @@ ShortcutsApp::~ShortcutsApp()
void
ShortcutsApp::AboutRequested()
{
BAlert* alert = new BAlert("About Shortcuts",
"Shortcuts\n\n"
"Based on SpicyKeys for BeOS made by Jeremy Friesner.", "OK");
BAlert* alert = new BAlert(B_TRANSLATE("About Shortcuts"),
B_TRANSLATE("Shortcuts\n\n"
"Based on SpicyKeys for BeOS made by Jeremy Friesner."),
B_TRANSLATE("OK"));
alert->Go();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2009 Haiku Inc. All rights reserved.
* Copyright 1999-2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -13,7 +13,9 @@
#include <stdio.h>
#include <Beep.h>
#include <Catalog.h>
#include <Directory.h>
#include <Locale.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Region.h>
@ -30,30 +32,23 @@
#define CLASS "ShortcutsSpec : "
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsSpec"
const float _height = 20.0f;
static MetaKeyStateMap _metaMaps[ShortcutsSpec::NUM_META_COLUMNS];
static bool _metaMapsInitialized = false;
static MetaKeyStateMap sMetaMaps[ShortcutsSpec::NUM_META_COLUMNS];
static bool _fontCached = false;
static BFont _viewFont;
static float _fontHeight;
static BBitmap * _actuatorBitmaps[2];
static bool sFontCached = false;
static BFont sViewFont;
static float sFontHeight;
static BBitmap* sActuatorBitmaps[2];
const char* ShortcutsSpec::sShiftName;
const char* ShortcutsSpec::sControlName;
const char* ShortcutsSpec::sOptionName;
const char* ShortcutsSpec::sCommandName;
// These meta-keys are pretty standard
#define SHIFT_NAME "Shift"
#define CONTROL_NAME "Control"
// These meta-keys have different names on an Intel keyboard
#if __INTEL__
#define OPTION_NAME "Window"
#define COMMAND_NAME "Alt"
#else
#define OPTION_NAME "Option"
#define COMMAND_NAME "Command"
#endif
#define ICON_BITMAP_RECT BRect(0.0f, 0.0f, 15.0f, 15.0f)
#define ICON_BITMAP_SPACE B_COLOR_8_BIT
@ -61,15 +56,13 @@ static BBitmap * _actuatorBitmaps[2];
// Returns the (pos)'th char in the string, or '\0' if (pos) if off the end of
// the string
static char GetLetterAt(const char* str, int pos);
static char
GetLetterAt(const char* str, int pos)
{
for (int i = 0; i < pos; i++)
for (int i = 0; i < pos; i++) {
if (str[i] == '\0')
return '\0';
}
return str[pos];
}
@ -99,13 +92,13 @@ SetupStandardMap(MetaKeyStateMap& map, const char* name, uint32 both,
}
MetaKeyStateMap & GetNthKeyMap(int which)
MetaKeyStateMap&
GetNthKeyMap(int which)
{
return _metaMaps[which];
return sMetaMaps[which];
}
static BBitmap* MakeActuatorBitmap(bool lit);
static BBitmap*
MakeActuatorBitmap(bool lit)
{
@ -135,23 +128,30 @@ MakeActuatorBitmap(bool lit)
}
void InitializeMetaMaps()
/*static*/ void
ShortcutsSpec::InitializeMetaMaps()
{
_metaMapsInitialized = true;
SetupStandardMap(_metaMaps[ShortcutsSpec::SHIFT_COLUMN_INDEX], SHIFT_NAME,
static bool metaMapsInitialized = false;
if (metaMapsInitialized)
return;
metaMapsInitialized = true;
_InitModifierNames();
SetupStandardMap(sMetaMaps[ShortcutsSpec::SHIFT_COLUMN_INDEX], sShiftName,
B_SHIFT_KEY, B_LEFT_SHIFT_KEY, B_RIGHT_SHIFT_KEY);
SetupStandardMap(_metaMaps[ShortcutsSpec::CONTROL_COLUMN_INDEX],
CONTROL_NAME, B_CONTROL_KEY, B_LEFT_CONTROL_KEY, B_RIGHT_CONTROL_KEY);
SetupStandardMap(sMetaMaps[ShortcutsSpec::CONTROL_COLUMN_INDEX],
sControlName, B_CONTROL_KEY, B_LEFT_CONTROL_KEY, B_RIGHT_CONTROL_KEY);
SetupStandardMap(_metaMaps[ShortcutsSpec::COMMAND_COLUMN_INDEX],
COMMAND_NAME, B_COMMAND_KEY, B_LEFT_COMMAND_KEY, B_RIGHT_COMMAND_KEY);
SetupStandardMap(sMetaMaps[ShortcutsSpec::COMMAND_COLUMN_INDEX],
sCommandName, B_COMMAND_KEY, B_LEFT_COMMAND_KEY, B_RIGHT_COMMAND_KEY);
SetupStandardMap(_metaMaps[ShortcutsSpec::OPTION_COLUMN_INDEX], OPTION_NAME
SetupStandardMap(sMetaMaps[ShortcutsSpec::OPTION_COLUMN_INDEX], sOptionName
, B_OPTION_KEY, B_LEFT_OPTION_KEY, B_RIGHT_OPTION_KEY);
_actuatorBitmaps[0] = MakeActuatorBitmap(false);
_actuatorBitmaps[1] = MakeActuatorBitmap(true);
sActuatorBitmaps[0] = MakeActuatorBitmap(false);
sActuatorBitmaps[1] = MakeActuatorBitmap(true);
}
@ -203,19 +203,24 @@ ShortcutsSpec::ShortcutsSpec(BMessage* from)
{
const char* temp;
if (from->FindString("command", &temp) != B_NO_ERROR) {
printf(CLASS " Error, no command string in archive BMessage!\n");
printf(CLASS);
printf(" Error, no command string in archive BMessage!\n");
temp = "";
}
SetCommand(temp);
if (from->FindInt32("key", (int32*) &fKey) != B_NO_ERROR)
printf(CLASS " Error, no key int32 in archive BMessage!\n");
if (from->FindInt32("key", (int32*) &fKey) != B_NO_ERROR) {
printf(CLASS);
printf(" Error, no key int32 in archive BMessage!\n");
}
for (int i = 0; i < NUM_META_COLUMNS; i++)
if (from->FindInt32("mcidx", i, (int32*)&fMetaCellStateIndex[i])
!= B_NO_ERROR)
printf(CLASS " Error, no modifiers int32 in archive BMessage!\n");
!= B_NO_ERROR) {
printf(CLASS);
printf(" Error, no modifiers int32 in archive BMessage!\n");
}
}
@ -234,7 +239,7 @@ ShortcutsSpec::SetCommand(const char* command)
const char*
ShortcutsSpec::GetColumnName(int i)
{
return _metaMaps[i].GetName();
return sMetaMaps[i].GetName();
}
@ -256,7 +261,7 @@ ShortcutsSpec::Archive(BMessage* into, bool deep) const
for (int i = 0; i < NUM_META_COLUMNS; i++) {
// for easy parsing by prefs applet on load-in
into->AddInt32("mcidx", fMetaCellStateIndex[i]);
test.AddSlave(_metaMaps[i].GetNthStateTester(fMetaCellStateIndex[i]));
test.AddSlave(sMetaMaps[i].GetNthStateTester(fMetaCellStateIndex[i]));
}
BMessage testerMsg;
@ -283,16 +288,16 @@ static bool IsValidActuatorName(const char* c);
static bool
IsValidActuatorName(const char* c)
{
return (strcmp(c, "InsertString") == 0
|| strcmp(c, "MoveMouse") == 0
|| strcmp(c, "MoveMouseTo") == 0
|| strcmp(c, "MouseButton") == 0
|| strcmp(c, "LaunchHandler") == 0
|| strcmp(c, "Multi") == 0
|| strcmp(c, "MouseDown") == 0
|| strcmp(c, "MouseUp") == 0
|| strcmp(c, "SendMessage") == 0
|| strcmp(c, "Beep") == 0);
return (strcmp(c, B_TRANSLATE("InsertString")) == 0
|| strcmp(c, B_TRANSLATE("MoveMouse")) == 0
|| strcmp(c, B_TRANSLATE("MoveMouseTo")) == 0
|| strcmp(c, B_TRANSLATE("MouseButton")) == 0
|| strcmp(c, B_TRANSLATE("LaunchHandler")) == 0
|| strcmp(c, B_TRANSLATE("Multi")) == 0
|| strcmp(c, B_TRANSLATE("MouseDown")) == 0
|| strcmp(c, B_TRANSLATE("MouseUp")) == 0
|| strcmp(c, B_TRANSLATE("SendMessage")) == 0
|| strcmp(c, B_TRANSLATE("Beep")) == 0);
}
@ -323,12 +328,12 @@ ShortcutsSpec::~ShortcutsSpec()
void
ShortcutsSpec::_CacheViewFont(BView* owner)
{
if (_fontCached == false) {
_fontCached = true;
owner->GetFont(&_viewFont);
if (sFontCached == false) {
sFontCached = true;
owner->GetFont(&sViewFont);
font_height fh;
_viewFont.GetHeight(&fh);
_fontHeight = fh.ascent - fh.descent;
sViewFont.GetHeight(&fh);
sFontHeight = fh.ascent - fh.descent;
}
}
@ -355,7 +360,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
if (text == NULL)
return;
float textWidth = _viewFont.StringWidth(text);
float textWidth = sViewFont.StringWidth(text);
BPoint point;
rgb_color lowColor = color;
@ -395,7 +400,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
_CacheViewFont(owner);
// How about I draw a nice "key" background for this one?
BRect textRect(point.x - KEY_MARGIN, (point.y-_fontHeight) - KEY_MARGIN
BRect textRect(point.x - KEY_MARGIN, (point.y-sFontHeight) - KEY_MARGIN
, point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN);
if (column_index == KEY_COLUMN_INDEX)
@ -439,7 +444,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
owner->SetDrawingMode(B_OP_OVER);
if ((fCommand != NULL) && (fCommand[0] == '*'))
owner->DrawBitmap(_actuatorBitmaps[fBitmapValid ? 1 : 0],
owner->DrawBitmap(sActuatorBitmaps[fBitmapValid ? 1 : 0],
ICON_BITMAP_RECT, item_column_rect);
else
// Draw icon, if any
@ -469,8 +474,7 @@ const char*
ShortcutsSpec::GetCellText(int whichColumn) const
{
const char* temp = ""; // default
switch(whichColumn)
{
switch(whichColumn) {
case KEY_COLUMN_INDEX:
{
if ((fKey > 0) && (fKey <= 0xFF)) {
@ -478,21 +482,21 @@ ShortcutsSpec::GetCellText(int whichColumn) const
if (temp == NULL)
temp = "";
} else if (fKey > 0xFF) {
sprintf(fScratch, "#%x", fKey);
sprintf(fScratch, "#%lx", fKey);
return fScratch;
}
break;
}
break;
case STRING_COLUMN_INDEX:
temp = fCommand;
break;
break;
default:
if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS))
temp = _metaMaps[whichColumn].GetNthStateDesc(
temp = sMetaMaps[whichColumn].GetNthStateDesc(
fMetaCellStateIndex[whichColumn]);
break;
break;
}
return temp;
}
@ -519,7 +523,7 @@ ShortcutsSpec::ProcessColumnTextString(int whichColumn, const char* string)
case STRING_COLUMN_INDEX:
SetCommand(string);
return true;
break;
break;
case KEY_COLUMN_INDEX:
{
@ -657,13 +661,13 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
bool ret = false;
switch(whichColumn) {
case KEY_COLUMN_INDEX:
if (key != -1) {
if (fKey != key) {
if (key > -1) {
if ((int32)fKey != key) {
fKey = key;
ret = true;
}
}
break;
break;
case STRING_COLUMN_INDEX:
{
@ -694,7 +698,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
bool reAllocString = false;
// Make sure we have enough room in our command string
// to add these chars...
while (fCommandLen - fCommandNul <= newCharLen) {
while ((int)fCommandLen - fCommandNul <= newCharLen) {
reAllocString = true;
// enough for a while...
fCommandLen = (fCommandLen + 10) * 2;
@ -717,12 +721,12 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
}
}
}
break;
}
break;
default:
if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) {
MetaKeyStateMap * map = &_metaMaps[whichColumn];
MetaKeyStateMap * map = &sMetaMaps[whichColumn];
int curState = fMetaCellStateIndex[whichColumn];
int origState = curState;
int numStates = map->GetNumStates();
@ -732,12 +736,12 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
case B_RETURN:
// cycle to the previous state
curState = (curState + numStates - 1) % numStates;
break;
break;
case B_SPACE:
// cycle to the next state
curState = (curState + 1) % numStates;
break;
break;
default:
{
@ -760,17 +764,17 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
break;
}
} else
printf("Error, NULL state description?\n");
printf(B_TRANSLATE("Error, NULL state description?\n"));
}
break;
}
break;
}
fMetaCellStateIndex[whichColumn] = curState;
if (curState != origState)
ret = true;
}
break;
break;
}
return ret;
@ -812,8 +816,8 @@ ShortcutsSpec::_UpdateIconBitmap()
BString firstWord = ParseArgvZeroFromString(fCommand);
// Only need to change if the first word has changed...
if ((fLastBitmapName == NULL) || (firstWord.Length() == 0) ||
(firstWord.Compare(fLastBitmapName))) {
if (fLastBitmapName == NULL || firstWord.Length() == 0
|| firstWord.Compare(fLastBitmapName)) {
if (firstWord.ByteAt(0) == '*')
fBitmapValid = IsValidActuatorName(&firstWord.String()[1]);
else {
@ -832,8 +836,9 @@ ShortcutsSpec::_UpdateIconBitmap()
BNodeInfo progNodeInfo(&progNode);
if ((progNodeInfo.InitCheck() == B_NO_ERROR)
&& (progNodeInfo.GetTrackerIcon(&fBitmap, B_MINI_ICON)
== B_NO_ERROR))
== B_NO_ERROR)) {
fBitmapValid = fBitmap.IsValid();
}
}
}
}
@ -841,3 +846,25 @@ ShortcutsSpec::_UpdateIconBitmap()
}
}
/*static*/ void
ShortcutsSpec::_InitModifierNames()
{
sShiftName = B_TRANSLATE_COMMENT("Shift",
"Name for modifier on keyboard");
sControlName = B_TRANSLATE_COMMENT("Control",
"Name for modifier on keyboard");
// TODO: Wrapping in __INTEL__ define probably won't work to extract catkeys?
#if __INTEL__
sOptionName = B_TRANSLATE_COMMENT("Window",
"Name for modifier on keyboard");
sCommandName = B_TRANSLATE_COMMENT("Alt",
"Name for modifier on keyboard");
#else
sOptionName = B_TRANSLATE_COMMENT("Option",
"Name for modifier on keyboard");
sCommandName = B_TRANSLATE_COMMENT("Command",
"Name for modifier on keyboard");
#endif
}

View File

@ -20,8 +20,6 @@ class MetaKeyStateMap;
MetaKeyStateMap & GetNthKeyMap(int which);
void InitializeMetaMaps();
/* Objects of this class represent one hotkey "entry" in the preferences
* ListView. Each ShortcutsSpec contains the info necessary to generate both
@ -30,6 +28,8 @@ void InitializeMetaMaps();
*/
class ShortcutsSpec : public CLVListItem {
public:
static void InitializeMetaMaps();
ShortcutsSpec(const char* command);
ShortcutsSpec(const ShortcutsSpec& copyMe);
ShortcutsSpec(BMessage* from);
@ -102,6 +102,14 @@ private:
bool fCursorPtsValid;
mutable char fScratch[50];
int32 fSelectedColumn;
private:
static void _InitModifierNames();
static const char* sShiftName;
static const char* sControlName;
static const char* sOptionName;
static const char* sCommandName;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2009 Haiku Inc. All rights reserved.
* Copyright 1999-2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -15,10 +15,12 @@
#include <Alert.h>
#include <Application.h>
#include <Catalog.h>
#include <Clipboard.h>
#include <File.h>
#include <FindDirectory.h>
#include <Input.h>
#include <Locale.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
@ -48,6 +50,9 @@
#define WINDOW_START_X 30
#define WINDOW_START_Y 100
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsWindow"
#define ERROR "Shortcuts error"
#define WARNING "Shortcuts warning"
@ -57,8 +62,8 @@
// Creates a pop-up-menu that reflects the possible states of the specified
// meta-key.
static BPopUpMenu* CreateMetaPopUp(int col);
static BPopUpMenu* CreateMetaPopUp(int col)
static BPopUpMenu*
CreateMetaPopUp(int col)
{
MetaKeyStateMap& map = GetNthKeyMap(col);
BPopUpMenu * popup = new BPopUpMenu(NULL, false);
@ -72,8 +77,8 @@ static BPopUpMenu* CreateMetaPopUp(int col)
// Creates a pop-up that allows the user to choose a key-cap visually
static BPopUpMenu* CreateKeysPopUp();
static BPopUpMenu* CreateKeysPopUp()
static BPopUpMenu*
CreateKeysPopUp()
{
BPopUpMenu* popup = new BPopUpMenu(NULL, false);
int numKeys = GetNumKeyIndices();
@ -90,33 +95,37 @@ static BPopUpMenu* CreateKeysPopUp()
ShortcutsWindow::ShortcutsWindow()
:
BWindow(BRect(WINDOW_START_X, WINDOW_START_Y, WINDOW_START_X + MIN_WIDTH,
WINDOW_START_Y + MIN_HEIGHT * 2), "Shortcuts", B_DOCUMENT_WINDOW, 0L),
fSavePanel(NULL),
fOpenPanel(NULL),
fSelectPanel(NULL),
fKeySetModified(false),
fLastOpenWasAppend(false)
WINDOW_START_Y + MIN_HEIGHT * 2), B_TRANSLATE("Shortcuts"),
B_DOCUMENT_WINDOW, 0L),
fSavePanel(NULL),
fOpenPanel(NULL),
fSelectPanel(NULL),
fKeySetModified(false),
fLastOpenWasAppend(false)
{
InitializeMetaMaps();
ShortcutsSpec::InitializeMetaMaps();
SetSizeLimits(MIN_WIDTH, MAX_WIDTH, MIN_HEIGHT, MAX_HEIGHT);
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar");
BMenu* fileMenu = new BMenu("File");
fileMenu->AddItem(new BMenuItem("Open KeySet...",
BMenu* fileMenu = new BMenu(B_TRANSLATE("File"));
fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Open KeySet" B_UTF8_ELLIPSIS),
new BMessage(OPEN_KEYSET), 'O'));
fileMenu->AddItem(new BMenuItem("Append KeySet...",
fileMenu->AddItem(new BMenuItem(
B_TRANSLATE("Append KeySet" B_UTF8_ELLIPSIS),
new BMessage(APPEND_KEYSET), 'A'));
fileMenu->AddItem(new BMenuItem("Revert to saved",
fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Revert to saved"),
new BMessage(REVERT_KEYSET), 'A'));
fileMenu->AddItem(new BSeparatorItem);
fileMenu->AddItem(new BMenuItem("Save KeySet as...",
fileMenu->AddItem(new BMenuItem(
B_TRANSLATE("Save KeySet as" B_UTF8_ELLIPSIS),
new BMessage(SAVE_KEYSET_AS), 'S'));
fileMenu->AddItem(new BSeparatorItem);
fileMenu->AddItem(new BMenuItem("About Shortcuts",
fileMenu->AddItem(new BMenuItem(B_TRANSLATE("About Shortcuts"),
new BMessage(B_ABOUT_REQUESTED)));
fileMenu->AddItem(new BSeparatorItem);
fileMenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
'Q'));
fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
new BMessage(B_QUIT_REQUESTED), 'Q'));
menuBar->AddItem(fileMenu);
AddChild(menuBar);
@ -141,30 +150,36 @@ ShortcutsWindow::ShortcutsWindow()
const float metaWidth = 50.0f;
for (int i = 0; i < ShortcutsSpec::NUM_META_COLUMNS; i++)
for (int i = 0; i < ShortcutsSpec::NUM_META_COLUMNS; i++) {
fColumnListView->AddColumn(
new CLVColumn(ShortcutsSpec::GetColumnName(i), CreateMetaPopUp(i),
metaWidth, CLV_SORT_KEYABLE));
}
fColumnListView->AddColumn(new CLVColumn("Key", CreateKeysPopUp(), 60,
CLV_SORT_KEYABLE));
fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Key"),
CreateKeysPopUp(), 60, CLV_SORT_KEYABLE));
BPopUpMenu* popup = new BPopUpMenu(NULL, false);
popup->AddItem(new BMenuItem("(Choose application with file requester)", NULL));
popup->AddItem(new BMenuItem("*InsertString \"Your Text Here\"", NULL));
popup->AddItem(new BMenuItem("*MoveMouse +20 +0", NULL));
popup->AddItem(new BMenuItem("*MoveMouseTo 50% 50%", NULL));
popup->AddItem(new BMenuItem("*MouseButton 1", NULL));
popup->AddItem(new BMenuItem("*LaunchHandler text/html", NULL));
popup->AddItem(new BMenuItem(
"*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\"", NULL));
popup->AddItem(new BMenuItem("*MouseDown", NULL));
popup->AddItem(new BMenuItem("*MouseUp", NULL));
B_TRANSLATE("(Choose application with file requester)"), NULL));
popup->AddItem(new BMenuItem(
"*SendMessage application/x-vnd.Be-TRAK 'Tfnd'", NULL));
popup->AddItem(new BMenuItem("*Beep", NULL));
fColumnListView->AddColumn(new CLVColumn("Application", popup, 323.0,
CLV_SORT_KEYABLE));
B_TRANSLATE("*InsertString \"Your Text Here\""), NULL));
popup->AddItem(new BMenuItem(
B_TRANSLATE("*MoveMouse +20 +0"), NULL));
popup->AddItem(new BMenuItem(B_TRANSLATE("*MoveMouseTo 50% 50%"), NULL));
popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseButton 1"), NULL));
popup->AddItem(new BMenuItem(
B_TRANSLATE("*LaunchHandler text/html"), NULL));
popup->AddItem(new BMenuItem(
B_TRANSLATE("*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\""),
NULL));
popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseDown"), NULL));
popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseUp"), NULL));
popup->AddItem(new BMenuItem(
B_TRANSLATE("*SendMessage application/x-vnd.Be-TRAK 'Tfnd'"), NULL));
popup->AddItem(new BMenuItem(B_TRANSLATE("*Beep"), NULL));
fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Application"), popup,
323.0, CLV_SORT_KEYABLE));
fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare);
AddChild(containerView);
@ -174,8 +189,8 @@ ShortcutsWindow::ShortcutsWindow()
BRect buttonBounds = Bounds();
buttonBounds.left += V_SPACING;
buttonBounds.right = ((buttonBounds.right - buttonBounds.left) / 2.0f) +
buttonBounds.left;
buttonBounds.right = ((buttonBounds.right - buttonBounds.left) / 2.0f)
+ buttonBounds.left;
buttonBounds.bottom -= V_SPACING * 2;
buttonBounds.top = buttonBounds.bottom - vButtonHeight;
buttonBounds.right -= B_V_SCROLL_BAR_WIDTH;
@ -183,11 +198,11 @@ ShortcutsWindow::ShortcutsWindow()
buttonBounds.right = (buttonBounds.left + origRight) * 0.40f -
(V_SPACING / 2);
AddChild(fAddButton = new ResizableButton(Bounds(), buttonBounds, "add",
"Add new shortcut", new BMessage(ADD_HOTKEY_ITEM)));
B_TRANSLATE("Add new shortcut"), new BMessage(ADD_HOTKEY_ITEM)));
buttonBounds.left = buttonBounds.right + V_SPACING;
buttonBounds.right = origRight;
AddChild(fRemoveButton = new ResizableButton(Bounds(), buttonBounds,
"remove", "Remove selected shortcut",
"remove", B_TRANSLATE("Remove selected shortcut"),
new BMessage(REMOVE_HOTKEY_ITEM)));
fRemoveButton->SetEnabled(false);
@ -197,7 +212,7 @@ ShortcutsWindow::ShortcutsWindow()
saveButtonBounds.right = Bounds().right - B_V_SCROLL_BAR_WIDTH - offset;
saveButtonBounds.left = buttonBounds.right + V_SPACING + offset;
AddChild(fSaveButton = new ResizableButton(Bounds(), saveButtonBounds,
"save", "Save & apply", new BMessage(SAVE_KEYSET)));
"save", B_TRANSLATE("Save & apply"), new BMessage(SAVE_KEYSET)));
fSaveButton->SetEnabled(false);
@ -228,31 +243,33 @@ ShortcutsWindow::QuitRequested()
if (fKeySetModified) {
BAlert* alert = new BAlert(WARNING,
"Really quit without saving your changes?", "Don't save", "Cancel",
"Save");
B_TRANSLATE("Really quit without saving your changes?"),
B_TRANSLATE("Don't save"), B_TRANSLATE("Cancel"),
B_TRANSLATE("Save"));
switch(alert->Go()) {
case 1:
ret = false;
break;
break;
case 2:
// Save: automatically if possible, otherwise go back and open
// up the file requester
if (fLastSaved.InitCheck() == B_NO_ERROR) {
if (fLastSaved.InitCheck() == B_OK) {
if (_SaveKeySet(fLastSaved) == false) {
(new BAlert(ERROR,
"Shortcuts was unable to save your KeySet file!",
"Oh no"))->Go();
B_TRANSLATE("Shortcuts was unable to save your "
"KeySet file!"),
B_TRANSLATE("Oh no")))->Go();
ret = true; //quit anyway
}
} else {
PostMessage(SAVE_KEYSET);
ret = false;
}
break;
break;
default:
ret = true;
break;
break;
}
}
@ -271,7 +288,7 @@ ShortcutsWindow::_GetSettingsFile(entry_ref* eref)
else
path.Append(SHORTCUTS_SETTING_FILE_NAME);
if (BEntry(path.Path(), true).GetRef(eref) == B_NO_ERROR)
if (BEntry(path.Path(), true).GetRef(eref) == B_OK)
return true;
else
return false;
@ -283,20 +300,20 @@ bool
ShortcutsWindow::_SaveKeySet(BEntry& saveEntry)
{
BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (saveTo.InitCheck() != B_NO_ERROR)
if (saveTo.InitCheck() != B_OK)
return false;
BMessage saveMsg;
for (int i = 0; i < fColumnListView->CountItems(); i++) {
BMessage next;
if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next)
== B_NO_ERROR)
== B_OK)
saveMsg.AddMessage("spec", &next);
else
printf("Error archiving ShortcutsSpec #%i!\n",i);
printf("Error archiving ShortcutsSpec #%i!\n", i);
}
bool ret = (saveMsg.Flatten(&saveTo) == B_NO_ERROR);
bool ret = (saveMsg.Flatten(&saveTo) == B_OK);
if (ret) {
fKeySetModified = false;
@ -314,7 +331,7 @@ ShortcutsWindow::_LoadKeySet(const BMessage& loadMsg)
{
int i = 0;
BMessage msg;
while (loadMsg.FindMessage("spec", i++, &msg) == B_NO_ERROR) {
while (loadMsg.FindMessage("spec", i++, &msg) == B_OK) {
ShortcutsSpec* spec = (ShortcutsSpec*)ShortcutsSpec::Instantiate(&msg);
if (spec != NULL)
fColumnListView->AddItem(spec);
@ -364,8 +381,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
fOpenPanel->Show();
}
fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ?
"Append" : "Open");
break;
B_TRANSLATE("Append") : B_TRANSLATE("Open"));
break;
case REVERT_KEYSET:
{
@ -377,8 +394,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
reload.AddRef("refs", &eref);
reload.AddString("startupRef", "yeah");
PostMessage(&reload);
break;
}
break;
// Respond to drag-and-drop messages here
case B_SIMPLE_DATA:
@ -386,12 +403,12 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
int i = 0;
entry_ref ref;
while (msg->FindRef("refs", i++, &ref) == B_NO_ERROR) {
while (msg->FindRef("refs", i++, &ref) == B_OK) {
BEntry entry(&ref);
if (entry.InitCheck() == B_NO_ERROR) {
if (entry.InitCheck() == B_OK) {
BPath path(&entry);
if (path.InitCheck() == B_NO_ERROR) {
if (path.InitCheck() == B_OK) {
// Add a new item with the given path.
BString str(path.Path());
DoStandardEscapes(str);
@ -399,8 +416,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
}
}
}
break;
}
break;
// Respond to FileRequester's messages here
case B_REFS_RECEIVED:
@ -408,21 +425,21 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
// Find file ref
entry_ref ref;
bool isStartMsg = msg->HasString("startupRef");
if (msg->FindRef("refs", &ref) == B_NO_ERROR) {
if (msg->FindRef("refs", &ref) == B_OK) {
// load the file into (fileMsg)
BMessage fileMsg;
{
BFile file(&ref, B_READ_ONLY);
if ((file.InitCheck() != B_NO_ERROR)
|| (fileMsg.Unflatten(&file) != B_NO_ERROR)) {
if ((file.InitCheck() != B_OK)
|| (fileMsg.Unflatten(&file) != B_OK)) {
if (isStartMsg) {
// use this to save to anyway
fLastSaved = BEntry(&ref);
break;
} else {
(new BAlert(ERROR,
"Shortcuts was couldn't open your KeySet file!"
, "Okay"))->Go(NULL);
B_TRANSLATE("Shortcuts was couldn't open your "
"KeySet file!"), B_TRANSLATE("OK")))->Go(NULL);
break;
}
}
@ -430,11 +447,10 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (fLastOpenWasAppend == false) {
// Clear the menu...
ShortcutsSpec * item;
do {
delete (item = ((ShortcutsSpec*)
fColumnListView->RemoveItem(int32(0))));
} while (item);
while (ShortcutsSpec* item
= ((ShortcutsSpec*)fColumnListView->RemoveItem(0L))) {
delete item;
}
}
if (_LoadKeySet(fileMsg)) {
@ -448,13 +464,14 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (ref == eref) fKeySetModified = false;
} else {
(new BAlert(ERROR,
"Shortcuts was unable to parse your KeySet file!",
"Okay"))->Go(NULL);
B_TRANSLATE("Shortcuts was unable to parse your "
"KeySet file!"),
B_TRANSLATE("OK")))->Go(NULL);
break;
}
}
break;
}
break;
// These messages come from the pop-up menu of the Applications column
case SELECT_APPLICATION:
@ -462,11 +479,11 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
int csel = fColumnListView->CurrentSelection();
if (csel >= 0) {
entry_ref aref;
if (msg->FindRef("refs", &aref) == B_NO_ERROR) {
if (msg->FindRef("refs", &aref) == B_OK) {
BEntry ent(&aref);
if (ent.InitCheck() == B_NO_ERROR) {
if (ent.InitCheck() == B_OK) {
BPath path;
if ((ent.GetPath(&path) == B_NO_ERROR)
if ((ent.GetPath(&path) == B_OK)
&& (((ShortcutsSpec *)
fColumnListView->ItemAt(csel))->
ProcessColumnTextString(ShortcutsSpec::
@ -478,8 +495,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
}
}
}
break;
}
break;
case SAVE_KEYSET:
{
@ -487,23 +504,24 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
const char * name;
entry_ref entry;
if ((msg->FindString("name", &name) == B_NO_ERROR)
&& (msg->FindRef("directory", &entry) == B_NO_ERROR)) {
if ((msg->FindString("name", &name) == B_OK)
&& (msg->FindRef("directory", &entry) == B_OK)) {
BDirectory dir(&entry);
BEntry saveTo(&dir, name, true);
showSaveError = ((saveTo.InitCheck() != B_NO_ERROR)
showSaveError = ((saveTo.InitCheck() != B_OK)
|| (_SaveKeySet(saveTo) == false));
} else if (fLastSaved.InitCheck() == B_NO_ERROR) {
} else if (fLastSaved.InitCheck() == B_OK) {
// We've saved this before, save over previous file.
showSaveError = (_SaveKeySet(fLastSaved) == false);
} else PostMessage(SAVE_KEYSET_AS); // open the save requester...
if (showSaveError) {
(new BAlert(ERROR, "Shortcuts wasn't able to save your keyset."
, "Okay"))->Go(NULL);
(new BAlert(ERROR,
B_TRANSLATE("Shortcuts wasn't able to save your keyset."),
B_TRANSLATE("OK")))->Go(NULL);
}
break;
}
break;
case SAVE_KEYSET_AS:
{
@ -516,16 +534,16 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
false, &msg);
fSavePanel->Show();
}
break;
}
break;
case B_ABOUT_REQUESTED:
be_app_messenger.SendMessage(B_ABOUT_REQUESTED);
break;
break;
case ADD_HOTKEY_ITEM:
_AddNewSpec(NULL);
break;
break;
case REMOVE_HOTKEY_ITEM:
{
@ -552,8 +570,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
}
}
}
break;
}
break;
// Received when the user clicks on the ColumnListView
case HOTKEY_ITEM_SELECTED:
@ -562,16 +580,16 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
msg->FindInt32("index", &index);
bool validItem = (index >= 0);
fRemoveButton->SetEnabled(validItem);
break;
}
break;
// Received when an entry is to be modified in response to GUI activity
case HOTKEY_ITEM_MODIFIED:
{
int32 row, column;
if ((msg->FindInt32("row", &row) == B_NO_ERROR)
&& (msg->FindInt32("column", &column) == B_NO_ERROR)) {
if ((msg->FindInt32("row", &row) == B_OK)
&& (msg->FindInt32("column", &column) == B_OK)) {
int32 key;
const char* bytes;
@ -582,17 +600,17 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (msg->HasInt32("mouseClick")) {
repaintNeeded = item->ProcessColumnMouseClick(column);
} else if ((msg->FindString("bytes", &bytes) == B_NO_ERROR)
&& (msg->FindInt32("key", &key) == B_NO_ERROR)) {
} else if ((msg->FindString("bytes", &bytes) == B_OK)
&& (msg->FindInt32("key", &key) == B_OK)) {
repaintNeeded = item->ProcessColumnKeyStroke(column,
bytes, key);
} else if (msg->FindInt32("unmappedkey", &key) ==
B_NO_ERROR) {
B_OK) {
repaintNeeded = ((column == item->KEY_COLUMN_INDEX)
&& ((key > 0xFF) || (GetKeyName(key) != NULL))
&& (item->ProcessColumnKeyStroke(column, NULL,
key)));
} else if (msg->FindString("text", &bytes) == B_NO_ERROR) {
} else if (msg->FindString("text", &bytes) == B_OK) {
if ((bytes[0] == '(')&&(bytes[1] == 'C')) {
if (fSelectPanel)
fSelectPanel->Show();
@ -604,10 +622,11 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
fSelectPanel->Show();
}
fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON,
"Select");
} else
B_TRANSLATE("Select"));
} else {
repaintNeeded = item->ProcessColumnTextString(
column, bytes);
}
}
if (repaintNeeded) {
@ -616,12 +635,12 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
}
}
}
break;
}
break;
default:
BWindow::MessageReceived(msg);
break;
break;
}
}
@ -686,7 +705,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
}
be_clipboard->Unlock();
}
break;
break;
case B_PASTE:
if (be_clipboard->Lock()) {
@ -694,7 +713,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
const char* text;
ssize_t textLen;
if (data->FindData("text/plain", B_MIME_TYPE, (const void**)
&text, &textLen) == B_NO_ERROR) {
&text, &textLen) == B_OK) {
int32 row = fColumnListView->CurrentSelection();
int32 column = fColumnListView->GetSelectedColumn();
if ((row >= 0)
@ -713,11 +732,11 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
}
be_clipboard->Unlock();
}
break;
break;
default:
BWindow::DispatchMessage(msg, handler);
break;
break;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2009 Haiku Inc. All rights reserved.
* Copyright 1999-2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -7,14 +7,22 @@
*/
#include <Catalog.h>
#include <Locale.h>
#include "KeyInfos.h"
#include "ShortcutsApp.h"
int main(int argc, char** argv)
int
main(int argc, char** argv)
{
InitKeyIndices();
ShortcutsApp app;
BCatalog appCatalog;
be_locale->GetAppCatalog(&appCatalog);
app.Run();
}