From 22f4086de03ac75e915e0333ed4577bd62389312 Mon Sep 17 00:00:00 2001 From: Cork Date: Tue, 23 Apr 2013 19:04:20 +0200 Subject: [PATCH 1/2] Normalize indents to 4 spaces --- extension.js | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/extension.js b/extension.js index 7692ea3..af13612 100644 --- a/extension.js +++ b/extension.js @@ -46,7 +46,7 @@ CalcResult.prototype = { result.add(exprLabel, { x_fill: false, x_align: St.Align.START }); result.add(resultLabel, { x_fill: false, x_align: St.Align.START }); - result.set_width(400); + result.set_width(400); } }; @@ -65,48 +65,48 @@ UnitProvider.prototype = { _tempRegex: /^(-?[0-9]+\.?[0-9]*)\s*([FCK]) ([FCK])$/i, _isTempConversion: function(term1, term2) { - return this._tempRegex.test(term1.concat(" ", term2)) - }, + return this._tempRegex.test(term1.concat(" ", term2)) + }, - _tempConversionRewrite: function(term1, term2) { - var parts = this._tempRegex.exec(term1.concat(" ", term2)) - return ["temp".concat(parts[2].toUpperCase(), "(", parts[1], ")"), "temp".concat(parts[3].toUpperCase())]; - }, + _tempConversionRewrite: function(term1, term2) { + var parts = this._tempRegex.exec(term1.concat(" ", term2)) + return ["temp".concat(parts[2].toUpperCase(), "(", parts[1], ")"), "temp".concat(parts[3].toUpperCase())]; + }, getInitialResultSet: function(terms) { - terms = terms.slice(); + terms = terms.slice(); var valid = false; var split = 0; for(var i in terms) { - if(terms[i] == "to") { - valid = true; - split = i; - break; - } - } - if (valid) { - let one = terms.splice(0, split).join(" "); - let two = terms.splice(1).join(" "); - let expr = one.concat(" to ", two); - - if(this._isTempConversion(one, two)) { - [one, two] = this._tempConversionRewrite(one, two); - } + if(terms[i] == "to") { + valid = true; + split = i; + break; + } + } + if (valid) { + let one = terms.splice(0, split).join(" "); + let two = terms.splice(1).join(" "); + let expr = one.concat(" to ", two); + + if(this._isTempConversion(one, two)) { + [one, two] = this._tempConversionRewrite(one, two); + } try { - let [success, out, err, error] = GLib.spawn_sync(null, ["units", "-t", one, two], null, 4, null) - if(error == 0) { - result = out.toString(); - this._lastResult = result; - this.searchSystem.pushResults(this, - [{'expr': expr, 'result': result}]); - return [{'expr': expr, 'result': result}]; - } + let [success, out, err, error] = GLib.spawn_sync(null, ["units", "-t", one, two], null, 4, null) + if(error == 0) { + result = out.toString(); + this._lastResult = result; + this.searchSystem.pushResults(this, + [{'expr': expr, 'result': result}]); + return [{'expr': expr, 'result': result}]; + } } catch(exp) { } } - this.searchSystem.pushResults(this, []); + this.searchSystem.pushResults(this, []); return []; }, @@ -115,11 +115,11 @@ UnitProvider.prototype = { }, getResultMetas: function(result, callback) { - let metas = []; - for(let i = 0; i < result.length; i++) { - metas.push({'id' : i, 'result' : result[i].result, 'expr' : result[i].expr}); - } - callback(metas) + let metas = []; + for(let i = 0; i < result.length; i++) { + metas.push({'id' : i, 'result' : result[i].result, 'expr' : result[i].expr}); + } + callback(metas) return metas; }, @@ -138,9 +138,9 @@ UnitProvider.prototype = { }, activateResult: function(resultId) { - if(this._lastResult) { - St.Clipboard.get_default().set_text(this._lastResult.replace("\n", "")); - } + if(this._lastResult) { + St.Clipboard.get_default().set_text(this._lastResult.replace("\n", "")); + } return true; } } From 4738f5f4974d88fee23db46d315c95050aecd6eb Mon Sep 17 00:00:00 2001 From: Cork Date: Tue, 23 Apr 2013 19:05:19 +0200 Subject: [PATCH 2/2] Upgrade to support gnome-shell 3.8 --- extension.js | 24 ++++++++++-------------- metadata.json | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/extension.js b/extension.js index af13612..73b8caf 100644 --- a/extension.js +++ b/extension.js @@ -3,6 +3,7 @@ const Main = imports.ui.main; const Search = imports.ui.search; const SearchDisplay = imports.ui.searchDisplay; const IconGrid = imports.ui.iconGrid; +const Lang = imports.lang; const GLib = imports.gi.GLib; const MAX_SEARCH_RESULTS_ROWS = 1; @@ -10,11 +11,9 @@ const ICON_SIZE = 81; let unitProvider = ""; -function CalcResult(result) { - this._init(result); -} +const UnitResult = new Lang.Class({ + Name: 'UnitResult', -CalcResult.prototype = { _init: function(resultMeta) { this.actor = new St.Bin({ style_class: 'contact', @@ -49,17 +48,14 @@ CalcResult.prototype = { result.set_width(400); } -}; - -function UnitProvider() { - this._init.apply(this, arguments); -} +}); -UnitProvider.prototype = { - __proto__: Search.SearchProvider.prototype, +const UnitProvider = new Lang.Class({ + Name: 'UnitProvider', + Extends: Search.SearchProvider, _init: function(title) { - Search.SearchProvider.prototype._init.call(this, title); + this.parent(title); }, _tempRegex: /^(-?[0-9]+\.?[0-9]*)\s*([FCK]) ([FCK])$/i, @@ -124,7 +120,7 @@ UnitProvider.prototype = { }, createResultActor: function(resultMeta, terms) { - let result = new CalcResult(resultMeta); + let result = new UnitResult(resultMeta); return result.actor; }, @@ -143,7 +139,7 @@ UnitProvider.prototype = { } return true; } -} +}); function init() { unitProvider = new UnitProvider('UNIT CONVERTER'); diff --git a/metadata.json b/metadata.json index d2b668c..32e5fec 100644 --- a/metadata.json +++ b/metadata.json @@ -1,5 +1,5 @@ { - "shell-version": ["3.6"], + "shell-version": ["3.6", "3.8"], "uuid": "UnitConverter@wrowclif.org", "name": "Unit Converter", "description": "Convert units from the overview search. In the form \"x this to that\""