Tracker: Code cleanup around add-ons.

Mostly de-indents and some shuffling in headers.
No functional change intended.
This commit is contained in:
Augustin Cavalier
2024-06-26 16:37:26 -04:00
parent 28748463d9
commit 1a3dae790e
3 changed files with 130 additions and 135 deletions
+40 -39
View File
@@ -2897,52 +2897,53 @@ BContainerWindow::EachAddOn(bool (*eachAddOn)(const Model*, const char*,
void* passThru, BStringList& mimeTypes, BMenu* menu)
{
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
if (lock.IsLocked()) {
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
struct AddOnShortcut* item = fAddOnsList->ItemAt(i);
bool primary = false;
if (!lock.IsLocked())
return;
if (mimeTypes.CountStrings() > 0) {
BFile file(item->model->EntryRef(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
BAppFileInfo info(&file);
if (info.InitCheck() == B_OK) {
bool secondary = true;
for (int i = fAddOnsList->CountItems() - 1; i >= 0; i--) {
struct AddOnShortcut* item = fAddOnsList->ItemAt(i);
bool primary = 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;
}
if (mimeTypes.CountStrings() > 0) {
BFile file(item->model->EntryRef(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
BAppFileInfo info(&file);
if (info.InitCheck() == B_OK) {
bool secondary = true;
// 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));
}
}
+4 -10
View File
@@ -186,14 +186,7 @@ public:
static bool DefaultStateSourceNode(const char* name, BNode* result,
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);
entry_ref GetCurrentDirRef();
BPopUpMenu* ContextMenu();
// drag&drop support
@@ -274,11 +267,12 @@ protected:
BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32,
const char*);
bool EachAddOn(BPath &path,
bool (*)(const Model*, const char*, uint32, bool, void*),
BObjectList<Model>*, void*, BStringList&);
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;
uint32 fOpenFlags;
bool fUsesLayout;
+86 -86
View File
@@ -263,24 +263,23 @@ void
BDeskWindow::InitAddOnsList(bool update)
{
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
if (lock.IsLocked()) {
if (update) {
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);
}
if (!lock.IsLocked())
return;
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);
if (update) {
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;
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)
{
AutoLock<LockingList<AddOnShortcut> > lock(fAddOnsList);
if (lock.IsLocked()) {
if (!update) {
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
BPathMonitor::StartWatching(path.Path(),
B_WATCH_STAT | B_WATCH_FILES_ONLY, this);
path.Append(kShortcutsSettings);
fShortcutsSettings = new char[strlen(path.Path()) + 1];
strcpy(fShortcutsSettings, path.Path());
if (!lock.IsLocked())
return;
if (!update) {
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
BPathMonitor::StartWatching(path.Path(),
B_WATCH_STAT | B_WATCH_FILES_ONLY, this);
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);
BMessage fileMsg;
if (shortcutSettings.InitCheck() != B_OK
|| fileMsg.Unflatten(&shortcutSettings) != B_OK) {
fNodeRef = NULL;
return;
}
shortcutSettings.GetNodeRef(fNodeRef);
BEntry entry(command);
if (entry.InitCheck() != B_OK)
continue;
int32 i = 0;
BMessage message;
while (fileMsg.FindMessage("spec", i++, &message) == B_OK) {
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;
const char* shortcut = GetKeyName(key);
if (strlen(shortcut) != 1)
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;
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;
}
}
if (message.FindInt32("mcidx", 1, &value) == B_OK)
modifiers |= (value != 0 ? B_CONTROL_KEY : 0);
if (!isInAddOns)
continue;
if (message.FindInt32("mcidx", 3, &value) == B_OK)
modifiers |= (value != 0 ? B_OPTION_KEY : 0);
BEntry entry(command);
if (entry.InitCheck() != B_OK)
continue;
Model model(&entry);
AddOnShortcut* item = fAddOnsList->EachElement(FindElement, &model);
if (item != NULL) {
if (item->key != '\0')
RemoveShortcut(item->key, item->modifiers);
const char* shortcut = GetKeyName(key);
if (strlen(shortcut) != 1)
continue;
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);
}
}
item->key = shortcut[0];
item->modifiers = modifiers;
AddOneShortcut(&model, item->key, item->modifiers, this);
}
}
}