Sfoglia il codice sorgente

keyboard controls completed

Michael 10 anni fa
parent
commit
722e513f62

+ 33 - 0
src/allplatforms/classes/DocumentMenu.js

@@ -97,6 +97,39 @@ SC.loadPackage({ 'DocumentMenu': {
                     document.body.removeChild(myNode);
                 }
 
+            }
+        },
+
+
+        callMenuItemAction: {
+            comment: 'I call a menuItem object\'s action',
+            code: function(config){
+
+                var menuItem = (function(){
+
+                                    var menuItemsTop  = this.get('menuItemsTop'),
+                                        menuItemsLeft = this.get('menuItemsLeft');
+
+                                    for(var i = 0, l = menuItemsTop.length; i < l; i++){
+                                        if(menuItemsTop[i].class() === config.menuItem){
+                                            return menuItemsTop[i];
+                                        }
+                                    }
+
+                                    for(var i = 0, l = menuItemsLeft.length; i < l; i++){
+                                        if(menuItemsLeft[i].class() === config.menuItem){
+                                            return menuItemsLeft[i];
+                                        }
+                                    }
+
+                                }).call(this);
+
+                if(!menuItem){
+                    return;
+                }
+
+                menuItem.do('action', config.modifier)
+                
             }
         }
 

+ 162 - 9
src/allplatforms/classes/Keyboard.js

