OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 var options = []; | 904 var options = []; |
905 for (var index = 0; index < this._states.length; index++) { | 905 for (var index = 0; index < this._states.length; index++) { |
906 if (this._states[index] !== this.state() && this._states[index] !==
this._currentState) | 906 if (this._states[index] !== this.state() && this._states[index] !==
this._currentState) |
907 options.push(this._buttons[index]); | 907 options.push(this._buttons[index]); |
908 } | 908 } |
909 return options; | 909 return options; |
910 }, | 910 }, |
911 | 911 |
912 __proto__: WebInspector.ToolbarButton.prototype | 912 __proto__: WebInspector.ToolbarButton.prototype |
913 } | 913 } |
| 914 |
| 915 /** |
| 916 * @constructor |
| 917 * @extends {WebInspector.Toolbar} |
| 918 * @param {string} location |
| 919 * @param {!Element=} parentElement |
| 920 */ |
| 921 WebInspector.ExtensibleToolbar = function(location, parentElement) |
| 922 { |
| 923 WebInspector.Toolbar.call(this, parentElement); |
| 924 this._loadItems(location); |
| 925 } |
| 926 |
| 927 WebInspector.ExtensibleToolbar.prototype = { |
| 928 /** |
| 929 * @param {string} location |
| 930 */ |
| 931 _loadItems: function(location) |
| 932 { |
| 933 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provid
er); |
| 934 var promises = []; |
| 935 for (var i = 0; i < extensions.length; ++i) { |
| 936 if (extensions[i].descriptor()["location"] === location) |
| 937 promises.push(resolveItem(extensions[i])); |
| 938 } |
| 939 Promise.all(promises).then(appendItemsInOrder.bind(this)); |
| 940 |
| 941 /** |
| 942 * @param {!Runtime.Extension} extension |
| 943 * @return {!Promise.<?WebInspector.ToolbarItem>} |
| 944 */ |
| 945 function resolveItem(extension) |
| 946 { |
| 947 var descriptor = extension.descriptor(); |
| 948 if (!descriptor.className) |
| 949 return Promise.resolve(new WebInspector.ToolbarButton(WebInspect
or.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandle
r); |
| 950 return extension.instancePromise().then(fetchItemFromProvider).then(
attachHandler); |
| 951 |
| 952 /** |
| 953 * @param {!Object} provider |
| 954 */ |
| 955 function fetchItemFromProvider(provider) |
| 956 { |
| 957 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provid
er).item(); |
| 958 } |
| 959 |
| 960 /** |
| 961 * @param {?WebInspector.ToolbarItem} item |
| 962 * @return {?WebInspector.ToolbarItem} item |
| 963 */ |
| 964 function attachHandler(item) |
| 965 { |
| 966 if (extension.descriptor()["actionId"] && item) |
| 967 item.addEventListener("click", handler); |
| 968 return item; |
| 969 } |
| 970 |
| 971 function handler() |
| 972 { |
| 973 WebInspector.actionRegistry.execute(extension.descriptor()["acti
onId"]); |
| 974 } |
| 975 } |
| 976 |
| 977 /** |
| 978 * @param {!Array.<?WebInspector.ToolbarItem>} items |
| 979 * @this {WebInspector.ExtensibleToolbar} |
| 980 */ |
| 981 function appendItemsInOrder(items) |
| 982 { |
| 983 for (var i = 0; i < items.length; ++i) { |
| 984 var item = items[i]; |
| 985 if (item) |
| 986 this.appendToolbarItem(item); |
| 987 } |
| 988 } |
| 989 }, |
| 990 |
| 991 __proto__: WebInspector.Toolbar.prototype |
| 992 } |
OLD | NEW |