Changeset 660

Show
Ignore:
Timestamp:
02/11/08 06:33:40 (10 months ago)
Author:
ma..@jesperkristensen.dk
Message:

Move script reordering from manage.js to config.js

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/config-service/src/chrome/chromeFiles/content/config.js

    r659 r660  
    272272} 
    273273 
     274/** 
     275 * Moves an installed user script to a new position in the array of installed scripts. 
     276 * 
     277 * @param script The script to be moved. 
     278 * @param destination Can be either (a) a numeric offset for the script to be 
     279 *                    moved or (b) another installet script to which position 
     280 *                    the script will be moved. 
     281 */ 
     282Config.prototype.move = function(script, destination) 
     283{ 
     284  var from = this.scripts.indexOf(script); 
     285  var to = -1; 
     286 
     287  // Make sure the user script is installed 
     288  if (from == -1) 
     289    return null; 
     290 
     291  if (typeof destination == 'number') { // if destination is an offset 
     292    to = from + destination; 
     293    to = Math.max(0, to); 
     294    to = Math.min(this.scripts.length - 1, to); 
     295  } else { // if destination is a script object 
     296    to = this.scripts.indexOf(destination); 
     297  } 
     298 
     299  if (to == -1) 
     300    return null; 
     301 
     302  var tmp = this.scripts.splice(from, 1)[0]; 
     303  this.scripts.splice(to, 0, tmp); 
     304 
     305  return {from: from, to: to}; 
     306}; 
     307 
    274308Config.prototype.__defineGetter__("scriptDir", function() { 
    275309  var newDir = this.newScriptDir; 
  • branches/config-service/src/chrome/chromeFiles/content/manage.js

    r656 r660  
    133133 
    134134function reorderScript(from, to) { 
    135   // make sure to and from are in range 
    136   if (from < 0 || to < 0 || 
    137     from > config.scripts.length || to > config.scripts.length 
    138   ) { 
    139     return false; 
    140   } 
    141  
    142   // REORDER CONFIG: 
    143   // save item-to-move 
    144   var tmp = config.scripts[from]; 
    145   // remove it 
    146   config.scripts.splice(from, 1); 
    147   // put it back in the new spot 
    148   config.scripts.splice(to, 0, tmp); 
    149  
    150135  // REORDER DISPLAY: 
    151136  var tmp = listbox.childNodes[from]; 
     
    159144  // then re-select the dropped script 
    160145  listbox.selectedIndex = to; 
    161  
    162   return true; 
    163146}; 
    164147 
     
    170153  var index = listbox.selectedIndex; 
    171154 
    172   if (KeyEvent.DOM_VK_UP == event.keyCode) { 
    173     if (0 == index) return; 
    174  
    175     !reorderScript(index, index - 1); 
    176     listbox.selectedIndex = index - 1; 
    177   } else if (KeyEvent.DOM_VK_DOWN == event.keyCode) { 
    178     if (index == config.scripts.length - 1) return; 
    179  
    180     !reorderScript(index, index + 1); 
    181     listbox.selectedIndex = index + 1; 
    182   } 
     155  var move = null; 
     156  if (KeyEvent.DOM_VK_UP == event.keyCode) 
     157    move = config.move(listbox.selectedItem.script, -1); 
     158  else if (KeyEvent.DOM_VK_DOWN == event.keyCode) 
     159    move = config.move(listbox.selectedItem.script, 1); 
     160 
     161  if (move) 
     162    reorderScript(move.from, move.to); 
    183163}; 
    184164 
     
    223203 
    224204    // do the move 
    225     reorderScript(index, newIndex); 
     205    var move = config.move(config.scripts[index], config.scripts[newIndex]); 
     206    if (move) 
     207      reorderScript(move.from, move.to); 
    226208  }, 
    227209