Permalink
Browse files

make keybinds configurable through config file

  • Loading branch information...
1 parent 7ced7d0 commit 2d751975dec7b0bfaabcfdfd338feffe0c05e453 @Dieterbe committed Dec 26, 2013
Showing with 45 additions and 31 deletions.
  1. +1 −1 README.md
  2. +18 −0 config_example/binds
  3. +18 −2 js/controllers.js
  4. +0 −11 js/directives.js
  5. +7 −0 js/services.js
  6. +0 −17 partials/photos.html
  7. +1 −0 pixie.go
View
@@ -67,7 +67,7 @@ cd ~/go/src/github.com/Dieterbe/pixie
* update `~/.pixie/config.ini` to point to the db and thumbnail directories, and to use your preferred image editor for edits (optional).
Note that on Linux you probably already have a thumbnails dir from
various desktop apps, it's best to use the existing one, that way multiple apps (incl pixie) can work with the same thumbnails.
-* configure keyboard shortcuts in partials/photos.html
+* configure keyboard shortcuts in `~/.pixie/binds`. Basically you'll want to add tag/untag pairs for the tags you will use. Make sure this file stays valid json because there's no validation yet.
* type `go run pixie.go`
* load `http://localhost:8080` in browser
* Enter a directory (full path) that contains pictures. You can now start navigating and tagging as per your keybinds.
View
@@ -0,0 +1,18 @@
+{
+ "h": "moveLeft()",
+ "j": "moveDown()",
+ "k": "moveUp()",
+ "l": "moveRight()",
+ "g g": "moveHome()",
+ "G": "moveEnd()",
+
+ "o": "openRecord()",
+ "e": "newEdit()",
+
+ "a": "tag('album-fb')",
+ "d a": "unTag('album-fb')",
+ "t": "tag('test')",
+ "d t": "unTag('test')",
+
+ "T": "autotag('test')"
+}
View
@@ -4,8 +4,24 @@
var photosControllers = angular.module('photosControllers', []);
-photosControllers.controller('PhotosCtrl', ['$scope', '$routeParams', 'Photos', 'Photo', 'Edit', '$timeout',
- function($scope, $routeParams, Photos, Photo, Edit, $timeout) {
+photosControllers.controller('PhotosCtrl', ['$scope', '$routeParams', 'Binds', 'Photos', 'Photo', 'Edit', '$timeout',
+ function($scope, $routeParams, Binds, Photos, Photo, Edit, $timeout) {
+ Binds.list(
+ function(response) {
+ // TODO: json validation!
+ //console.debug(response);
+ $.map(response, function (v, k) {
+ // ignore object built-ins, we only want the actual json key-values
+ if (typeof(v) == "string") {
+ // later we may want to do this properly will apply() or smth
+ Mousetrap.bind(k, function (){ eval("$scope." + v); });
+ }
+ });
+ $scope.logs.push({msg: "keybinds loaded", type: 'info'});
+ }, function(response) {
+ console.debug(response);
+ $scope.logs.push({msg: "could not load keybinds", type: 'error'});
+ });
// routeParams.dir
$scope.focusIndex = 0; // determines position top-bottom
View
@@ -2,17 +2,6 @@
angular.module('directives', []).
-directive('keybinding', function () {
- return {
- restrict: 'E',
- scope: {
- invoke: '&'
- },
- link: function (scope, el, attr) {
- Mousetrap.bind(attr.on, scope.invoke);
- }
- };
-}).
// http://stackoverflow.com/questions/12790854/angular-directive-to-scroll-to-a-given-item
directive('scrollIf', function () {
console.log("scroll top level");
View
@@ -2,6 +2,13 @@
var photosServices = angular.module('photosServices', ['ngResource']);
+photosServices.factory('Binds', ['$resource',
+ function($resource){
+ return $resource('/api/config/binds', {}, {
+ list: { method:'GET', isArray: false}}
+ );
+ }
+]);
photosServices.factory('Photos', ['$resource',
function($resource){
return $resource('/api/photos/:directory', {}, {
View
@@ -4,23 +4,6 @@
<div class="row-fluid">
<div class="span12">
- <keybinding on="j" invoke="moveDown()" />
- <keybinding on="k" invoke="moveUp()" />
- <keybinding on="l" invoke="moveRight()" />
- <keybinding on="h" invoke="moveLeft()" />
- <keybinding on="g g" invoke="moveHome()" />
- <keybinding on="G" invoke="moveEnd()" />
-
- <keybinding on="o" invoke="openRecord()" />
- <keybinding on="e" invoke="newEdit()" />
-
- <keybinding on="a" invoke="tag('album-fb')" />
- <keybinding on="d a" invoke="unTag('album-fb')" />
- <keybinding on="t" invoke="tag('test')" />
- <keybinding on="d t" invoke="unTag('test')" />
-
- <keybinding on="T" invoke="autotag('test')" />
-
<div class="jumbotron">
<h1>Pixie</h1>
<form class="bs-example form-horizontal" ng-submit="setDirectory()">
View
@@ -343,6 +343,7 @@ func main() {
http.HandleFunc("/api/edit", func(w http.ResponseWriter, r *http.Request) {
api_edit_handler(w, r, conn_sqlite)
})
+ http.Handle("/api/config/binds", http.StripPrefix("/api/config", http.FileServer(http.Dir(Expand("~/.pixie")))))
http.Handle("/thumbnails/", http.StripPrefix("/thumbnails", serveThumb()))
http.Handle("/", http.FileServer(http.Dir(".")))

0 comments on commit 2d75197

Please sign in to comment.