-
Notifications
You must be signed in to change notification settings - Fork 619
Added support of Native Menus in Linux #602
Conversation
…ets-shell into ingo/linux-native-menus
it's been 3 years since I wrote that code 😄 |
sorry, can't review linux cpp code |
There was a problem hiding this 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.
appshell/appshell_extensions_gtk.cpp
Outdated
} | ||
} | ||
gchar* val = (gchar*)shortcut.c_str(); | ||
gtk_accelerator_parse (val, keyVal, modifier); |
There was a problem hiding this comment.
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.
appshell/appshell_extensions_gtk.cpp
Outdated
accel_group = gtk_accel_group_new(); | ||
|
||
std::vector<std::string> tokens; | ||
std::istringstream f(key.c_str()); |
There was a problem hiding this comment.
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?
appshell/appshell_extensions_gtk.cpp
Outdated
std::istringstream f(key.c_str()); | ||
std::string s; | ||
while (getline(f, s, '-')) { | ||
tokens.push_back(s); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
appshell/appshell_extensions_gtk.cpp
Outdated
} | ||
|
||
|
||
int32 ParseShortcut(CefRefPtr<CefBrowser> browser, GtkWidget* entry, ExtensionString& key, GdkModifierType* modifier, guint* keyVal, ExtensionString& commandId) { |
There was a problem hiding this comment.
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.
Thanks @eyelash for reviewing this PR 😄 |
@saurabh95 |
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
I'm sorry, but I cannot review cpp code |
appshell/appshell_extensions_gtk.cpp
Outdated
return -1; | ||
else if (positionString == "first") | ||
return 0; | ||
else if (relativeId.size() > 0) { |
There was a problem hiding this comment.
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") | ||
; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
appshell/appshell_extensions_gtk.cpp
Outdated
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++) { |
There was a problem hiding this comment.
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?
appshell/appshell_extensions_gtk.cpp
Outdated
shortcut += "<"; | ||
} | ||
shortcut += tokens[i]; | ||
if (i != tokens.size() - 1) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 <>
appshell/appshell_extensions_gtk.cpp
Outdated
modifier = GdkModifierType(modifier | GDK_SHIFT_MASK); | ||
} else if (tokens[i] == "Enter") { | ||
keyVal = GDK_KEY_KP_Enter; | ||
} else if (tokens[i] == "Up" || tokens[i] == "\u2191") { |
There was a problem hiding this comment.
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
Great work @saurabh95 👍 |
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. |
@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. |
@saurabh95 Thank you, I'm glad to hear that. |
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