From 4e9d870945d67503a3397b000a55e045b8dd0506 Mon Sep 17 00:00:00 2001 From: Green Luo Date: Sun, 7 Apr 2013 09:13:01 +1000 Subject: [PATCH 01/39] add shortcuts to editor UI --- angular-seed/app/js/app.js | 0 angular-seed/app/js/controllers.js | 11 +++++++++-- angular-seed/app/partials/editor.html | 6 +++++- angular-seed/app/partials/save_dialog.html | 2 +- public/libs/codemirror/3.1/lib/codemirror.js | 0 5 files changed, 15 insertions(+), 4 deletions(-) mode change 100644 => 100755 angular-seed/app/js/app.js mode change 100644 => 100755 public/libs/codemirror/3.1/lib/codemirror.js diff --git a/angular-seed/app/js/app.js b/angular-seed/app/js/app.js old mode 100644 new mode 100755 diff --git a/angular-seed/app/js/controllers.js b/angular-seed/app/js/controllers.js index 2f7f977..6617a02 100755 --- a/angular-seed/app/js/controllers.js +++ b/angular-seed/app/js/controllers.js @@ -69,6 +69,12 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { var keyCode = $event.keyCode; if (keyCode === 10 || keyCode == 13 && $event.ctrlKey) { run(); + } else if (keyCode == 84 && $event.ctrlKey && $event.altKey) { + $('.source textarea').focus(); + } else if (keyCode == 80 && $event.ctrlKey && $event.altKey) { + $('.params textarea').focus(); + } else { + //console.log(keyCode); } } @@ -262,9 +268,10 @@ function SaveDialogCtrl($scope, dialog, code, $http, saveAsNew) { } $http.post('/api/Application/save', code).success(function (code) { dialog.close(code); + //TODO: $scope.run(); }).error(function (data) { - alert(data); - }); + alert(data); + }); } } diff --git a/angular-seed/app/partials/editor.html b/angular-seed/app/partials/editor.html index 3a7ef03..88c0302 100755 --- a/angular-seed/app/partials/editor.html +++ b/angular-seed/app/partials/editor.html @@ -96,9 +96,10 @@
-
@@ -134,6 +135,9 @@ h2 = $('.params .CodeMirror').height(); $('#RESULT_PANEL pre.result').css({'height': (h1 - h2 - 27) + 'px', 'overflow-y':'auto'}); }, 300); + CodeMirror.commands.save = function(cm){ + $('button[ng-click="save()"]').click(); + } diff --git a/angular-seed/app/partials/save_dialog.html b/angular-seed/app/partials/save_dialog.html index 1ce5b18..8547b97 100755 --- a/angular-seed/app/partials/save_dialog.html +++ b/angular-seed/app/partials/save_dialog.html @@ -4,7 +4,7 @@
- +
diff --git a/public/libs/codemirror/3.1/lib/codemirror.js b/public/libs/codemirror/3.1/lib/codemirror.js old mode 100644 new mode 100755 From e3eb9a837bc05aba7e9f62df0f4853d823f6603e Mon Sep 17 00:00:00 2001 From: Green Luo Date: Sun, 7 Apr 2013 10:28:00 +1000 Subject: [PATCH 02/39] F2 to rename current source;escape to cancel rename or add new source --- angular-seed/app/js/controllers.js | 48 ++++++++++++++++++++------- angular-seed/app/partials/editor.html | 15 ++++++--- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/angular-seed/app/js/controllers.js b/angular-seed/app/js/controllers.js index 6617a02..99492fe 100755 --- a/angular-seed/app/js/controllers.js +++ b/angular-seed/app/js/controllers.js @@ -59,22 +59,40 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { $scope.switchFile = switchFile; $scope.removeFile = removeFile; $scope.setMain = setMain; - $scope.editFileName = editFileName; - $scope.cancelEditFileName = cancelEditFileName; + $scope.renameFile = renameFile; + $scope.cancelRenameFile = cancelRenameFile; $scope.getActiveFile = getActiveFile; $scope.getMainFile = getMainFile; $scope.keyEventHandlerForCodeMirror = keyEventHandlerForCodeMirror; + $scope.ta = { + $source: function() {return $('.source textarea');}, + $params: function() {return $('.params textarea');} + }; + $scope.$focus = false; + $scope.storeCurFocus = function(){ + $scope.$focus = $scope.ta.$source; + var $p = $scope.ta.$params(); + if ($p.is(":focus")) { + $scope.$focus = $scope.ta.$params; + } + }; + $scope.restoreFocus = function() { + if ($scope.$focus) { + $scope.$focus().focus(); + } + else alert("no focus"); + } function keyEventHandlerForCodeMirror($event) { var keyCode = $event.keyCode; if (keyCode === 10 || keyCode == 13 && $event.ctrlKey) { run(); - } else if (keyCode == 84 && $event.ctrlKey && $event.altKey) { - $('.source textarea').focus(); - } else if (keyCode == 80 && $event.ctrlKey && $event.altKey) { - $('.params textarea').focus(); - } else { - //console.log(keyCode); + } else if (keyCode == 84 && $event.ctrlKey && $event.altKey) /*ctrl-al-t*/ { + var $t = $scope.ta.$source(), $p = $scope.ta.$params(); + if ($t.is(':focus')) $p.focus(); + else $t.focus(); + } else if (keyCode == 113 /*F2*/) { + renameFile(); } } @@ -114,6 +132,7 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { } function setMain(file) { + if (!file) file = getActiveFile(); _.each($scope.currentCode.files, function (file) { file.isMain = false; }); @@ -128,6 +147,7 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { } function removeFile(file, noAlert) { + if (!file) file = getActiveFile(); if ($scope.currentCode.files.length > 1) { if (noAlert || confirm('Delete this template?')) { $scope.currentCode.files = _.without($scope.currentCode.files, file); @@ -164,18 +184,22 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { } } - function editFileName(file) { + function renameFile(file) { + $scope.storeCurFocus(); + if (!file) file = getActiveFile(); file.editName = file.filename; file.editing = !file.editing; } - function cancelEditFileName(file) { + function cancelRenameFile(file) { + if (!file) file = getActiveFile(); if (!file.filename) { removeFile(file, true); return; } file.editName = null; file.editing = false; + setTimeout(function(){$scope.restoreFocus();}, 1); } function removeCurrentCode() { @@ -215,7 +239,7 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { } function run() { - if ($scope.currentCode.files.length > 0) { + if ($scope.currentCode.files.length > 0) { if ($scope.running) return; $scope.running = true; $scope.resultPageActive = true; @@ -252,7 +276,6 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { newOne.isMain = true; } } - } EditorCtrl.$inject = ['$scope', '$http', '$routeParams', '$dialog', '$location', '$timeout']; @@ -273,6 +296,7 @@ function SaveDialogCtrl($scope, dialog, code, $http, saveAsNew) { alert(data); }); } + } SaveDialogCtrl.$inject = ['$scope', 'dialog', 'code', '$http', 'saveAsNew']; diff --git a/angular-seed/app/partials/editor.html b/angular-seed/app/partials/editor.html index 88c0302..fa290eb 100755 --- a/angular-seed/app/partials/editor.html +++ b/angular-seed/app/partials/editor.html @@ -61,13 +61,13 @@ - + - + - @@ -80,11 +80,11 @@
- + - + @@ -138,6 +138,11 @@ CodeMirror.commands.save = function(cm){ $('button[ng-click="save()"]').click(); } + $(window).on('keydown', function(event) { + if (event.which == 113) { // F2 + $('.btn[ng-click="renameFile()"]').click(); + } + }); From fd96c0cb5585c9d89f29c45fdeafc32552caba02 Mon Sep 17 00:00:00 2001 From: Green Luo Date: Sun, 7 Apr 2013 10:45:17 +1000 Subject: [PATCH 03/39] Add shortcut information to about dialog --- angular-seed/app/js/controllers.js | 6 +++--- angular-seed/app/partials/about.html | 13 +++++++++++-- angular-seed/app/partials/editor.html | 12 ++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/angular-seed/app/js/controllers.js b/angular-seed/app/js/controllers.js index 99492fe..46f1ca5 100755 --- a/angular-seed/app/js/controllers.js +++ b/angular-seed/app/js/controllers.js @@ -88,9 +88,9 @@ function EditorCtrl($scope, $http, $routeParams, $dialog, $location, $timeout) { if (keyCode === 10 || keyCode == 13 && $event.ctrlKey) { run(); } else if (keyCode == 84 && $event.ctrlKey && $event.altKey) /*ctrl-al-t*/ { - var $t = $scope.ta.$source(), $p = $scope.ta.$params(); - if ($t.is(':focus')) $p.focus(); - else $t.focus(); +// var $t = $scope.ta.$source(), $p = $scope.ta.$params(); +// if ($t.is(':focus')) $p.focus(); +// else $t.focus(); } else if (keyCode == 113 /*F2*/) { renameFile(); } diff --git a/angular-seed/app/partials/about.html b/angular-seed/app/partials/about.html index cd21fce..0d051db 100755 --- a/angular-seed/app/partials/about.html +++ b/angular-seed/app/partials/about.html @@ -3,12 +3,21 @@

Rythm Fiddle