Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further optimizations to menu applet:

- Remove unneeded signal methods
- Replace heavily used anon functions
- Improve method of sorting through hide/show of apps
  • Loading branch information...
commit 5494a3c192361226ba54532247c0760bffd41f8f 1 parent 687ab25
@mtwebster mtwebster authored
View
6 NEWS
@@ -99,9 +99,3 @@ THEME CHANGES SINCE 1.4
max-height: 100px;
}
-/* ===================================================================
- * Menu Applet
- * ===================================================================*/
-
-.menu-place-cat-button-label {
-}
View
8 data/theme/cinnamon.css
@@ -1316,14 +1316,6 @@ StScrollBar StButton#vhandle:hover {
.menu-application-button-label:rtl {
padding-right: 5px;
}
-.menu-place-cat-button-label:ltr {
- padding-top: 4px;
- padding-left: 5px;
-}
-.menu-place-cat-button-label:rtl {
- padding-top: 4px;
- padding-right: 5px;
-}
.menu-category-button {
padding-top: 7px;
padding-left: 7px;
View
262 files/usr/share/cinnamon/applets/menu@cinnamon.org/applet.js
@@ -230,7 +230,7 @@ ApplicationButton.prototype = {
_init: function(appsMenuButton, app) {
GenericApplicationButton.prototype._init.call(this, appsMenuButton, app, true);
-
+ this.category = new Array();
this.actor.set_style_class_name('menu-application-button');
this.icon = this.app.create_icon_texture(APPLICATION_ICON_SIZE);
this.addActor(this.icon);
@@ -261,86 +261,102 @@ ApplicationButton.prototype = {
return this.actor;
}
};
-Signals.addSignalMethods(ApplicationButton.prototype);
function PlaceButton(appsMenuButton, place, button_name) {
this._init(appsMenuButton, place, button_name);
}
PlaceButton.prototype = {
- _init: function(appsMenuButton,place, button_name) {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
+ _init: function(appsMenuButton, place, button_name) {
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
+ this.appsMenuButton = appsMenuButton;
this.place = place;
this.button_name = button_name;
- this.actor = new St.Button({ reactive: true, style_class: 'menu-application-button', x_align: St.Align.START });
+ this.actor.set_style_class_name('menu-application-button');
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
- this.label = new St.Label({ text: this.button_name, style_class: 'menu-place-cat-button-label' });
+ this.label = new St.Label({ text: this.button_name, style_class: 'menu-application-button-label' });
this.icon = place.iconFactory(APPLICATION_ICON_SIZE);
- this.buttonbox.add_actor(this.icon);
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
- this.actor.connect('clicked', Lang.bind(this, function() {
+ this.addActor(this.icon);
+ this.addActor(this.label);
+ },
+
+ _onButtonReleaseEvent: function (actor, event) {
+ if (event.get_button()==1){
this.place.launch();
- appsMenuButton.menu.close();
- }));
+ this.appsMenuButton.menu.close();
+ }
}
};
-Signals.addSignalMethods(PlaceButton.prototype);
function RecentButton(appsMenuButton, file) {
this._init(appsMenuButton, file);
}
RecentButton.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
_init: function(appsMenuButton, file) {
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
this.file = file;
+ this.appsMenuButton = appsMenuButton;
this.button_name = this.file.name;
- this.actor = new St.Button({ reactive: true, style_class: 'menu-application-button', x_align: St.Align.START });
+ this.actor.set_style_class_name('menu-application-button');
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
- this.label = new St.Label({ text: this.button_name, style_class: 'menu-place-cat-button-label' });
+ this.label = new St.Label({ text: this.button_name, style_class: 'menu-application-button-label' });
this.icon = file.createIcon(APPLICATION_ICON_SIZE);
- this.buttonbox.add_actor(this.icon);
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
- this.actor.connect('clicked', Lang.bind(this, function() {
+ this.addActor(this.icon);
+ this.addActor(this.label);
+ },
+
+ _onButtonReleaseEvent: function (actor, event) {
+ if (event.get_button()==1){
Gio.app_info_launch_default_for_uri(this.file.uri, global.create_app_launch_context());
- appsMenuButton.menu.close();
- }));
+ this.appsMenuButton.menu.close();
+ }
}
};
-Signals.addSignalMethods(RecentButton.prototype);
function RecentClearButton(appsMenuButton) {
this._init(appsMenuButton);
}
RecentClearButton.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
_init: function(appsMenuButton) {
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
+ this.appsMenuButton = appsMenuButton;
+ this.actor.set_style_class_name('menu-application-button');
this.button_name = _("Clear list");
- this.actor = new St.Button({ reactive: true, style_class: 'menu-application-button', x_align: St.Align.START });
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
- this.label = new St.Label({ text: this.button_name, style_class: 'menu-place-cat-button-label' });
- let icon = new St.Icon({ icon_name: 'edit-clear', icon_type: St.IconType.SYMBOLIC, icon_size: APPLICATION_ICON_SIZE });
- this.buttonbox.add_actor(icon);
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
- this.actor.connect('clicked', Lang.bind(this, function() {
- appsMenuButton.menu.close();
+ this.label = new St.Label({ text: this.button_name, style_class: 'menu-application-button-label' });
+ this.icon = new St.Icon({ icon_name: 'edit-clear', icon_type: St.IconType.SYMBOLIC, icon_size: APPLICATION_ICON_SIZE });
+ this.addActor(this.icon);
+ this.addActor(this.label);
+ },
+
+ _onButtonReleaseEvent: function (actor, event) {
+ if (event.get_button()==1){
+ this.appsMenuButton.menu.close();
let GtkRecent = new Gtk.RecentManager();
GtkRecent.purge_items();
- }));
+ }
}
};
-Signals.addSignalMethods(RecentClearButton.prototype);
function CategoryButton(app) {
this._init(app);
}
CategoryButton.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
_init: function(category) {
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
+
+ this.actor.set_style_class_name('menu-category-button');
var label;
if (category) {
let icon = category.get_icon();
@@ -351,58 +367,52 @@ CategoryButton.prototype = {
label = category.get_name();
} else
label = _("All Applications");
- this.actor = new St.Button({ reactive: true, style_class: 'menu-category-button', x_align: St.Align.START });
+
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
- this.label = new St.Label({ text: label, style_class: 'menu-place-cat-button-label' });
+ this.label = new St.Label({ text: label, style_class: 'menu-category-button-label' });
if (category && this.icon_name) {
this.icon = new St.Icon({icon_name: this.icon_name, icon_size: CATEGORY_ICON_SIZE, icon_type: St.IconType.FULLCOLOR});
- this.buttonbox.add_actor(this.icon);
+ this.addActor(this.icon);
}
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
- //this.actor.set_tooltip_text(category.get_name());
+ this.addActor(this.label);
}
};
-Signals.addSignalMethods(CategoryButton.prototype);
function PlaceCategoryButton(app) {
this._init(app);
}
PlaceCategoryButton.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
_init: function(category) {
- this.actor = new St.Button({ reactive: true, style_class: 'menu-category-button', x_align: St.Align.START });
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
+ this.actor.set_style_class_name('menu-category-button');
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
- this.label = new St.Label({ text: _("Places"), style_class: 'menu-place-cat-button-label' });
+ this.label = new St.Label({ text: _("Places"), style_class: 'menu-category-button-label' });
this.icon = new St.Icon({icon_name: "folder", icon_size: CATEGORY_ICON_SIZE, icon_type: St.IconType.FULLCOLOR});
- this.buttonbox.add_actor(this.icon);
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
+ this.addActor(this.icon);
+ this.addActor(this.label);
}
};
-Signals.addSignalMethods(PlaceCategoryButton.prototype);
function RecentCategoryButton(app) {
this._init(app);
}
RecentCategoryButton.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
_init: function(category) {
- this.actor = new St.Button({ reactive: true, style_class: 'menu-category-button', x_align: St.Align.START });
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this, {hover: false});
+ this.actor.set_style_class_name('menu-category-button');
this.actor._delegate = this;
- this.buttonbox = new St.BoxLayout();
this.label = new St.Label({ text: _("Recent Files"), style_class: 'menu-place-cat-button-label' });
this.icon = new St.Icon({icon_name: "folder-recent", icon_size: CATEGORY_ICON_SIZE, icon_type: St.IconType.FULLCOLOR});
- this.buttonbox.add_actor(this.icon);
- this.buttonbox.add_actor(this.label);
- this.actor.set_child(this.buttonbox);
+ this.addActor(this.icon);
+ this.addActor(this.label);
}
};
-Signals.addSignalMethods(RecentCategoryButton.prototype);
-
-
function FavoritesButton(appsMenuButton, app, nbFavorites) {
this._init(appsMenuButton, app, nbFavorites);
@@ -842,6 +852,7 @@ MyApplet.prototype = {
index = this.appBoxIter.getAbsoluteIndexOfChild(item_actor);
} else {
this._previousSelectedActor = this.categoriesBox.get_child_at_index(index);
+ this._previousSelectedActor._delegate.isHovered = false;
item_actor = this.catBoxIter.getPrevVisible(this._activeActor)
index = this.catBoxIter.getAbsoluteIndexOfChild(item_actor);
}
@@ -852,6 +863,7 @@ MyApplet.prototype = {
index = this.appBoxIter.getAbsoluteIndexOfChild(item_actor);
} else {
this._previousSelectedActor = this.categoriesBox.get_child_at_index(index);
+ this._previousSelectedActor._delegate.isHovered = false;
item_actor = this.catBoxIter.getNextVisible(this._activeActor)
index = this.catBoxIter.getAbsoluteIndexOfChild(item_actor);
}
@@ -874,9 +886,7 @@ MyApplet.prototype = {
if (!item_actor || item_actor === this.searchEntry) {
return false;
}
- // if (item_actor !== this._previousSelectedActor) {
- item_actor._delegate.emit('enter-event');
- //}
+ item_actor._delegate.emit('enter-event');
return true;
},
@@ -935,18 +945,9 @@ MyApplet.prototype = {
let applicationsBoxHeight = this.applicationsBox.get_allocation_box().y2-this.applicationsBox.get_allocation_box().y1;
let scrollBoxHeight = (this.leftBox.get_allocation_box().y2-this.leftBox.get_allocation_box().y1)
-(this.searchBox.get_allocation_box().y2-this.searchBox.get_allocation_box().y1);
-
-
-
- // if (scrollBoxHeight < (0.2*monitorHeight) && (scrollBoxHeight < applicationsBoxHeight)) {
- // scrollBoxHeight = Math.min(0.2*monitorHeight, applicationsBoxHeight);
- // }
- this.applicationsScrollBox.style = "height: "+scrollBoxHeight+"px;";
+ this.applicationsScrollBox.style = "height: "+scrollBoxHeight+"px;";
} else {
this.closeApplicationsContextMenus(null, false);
- //this.resetSearch();
- //this._clearSelections(this.categoriesBox);
- //this._clearSelections(this.applicationsBox);
}
},
@@ -960,10 +961,7 @@ MyApplet.prototype = {
this.categoriesBox.destroy_all_children();
this._allAppsCategoryButton = new CategoryButton(null);
- this._allAppsCategoryButton.actor.connect('clicked', Lang.bind(this, function() {
- this._select_category(null, this._allAppsCategoryButton);
- }));
- this._addEnterEvent(this._allAppsCategoryButton, Lang.bind(this, function() {
+ this._addEnterEvent(this._allAppsCategoryButton, Lang.bind(this, function() {
if (!this.searchActive) {
this._allAppsCategoryButton.isHovered = true;
Tweener.addTween(this, {
@@ -973,6 +971,8 @@ MyApplet.prototype = {
this._allAppsCategoryButton.actor.style_class = "menu-category-button-selected";
this._clearPrevCatSelection(this._allAppsCategoryButton.actor);
this._select_category(null, this._allAppsCategoryButton);
+ } else {
+ this._allAppsCategoryButton.actor.style_class = "menu-category-button";
}
}
});
@@ -1004,9 +1004,6 @@ MyApplet.prototype = {
this._loadCategory(dir);
if (this.applicationsByCategory[dir.get_menu_id()].length>0){
let categoryButton = new CategoryButton(dir);
- categoryButton.actor.connect('clicked', Lang.bind(this, function() {
- this._select_category(dir, categoryButton);
- }));
this._addEnterEvent(categoryButton, Lang.bind(this, function() {
if (!this.searchActive) {
categoryButton.isHovered = true;
@@ -1017,6 +1014,8 @@ MyApplet.prototype = {
categoryButton.actor.style_class = "menu-category-button-selected";
this._clearPrevCatSelection(categoryButton.actor);
this._select_category(dir, categoryButton);
+ } else {
+ categoryButton.actor.style_class = "menu-category-button";
}
}
});
@@ -1049,9 +1048,6 @@ MyApplet.prototype = {
// Now generate Places category and places buttons and add to the list
if (this.showPlaces) {
this.placesButton = new PlaceCategoryButton();
- this.placesButton.actor.connect('clicked', Lang.bind(this, function() {
- this._displayButtons(null, -1);
- }));
this._addEnterEvent(this.placesButton, Lang.bind(this, function() {
if (!this.searchActive) {
this.placesButton.isHovered = true;
@@ -1098,9 +1094,6 @@ MyApplet.prototype = {
// Now generate recent category and recent files buttons and add to the list
if (this.showRecent) {
this.recentButton = new RecentCategoryButton();
- this.recentButton.actor.connect('clicked', Lang.bind(this, function() {
- this._displayButtons(null, null, -1);
- }));
this._addEnterEvent(this.recentButton, Lang.bind(this, function() {
if (!this.searchActive) {
this.recentButton.isHovered = true;
@@ -1269,26 +1262,17 @@ MyApplet.prototype = {
if (!dupe) {
let applicationButton = new ApplicationButton(this, app);
applicationButton.actor.connect('realize', Lang.bind(this, this._onApplicationButtonRealized));
- applicationButton.actor.connect('leave-event', Lang.bind(this, function() {
- this._previousSelectedActor = applicationButton.actor;
- applicationButton.actor.style_class = "menu-application-button";
- this.selectedAppTitle.set_text("");
- this.selectedAppDescription.set_text("");
- }));
- this._addEnterEvent(applicationButton, Lang.bind(this, function() {
- this.selectedAppTitle.set_text(applicationButton.app.get_name());
- if (applicationButton.app.get_description())
- this.selectedAppDescription.set_text(applicationButton.app.get_description());
- else
- this.selectedAppDescription.set_text("");
- this._clearPrevAppSelection(applicationButton.actor);
- applicationButton.actor.style_class = "menu-application-button-selected";
- this._scrollToButton(applicationButton);
- }));
+ applicationButton.actor.connect('leave-event', Lang.bind(this, this._appLeaveEvent, applicationButton));
+ this._addEnterEvent(applicationButton, Lang.bind(this, this._appEnterEvent, applicationButton));
this._applicationsButtons.push(applicationButton);
+ applicationButton.category.push(dir.get_menu_id());
this.applicationsByCategory[dir.get_menu_id()].push(app.get_name());
} else {
- this.applicationsByCategory[dir.get_menu_id()].push(app.get_name());
+ for (let i = 0; i < this._applicationsButtons.length; i++) {
+ if (this._applicationsButtons[i].app == app) {
+ this._applicationsButtons[i].category.push(dir.get_menu_id());
+ }
+ }
}
}
} else if (nextType == GMenu.TreeItemType.DIRECTORY) {
@@ -1297,6 +1281,24 @@ MyApplet.prototype = {
}
},
+ _appLeaveEvent: function(a, b, applicationButton) {
+ this._previousSelectedActor = applicationButton.actor;
+ applicationButton.actor.style_class = "menu-application-button";
+ this.selectedAppTitle.set_text("");
+ this.selectedAppDescription.set_text("");
+ },
+
+ _appEnterEvent: function(applicationButton) {
+ this.selectedAppTitle.set_text(applicationButton.app.get_name());
+ if (applicationButton.app.get_description())
+ this.selectedAppDescription.set_text(applicationButton.app.get_description());
+ else
+ this.selectedAppDescription.set_text("");
+ this._clearPrevAppSelection(applicationButton.actor);
+ applicationButton.actor.style_class = "menu-application-button-selected";
+ this._scrollToButton(applicationButton);
+ },
+
find_dupe: function(app) {
let ret = false;
for (let i = 0; i < this._applicationsButtons.length; i++) {
@@ -1438,31 +1440,39 @@ MyApplet.prototype = {
}
},
- _displayButtons: function(apps, places, recent){
- if (apps) {
- if (apps[0] == "all") {
- for (let i = 0; i < this._applicationsButtons.length; i++) {
- this._applicationsButtons[i].actor.show();
- }
+ _displayButtons: function(appCategory, places, recent, apps){
+ if (appCategory) {
+ if (appCategory == "all") {
+ this._applicationsButtons.forEach( function (item, index) {
+ item.actor.show();
+ });
} else {
- for (let i = 0; i < this._applicationsButtons.length; i++) {
+ this._applicationsButtons.forEach( function (item, index) {
+ if (item.category.indexOf(appCategory) != -1) {
+ item.actor.show();
+ } else {
+ item.actor.hide();
+ }
+ });
+ }
+ } else if (apps) {
+ for (let i = 0; i < this._applicationsButtons.length; i++) {
if (apps.indexOf(this._applicationsButtons[i].name) != -1) {
this._applicationsButtons[i].actor.show();
} else {
this._applicationsButtons[i].actor.hide();
}
- }
}
} else {
- for (let i = 0; i < this._applicationsButtons.length; i++) {
- this._applicationsButtons[i].actor.hide();
- }
+ this._applicationsButtons.forEach( function (item, index) {
+ item.actor.hide();
+ });
}
if (places) {
if (places == -1) {
- for (let i = 0; i < this._placesButtons.length; i++) {
- this._placesButtons[i].actor.show();
- }
+ this._placesButtons.forEach( function (item, index) {
+ item.actor.show();
+ });
} else {
for (let i = 0; i < this._placesButtons.length; i++) {
if (places.indexOf(this._placesButtons[i].button_name) != -1) {
@@ -1473,15 +1483,15 @@ MyApplet.prototype = {
}
}
} else {
- for (let i = 0; i < this._placesButtons.length; i++) {
- this._placesButtons[i].actor.hide();
- }
+ this._placesButtons.forEach( function (item, index) {
+ item.actor.hide();
+ });
}
if (recent) {
if (recent == -1) {
- for (let i = 0; i < this._recentButtons.length; i++) {
- this._recentButtons[i].actor.show();
- }
+ this._recentButtons.forEach( function (item, index) {
+ item.actor.show();
+ });
} else {
for (let i = 0; i < this._recentButtons.length; i++) {
if (recent.indexOf(this._recentButtons[i].button_name) != -1) {
@@ -1492,9 +1502,9 @@ MyApplet.prototype = {
}
}
} else {
- for (let i = 0; i < this._recentButtons.length; i++) {
- this._recentButtons[i].actor.hide();
- }
+ this._recentButtons.forEach( function (item, index) {
+ item.actor.hide();
+ });
}
},
@@ -1578,9 +1588,9 @@ MyApplet.prototype = {
_listApplications: function(category_menu_id, pattern){
var applist = new Array();
if (category_menu_id) {
- applist = this.applicationsByCategory[category_menu_id];
+ applist = category_menu_id;
} else {
- applist.push('all');
+ applist = "all";
}
let res;
if (pattern){
@@ -1627,7 +1637,7 @@ MyApplet.prototype = {
recentResults.push(this._recentButtons[i].button_name);
}
- this._displayButtons(appResults, placesResults, recentResults);
+ this._displayButtons(null, placesResults, recentResults, appResults);
this.appBoxIter.reloadVisible();
if (this.appBoxIter.getNumVisibleChildren() > 0) {
Please sign in to comment.
Something went wrong with that request. Please try again.