Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Added support of Native Menus in Linux #602

Merged
merged 13 commits into from
May 3, 2017
Merged

Conversation

saurabh95
Copy link
Collaborator

@saurabh95 saurabh95 commented Apr 20, 2017

To test this global.brackets.nativeMenus in https://github.com/adobe/brackets/blob/master/src/utils/Global.js#L84 needs to be set to true.
// cc @abhijitapte for review.

@eyelash Could you also review the part added by me?

Fixes adobe/brackets#7236

Screenshot for Ubuntu 16.04

screenshot from 2017-04-23 13-04-15

@eyelash
Copy link
Contributor

eyelash commented Apr 20, 2017

it's been 3 years since I wrote that code 😄

@zaggino zaggino removed their request for review April 24, 2017 01:09
@zaggino
Copy link
Contributor

zaggino commented Apr 24, 2017

sorry, can't review linux cpp code

Copy link
Contributor

@eyelash eyelash left a comment

Choose a reason for hiding this comment

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

I don't have the time to set up a build of brackets-shell on my machine, so I just leave a few comments in the hope that they are useful.

}
}
gchar* val = (gchar*)shortcut.c_str();
gtk_accelerator_parse (val, keyVal, modifier);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: everywhere else there is no space between function name and parameters.

accel_group = gtk_accel_group_new();

std::vector<std::string> tokens;
std::istringstream f(key.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the .c_str() necessary here?

std::istringstream f(key.c_str());
std::string s;
while (getline(f, s, '-')) {
tokens.push_back(s);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether the tokens could be parsed here directly instead of copying them to a vector first and the parsing the vector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I have used tokens in creating shortcut of type A and also in the fallback, so I won't be able to have fallback if there is no tokens vector.

}


int32 ParseShortcut(CefRefPtr<CefBrowser> browser, GtkWidget* entry, ExtensionString& key, GdkModifierType* modifier, guint* keyVal, ExtensionString& commandId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function could probably be static if it is not used outside this file.

@saurabh95
Copy link
Collaborator Author

Thanks @eyelash for reviewing this PR 😄
I have updated the PR as per your comments.

@eyelash
Copy link
Contributor

eyelash commented Apr 24, 2017

@saurabh95 GetDisplayKeyString could probably be static as well. The rest looks fine to me. As I said, I only took a quick look at your code without compiling and I'm also no expert on GTK+ shortcuts.

@@ -606,6 +606,9 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
bool enabled = argList->GetBool(2);
bool checked = argList->GetBool(3);
error = NativeMenuModel::getInstance(getMenuParent(browser)).setMenuItemState(command, enabled, checked);
if (error == NO_ERROR) {
error = SetMenuItemState(browser, command, enabled, checked);

Choose a reason for hiding this comment

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

this seems to be common code (i.e. windows, mac and win).
Isn't the menu item state being set in line 608?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually NativeMenuModel::getInstance(getMenuParent(browser)).setMenuItemState(command, enabled, checked); does not work for Linux as it only sets a flag, so I have added SetMenuState function which is meant only for Linux and for case of Windows and MAC it is No Op

@ficristo
Copy link
Collaborator

I'm sorry, but I cannot review cpp code

@ficristo ficristo removed their request for review April 26, 2017 08:29
return -1;
else if (positionString == "first")
return 0;
else if (relativeId.size() > 0) {

Choose a reason for hiding this comment

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

use empty() instead

if (iter == NULL)
position = -1;
else if (positionString == "before")
;

Choose a reason for hiding this comment

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

can't you instead set position as 0 here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't set position to 0 here, as in https://github.com/adobe/brackets-shell/pull/602/files#diff-10aa13d798996c2d964d38b1f328ae62R698 we are incrementing value of position, so setting it to 0 will always add the menu in the first index, which is not desired.

Copy link

@abhijitapte abhijitapte left a comment

Choose a reason for hiding this comment

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

please address the comments.

}
else
position = -1;
g_list_free(children);

Choose a reason for hiding this comment

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

can you point to the documentation in GTK where they specify that you need to explicitly free it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@eyelash eyelash May 2, 2017

Choose a reason for hiding this comment

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

also https://developer.gnome.org/gtk3/stable/GtkContainer.html#gtk-container-get-children says:

Returns a newly-allocated list of the container’s non-internal children.

and the tooltip of [transfer-container] says Free data container after the code is done.

Choose a reason for hiding this comment

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

Just checked the tooltip indeed conveys that we need to free.
I looked at documentation of https://developer.gnome.org/gtk3/stable/GtkContainer.html#gtk_container_get_focus_chain and noticed the explicit free mentioned there.

}

int32 AddMenu(CefRefPtr<CefBrowser> browser, ExtensionString title, ExtensionString command,
ExtensionString position, ExtensionString relativeId)
ExtensionString positionString, ExtensionString relativeId)

Choose a reason for hiding this comment

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

why can't these parameters be passed by const ref?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are actually implementation of interface which is used by all platforms, so changing this would mean changing in all the platforms implementation.
We can take this for later PR.

std::string shortcut = "";
// convert shortcut format
// e.g. Ctrl+A converts to <Ctrl>A whose entry is stored in accelerator table
for (int i=0;i<tokens.size();i++) {

Choose a reason for hiding this comment

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

isn't it better to take the size() in a local and use that instead?

shortcut += "<";
}
shortcut += tokens[i];
if (i != tokens.size() - 1) {

Choose a reason for hiding this comment

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

why is the last token excluded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually in this we are changing the token string from Ctrl+A to A whose entry is stored in accelerator table, so for the last token there is no need to enclose it in <>

modifier = GdkModifierType(modifier | GDK_SHIFT_MASK);
} else if (tokens[i] == "Enter") {
keyVal = GDK_KEY_KP_Enter;
} else if (tokens[i] == "Up" || tokens[i] == "\u2191") {

Choose a reason for hiding this comment

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

It is better to use macros or constants instead of these string literals

@swmitra
Copy link
Collaborator

swmitra commented May 3, 2017

Great work @saurabh95 👍

@swmitra swmitra merged commit 0f813d8 into linux-1547 May 3, 2017
@swmitra swmitra deleted the ingo/linux-native-menus branch May 3, 2017 06:18
@eyelash
Copy link
Contributor

eyelash commented Jul 4, 2017

I don't know if that was intentional but while merging this work to master all the commits were squashed (aa03360). Just to give you guys some feedback for the future: Seeing all your work merged without getting credit for it is not very motivating for a community contributor like me.

@saurabh95
Copy link
Collaborator Author

@eyelash it was by mistake and we will be having Release Notes in which we highlight top features and their authors and we will have your name in that.
We will definitely take care of this from next time.

@eyelash
Copy link
Contributor

eyelash commented Jul 4, 2017

@saurabh95 Thank you, I'm glad to hear that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
7 participants