Commit 91d96d2bd4b40bc609a7f867aad2d50ef10a662d

app-launcher-page-selector, adds a view menu with shortcuts to launcher pages
  
1Copyright (c) 2010 Leslie Michael Orchard <l.m.orchard@pobox.com>
2
3Permission is hereby granted, free of charge, to any person
4obtaining a copy of this software and associated documentation
5files (the "Software"), to deal in the Software without
6restriction, including without limitation the rights to use,
7copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the
9Software is furnished to do so, subject to the following
10conditions:
11
12The above copyright notice and this permission notice shall be
13included in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
  
1Name: Page Selection Tabs in App Launcher
2Version: 1.0.0
3Author: l.m.orchard@pobox.com
4Description: This patch adds a row of view menu tabs for quick access to any page of the App Launcher (MIT License)
5
6Index: /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
7===================================================================
8--- .orig/usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
9+++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
10@@ -17,6 +17,7 @@ var LauncherAssistant = Class.create({
11 kAppsPerRow: NaN,
12 kAppHeight: NaN,
13 kAppWidth: NaN,
14+ kMaxPageSelectorTabs: 5,
15 /* constant end */
16
17 appMenuModel: {
18@@ -76,6 +77,18 @@ var LauncherAssistant = Class.create({
19 onAppUpdated: this.onAppUpdated.bind(this)
20 }
21 );
22+
23+ // Set up an initial blank view menu widget for page selection. (LMO)
24+ this.viewMenuModel = {
25+ label: $L('Launcher pages'), items: [
26+ { items: [] },
27+ { label: $L('Pages'), items: [] },
28+ { items: [] }
29+ ]
30+ };
31+ this.controller.setupWidget(
32+ Mojo.Menu.viewMenu, { menuClass: 'no-fade' }, this.viewMenuModel
33+ );
34
35 this.globalSearchAssistant = new GlobalSearchAssistant(this.controller, this);
36
37@@ -114,6 +127,14 @@ var LauncherAssistant = Class.create({
38
39 handleCommand: function(event) {
40 if (event.type == Mojo.Event.command) {
41+
42+ // Check for pageselect_{number} commands to switch pages. (LMO)
43+ var m;
44+ if (m = (/^pageselect_(\d+)$/.exec(event.command))) {
45+ // Note: parseInt() needed here so scroller math doesn't break
46+ return this.gotoPage(parseInt(m[1]));
47+ }
48+
49 switch (event.command) {
50 case Mojo.Menu.helpCmd:
51 ApplicationService.launch(this.helpInfo.id, this.helpInfo.params);
52@@ -260,6 +281,7 @@ var LauncherAssistant = Class.create({
53
54 // tell our scroller widget that it has a new page element to snap
55 this.updatePageSnappingPoints();
56+ this.rebuildPageSelector(); // (LMO)
57 },
58
59 deletePage: function(pageIndex) {
60@@ -312,6 +334,7 @@ var LauncherAssistant = Class.create({
61 }
62
63 this.updatePageSnappingPoints();
64+ this.rebuildPageSelector(); // (LMO)
65 },
66
67 /* creates and appends a new application div in the provided page container */
68@@ -658,6 +681,9 @@ var LauncherAssistant = Class.create({
69
70 /* Updates the positions of all page indicators. */
71 updatePageIndicators: function() {
72+
73+ // Ensure that the view menu tabs reflect the active page. (LMO)
74+ this.setPageSelectorState(this.activePageIndex);
75
76 if (this.indicators.length <= 0) {
77 return;
78@@ -778,6 +804,91 @@ var LauncherAssistant = Class.create({
79 onLaunchCompleted: function(response) {
80
81 delete this.launchRequest;
82- }
83+ },
84+
85+ /**
86+ * Rebuild the page selector tabs and possible overflow submenu. (LMO)
87+ */
88+ rebuildPageSelector: function () {
89+
90+ var items = [],
91+ submenu_items = [];
92+
93+ for (var i=0,l=this.pageDivs.length; i<l; i++) {
94+
95+ // Build a new page selection item.
96+ var new_item = { label: '#'+(i+1), command: 'pageselect_' + i };
97+
98+ // If there are exactly 5 items, or this is item 4 or less,
99+ // drop it into the top-level items list.
100+ if (l<=this.kMaxPageSelectorTabs || i<(this.kMaxPageSelectorTabs-1)) {
101+ items.push(new_item);
102+ }
103+
104+ // If there are more than 5 items, the fifth top-level item
105+ // invokes a sub-menu containing the rest of the items.
106+ if (l>this.kMaxPageSelectorTabs) {
107+ if (i==(this.kMaxPageSelectorTabs-1)) {
108+ // Create the overflow submenu button.
109+ items.push({ label: '...', command: 'pageselect_more_pages',
110+ submenu: 'pageselect_more_pages' });
111+ }
112+ if (i>=(this.kMaxPageSelectorTabs-1)) {
113+ // Add the current item to the overflow submenu.
114+ submenu_items.push(new_item);
115+ }
116+ }
117+
118+ }
119+
120+ // Update the view menu model for page selection.
121+ this.viewMenuModel.items[1].items = items;
122+
123+ // If there was a submenu of items built, rebuild the submenu itself.
124+ if (submenu_items.length) {
125+ this.controller.setupWidget('pageselect_more_pages', undefined,
126+ this.pageselectSubmenuModel = {
127+ label: $('More pages'), items: submenu_items
128+ }
129+ );
130+ }
131+
132+ // Make the widget refresh with the new data, ensure state matches
133+ // active page state.
134+ this.controller.modelChanged(this.viewMenuModel);
135+ this.setPageSelectorState(this.activePageIndex);
136+ },
137+
138+ /**
139+ * Update the view menu tabs to reflect a given page index. (LMO)
140+ *
141+ * @param {int} idx Page index.
142+ */
143+ setPageSelectorState: function (idx) {
144+ if (idx >= (this.kMaxPageSelectorTabs-1) && this.pageDivs.length > this.kMaxPageSelectorTabs) {
145+ // Tab selected belongs to the overflow submenu, so set a checkmark
146+ this.viewMenuModel.items[1].toggleCmd = 'pageselect_more_pages';
147+ this.pageselectSubmenuModel.toggleCmd = 'pageselect_' + idx;
148+ } else {
149+ // Tab belongs to the visible tabs, so toggle one on.
150+ this.viewMenuModel.items[1].toggleCmd = 'pageselect_' + idx;
151+ if (this.pageselectSubmenuModel) {
152+ // If there happens to be a submenu, clear the checkmark.
153+ this.pageselectSubmenuModel.toggleCmd = '';
154+ }
155+ }
156+ this.controller.modelChanged(this.viewMenuModel);
157+ },
158+
159+ /**
160+ * Switch directly to a page. (LMO)
161+ *
162+ * @param {int} idx Page index.
163+ */
164+ gotoPage: function (idx) {
165+ $('launcher_root').mojo.setSnapIndex(idx, true);
166+ this.activePageIndex = idx;
167+ this.updatePageIndicators();
168+ }
169
170 });
171Index: /usr/lib/luna/system/luna-applauncher/stylesheets/launcher.css
172===================================================================
173--- .orig/usr/lib/luna/system/luna-applauncher/stylesheets/launcher.css
174+++ /usr/lib/luna/system/luna-applauncher/stylesheets/launcher.css
175@@ -59,7 +59,7 @@ body.palm-default
176 width: 100%;
177 z-index: 29;
178 height: 24px;
179- top: 1px;
180+ top: 45px; /* Insert some space for the page selector (LMO) */
181 background: url(../images/fade-arrow-up.png) center center no-repeat;
182 -webkit-palm-mouse-target: ignore;
183 }
184@@ -106,7 +106,7 @@ body.palm-default
185 }
186
187 .page_scroller_container {
188- margin-top: 10px;
189+ margin-top: 55px; /* Insert some space for the page selector (LMO) */
190 margin-bottom: -20px;
191 }
192