git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34059 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström
2009-11-15 13:09:37 +00:00
parent 51e49965a7
commit fa1ee6d4d1
14 changed files with 145 additions and 108 deletions
+1 -1
View File
@@ -21,5 +21,5 @@ Preference Shortcuts :
ScrollViewCorner.cpp ScrollViewCorner.cpp
: be tracker libshortcuts_shared.a $(TARGET_LIBSTDC++) : be tracker libshortcuts_shared.a $(TARGET_LIBSTDC++)
: Shortcuts.rsrc : Shortcuts.rdef
; ;
@@ -89,3 +89,4 @@ MetaKeyStateMap::GetName() const
{ {
return fKeyName; return fKeyName;
} }
+28 -25
View File
@@ -5,16 +5,17 @@
* Authors: * Authors:
* Jeremy Friesner * Jeremy Friesner
*/ */
#ifndef MetaKeyStateMap_h #ifndef MetaKeyStateMap_h
#define MetaKeyStateMap_h #define MetaKeyStateMap_h
#include <SupportDefs.h>
#include <List.h> #include <List.h>
#include <SupportDefs.h>
class BitFieldTester; class BitFieldTester;
// This class defines a set of possible chording states (e.g. "Left only", // This class defines a set of possible chording states (e.g. "Left only",
// "Right only", "Both", "Either") for a meta-key (e.g. Shift), and the // "Right only", "Both", "Either") for a meta-key (e.g. Shift), and the
// description strings and qualifier bit-chords that go with them. // description strings and qualifier bit-chords that go with them.
@@ -22,45 +23,47 @@ class MetaKeyStateMap {
public: public:
// Note: You MUST call SetInfo() directly after using this ctor! // Note: You MUST call SetInfo() directly after using this ctor!
MetaKeyStateMap(); MetaKeyStateMap();
// Creates a MetaKeyStateMap with the give name // Creates a MetaKeyStateMap with the give name
// (e.g. "Shift" or "Ctrl") // (e.g. "Shift" or "Ctrl")
MetaKeyStateMap(const char* keyName); MetaKeyStateMap(const char* keyName);
~MetaKeyStateMap(); ~MetaKeyStateMap();
// For when you have to use the default ctor // For when you have to use the default ctor
void SetInfo(const char* keyName); void SetInfo(const char* keyName);
// (tester) becomes property of this map! // (tester) becomes property of this map!
void AddState(const char* desc, const BitFieldTester* tester); void AddState(const char* desc,
const BitFieldTester* tester);
// Returns the name of the meta-key (e.g. "Ctrl") // Returns the name of the meta-key (e.g. "Ctrl")
const char* GetName() const; const char* GetName() const;
// Returns the number of possible states contained in this // Returns the number of possible states contained in this
// MetaKeyStateMap. // MetaKeyStateMap.
int GetNumStates() const; int GetNumStates() const;
// Returns a BitFieldTester that tests for the nth state's // Returns a BitFieldTester that tests for the nth state's
// presence. // presence.
const BitFieldTester* GetNthStateTester(int stateNum) const; const BitFieldTester* GetNthStateTester(int stateNum) const;
// Returns a textual description of the nth state (e.g. "Left") // Returns a textual description of the nth state (e.g. "Left")
const char* GetNthStateDesc(int stateNum) const; const char* GetNthStateDesc(int stateNum) const;
private: private:
// e.g. "Alt" or "Ctrl" // e.g. "Alt" or "Ctrl"
char* fKeyName; char* fKeyName;
// list of strings e.g. "Left" or "Both" // list of strings e.g. "Left" or "Both"
BList fStateDescs; BList fStateDescs;
// list of BitFieldTesters for testing bits of modifiers // list of BitFieldTesters for testing bits of modifiers in state
// in state BList fStateTesters;
BList fStateTesters;
}; };
#endif #endif
@@ -9,10 +9,11 @@
#include "ResizableButton.h" #include "ResizableButton.h"
ResizableButton::ResizableButton(BRect parentFrame, BRect frame, ResizableButton::ResizableButton(BRect parentFrame, BRect frame,
const char* name, const char* label, BMessage* msg) const char* name, const char* label, BMessage* message)
: :
BButton(frame, name, label, msg, B_FOLLOW_BOTTOM) BButton(frame, name, label, message, B_FOLLOW_BOTTOM)
{ {
float width = parentFrame.right - parentFrame.left; float width = parentFrame.right - parentFrame.left;
float height = parentFrame.bottom - parentFrame.top; float height = parentFrame.bottom - parentFrame.top;
@@ -33,3 +34,4 @@ ResizableButton::ChangeToNewSize(float newWidth, float newHeight)
ResizeTo(newW, b.bottom - b.top); ResizeTo(newW, b.bottom - b.top);
Invalidate(); Invalidate();
} }
+9 -11
View File
@@ -5,26 +5,24 @@
* Authors: * Authors:
* Jeremy Friesner * Jeremy Friesner
*/ */
#ifndef ResizableButton_h #ifndef ResizableButton_h
#define ResizableButton_h #define ResizableButton_h
#include <Message.h>
#include <Rect.h>
#include <View.h>
#include <Button.h> #include <Button.h>
//Just like a regular BButton, but with a handy resize method added
class ResizableButton : public BButton { class ResizableButton : public BButton {
public: public:
ResizableButton(BRect parentFrame, BRect frame, ResizableButton(BRect parentFrame, BRect frame,
const char* name, const char* label, const char* name, const char* label,
BMessage* msg); BMessage* message);
virtual void ChangeToNewSize(float newWidth, float newHeight); virtual void ChangeToNewSize(float newWidth, float newHeight);
private: private:
BRect fPercentages; BRect fPercentages;
}; };
#endif #endif
+19
View File
@@ -0,0 +1,19 @@
resource app_signature "application/x-vnd.Haiku-Shortcuts";
resource app_flags B_SINGLE_LAUNCH;
resource app_version {
major = 1,
middle = 0,
minor = 0,
/* 0 = development 1 = alpha 2 = beta
3 = gamma 4 = golden master 5 = final */
variety = 2,
internal = 0,
short_info = "Shortcuts",
long_info = "Shortcuts ©1999-2009 Jeremy Friesner ©2009 Haiku Inc."
};
Binary file not shown.
+8 -7
View File
@@ -7,15 +7,16 @@
* Fredrik Modéen * Fredrik Modéen
*/ */
#include "ShortcutsApp.h" #include "ShortcutsApp.h"
#include <Alert.h>
#include "Alert.h"
#include "ShortcutsWindow.h" #include "ShortcutsWindow.h"
#define APPLICATION_SIGNATURE "application/x-vnd.ShortcutsKeys"
#define APPLICATION_SIGNATURE "application/x-vnd.Haiku-Shortcuts"
ShortcutsApp::ShortcutsApp() ShortcutsApp::ShortcutsApp()
: :
@@ -34,7 +35,6 @@ ShortcutsApp::ReadyToRun()
ShortcutsApp::~ShortcutsApp() ShortcutsApp::~ShortcutsApp()
{ {
} }
@@ -42,7 +42,8 @@ void
ShortcutsApp::AboutRequested() ShortcutsApp::AboutRequested()
{ {
BAlert* alert = new BAlert("About Shortcuts", BAlert* alert = new BAlert("About Shortcuts",
"Shortcuts v1.28(SpicyKeys v1.28)\nby Jeremy Friesner" "Shortcuts\n\n"
, "Ok"); "Based on SpicyKeys for BeOS made by Jeremy Friesner.", "Ok");
alert->Go(); alert->Go();
} }
+8 -6
View File
@@ -6,19 +6,21 @@
* Jeremy Friesner * Jeremy Friesner
* Fredrik Modéen * Fredrik Modéen
*/ */
#ifndef ShortcutsApp_h #ifndef ShortcutsApp_h
#define ShortcutsApp_h #define ShortcutsApp_h
#include <Application.h> #include <Application.h>
class ShortcutsApp : public BApplication { class ShortcutsApp : public BApplication {
public: public:
ShortcutsApp(); ShortcutsApp();
~ShortcutsApp(); ~ShortcutsApp();
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void AboutRequested(); virtual void AboutRequested();
}; };
#endif #endif
+30 -25
View File
@@ -9,29 +9,28 @@
#include "ShortcutsSpec.h" #include "ShortcutsSpec.h"
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <Beep.h>
#include <Directory.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
#include <Directory.h>
#include <Path.h>
#include <NodeInfo.h>
#include <Beep.h>
#include "ColumnListView.h" #include "ColumnListView.h"
#include "Colors.h"
#include "MetaKeyStateMap.h"
#include "BitFieldTesters.h" #include "BitFieldTesters.h"
#include "Colors.h"
#include "CommandActuators.h" #include "CommandActuators.h"
#include "MetaKeyStateMap.h"
#include "ParseCommandLine.h" #include "ParseCommandLine.h"
#define CLASS "ShortcutsSpec : " #define CLASS "ShortcutsSpec : "
const float _height = 20.0f; const float _height = 20.0f;
static MetaKeyStateMap _metaMaps[ShortcutsSpec::NUM_META_COLUMNS]; static MetaKeyStateMap _metaMaps[ShortcutsSpec::NUM_META_COLUMNS];
@@ -42,6 +41,7 @@ static BFont _viewFont;
static float _fontHeight; static float _fontHeight;
static BBitmap * _actuatorBitmaps[2]; static BBitmap * _actuatorBitmaps[2];
// These meta-keys are pretty standard // These meta-keys are pretty standard
#define SHIFT_NAME "Shift" #define SHIFT_NAME "Shift"
#define CONTROL_NAME "Control" #define CONTROL_NAME "Control"
@@ -58,10 +58,12 @@ static BBitmap * _actuatorBitmaps[2];
#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
// 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 GetLetterAt(const char* str, int pos);
static char static char
GetLetterAt(const char* str, int pos) GetLetterAt(const char* str, int pos)
{ {
@@ -281,16 +283,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, "InsertString") == 0
(strcmp(c, "MoveMouse") == 0) || || strcmp(c, "MoveMouse") == 0
(strcmp(c, "MoveMouseTo") == 0) || || strcmp(c, "MoveMouseTo") == 0
(strcmp(c, "MouseButton") == 0) || || strcmp(c, "MouseButton") == 0
(strcmp(c, "LaunchHandler") == 0) || // new for v1.21 --jaf || strcmp(c, "LaunchHandler") == 0
(strcmp(c, "Multi") == 0) || // new for v1.24 --jaf || strcmp(c, "Multi") == 0
(strcmp(c, "MouseDown") == 0) || // new for v1.24 --jaf || strcmp(c, "MouseDown") == 0
(strcmp(c, "MouseUp") == 0) || // new for v1.24 --jaf || strcmp(c, "MouseUp") == 0
(strcmp(c, "SendMessage") == 0) || // new for v1.25 --jaf || strcmp(c, "SendMessage") == 0
(strcmp(c, "Beep") == 0)); || strcmp(c, "Beep") == 0);
} }
@@ -300,7 +302,7 @@ ShortcutsSpec::Instantiate(BMessage* from)
bool validateOK = false; bool validateOK = false;
if (validate_instantiation(from, "ShortcutsSpec")) if (validate_instantiation(from, "ShortcutsSpec"))
validateOK = true; validateOK = true;
else //test the old one. else // test the old one.
if (validate_instantiation(from, "SpicyKeysSpec")) if (validate_instantiation(from, "SpicyKeysSpec"))
validateOK = true; validateOK = true;
@@ -362,7 +364,8 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
point.Set(item_column_rect.left + STRING_COLUMN_LEFT_MARGIN, point.Set(item_column_rect.left + STRING_COLUMN_LEFT_MARGIN,
item_column_rect.top + fTextOffset); item_column_rect.top + fTextOffset);
item_column_rect.left = point.x;//keep text from drawing into icon area item_column_rect.left = point.x;
// keep text from drawing into icon area
// scroll if too wide // scroll if too wide
float rectWidth = item_column_rect.Width() - STRING_COLUMN_LEFT_MARGIN; float rectWidth = item_column_rect.Width() - STRING_COLUMN_LEFT_MARGIN;
@@ -668,7 +671,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
case B_BACKSPACE: case B_BACKSPACE:
case B_DELETE: case B_DELETE:
if (fCommandNul > 0) { if (fCommandNul > 0) {
//trim a char off the string // trim a char off the string
fCommand[fCommandNul - 1] = '\0'; fCommand[fCommandNul - 1] = '\0';
fCommandNul--; // note new nul position fCommandNul--; // note new nul position
ret = true; ret = true;
@@ -745,7 +748,8 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
letter = toupper(letter); // convert to upper case letter = toupper(letter); // convert to upper case
if ((letter == B_BACKSPACE) || (letter == B_DELETE)) if ((letter == B_BACKSPACE) || (letter == B_DELETE))
letter = '(';//so space bar will blank out an entry letter = '(';
// so space bar will blank out an entry
for (int i = 0; i < numStates; i++) { for (int i = 0; i < numStates; i++) {
const char* desc = map->GetNthStateDesc(i); const char* desc = map->GetNthStateDesc(i);
@@ -774,8 +778,8 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
int int
ShortcutsSpec::MyCompare(const CLVListItem* a_Item1, const CLVListItem* a_Item2 ShortcutsSpec::MyCompare(const CLVListItem* a_Item1, const CLVListItem* a_Item2,
, int32 KeyColumn) int32 KeyColumn)
{ {
ShortcutsSpec* left = (ShortcutsSpec*) a_Item1; ShortcutsSpec* left = (ShortcutsSpec*) a_Item1;
ShortcutsSpec* right = (ShortcutsSpec*) a_Item2; ShortcutsSpec* right = (ShortcutsSpec*) a_Item2;
@@ -836,3 +840,4 @@ ShortcutsSpec::_UpdateIconBitmap()
} }
} }
} }
+9 -5
View File
@@ -5,23 +5,24 @@
* Authors: * Authors:
* Jeremy Friesner * Jeremy Friesner
*/ */
#ifndef ShortcutsSpec_h #ifndef ShortcutsSpec_h
#define ShortcutsSpec_h #define ShortcutsSpec_h
#include <Bitmap.h>
#include <Bitmap.h>
#include "CLVListItem.h" #include "CLVListItem.h"
#include "KeyInfos.h" #include "KeyInfos.h"
class CommandActuator; class CommandActuator;
class MetaKeyStateMap; class MetaKeyStateMap;
MetaKeyStateMap & GetNthKeyMap(int which); MetaKeyStateMap & GetNthKeyMap(int which);
void InitializeMetaMaps(); 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
* the proper GUI display, and the proper BitFieldTester and CommandActuator * the proper GUI display, and the proper BitFieldTester and CommandActuator
@@ -41,7 +42,9 @@ public:
const char* GetCellText(int whichColumn) const; const char* GetCellText(int whichColumn) const;
void SetCommand(const char* commandStr); void SetCommand(const char* commandStr);
virtual void DrawItemColumn(BView* owner, BRect item_column_rect, int32 column_index, bool columnSelected, bool complete); virtual void DrawItemColumn(BView* owner, BRect item_column_rect,
int32 column_index, bool columnSelected,
bool complete);
static int MyCompare(const CLVListItem* a_Item1, static int MyCompare(const CLVListItem* a_Item1,
const CLVListItem* a_Item2, int32 KeyColumn); const CLVListItem* a_Item2, int32 KeyColumn);
@@ -97,8 +100,9 @@ private:
BPoint fCursorPt1; BPoint fCursorPt1;
BPoint fCursorPt2; BPoint fCursorPt2;
bool fCursorPtsValid; bool fCursorPtsValid;
mutable char fScratch[50]; mutable char fScratch[50];
int32 fSelectedColumn; int32 fSelectedColumn;
}; };
#endif #endif
+16 -15
View File
@@ -6,39 +6,37 @@
* Jeremy Friesner * Jeremy Friesner
* Fredrik Modéen * Fredrik Modéen
*/ */
#include "ShortcutsWindow.h" #include "ShortcutsWindow.h"
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <MessageFilter.h> #include <File.h>
#include <FindDirectory.h>
#include <Input.h>
#include <Menu.h> #include <Menu.h>
#include <MenuItem.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h>
#include <MessageFilter.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <ScrollBar.h> #include <ScrollBar.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <String.h> #include <String.h>
#include <Input.h>
#include <PopUpMenu.h>
#include <File.h>
#include <Path.h>
#include <FindDirectory.h>
#include "ColumnListView.h" #include "ColumnListView.h"
#include "KeyInfos.h" #include "KeyInfos.h"
#include "ShortcutsSpec.h"
#include "ParseCommandLine.h"
#include "MetaKeyStateMap.h" #include "MetaKeyStateMap.h"
#include "ParseCommandLine.h"
#include "ShortcutsFilterConstants.h" #include "ShortcutsFilterConstants.h"
#include "ShortcutsSpec.h"
// Window sizing constraints // Window sizing constraints
#define MIN_WIDTH 600 #define MIN_WIDTH 600
@@ -72,6 +70,7 @@ static BPopUpMenu* CreateMetaPopUp(int col)
return popup; return popup;
} }
// 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* CreateKeysPopUp();
static BPopUpMenu* CreateKeysPopUp() static BPopUpMenu* CreateKeysPopUp()
@@ -113,7 +112,8 @@ ShortcutsWindow::ShortcutsWindow()
fileMenu->AddItem(new BMenuItem("Save KeySet As...", fileMenu->AddItem(new BMenuItem("Save KeySet As...",
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", new BMessage(B_ABOUT_REQUESTED))); fileMenu->AddItem(new BMenuItem("About Shortcuts",
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("Quit", new BMessage(B_QUIT_REQUESTED),
'Q')); 'Q'));
@@ -257,7 +257,7 @@ ShortcutsWindow::QuitRequested()
} }
if (ret) if (ret)
fColumnListView->DeselectAll(); // avoid mysterious crash on PPC!? fColumnListView->DeselectAll();
return ret; return ret;
} }
@@ -720,3 +720,4 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
break; break;
} }
} }
+7 -8
View File
@@ -5,26 +5,23 @@
* Authors: * Authors:
* Jeremy Friesner * Jeremy Friesner
*/ */
#ifndef ShortcutsWindow_h #ifndef ShortcutsWindow_h
#define ShortcutsWindow_h #define ShortcutsWindow_h
#include <Message.h>
#include <Window.h>
#include <Point.h>
#include <Entry.h> #include <Entry.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <Message.h>
#include <Point.h>
#include <Window.h>
#include "ColumnListView.h" #include "ColumnListView.h"
#include "ResizableButton.h" #include "ResizableButton.h"
// This class defines our preferences/configuration window. // This class defines our preferences/configuration window.
class ShortcutsWindow : public BWindow { class ShortcutsWindow : public BWindow {
public: public:
// If (optSaveTo) is non-NULL, settings will be loaded from the file it
// represents.
ShortcutsWindow(); ShortcutsWindow();
~ShortcutsWindow(); ~ShortcutsWindow();
@@ -81,4 +78,6 @@ private:
bool fLastOpenWasAppend; bool fLastOpenWasAppend;
}; };
#endif #endif
+5 -3
View File
@@ -7,12 +7,14 @@
*/ */
#include "ShortcutsApp.h"
#include "KeyInfos.h" #include "KeyInfos.h"
#include "ShortcutsApp.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
InitKeyIndices(); InitKeyIndices();
(new ShortcutsApp)->Run(); ShortcutsApp app;
delete be_app; app.Run();
} }