Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: samples/total/client/ContextMenu.dart

Issue 10635015: Delete proxy and total samples, which have bit-rotted. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/total/client/Command.dart ('k') | samples/total/client/ContextMenuBuilder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 typedef bool EnabledFunction();
6 typedef void CallbackFunction(Element elmt, int value);
7
8 class ElementFunc {
9 Element _element;
10 EnabledFunction _func;
11
12 Element get element() => _element;
13
14 EnabledFunction get func() => _func;
15
16 ElementFunc(this._element, this._func) { }
17 }
18
19 class ContextMenu {
20 Element _contextMenu;
21 List<ElementFunc> _enableFunctions;
22 Element _parent;
23 Spreadsheet _spreadsheet;
24 SpreadsheetPresenter _spreadsheetPresenter;
25
26 Element get parent() => _parent;
27
28 ContextMenu(this._spreadsheetPresenter) {
29 Document doc = document;
30 _contextMenu = new Element.tag("ul");
31 _contextMenu.style.setProperty("left","0px");
32 _contextMenu.style.setProperty("top", "0px");
33 _contextMenu.classes.add("contextMenu");
34 _contextMenu.classes.add("fadeOut");
35
36 // Parent off the document body to avoid problems when the menu
37 // extends past the border of its owner spreadsheet
38 _parent = doc.body;
39 _parent.nodes.add(_contextMenu);
40 _spreadsheet = _spreadsheetPresenter.spreadsheet;
41 }
42
43 Element addMenuItem(String label, int value,
44 EnabledFunction enabled, CallbackFunction callback) {
45 Element item = new Element.tag("li");
46 item.classes.add("contextMenuItem");
47 item.classes.add("contextMenuItem-enabled");
48 item.innerHTML = label;
49 item.on.click.add((Event e) {
50 _spreadsheetPresenter.popdownMenu(_contextMenu, value, callback);
51 });
52 _contextMenu.nodes.add(item);
53 if (_enableFunctions == null) {
54 _enableFunctions = new List<ElementFunc>();
55 }
56 _enableFunctions.add(new ElementFunc(item, enabled));
57 return item;
58 }
59
60 // Display the popup at the given coordinates
61 void show(int x, int y) {
62 // Enable or disable the menu items
63 _enableFunctions.forEach((ElementFunc elementFunc) {
64 _enableMenuItem(elementFunc.element, (elementFunc.func)());
65 });
66 _spreadsheetPresenter.popupMenu(_contextMenu, x, y);
67 }
68
69 // Enable or disable a particular menu item
70 void _enableMenuItem(Element item, bool enabled) {
71 if (enabled) {
72 item.classes.remove("contextMenuItem-disabled");
73 item.classes.add("contextMenuItem-enabled");
74 } else {
75 item.classes.remove("contextMenuItem-enabled");
76 item.classes.add("contextMenuItem-disabled");
77 }
78 }
79 }
OLDNEW
« no previous file with comments | « samples/total/client/Command.dart ('k') | samples/total/client/ContextMenuBuilder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698