DonationCoder.com Software > Ecaradec's Software
Qatapult
pigeonlips:
That's a very impressive work for a newcomer to javascript. - I've also added a few things to allow path trimming
--- End quote ---
lol - while writing and testing , writing and testing you wouldn't believe the pain i was causing qatapult and the crazy erratic behavior i got :) - thanks for the kind comment, but i'm still worried its buggy.
also dont add to much - the learning curve is hard! LOL - just kidding.
ewemoa:
This skin is my first time ever using js so please point out anything that's wrong.
-pigeonlips (March 07, 2012, 04:53 PM)
--- End quote ---
You may find strong opinions about JavaScript :)
As I understand it, JavaScript didn't get much time for design and polish before it got shipped and this shows. There are many oddities / warts in the language and sadly often trying to do things in a way that seems to make sense can backfire -- particularly if one has expectations about the language coming from a C / C++ (or similar) background.
If you intend to continue with the language, I highly recommend checking out some of Douglas Crockford's material early on, perhaps starting with:
Crockford on JavaScript
Even if one doesn't agree with some or much of what he says, I've found his material well worth the time.
He suggests an approach to the language based on being quite selective in what to use in the language and staying away from certain bits (e.g. he suggests not using == or != and instead using === and !==). I have found this helps tremendously for JavaScript (and even AHK) but it isn't necessarily the easiest thing to figure out or get used to.
To help in this process, there is a tool Crockford developed and maintains called jslint (and now at least one fork called jshint). I used jslint while doing JavaScript (via FScript) plugin development for FARR and found it to be really helpful. Haven't set it up for Qatapult yet, but based on working with the OpenWith plugin, getting the feeling it may be a good idea.
After writing the above, I remembered that there is now this thing called CoffeeScript. It compiles to JavaScript and although it has its problems, seems a far nicer language to be writing in. It's pretty easy to get it set up once one has Node.js installed. May be I'll see how practical it would be to use for Qatapult-related things.
Any interest?
ewemoa:
BTW, any chance of being able to use PgUp and PgDn for results navigation?
ewemoa:
Just a quick note to mention that slightly modifying the output of coffee (a CoffeeScript compiler), seems to produce a Qatapult-usable result.
The following CoffeeScript content for snippets.collecter.js:
--- Code: Text ---collect = (query, results) -> if results.expects('TEXT') fso = new ActiveXObject("Scripting.FileSystemObject") f = fso.OpenTextFile("plugins\\snippets\\text.txt") while not f.AtEndOfStream l = f.ReadLine() if qatapult.match(l, query) obj = key: l text: l icon: "plugins\\snippets\\text.jpg" results.addObject('TEXT', l, obj)
turns into:
--- Code: Javascript ---(function() { var collect; collect = function(query, results) { var f, fso, l, obj, _results; if (results.expects('TEXT')) { fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.OpenTextFile("plugins\\snippets\\text.txt"); _results = []; while (!f.AtEndOfStream) { l = f.ReadLine(); if (qatapult.match(l, query)) { obj = { key: l, text: l, icon: "plugins\\snippets\\text.jpg" }; _results.push(results.addObject('TEXT', l, obj)); } else { _results.push(void 0); } } return _results; } }; }).call(this);
I think removing the first and last lines may make the result usable by Qatapult.
ewemoa:
I tried a rough rewrite (non-idiomatic CoffeeScript) of OpenWith.collecter.js. Removing the debugging related stuff, it looks like:
--- Code: Text ---collect = (query, results) -> # for OpenTextFile ForReading = 1 ForWriting = 2 ForAppending = 8 # http://coffeescriptcookbook.com/chapters/classes_and_objects/type-function type = (obj) -> if obj == undefined or obj == null return String obj classToType = new Object for name in "Boolean Number String Function Array Date RegExp".split(" ") classToType["[object " + name + "]"] = name.toLowerCase() myClass = Object.prototype.toString.call obj if myClass of classToType return classToType[myClass] return "object" # file extension from file path pathToExtension = (filePath) -> extRE = /\.([^\\.]*)$/ ma = extRE.exec(filePath) if not ma return null ma[1] # if not results.expects('FILE') return # pane = qatapult.getFocus() if pane != 2 return # fso = new ActiveXObject("Scripting.FileSystemObject") # p0 = qatapult.getArgValue(0, "path") ext = pathToExtension(p0) if not ext ext = 'NONE' # table = {} try rf = fso.OpenTextFile("plugins\\OpenWith\\associations.js") text = rf.ReadAll() result = eval(text) catch e # finally rf.close() # if fso.FolderExists(p0) if "_folderhandler" of table ext = "_folderhandler" if ext of table rule = table[ext] theType = type(rule) switch theType when "string" path = rule obj = key: path text: path path: path results.addObject('FILE', path, obj) when "array" for path in rule obj = key: path text: path path: path results.addObject('FILE', path, obj)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version