Tracker: Code cleanup around add-ons.
Mostly de-indents and some shuffling in headers. No functional change intended.
This commit is contained in:
@@ -2897,52 +2897,53 @@ BContainerWindow::EachAddOn(bool (*eachAddOn)(const Model*, const char*,
|
|||||||
void* passThru, BStringList& mimeTypes, BMenu* menu)
|
void* passThru, BStringList& mimeTypes, BMenu* menu)
|
||||||
{
|
{
|
||||||
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
||||||
if (lock.IsLocked()) {
|
if (!lock.IsLocked())
|
||||||
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
|
return;
|
||||||
struct AddOnShortcut* item = fAddOnsList->ItemAt(i);
|
|
||||||
bool primary = false;
|
|
||||||
|
|
||||||
if (mimeTypes.CountStrings() > 0) {
|
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
|
||||||
BFile file(item->model->EntryRef(), B_READ_ONLY);
|
struct AddOnShortcut* item = fAddOnsList->ItemAt(i);
|
||||||
if (file.InitCheck() == B_OK) {
|
bool primary = false;
|
||||||
BAppFileInfo info(&file);
|
|
||||||
if (info.InitCheck() == B_OK) {
|
|
||||||
bool secondary = true;
|
|
||||||
|
|
||||||
// does this add-on has types set at all?
|
if (mimeTypes.CountStrings() > 0) {
|
||||||
BMessage message;
|
BFile file(item->model->EntryRef(), B_READ_ONLY);
|
||||||
if (info.GetSupportedTypes(&message) == B_OK) {
|
if (file.InitCheck() == B_OK) {
|
||||||
type_code typeCode;
|
BAppFileInfo info(&file);
|
||||||
int32 count;
|
if (info.InitCheck() == B_OK) {
|
||||||
if (message.GetInfo("types", &typeCode,
|
bool secondary = true;
|
||||||
&count) == B_OK) {
|
|
||||||
secondary = false;
|
// does this add-on has types set at all?
|
||||||
}
|
BMessage message;
|
||||||
|
if (info.GetSupportedTypes(&message) == B_OK) {
|
||||||
|
type_code typeCode;
|
||||||
|
int32 count;
|
||||||
|
if (message.GetInfo("types", &typeCode,
|
||||||
|
&count) == B_OK) {
|
||||||
|
secondary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check all supported types if it has some set
|
|
||||||
if (!secondary) {
|
|
||||||
for (int32 i = mimeTypes.CountStrings();
|
|
||||||
!primary && i-- > 0;) {
|
|
||||||
BString type = mimeTypes.StringAt(i);
|
|
||||||
if (info.IsSupportedType(type.String())) {
|
|
||||||
BMimeType mimeType(type.String());
|
|
||||||
if (info.Supports(&mimeType))
|
|
||||||
primary = true;
|
|
||||||
else
|
|
||||||
secondary = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!secondary && !primary)
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check all supported types if it has some set
|
||||||
|
if (!secondary) {
|
||||||
|
for (int32 i = mimeTypes.CountStrings();
|
||||||
|
!primary && i-- > 0;) {
|
||||||
|
BString type = mimeTypes.StringAt(i);
|
||||||
|
if (info.IsSupportedType(type.String())) {
|
||||||
|
BMimeType mimeType(type.String());
|
||||||
|
if (info.Supports(&mimeType))
|
||||||
|
primary = true;
|
||||||
|
else
|
||||||
|
secondary = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!secondary && !primary)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
((eachAddOn)(item->model, item->model->Name(), item->key,
|
|
||||||
item->modifiers, primary, passThru, this, menu));
|
|
||||||
}
|
}
|
||||||
|
((eachAddOn)(item->model, item->model->Name(), item->key,
|
||||||
|
item->modifiers, primary, passThru, this, menu));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,14 +186,7 @@ public:
|
|||||||
static bool DefaultStateSourceNode(const char* name, BNode* result,
|
static bool DefaultStateSourceNode(const char* name, BNode* result,
|
||||||
bool createNew = false, bool createFolder = true);
|
bool createNew = false, bool createFolder = true);
|
||||||
|
|
||||||
// add-on iteration
|
|
||||||
void EachAddOn(bool (*)(const Model*, const char*, uint32 shortcut,
|
|
||||||
uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*),
|
|
||||||
void*, BStringList&, BMenu*);
|
|
||||||
|
|
||||||
BMessage* AddOnMessage(int32);
|
BMessage* AddOnMessage(int32);
|
||||||
entry_ref GetCurrentDirRef();
|
|
||||||
|
|
||||||
BPopUpMenu* ContextMenu();
|
BPopUpMenu* ContextMenu();
|
||||||
|
|
||||||
// drag&drop support
|
// drag&drop support
|
||||||
@@ -274,11 +267,12 @@ protected:
|
|||||||
BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32,
|
BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32,
|
||||||
const char*);
|
const char*);
|
||||||
|
|
||||||
bool EachAddOn(BPath &path,
|
|
||||||
bool (*)(const Model*, const char*, uint32, bool, void*),
|
|
||||||
BObjectList<Model>*, void*, BStringList&);
|
|
||||||
void LoadAddOn(BMessage*);
|
void LoadAddOn(BMessage*);
|
||||||
|
void EachAddOn(bool (*)(const Model*, const char*, uint32 shortcut,
|
||||||
|
uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*),
|
||||||
|
void*, BStringList&, BMenu*);
|
||||||
|
|
||||||
|
protected:
|
||||||
LockingList<BWindow>* fWindowList;
|
LockingList<BWindow>* fWindowList;
|
||||||
uint32 fOpenFlags;
|
uint32 fOpenFlags;
|
||||||
bool fUsesLayout;
|
bool fUsesLayout;
|
||||||
|
|||||||
@@ -263,24 +263,23 @@ void
|
|||||||
BDeskWindow::InitAddOnsList(bool update)
|
BDeskWindow::InitAddOnsList(bool update)
|
||||||
{
|
{
|
||||||
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
||||||
if (lock.IsLocked()) {
|
if (!lock.IsLocked())
|
||||||
if (update) {
|
return;
|
||||||
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
|
|
||||||
AddOnShortcut* item = fAddOnsList->ItemAt(i);
|
|
||||||
RemoveShortcut(item->key, B_OPTION_KEY | B_COMMAND_KEY);
|
|
||||||
}
|
|
||||||
fAddOnsList->MakeEmpty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
BStringList addOnPaths;
|
if (update) {
|
||||||
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Tracker",
|
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
|
||||||
addOnPaths);
|
AddOnShortcut* item = fAddOnsList->ItemAt(i);
|
||||||
int32 count = addOnPaths.CountStrings();
|
RemoveShortcut(item->key, B_OPTION_KEY | B_COMMAND_KEY);
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
LoadAddOnDir(BDirectory(addOnPaths.StringAt(i)), this,
|
|
||||||
fAddOnsList);
|
|
||||||
}
|
}
|
||||||
|
fAddOnsList->MakeEmpty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BStringList addOnPaths;
|
||||||
|
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Tracker",
|
||||||
|
addOnPaths);
|
||||||
|
int32 count = addOnPaths.CountStrings();
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
LoadAddOnDir(BDirectory(addOnPaths.StringAt(i)), this, fAddOnsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -288,87 +287,88 @@ void
|
|||||||
BDeskWindow::ApplyShortcutPreferences(bool update)
|
BDeskWindow::ApplyShortcutPreferences(bool update)
|
||||||
{
|
{
|
||||||
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
|
||||||
if (lock.IsLocked()) {
|
if (!lock.IsLocked())
|
||||||
if (!update) {
|
return;
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
if (!update) {
|
||||||
BPathMonitor::StartWatching(path.Path(),
|
BPath path;
|
||||||
B_WATCH_STAT | B_WATCH_FILES_ONLY, this);
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||||
path.Append(kShortcutsSettings);
|
BPathMonitor::StartWatching(path.Path(),
|
||||||
fShortcutsSettings = new char[strlen(path.Path()) + 1];
|
B_WATCH_STAT | B_WATCH_FILES_ONLY, this);
|
||||||
strcpy(fShortcutsSettings, path.Path());
|
path.Append(kShortcutsSettings);
|
||||||
|
fShortcutsSettings = new char[strlen(path.Path()) + 1];
|
||||||
|
strcpy(fShortcutsSettings, path.Path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fAddOnsList->EachElement(RevertToDefault, this);
|
||||||
|
|
||||||
|
BFile shortcutSettings(fShortcutsSettings, B_READ_ONLY);
|
||||||
|
BMessage fileMsg;
|
||||||
|
if (shortcutSettings.InitCheck() != B_OK
|
||||||
|
|| fileMsg.Unflatten(&shortcutSettings) != B_OK) {
|
||||||
|
fNodeRef = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shortcutSettings.GetNodeRef(fNodeRef);
|
||||||
|
|
||||||
|
int32 i = 0;
|
||||||
|
BMessage message;
|
||||||
|
while (fileMsg.FindMessage("spec", i++, &message) == B_OK) {
|
||||||
|
int32 key;
|
||||||
|
if (message.FindInt32("key", &key) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// only handle shortcuts referring add-ons
|
||||||
|
BString command;
|
||||||
|
if (message.FindString("command", &command) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isInAddOns = false;
|
||||||
|
|
||||||
|
BStringList addOnPaths;
|
||||||
|
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
|
||||||
|
"Tracker/", addOnPaths);
|
||||||
|
for (int32 i = 0; i < addOnPaths.CountStrings(); i++) {
|
||||||
|
if (command.StartsWith(addOnPaths.StringAt(i))) {
|
||||||
|
isInAddOns = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fAddOnsList->EachElement(RevertToDefault, this);
|
if (!isInAddOns)
|
||||||
|
continue;
|
||||||
|
|
||||||
BFile shortcutSettings(fShortcutsSettings, B_READ_ONLY);
|
BEntry entry(command);
|
||||||
BMessage fileMsg;
|
if (entry.InitCheck() != B_OK)
|
||||||
if (shortcutSettings.InitCheck() != B_OK
|
continue;
|
||||||
|| fileMsg.Unflatten(&shortcutSettings) != B_OK) {
|
|
||||||
fNodeRef = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shortcutSettings.GetNodeRef(fNodeRef);
|
|
||||||
|
|
||||||
int32 i = 0;
|
const char* shortcut = GetKeyName(key);
|
||||||
BMessage message;
|
if (strlen(shortcut) != 1)
|
||||||
while (fileMsg.FindMessage("spec", i++, &message) == B_OK) {
|
continue;
|
||||||
int32 key;
|
|
||||||
if (message.FindInt32("key", &key) == B_OK) {
|
|
||||||
// only handle shortcuts referring add-ons
|
|
||||||
BString command;
|
|
||||||
if (message.FindString("command", &command) != B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool isInAddOns = false;
|
uint32 modifiers = B_COMMAND_KEY;
|
||||||
|
// it's required by interface kit to at least
|
||||||
|
// have B_COMMAND_KEY
|
||||||
|
int32 value;
|
||||||
|
if (message.FindInt32("mcidx", 0, &value) == B_OK)
|
||||||
|
modifiers |= (value != 0 ? B_SHIFT_KEY : 0);
|
||||||
|
|
||||||
BStringList addOnPaths;
|
if (message.FindInt32("mcidx", 1, &value) == B_OK)
|
||||||
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
|
modifiers |= (value != 0 ? B_CONTROL_KEY : 0);
|
||||||
"Tracker/", addOnPaths);
|
|
||||||
for (int32 i = 0; i < addOnPaths.CountStrings(); i++) {
|
|
||||||
if (command.StartsWith(addOnPaths.StringAt(i))) {
|
|
||||||
isInAddOns = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isInAddOns)
|
if (message.FindInt32("mcidx", 3, &value) == B_OK)
|
||||||
continue;
|
modifiers |= (value != 0 ? B_OPTION_KEY : 0);
|
||||||
|
|
||||||
BEntry entry(command);
|
Model model(&entry);
|
||||||
if (entry.InitCheck() != B_OK)
|
AddOnShortcut* item = fAddOnsList->EachElement(FindElement, &model);
|
||||||
continue;
|
if (item != NULL) {
|
||||||
|
if (item->key != '\0')
|
||||||
|
RemoveShortcut(item->key, item->modifiers);
|
||||||
|
|
||||||
const char* shortcut = GetKeyName(key);
|
item->key = shortcut[0];
|
||||||
if (strlen(shortcut) != 1)
|
item->modifiers = modifiers;
|
||||||
continue;
|
AddOneShortcut(&model, item->key, item->modifiers, this);
|
||||||
|
|
||||||
uint32 modifiers = B_COMMAND_KEY;
|
|
||||||
// it's required by interface kit to at least
|
|
||||||
// have B_COMMAND_KEY
|
|
||||||
int32 value;
|
|
||||||
if (message.FindInt32("mcidx", 0, &value) == B_OK)
|
|
||||||
modifiers |= (value != 0 ? B_SHIFT_KEY : 0);
|
|
||||||
|
|
||||||
if (message.FindInt32("mcidx", 1, &value) == B_OK)
|
|
||||||
modifiers |= (value != 0 ? B_CONTROL_KEY : 0);
|
|
||||||
|
|
||||||
if (message.FindInt32("mcidx", 3, &value) == B_OK)
|
|
||||||
modifiers |= (value != 0 ? B_OPTION_KEY : 0);
|
|
||||||
|
|
||||||
Model model(&entry);
|
|
||||||
AddOnShortcut* item = fAddOnsList->EachElement(FindElement,
|
|
||||||
&model);
|
|
||||||
if (item != NULL) {
|
|
||||||
if (item->key != '\0')
|
|
||||||
RemoveShortcut(item->key, item->modifiers);
|
|
||||||
|
|
||||||
item->key = shortcut[0];
|
|
||||||
item->modifiers = modifiers;
|
|
||||||
AddOneShortcut(&model, item->key, item->modifiers, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user