@@ -14,10 +14,14 @@ SC.loadPackage({ 'Keyboard': {
             comment:    'method comment',
             code:       function(){
 
-                var self = this;
+                var self = this,
+                    spaceBarDown = false;
 
 
                 document.addEventListener('keydown', function(evt){
+                    if(evt.target.tagName === 'INPUT' || evt.target.tagName === 'TEXTAREA' ){
+                        return;
+                    }
                     self.do('processKeyEvent', evt);
                 }, false);
 
@@ -28,18 +32,50 @@ SC.loadPackage({ 'Keyboard': {
                 this.set({ helperOverlay: helperOverlay })
 
                 document.addEventListener('keydown', function(evt){
+
+                    if(evt.target.tagName === 'INPUT' || evt.target.tagName === 'TEXTAREA' ){
+                        return;
+                    }
+
                     if(evt.keyCode === 72){
+
                         var helperOverlay = self.get('helperOverlay');
                         helperOverlay.style.width  = window.innerWidth + 'px';
                         helperOverlay.style.height = window.innerHeight + 'px';
                         document.body.appendChild(helperOverlay);
+
+                    } else if(evt.keyCode === 32){
+
+                        if(spaceBarDown === false){
+                            var myDocument = SuperGlue.get('document');
+                            myDocument.set({ showOutlines: !myDocument.get('showOutlines') });
+                            spaceBarDown = true;
+                        }
+
                     }
+
                 }, false);
 
                 document.addEventListener('keyup', function(evt){
+
+                    if(evt.target.tagName === 'INPUT' || evt.target.tagName === 'TEXTAREA' ){
+                        return;
+                    }
+
                     if(evt.keyCode === 72){
+
                         document.body.removeChild(self.get('helperOverlay'));
+
+                    } else if(evt.keyCode === 32){
+
+                        if(spaceBarDown === true){
+                            var myDocument = SuperGlue.get('document');
+                            myDocument.set({ showOutlines: !myDocument.get('showOutlines') });
+                            spaceBarDown = false;
+                        }
+
                     }
+
                 }, false);
 
 
@@ -51,8 +87,7 @@ SC.loadPackage({ 'Keyboard': {
             comment: 'I process key events.',
             code: function(evt){
 
-                var self      = this,
-                    relevant  = true;
+                var relevant  = true;
 
                 if(evt.ctrlKey){
 
@@ -81,6 +116,8 @@ SC.loadPackage({ 'Keyboard': {
 
                         case 65:
                             // Ctrl+A
+
+                            this.do('selectAll');
                             
                             break;
 
@@ -102,24 +139,70 @@ SC.loadPackage({ 'Keyboard': {
 
                             break;
 
+                        case 73:
+                            // Ctrl+I
+                            
+                            SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                menuItem: 'MenuItemNewPage'
+                            });
+
+                            break;
+
+                        case 79:
+                            // Ctrl+O
+                            
+                            SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                menuItem: 'MenuItemFileManager'
+                            });
+
+                            break;
+
                         case 83:
                             // Ctrl+S
-                                alert('ja SSSSS')
+                            
+                            if(evt.shiftKey){
+                                SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                    menuItem: 'MenuItemSaveAs'
+                                });
+                            }else{
+                                SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                    menuItem: 'MenuItemSave'
+                                });
+                            }
+
                             break;
 
                         case 86:
                             // Ctrl+V
-                                
+                            
+                            SuperGlue.get('selection').do('clearAll');
+
+                            SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                menuItem: 'MenuItemPaste'
+                            });
+
                             break;
 
                         case 89:
                             // Ctrl+Y
+
+                            SuperGlue.get('selection').do('clearAll');
                             
+                            SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                menuItem: 'MenuItemRedo'
+                            });
+
                             break;
 
                         case 90:
                             // Ctrl+Z
+
+                            SuperGlue.get('selection').do('clearAll');
                             
+                            SuperGlue.get('document').get('documentMenu').do('callMenuItemAction', { 
+                                menuItem: 'MenuItemUndo'
+                            });
+
                             break;
 
                         default:
@@ -141,28 +224,32 @@ SC.loadPackage({ 'Keyboard': {
                             
                             break;
 
-                        case 32:
-                            // Space
-                            
-                            break;
 
                         case 37:
                             // ArrowLeft
+
+                            this.do('moveSelection', 'left');
                             
                             break;
 
                         case 38:
                             // ArrowUp
+
+                            this.do('moveSelection', 'up');
                             
                             break;
 
                         case 39:
                             // ArrowRight
+
+                            this.do('moveSelection', 'right');
                             
                             break;
 
                         case 40:
                             // ArrowDown
+
+                            this.do('moveSelection', 'down');
                             
                             break;
 
@@ -181,9 +268,75 @@ SC.loadPackage({ 'Keyboard': {
                 }
 
 
+            }
+        },
+
+
+        selectAll: {
+            comment: 'I select all (Ctrl+A)',
+            code: function(){
+
+                for(var selection   = SuperGlue.get('selection'),
+                        allElements = SuperGlue.get('document').get('children'),
+                        i = 0, l = allElements.length;
+                        i < l; i++){
+
+                    selection.do('addElement', allElements[i]);
+
+                }
+
+            }
+        },
+
+
+        moveSelection: {
+            comment: 'I move the selected elements on arrow key strokes in the given direction.',
+            code: function(direction){
+
+                var elements = SuperGlue.get('selection').get('elements'),
+                    stepSize = SuperGlue.get('document').get('grid').get('active') 
+                                ? SuperGlue.get('document').get('grid').get('gridSize') 
+                                : 1,
+                    layout   = SuperGlue.get('document').get('layout');
+
+
+                for(var i = 0, l = elements.length; i < l; i++){
+
+                    switch(direction){
+
+                        case 'up':
+                            elements[i].set({ top: (elements[i].get('top') - stepSize) });
+                            break;
+
+                        case 'down':
+                            elements[i].set({ top: (elements[i].get('top') + stepSize) });
+                            break;
+
+                        case 'left':
+                            elements[i].set({ left: (elements[i].get('left') - stepSize) });
+                            break;
+
+                        case 'right':
+                            if(layout.centered){
+                                if(layout.width >= elements[i].get('left') + elements[i].get('width') + stepSize){
+                                    elements[i].set({ left: (elements[i].get('left') + stepSize) });
+                                }
+                            }else{
+                                elements[i].set({ left: (elements[i].get('left') + stepSize) });
+                            }
+                            break;
+
+                    }
+
+                }
+
+                SuperGlue.get('selection').do('updateDimensions');
+                
             }
         }
 
+
+
     }
 
 

+ 13 - 5
src/allplatforms/classes/MenuItemFileManager.js

@@ -16,21 +16,29 @@ SC.loadPackage({ 'MenuItemFileManager': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
                 this.set({ isActionButton: true });
                 
                 this.get('menuContainer').firstChild.addEventListener('mouseup', function(evt){
-
-                    SuperGlue.get('fileManager').do('open')
-
+                    self.do('action');
                     theDocumentMenu.do('close');
-
                 }, false);
 
 
     		}
 
-    	}
+    	}, 
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                SuperGlue.get('fileManager').do('open');
+
+            }
+        }
 
 
     }

+ 13 - 5
src/allplatforms/classes/MenuItemNewPage.js

@@ -16,21 +16,29 @@ SC.loadPackage({ 'MenuItemNewPage': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
                 this.set({ isActionButton: true });
                 
                 this.get('menuContainer').firstChild.addEventListener('mouseup', function(evt){
-
-                    SuperGlue.get('fileManager').do('newPage')
-
+                    self.do('action');
                     theDocumentMenu.do('close');
-
                 }, false);
 
 
     		}
 
-    	}
+    	}, 
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                SuperGlue.get('fileManager').do('newPage');
+
+            }
+        }
 
 
     }

