Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/extensions/manager #408

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

nexus6-haiku
Copy link
Collaborator

This PR enables the ExtensionManager and the tools and context menus in Editors and the ProjectBrowser. Currently it implements only extensions type "Script"

extension.ShowInToolsMenu = msg.GetBool("ShowInToolsMenu", false);
extension.ShowInContextMenu = msg.GetBool("ShowInContextMenu", false);
auto shortcut = msg.GetString("Shortcut", "");
if (shortcut == nullptr || strlen(shortcut) > 1)

Check notice

Code scanning / Flawfinder (reported by Codacy)

Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). Note

Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126).
@@ -300,6 +302,17 @@ void
GenioWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_INVOKE_EXTENSION:
{
printf("window ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf left

case MSG_INVOKE_EXTENSION:
{
printf("window ");
message->PrintToStream();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrintToStream left

auto context = [&]() {
ExtensionContext context = {
.menuKind = ExtensionToolsMenu,
.editor = fTabManager->CountTabs()>0 ? fTabManager->SelectedEditor() : nullptr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SelectedEditor return null if no tabs are present

Copy link
Collaborator Author

@nexus6-haiku nexus6-haiku Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before introducing the lambda, it used to crash if no editors were opened. Now it is probably safe to remove the additional check.


extension.ShowInToolsMenu = msg.GetBool("ShowInToolsMenu", false);
extension.ShowInContextMenu = msg.GetBool("ShowInContextMenu", false);
auto shortcut = msg.GetString("Shortcut", "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use BString here, so you can skip the if (nullptr) and avoid using strlen()

{
BString scope;
int i = 0;
while(msg.FindString("Scope", i, &scope) == B_OK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between while and (

{
BString fileType;
int i = 0;
while(msg.FindString("FileTypes", i, &fileType) == B_OK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

} else if (strcmp(attrName, "BEOS:APP_SIG") == 0) {
extension.Signature = buf;
// printf("Signature %s\n", extension.Signature.String());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug printf leftovers


extension.ShowInToolsMenu = msg.GetBool("ShowInToolsMenu", false);
extension.ShowInContextMenu = msg.GetBool("ShowInContextMenu", false);
auto shortcut = msg.GetString("Shortcut", "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use BString here, so you can avoid the if (nullptr) and the strlen() call

{
BString scope;
int i = 0;
while(msg.FindString("Scope", i, &scope) == B_OK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: space between while and (

{
BString fileType;
int i = 0;
while(msg.FindString("FileTypes", i, &fileType) == B_OK) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

extension.LongDescription = BString(buf+5*sizeof(uint32)+64, 256);
// printf("version %s\n", extension.Version.String());
// printf("ShortDescription %s\n", extension.ShortDescription.String());
// printf("LongDescription %s\n", extension.LongDescription.String());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

various debug leftovers

(context.projectItem != nullptr &&
std::count(extension.Scope.begin(), extension.Scope.end(), "ProjectBrowser"))) {
auto filePath = context.editor->FilePath();
for(auto& ft: extension.FileTypes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between for and (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants