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
+11 -1
View File
@@ -20,6 +20,16 @@ Preference Shortcuts :
PrefilledBitmap.cpp PrefilledBitmap.cpp
ScrollViewCorner.cpp ScrollViewCorner.cpp
: be tracker libshortcuts_shared.a $(TARGET_LIBSTDC++) : be locale tracker libshortcuts_shared.a $(TARGET_LIBSTDC++)
: Shortcuts.rdef : Shortcuts.rdef
; ;
DoCatalogs Shortcuts :
x-vnd.Haiku-Shortcuts
:
ShortcutsApp.cpp
ShortcutsWindow.cpp
ShortcutsSpec.cpp
;
+10 -4
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -11,12 +11,17 @@
#include "ShortcutsApp.h" #include "ShortcutsApp.h"
#include <Alert.h> #include <Alert.h>
#include <Catalog.h>
#include <Locale.h>
#include "ShortcutsWindow.h" #include "ShortcutsWindow.h"
#define APPLICATION_SIGNATURE "application/x-vnd.Haiku-Shortcuts" #define APPLICATION_SIGNATURE "application/x-vnd.Haiku-Shortcuts"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsApp"
ShortcutsApp::ShortcutsApp() ShortcutsApp::ShortcutsApp()
: :
@@ -41,9 +46,10 @@ ShortcutsApp::~ShortcutsApp()
void void
ShortcutsApp::AboutRequested() ShortcutsApp::AboutRequested()
{ {
BAlert* alert = new BAlert("About Shortcuts", BAlert* alert = new BAlert(B_TRANSLATE("About Shortcuts"),
"Shortcuts\n\n" B_TRANSLATE("Shortcuts\n\n"
"Based on SpicyKeys for BeOS made by Jeremy Friesner.", "OK"); "Based on SpicyKeys for BeOS made by Jeremy Friesner."),
B_TRANSLATE("OK"));
alert->Go(); alert->Go();
} }
+110 -83
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -13,7 +13,9 @@
#include <stdio.h> #include <stdio.h>
#include <Beep.h> #include <Beep.h>
#include <Catalog.h>
#include <Directory.h> #include <Directory.h>
#include <Locale.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Path.h> #include <Path.h>
#include <Region.h> #include <Region.h>
@@ -30,30 +32,23 @@
#define CLASS "ShortcutsSpec : " #define CLASS "ShortcutsSpec : "
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsSpec"
const float _height = 20.0f; const float _height = 20.0f;
static MetaKeyStateMap _metaMaps[ShortcutsSpec::NUM_META_COLUMNS]; static MetaKeyStateMap sMetaMaps[ShortcutsSpec::NUM_META_COLUMNS];
static bool _metaMapsInitialized = false;
static bool _fontCached = false; static bool sFontCached = false;
static BFont _viewFont; static BFont sViewFont;
static float _fontHeight; static float sFontHeight;
static BBitmap * _actuatorBitmaps[2]; 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_RECT BRect(0.0f, 0.0f, 15.0f, 15.0f)
#define ICON_BITMAP_SPACE B_COLOR_8_BIT #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 // Returns the (pos)'th char in the string, or '\0' if (pos) if off the end of
// the string // the string
static char GetLetterAt(const char* str, int pos);
static char static char
GetLetterAt(const char* str, int pos) GetLetterAt(const char* str, int pos)
{ {
for (int i = 0; i < pos; i++) for (int i = 0; i < pos; i++) {
if (str[i] == '\0') if (str[i] == '\0')
return '\0'; return '\0';
}
return str[pos]; 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* static BBitmap*
MakeActuatorBitmap(bool lit) MakeActuatorBitmap(bool lit)
{ {
@@ -135,23 +128,30 @@ MakeActuatorBitmap(bool lit)
} }
void InitializeMetaMaps() /*static*/ void
ShortcutsSpec::InitializeMetaMaps()
{ {
_metaMapsInitialized = true; static bool metaMapsInitialized = false;
SetupStandardMap(_metaMaps[ShortcutsSpec::SHIFT_COLUMN_INDEX], SHIFT_NAME, if (metaMapsInitialized)
return;
metaMapsInitialized = true;
_InitModifierNames();
SetupStandardMap(sMetaMaps[ShortcutsSpec::SHIFT_COLUMN_INDEX], sShiftName,
B_SHIFT_KEY, B_LEFT_SHIFT_KEY, B_RIGHT_SHIFT_KEY); B_SHIFT_KEY, B_LEFT_SHIFT_KEY, B_RIGHT_SHIFT_KEY);
SetupStandardMap(_metaMaps[ShortcutsSpec::CONTROL_COLUMN_INDEX], SetupStandardMap(sMetaMaps[ShortcutsSpec::CONTROL_COLUMN_INDEX],
CONTROL_NAME, B_CONTROL_KEY, B_LEFT_CONTROL_KEY, B_RIGHT_CONTROL_KEY); sControlName, B_CONTROL_KEY, B_LEFT_CONTROL_KEY, B_RIGHT_CONTROL_KEY);
SetupStandardMap(_metaMaps[ShortcutsSpec::COMMAND_COLUMN_INDEX], SetupStandardMap(sMetaMaps[ShortcutsSpec::COMMAND_COLUMN_INDEX],
COMMAND_NAME, B_COMMAND_KEY, B_LEFT_COMMAND_KEY, B_RIGHT_COMMAND_KEY); 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); , B_OPTION_KEY, B_LEFT_OPTION_KEY, B_RIGHT_OPTION_KEY);
_actuatorBitmaps[0] = MakeActuatorBitmap(false); sActuatorBitmaps[0] = MakeActuatorBitmap(false);
_actuatorBitmaps[1] = MakeActuatorBitmap(true); sActuatorBitmaps[1] = MakeActuatorBitmap(true);
} }
@@ -203,19 +203,24 @@ ShortcutsSpec::ShortcutsSpec(BMessage* from)
{ {
const char* temp; const char* temp;
if (from->FindString("command", &temp) != B_NO_ERROR) { 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 = ""; temp = "";
} }
SetCommand(temp); SetCommand(temp);
if (from->FindInt32("key", (int32*) &fKey) != B_NO_ERROR) if (from->FindInt32("key", (int32*) &fKey) != B_NO_ERROR) {
printf(CLASS " Error, no key int32 in archive BMessage!\n"); printf(CLASS);
printf(" Error, no key int32 in archive BMessage!\n");
}
for (int i = 0; i < NUM_META_COLUMNS; i++) for (int i = 0; i < NUM_META_COLUMNS; i++)
if (from->FindInt32("mcidx", i, (int32*)&fMetaCellStateIndex[i]) if (from->FindInt32("mcidx", i, (int32*)&fMetaCellStateIndex[i])
!= B_NO_ERROR) != B_NO_ERROR) {
printf(CLASS " Error, no modifiers int32 in archive BMessage!\n"); printf(CLASS);
printf(" Error, no modifiers int32 in archive BMessage!\n");
}
} }
@@ -234,7 +239,7 @@ ShortcutsSpec::SetCommand(const char* command)
const char* const char*
ShortcutsSpec::GetColumnName(int i) 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 (int i = 0; i < NUM_META_COLUMNS; i++) {
// for easy parsing by prefs applet on load-in // for easy parsing by prefs applet on load-in
into->AddInt32("mcidx", fMetaCellStateIndex[i]); into->AddInt32("mcidx", fMetaCellStateIndex[i]);
test.AddSlave(_metaMaps[i].GetNthStateTester(fMetaCellStateIndex[i])); test.AddSlave(sMetaMaps[i].GetNthStateTester(fMetaCellStateIndex[i]));
} }
BMessage testerMsg; BMessage testerMsg;
@@ -283,16 +288,16 @@ static bool IsValidActuatorName(const char* c);
static bool static bool
IsValidActuatorName(const char* c) IsValidActuatorName(const char* c)
{ {
return (strcmp(c, "InsertString") == 0 return (strcmp(c, B_TRANSLATE("InsertString")) == 0
|| strcmp(c, "MoveMouse") == 0 || strcmp(c, B_TRANSLATE("MoveMouse")) == 0
|| strcmp(c, "MoveMouseTo") == 0 || strcmp(c, B_TRANSLATE("MoveMouseTo")) == 0
|| strcmp(c, "MouseButton") == 0 || strcmp(c, B_TRANSLATE("MouseButton")) == 0
|| strcmp(c, "LaunchHandler") == 0 || strcmp(c, B_TRANSLATE("LaunchHandler")) == 0
|| strcmp(c, "Multi") == 0 || strcmp(c, B_TRANSLATE("Multi")) == 0
|| strcmp(c, "MouseDown") == 0 || strcmp(c, B_TRANSLATE("MouseDown")) == 0
|| strcmp(c, "MouseUp") == 0 || strcmp(c, B_TRANSLATE("MouseUp")) == 0
|| strcmp(c, "SendMessage") == 0 || strcmp(c, B_TRANSLATE("SendMessage")) == 0
|| strcmp(c, "Beep") == 0); || strcmp(c, B_TRANSLATE("Beep")) == 0);
} }
@@ -323,12 +328,12 @@ ShortcutsSpec::~ShortcutsSpec()
void void
ShortcutsSpec::_CacheViewFont(BView* owner) ShortcutsSpec::_CacheViewFont(BView* owner)
{ {
if (_fontCached == false) { if (sFontCached == false) {
_fontCached = true; sFontCached = true;
owner->GetFont(&_viewFont); owner->GetFont(&sViewFont);
font_height fh; font_height fh;
_viewFont.GetHeight(&fh); sViewFont.GetHeight(&fh);
_fontHeight = fh.ascent - fh.descent; sFontHeight = fh.ascent - fh.descent;
} }
} }
@@ -355,7 +360,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
if (text == NULL) if (text == NULL)
return; return;
float textWidth = _viewFont.StringWidth(text); float textWidth = sViewFont.StringWidth(text);
BPoint point; BPoint point;
rgb_color lowColor = color; rgb_color lowColor = color;
@@ -395,7 +400,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
_CacheViewFont(owner); _CacheViewFont(owner);
// How about I draw a nice "key" background for this one? // 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); , point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN);
if (column_index == KEY_COLUMN_INDEX) if (column_index == KEY_COLUMN_INDEX)
@@ -439,7 +444,7 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
owner->SetDrawingMode(B_OP_OVER); owner->SetDrawingMode(B_OP_OVER);
if ((fCommand != NULL) && (fCommand[0] == '*')) if ((fCommand != NULL) && (fCommand[0] == '*'))
owner->DrawBitmap(_actuatorBitmaps[fBitmapValid ? 1 : 0], owner->DrawBitmap(sActuatorBitmaps[fBitmapValid ? 1 : 0],
ICON_BITMAP_RECT, item_column_rect); ICON_BITMAP_RECT, item_column_rect);
else else
// Draw icon, if any // Draw icon, if any
@@ -469,8 +474,7 @@ const char*
ShortcutsSpec::GetCellText(int whichColumn) const ShortcutsSpec::GetCellText(int whichColumn) const
{ {
const char* temp = ""; // default const char* temp = ""; // default
switch(whichColumn) switch(whichColumn) {
{
case KEY_COLUMN_INDEX: case KEY_COLUMN_INDEX:
{ {
if ((fKey > 0) && (fKey <= 0xFF)) { if ((fKey > 0) && (fKey <= 0xFF)) {
@@ -478,21 +482,21 @@ ShortcutsSpec::GetCellText(int whichColumn) const
if (temp == NULL) if (temp == NULL)
temp = ""; temp = "";
} else if (fKey > 0xFF) { } else if (fKey > 0xFF) {
sprintf(fScratch, "#%x", fKey); sprintf(fScratch, "#%lx", fKey);
return fScratch; return fScratch;
} }
break;
} }
break;
case STRING_COLUMN_INDEX: case STRING_COLUMN_INDEX:
temp = fCommand; temp = fCommand;
break; break;
default: default:
if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS))
temp = _metaMaps[whichColumn].GetNthStateDesc( temp = sMetaMaps[whichColumn].GetNthStateDesc(
fMetaCellStateIndex[whichColumn]); fMetaCellStateIndex[whichColumn]);
break; break;
} }
return temp; return temp;
} }
@@ -519,7 +523,7 @@ ShortcutsSpec::ProcessColumnTextString(int whichColumn, const char* string)
case STRING_COLUMN_INDEX: case STRING_COLUMN_INDEX:
SetCommand(string); SetCommand(string);
return true; return true;
break; break;
case KEY_COLUMN_INDEX: case KEY_COLUMN_INDEX:
{ {
@@ -657,13 +661,13 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
bool ret = false; bool ret = false;
switch(whichColumn) { switch(whichColumn) {
case KEY_COLUMN_INDEX: case KEY_COLUMN_INDEX:
if (key != -1) { if (key > -1) {
if (fKey != key) { if ((int32)fKey != key) {
fKey = key; fKey = key;
ret = true; ret = true;
} }
} }
break; break;
case STRING_COLUMN_INDEX: case STRING_COLUMN_INDEX:
{ {
@@ -694,7 +698,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
bool reAllocString = false; bool reAllocString = false;
// Make sure we have enough room in our command string // Make sure we have enough room in our command string
// to add these chars... // to add these chars...
while (fCommandLen - fCommandNul <= newCharLen) { while ((int)fCommandLen - fCommandNul <= newCharLen) {
reAllocString = true; reAllocString = true;
// enough for a while... // enough for a while...
fCommandLen = (fCommandLen + 10) * 2; fCommandLen = (fCommandLen + 10) * 2;
@@ -717,12 +721,12 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
} }
} }
} }
break;
} }
break;
default: default:
if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) { if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) {
MetaKeyStateMap * map = &_metaMaps[whichColumn]; MetaKeyStateMap * map = &sMetaMaps[whichColumn];
int curState = fMetaCellStateIndex[whichColumn]; int curState = fMetaCellStateIndex[whichColumn];
int origState = curState; int origState = curState;
int numStates = map->GetNumStates(); int numStates = map->GetNumStates();
@@ -732,12 +736,12 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
case B_RETURN: case B_RETURN:
// cycle to the previous state // cycle to the previous state
curState = (curState + numStates - 1) % numStates; curState = (curState + numStates - 1) % numStates;
break; break;
case B_SPACE: case B_SPACE:
// cycle to the next state // cycle to the next state
curState = (curState + 1) % numStates; curState = (curState + 1) % numStates;
break; break;
default: default:
{ {
@@ -760,17 +764,17 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
break; break;
} }
} else } else
printf("Error, NULL state description?\n"); printf(B_TRANSLATE("Error, NULL state description?\n"));
} }
break;
} }
break;
} }
fMetaCellStateIndex[whichColumn] = curState; fMetaCellStateIndex[whichColumn] = curState;
if (curState != origState) if (curState != origState)
ret = true; ret = true;
} }
break; break;
} }
return ret; return ret;
@@ -812,8 +816,8 @@ ShortcutsSpec::_UpdateIconBitmap()
BString firstWord = ParseArgvZeroFromString(fCommand); BString firstWord = ParseArgvZeroFromString(fCommand);
// Only need to change if the first word has changed... // Only need to change if the first word has changed...
if ((fLastBitmapName == NULL) || (firstWord.Length() == 0) || if (fLastBitmapName == NULL || firstWord.Length() == 0
(firstWord.Compare(fLastBitmapName))) { || firstWord.Compare(fLastBitmapName)) {
if (firstWord.ByteAt(0) == '*') if (firstWord.ByteAt(0) == '*')
fBitmapValid = IsValidActuatorName(&firstWord.String()[1]); fBitmapValid = IsValidActuatorName(&firstWord.String()[1]);
else { else {
@@ -832,8 +836,9 @@ ShortcutsSpec::_UpdateIconBitmap()
BNodeInfo progNodeInfo(&progNode); BNodeInfo progNodeInfo(&progNode);
if ((progNodeInfo.InitCheck() == B_NO_ERROR) if ((progNodeInfo.InitCheck() == B_NO_ERROR)
&& (progNodeInfo.GetTrackerIcon(&fBitmap, B_MINI_ICON) && (progNodeInfo.GetTrackerIcon(&fBitmap, B_MINI_ICON)
== B_NO_ERROR)) == B_NO_ERROR)) {
fBitmapValid = fBitmap.IsValid(); 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
}
+10 -2
View File
@@ -20,8 +20,6 @@ class MetaKeyStateMap;
MetaKeyStateMap & GetNthKeyMap(int which); MetaKeyStateMap & GetNthKeyMap(int which);
void InitializeMetaMaps();
/* Objects of this class represent one hotkey "entry" in the preferences /* Objects of this class represent one hotkey "entry" in the preferences
* ListView. Each ShortcutsSpec contains the info necessary to generate both * ListView. Each ShortcutsSpec contains the info necessary to generate both
@@ -30,6 +28,8 @@ void InitializeMetaMaps();
*/ */
class ShortcutsSpec : public CLVListItem { class ShortcutsSpec : public CLVListItem {
public: public:
static void InitializeMetaMaps();
ShortcutsSpec(const char* command); ShortcutsSpec(const char* command);
ShortcutsSpec(const ShortcutsSpec& copyMe); ShortcutsSpec(const ShortcutsSpec& copyMe);
ShortcutsSpec(BMessage* from); ShortcutsSpec(BMessage* from);
@@ -102,6 +102,14 @@ private:
bool fCursorPtsValid; bool fCursorPtsValid;
mutable char fScratch[50]; mutable char fScratch[50];
int32 fSelectedColumn; int32 fSelectedColumn;
private:
static void _InitModifierNames();
static const char* sShiftName;
static const char* sControlName;
static const char* sOptionName;
static const char* sCommandName;
}; };
#endif #endif
+124 -105
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -15,10 +15,12 @@
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Catalog.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Input.h> #include <Input.h>
#include <Locale.h>
#include <Menu.h> #include <Menu.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -48,6 +50,9 @@
#define WINDOW_START_X 30 #define WINDOW_START_X 30
#define WINDOW_START_Y 100 #define WINDOW_START_Y 100
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ShortcutsWindow"
#define ERROR "Shortcuts error" #define ERROR "Shortcuts error"
#define WARNING "Shortcuts warning" #define WARNING "Shortcuts warning"
@@ -57,8 +62,8 @@
// Creates a pop-up-menu that reflects the possible states of the specified // Creates a pop-up-menu that reflects the possible states of the specified
// meta-key. // meta-key.
static BPopUpMenu* CreateMetaPopUp(int col); static BPopUpMenu*
static BPopUpMenu* CreateMetaPopUp(int col) CreateMetaPopUp(int col)
{ {
MetaKeyStateMap& map = GetNthKeyMap(col); MetaKeyStateMap& map = GetNthKeyMap(col);
BPopUpMenu * popup = new BPopUpMenu(NULL, false); 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 // Creates a pop-up that allows the user to choose a key-cap visually
static BPopUpMenu* CreateKeysPopUp(); static BPopUpMenu*
static BPopUpMenu* CreateKeysPopUp() CreateKeysPopUp()
{ {
BPopUpMenu* popup = new BPopUpMenu(NULL, false); BPopUpMenu* popup = new BPopUpMenu(NULL, false);
int numKeys = GetNumKeyIndices(); int numKeys = GetNumKeyIndices();
@@ -90,33 +95,37 @@ static BPopUpMenu* CreateKeysPopUp()
ShortcutsWindow::ShortcutsWindow() ShortcutsWindow::ShortcutsWindow()
: :
BWindow(BRect(WINDOW_START_X, WINDOW_START_Y, WINDOW_START_X + MIN_WIDTH, BWindow(BRect(WINDOW_START_X, WINDOW_START_Y, WINDOW_START_X + MIN_WIDTH,
WINDOW_START_Y + MIN_HEIGHT * 2), "Shortcuts", B_DOCUMENT_WINDOW, 0L), WINDOW_START_Y + MIN_HEIGHT * 2), B_TRANSLATE("Shortcuts"),
fSavePanel(NULL), B_DOCUMENT_WINDOW, 0L),
fOpenPanel(NULL), fSavePanel(NULL),
fSelectPanel(NULL), fOpenPanel(NULL),
fKeySetModified(false), fSelectPanel(NULL),
fLastOpenWasAppend(false) fKeySetModified(false),
fLastOpenWasAppend(false)
{ {
InitializeMetaMaps(); ShortcutsSpec::InitializeMetaMaps();
SetSizeLimits(MIN_WIDTH, MAX_WIDTH, MIN_HEIGHT, MAX_HEIGHT); SetSizeLimits(MIN_WIDTH, MAX_WIDTH, MIN_HEIGHT, MAX_HEIGHT);
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar"); BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar");
BMenu* fileMenu = new BMenu("File"); BMenu* fileMenu = new BMenu(B_TRANSLATE("File"));
fileMenu->AddItem(new BMenuItem("Open KeySet...", fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Open KeySet" B_UTF8_ELLIPSIS),
new BMessage(OPEN_KEYSET), 'O')); 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')); 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')); new BMessage(REVERT_KEYSET), 'A'));
fileMenu->AddItem(new BSeparatorItem); 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')); new BMessage(SAVE_KEYSET_AS), 'S'));
fileMenu->AddItem(new BSeparatorItem); fileMenu->AddItem(new BSeparatorItem);
fileMenu->AddItem(new BMenuItem("About Shortcuts", fileMenu->AddItem(new BMenuItem(B_TRANSLATE("About Shortcuts"),
new BMessage(B_ABOUT_REQUESTED))); new BMessage(B_ABOUT_REQUESTED)));
fileMenu->AddItem(new BSeparatorItem); fileMenu->AddItem(new BSeparatorItem);
fileMenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
'Q')); new BMessage(B_QUIT_REQUESTED), 'Q'));
menuBar->AddItem(fileMenu); menuBar->AddItem(fileMenu);
AddChild(menuBar); AddChild(menuBar);
@@ -141,30 +150,36 @@ ShortcutsWindow::ShortcutsWindow()
const float metaWidth = 50.0f; 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( fColumnListView->AddColumn(
new CLVColumn(ShortcutsSpec::GetColumnName(i), CreateMetaPopUp(i), new CLVColumn(ShortcutsSpec::GetColumnName(i), CreateMetaPopUp(i),
metaWidth, CLV_SORT_KEYABLE)); metaWidth, CLV_SORT_KEYABLE));
}
fColumnListView->AddColumn(new CLVColumn("Key", CreateKeysPopUp(), 60, fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Key"),
CLV_SORT_KEYABLE)); CreateKeysPopUp(), 60, CLV_SORT_KEYABLE));
BPopUpMenu* popup = new BPopUpMenu(NULL, false); 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( popup->AddItem(new BMenuItem(
"*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\"", NULL)); B_TRANSLATE("(Choose application with file requester)"), NULL));
popup->AddItem(new BMenuItem("*MouseDown", NULL));
popup->AddItem(new BMenuItem("*MouseUp", NULL));
popup->AddItem(new BMenuItem( popup->AddItem(new BMenuItem(
"*SendMessage application/x-vnd.Be-TRAK 'Tfnd'", NULL)); B_TRANSLATE("*InsertString \"Your Text Here\""), NULL));
popup->AddItem(new BMenuItem("*Beep", NULL)); popup->AddItem(new BMenuItem(
fColumnListView->AddColumn(new CLVColumn("Application", popup, 323.0, B_TRANSLATE("*MoveMouse +20 +0"), NULL));
CLV_SORT_KEYABLE)); 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); fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare);
AddChild(containerView); AddChild(containerView);
@@ -174,8 +189,8 @@ ShortcutsWindow::ShortcutsWindow()
BRect buttonBounds = Bounds(); BRect buttonBounds = Bounds();
buttonBounds.left += V_SPACING; buttonBounds.left += V_SPACING;
buttonBounds.right = ((buttonBounds.right - buttonBounds.left) / 2.0f) + buttonBounds.right = ((buttonBounds.right - buttonBounds.left) / 2.0f)
buttonBounds.left; + buttonBounds.left;
buttonBounds.bottom -= V_SPACING * 2; buttonBounds.bottom -= V_SPACING * 2;
buttonBounds.top = buttonBounds.bottom - vButtonHeight; buttonBounds.top = buttonBounds.bottom - vButtonHeight;
buttonBounds.right -= B_V_SCROLL_BAR_WIDTH; buttonBounds.right -= B_V_SCROLL_BAR_WIDTH;
@@ -183,11 +198,11 @@ ShortcutsWindow::ShortcutsWindow()
buttonBounds.right = (buttonBounds.left + origRight) * 0.40f - buttonBounds.right = (buttonBounds.left + origRight) * 0.40f -
(V_SPACING / 2); (V_SPACING / 2);
AddChild(fAddButton = new ResizableButton(Bounds(), buttonBounds, "add", 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.left = buttonBounds.right + V_SPACING;
buttonBounds.right = origRight; buttonBounds.right = origRight;
AddChild(fRemoveButton = new ResizableButton(Bounds(), buttonBounds, AddChild(fRemoveButton = new ResizableButton(Bounds(), buttonBounds,
"remove", "Remove selected shortcut", "remove", B_TRANSLATE("Remove selected shortcut"),
new BMessage(REMOVE_HOTKEY_ITEM))); new BMessage(REMOVE_HOTKEY_ITEM)));
fRemoveButton->SetEnabled(false); fRemoveButton->SetEnabled(false);
@@ -197,7 +212,7 @@ ShortcutsWindow::ShortcutsWindow()
saveButtonBounds.right = Bounds().right - B_V_SCROLL_BAR_WIDTH - offset; saveButtonBounds.right = Bounds().right - B_V_SCROLL_BAR_WIDTH - offset;
saveButtonBounds.left = buttonBounds.right + V_SPACING + offset; saveButtonBounds.left = buttonBounds.right + V_SPACING + offset;
AddChild(fSaveButton = new ResizableButton(Bounds(), saveButtonBounds, 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); fSaveButton->SetEnabled(false);
@@ -228,31 +243,33 @@ ShortcutsWindow::QuitRequested()
if (fKeySetModified) { if (fKeySetModified) {
BAlert* alert = new BAlert(WARNING, BAlert* alert = new BAlert(WARNING,
"Really quit without saving your changes?", "Don't save", "Cancel", B_TRANSLATE("Really quit without saving your changes?"),
"Save"); B_TRANSLATE("Don't save"), B_TRANSLATE("Cancel"),
B_TRANSLATE("Save"));
switch(alert->Go()) { switch(alert->Go()) {
case 1: case 1:
ret = false; ret = false;
break; break;
case 2: case 2:
// Save: automatically if possible, otherwise go back and open // Save: automatically if possible, otherwise go back and open
// up the file requester // up the file requester
if (fLastSaved.InitCheck() == B_NO_ERROR) { if (fLastSaved.InitCheck() == B_OK) {
if (_SaveKeySet(fLastSaved) == false) { if (_SaveKeySet(fLastSaved) == false) {
(new BAlert(ERROR, (new BAlert(ERROR,
"Shortcuts was unable to save your KeySet file!", B_TRANSLATE("Shortcuts was unable to save your "
"Oh no"))->Go(); "KeySet file!"),
B_TRANSLATE("Oh no")))->Go();
ret = true; //quit anyway ret = true; //quit anyway
} }
} else { } else {
PostMessage(SAVE_KEYSET); PostMessage(SAVE_KEYSET);
ret = false; ret = false;
} }
break; break;
default: default:
ret = true; ret = true;
break; break;
} }
} }
@@ -271,7 +288,7 @@ ShortcutsWindow::_GetSettingsFile(entry_ref* eref)
else else
path.Append(SHORTCUTS_SETTING_FILE_NAME); 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; return true;
else else
return false; return false;
@@ -283,20 +300,20 @@ bool
ShortcutsWindow::_SaveKeySet(BEntry& saveEntry) ShortcutsWindow::_SaveKeySet(BEntry& saveEntry)
{ {
BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 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; return false;
BMessage saveMsg; BMessage saveMsg;
for (int i = 0; i < fColumnListView->CountItems(); i++) { for (int i = 0; i < fColumnListView->CountItems(); i++) {
BMessage next; BMessage next;
if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next) if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next)
== B_NO_ERROR) == B_OK)
saveMsg.AddMessage("spec", &next); saveMsg.AddMessage("spec", &next);
else 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) { if (ret) {
fKeySetModified = false; fKeySetModified = false;
@@ -314,7 +331,7 @@ ShortcutsWindow::_LoadKeySet(const BMessage& loadMsg)
{ {
int i = 0; int i = 0;
BMessage msg; 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); ShortcutsSpec* spec = (ShortcutsSpec*)ShortcutsSpec::Instantiate(&msg);
if (spec != NULL) if (spec != NULL)
fColumnListView->AddItem(spec); fColumnListView->AddItem(spec);
@@ -364,8 +381,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
fOpenPanel->Show(); fOpenPanel->Show();
} }
fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ? fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ?
"Append" : "Open"); B_TRANSLATE("Append") : B_TRANSLATE("Open"));
break; break;
case REVERT_KEYSET: case REVERT_KEYSET:
{ {
@@ -377,8 +394,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
reload.AddRef("refs", &eref); reload.AddRef("refs", &eref);
reload.AddString("startupRef", "yeah"); reload.AddString("startupRef", "yeah");
PostMessage(&reload); PostMessage(&reload);
break;
} }
break;
// Respond to drag-and-drop messages here // Respond to drag-and-drop messages here
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
@@ -386,12 +403,12 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
int i = 0; int i = 0;
entry_ref ref; entry_ref ref;
while (msg->FindRef("refs", i++, &ref) == B_NO_ERROR) { while (msg->FindRef("refs", i++, &ref) == B_OK) {
BEntry entry(&ref); BEntry entry(&ref);
if (entry.InitCheck() == B_NO_ERROR) { if (entry.InitCheck() == B_OK) {
BPath path(&entry); BPath path(&entry);
if (path.InitCheck() == B_NO_ERROR) { if (path.InitCheck() == B_OK) {
// Add a new item with the given path. // Add a new item with the given path.
BString str(path.Path()); BString str(path.Path());
DoStandardEscapes(str); DoStandardEscapes(str);
@@ -399,8 +416,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
} }
} }
} }
break;
} }
break;
// Respond to FileRequester's messages here // Respond to FileRequester's messages here
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
@@ -408,21 +425,21 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
// Find file ref // Find file ref
entry_ref ref; entry_ref ref;
bool isStartMsg = msg->HasString("startupRef"); 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) // load the file into (fileMsg)
BMessage fileMsg; BMessage fileMsg;
{ {
BFile file(&ref, B_READ_ONLY); BFile file(&ref, B_READ_ONLY);
if ((file.InitCheck() != B_NO_ERROR) if ((file.InitCheck() != B_OK)
|| (fileMsg.Unflatten(&file) != B_NO_ERROR)) { || (fileMsg.Unflatten(&file) != B_OK)) {
if (isStartMsg) { if (isStartMsg) {
// use this to save to anyway // use this to save to anyway
fLastSaved = BEntry(&ref); fLastSaved = BEntry(&ref);
break; break;
} else { } else {
(new BAlert(ERROR, (new BAlert(ERROR,
"Shortcuts was couldn't open your KeySet file!" B_TRANSLATE("Shortcuts was couldn't open your "
, "Okay"))->Go(NULL); "KeySet file!"), B_TRANSLATE("OK")))->Go(NULL);
break; break;
} }
} }
@@ -430,11 +447,10 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (fLastOpenWasAppend == false) { if (fLastOpenWasAppend == false) {
// Clear the menu... // Clear the menu...
ShortcutsSpec * item; while (ShortcutsSpec* item
do { = ((ShortcutsSpec*)fColumnListView->RemoveItem(0L))) {
delete (item = ((ShortcutsSpec*) delete item;
fColumnListView->RemoveItem(int32(0)))); }
} while (item);
} }
if (_LoadKeySet(fileMsg)) { if (_LoadKeySet(fileMsg)) {
@@ -448,13 +464,14 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (ref == eref) fKeySetModified = false; if (ref == eref) fKeySetModified = false;
} else { } else {
(new BAlert(ERROR, (new BAlert(ERROR,
"Shortcuts was unable to parse your KeySet file!", B_TRANSLATE("Shortcuts was unable to parse your "
"Okay"))->Go(NULL); "KeySet file!"),
B_TRANSLATE("OK")))->Go(NULL);
break; break;
} }
} }
break;
} }
break;
// These messages come from the pop-up menu of the Applications column // These messages come from the pop-up menu of the Applications column
case SELECT_APPLICATION: case SELECT_APPLICATION:
@@ -462,11 +479,11 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
int csel = fColumnListView->CurrentSelection(); int csel = fColumnListView->CurrentSelection();
if (csel >= 0) { if (csel >= 0) {
entry_ref aref; entry_ref aref;
if (msg->FindRef("refs", &aref) == B_NO_ERROR) { if (msg->FindRef("refs", &aref) == B_OK) {
BEntry ent(&aref); BEntry ent(&aref);
if (ent.InitCheck() == B_NO_ERROR) { if (ent.InitCheck() == B_OK) {
BPath path; BPath path;
if ((ent.GetPath(&path) == B_NO_ERROR) if ((ent.GetPath(&path) == B_OK)
&& (((ShortcutsSpec *) && (((ShortcutsSpec *)
fColumnListView->ItemAt(csel))-> fColumnListView->ItemAt(csel))->
ProcessColumnTextString(ShortcutsSpec:: ProcessColumnTextString(ShortcutsSpec::
@@ -478,8 +495,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
} }
} }
} }
break;
} }
break;
case SAVE_KEYSET: case SAVE_KEYSET:
{ {
@@ -487,23 +504,24 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
const char * name; const char * name;
entry_ref entry; entry_ref entry;
if ((msg->FindString("name", &name) == B_NO_ERROR) if ((msg->FindString("name", &name) == B_OK)
&& (msg->FindRef("directory", &entry) == B_NO_ERROR)) { && (msg->FindRef("directory", &entry) == B_OK)) {
BDirectory dir(&entry); BDirectory dir(&entry);
BEntry saveTo(&dir, name, true); BEntry saveTo(&dir, name, true);
showSaveError = ((saveTo.InitCheck() != B_NO_ERROR) showSaveError = ((saveTo.InitCheck() != B_OK)
|| (_SaveKeySet(saveTo) == false)); || (_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. // We've saved this before, save over previous file.
showSaveError = (_SaveKeySet(fLastSaved) == false); showSaveError = (_SaveKeySet(fLastSaved) == false);
} else PostMessage(SAVE_KEYSET_AS); // open the save requester... } else PostMessage(SAVE_KEYSET_AS); // open the save requester...
if (showSaveError) { if (showSaveError) {
(new BAlert(ERROR, "Shortcuts wasn't able to save your keyset." (new BAlert(ERROR,
, "Okay"))->Go(NULL); B_TRANSLATE("Shortcuts wasn't able to save your keyset."),
B_TRANSLATE("OK")))->Go(NULL);
} }
break;
} }
break;
case SAVE_KEYSET_AS: case SAVE_KEYSET_AS:
{ {
@@ -516,16 +534,16 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
false, &msg); false, &msg);
fSavePanel->Show(); fSavePanel->Show();
} }
break;
} }
break;
case B_ABOUT_REQUESTED: case B_ABOUT_REQUESTED:
be_app_messenger.SendMessage(B_ABOUT_REQUESTED); be_app_messenger.SendMessage(B_ABOUT_REQUESTED);
break; break;
case ADD_HOTKEY_ITEM: case ADD_HOTKEY_ITEM:
_AddNewSpec(NULL); _AddNewSpec(NULL);
break; break;
case REMOVE_HOTKEY_ITEM: case REMOVE_HOTKEY_ITEM:
{ {
@@ -552,8 +570,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
} }
} }
} }
break;
} }
break;
// Received when the user clicks on the ColumnListView // Received when the user clicks on the ColumnListView
case HOTKEY_ITEM_SELECTED: case HOTKEY_ITEM_SELECTED:
@@ -562,16 +580,16 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
msg->FindInt32("index", &index); msg->FindInt32("index", &index);
bool validItem = (index >= 0); bool validItem = (index >= 0);
fRemoveButton->SetEnabled(validItem); fRemoveButton->SetEnabled(validItem);
break;
} }
break;
// Received when an entry is to be modified in response to GUI activity // Received when an entry is to be modified in response to GUI activity
case HOTKEY_ITEM_MODIFIED: case HOTKEY_ITEM_MODIFIED:
{ {
int32 row, column; int32 row, column;
if ((msg->FindInt32("row", &row) == B_NO_ERROR) if ((msg->FindInt32("row", &row) == B_OK)
&& (msg->FindInt32("column", &column) == B_NO_ERROR)) { && (msg->FindInt32("column", &column) == B_OK)) {
int32 key; int32 key;
const char* bytes; const char* bytes;
@@ -582,17 +600,17 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
if (msg->HasInt32("mouseClick")) { if (msg->HasInt32("mouseClick")) {
repaintNeeded = item->ProcessColumnMouseClick(column); repaintNeeded = item->ProcessColumnMouseClick(column);
} else if ((msg->FindString("bytes", &bytes) == B_NO_ERROR) } else if ((msg->FindString("bytes", &bytes) == B_OK)
&& (msg->FindInt32("key", &key) == B_NO_ERROR)) { && (msg->FindInt32("key", &key) == B_OK)) {
repaintNeeded = item->ProcessColumnKeyStroke(column, repaintNeeded = item->ProcessColumnKeyStroke(column,
bytes, key); bytes, key);
} else if (msg->FindInt32("unmappedkey", &key) == } else if (msg->FindInt32("unmappedkey", &key) ==
B_NO_ERROR) { B_OK) {
repaintNeeded = ((column == item->KEY_COLUMN_INDEX) repaintNeeded = ((column == item->KEY_COLUMN_INDEX)
&& ((key > 0xFF) || (GetKeyName(key) != NULL)) && ((key > 0xFF) || (GetKeyName(key) != NULL))
&& (item->ProcessColumnKeyStroke(column, NULL, && (item->ProcessColumnKeyStroke(column, NULL,
key))); 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 ((bytes[0] == '(')&&(bytes[1] == 'C')) {
if (fSelectPanel) if (fSelectPanel)
fSelectPanel->Show(); fSelectPanel->Show();
@@ -604,10 +622,11 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
fSelectPanel->Show(); fSelectPanel->Show();
} }
fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON, fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON,
"Select"); B_TRANSLATE("Select"));
} else } else {
repaintNeeded = item->ProcessColumnTextString( repaintNeeded = item->ProcessColumnTextString(
column, bytes); column, bytes);
}
} }
if (repaintNeeded) { if (repaintNeeded) {
@@ -616,12 +635,12 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
} }
} }
} }
break;
} }
break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
} }
} }
@@ -686,7 +705,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
} }
be_clipboard->Unlock(); be_clipboard->Unlock();
} }
break; break;
case B_PASTE: case B_PASTE:
if (be_clipboard->Lock()) { if (be_clipboard->Lock()) {
@@ -694,7 +713,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
const char* text; const char* text;
ssize_t textLen; ssize_t textLen;
if (data->FindData("text/plain", B_MIME_TYPE, (const void**) if (data->FindData("text/plain", B_MIME_TYPE, (const void**)
&text, &textLen) == B_NO_ERROR) { &text, &textLen) == B_OK) {
int32 row = fColumnListView->CurrentSelection(); int32 row = fColumnListView->CurrentSelection();
int32 column = fColumnListView->GetSelectedColumn(); int32 column = fColumnListView->GetSelectedColumn();
if ((row >= 0) if ((row >= 0)
@@ -713,11 +732,11 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
} }
be_clipboard->Unlock(); be_clipboard->Unlock();
} }
break; break;
default: default:
BWindow::DispatchMessage(msg, handler); BWindow::DispatchMessage(msg, handler);
break; break;
} }
} }
+10 -2
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -7,14 +7,22 @@
*/ */
#include <Catalog.h>
#include <Locale.h>
#include "KeyInfos.h" #include "KeyInfos.h"
#include "ShortcutsApp.h" #include "ShortcutsApp.h"
int main(int argc, char** argv) int
main(int argc, char** argv)
{ {
InitKeyIndices(); InitKeyIndices();
ShortcutsApp app; ShortcutsApp app;
BCatalog appCatalog;
be_locale->GetAppCatalog(&appCatalog);
app.Run(); app.Run();
} }