+ 17 - 9
src/allplatforms/classes/MenuItemPaste.js

@@ -23,8 +23,22 @@ SC.loadPackage({ 'MenuItemPaste': {
                 var self = this;
                 
                 this.get('menuButton').addEventListener('mouseup', function(){
+                    self.do('action');
+                    theDocumentMenu.do('close');
+                }, false)
+
+    		}
+
+    	}, 
+
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                var self = this;
 
-                    SuperGlue.get('clipboard').do('paste', function(pasteData){
+                SuperGlue.get('clipboard').do('paste', function(pasteData){
 
                         SuperGlue.get('history').do('actionHasStarted', self.do('createState'));
 
@@ -40,17 +54,11 @@ SC.loadPackage({ 'MenuItemPaste': {
 
                         SuperGlue.get('history').do('actionHasSucceeded', self.do('createState'));
 
-                        self.set({ isMenuItemActive: false });
-                        theDocumentMenu.do('close');
-
-
                     });
 
-                }, false)
-
-    		}
+            }
+        },
 
-    	},
 
         pasteSGElement: {
             comment: 'I paste a SuperGlue Element.', 

+ 13 - 2
src/allplatforms/classes/MenuItemRedo.js

@@ -16,17 +16,28 @@ SC.loadPackage({ 'MenuItemRedo': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
                 this.set({ isActionButton: true });
 
                 this.get('menuButton').addEventListener('mouseup', function(){
-                    SuperGlue.get('history').do('redo');
+                    self.do('action');
                 }, false);
 
 
     		}
 
-    	}
+    	}, 
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                SuperGlue.get('history').do('redo');
+
+            }
+        }
 
 
     }

+ 15 - 7
src/allplatforms/classes/MenuItemSave.js

@@ -16,23 +16,31 @@ SC.loadPackage({ 'MenuItemSave': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
                 this.set({ isActionButton: true });
 
                 this.get('menuContainer').firstChild.addEventListener('mouseup', function(evt){
-
-                    SuperGlue.do('savePage', {
-                        path: document.location.pathname
-                    });
-
+                    self.do('action');
                     theDocumentMenu.do('close');
-
                 }, false);
 
 
     		}
 
-    	}
+    	}, 
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                SuperGlue.do('savePage', {
+                        path: document.location.pathname
+                    });
+
+            }
+        }
 
 
     }

+ 17 - 11
src/allplatforms/classes/MenuItemSaveAs.js

@@ -16,28 +16,34 @@ SC.loadPackage({ 'MenuItemSaveAs': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
 
                 this.get('menuContainer').firstChild.addEventListener('mouseup', function(evt){
-
+                    self.do('action');
                     theDocumentMenu.do('close');
-                    
-                    SuperGlue.get('fileManager').do('saveAs', function(filePath){
+                }, false);
 
-                        SuperGlue.do('savePage', {
-                            path: filePath
-                        })
 
-                    });
+    		}
 
-                    
+    	}, 
 
-                }, false);
+        action: {
+            comment: 'I do the job.',
+            code: function(){
 
+                SuperGlue.get('fileManager').do('saveAs', function(filePath){
 
-    		}
+                        SuperGlue.do('savePage', {
+                            path: filePath
+                        })
+
+                    });
 
-    	}
+            }
+        }
 
 
     }

+ 13 - 2
src/allplatforms/classes/MenuItemUndo.js

@@ -16,16 +16,27 @@ SC.loadPackage({ 'MenuItemUndo': {
     		comment: 	'I init the MenuItem.',
     		code: 		function(theDocumentMenu){
 
+                var self = this;
+
                 this.delegate('MenuItem', 'init', theDocumentMenu);
                 this.set({ isActionButton: true });
 
                 this.get('menuButton').addEventListener('mouseup', function(){
-                    SuperGlue.get('history').do('undo');
+                    self.do('action');
                 }, false);
 
     		}
 
-    	}
+    	}, 
+
+        action: {
+            comment: 'I do the job.',
+            code: function(){
+
+                SuperGlue.get('history').do('undo');
+
+            }
+        }
 
 
     }