Added 'Go to line' functionality

This commit is contained in:
Tom Needham 2012-01-09 21:16:41 +00:00
parent 6c78cd2765
commit 27d9cbd8c0
2 changed files with 28 additions and 10 deletions

View File

@ -12,11 +12,6 @@
left: 160px; left: 160px;
display: none; display: none;
} }
#editor_close{
margin-left: auto;
margin-right: 170px;
display: block;
}
#editor_save{ #editor_save{
margin-left: 7px; margin-left: 7px;
float: left; float: left;
@ -25,3 +20,6 @@
margin-top: 3px; margin-top: 3px;
float: left; float: left;
} }
#gotolineval{
width: 30px;
}

View File

@ -60,26 +60,36 @@ function showControls(filename,writeperms){
// Load the new toolbar. // Load the new toolbar.
var savebtnhtml; var savebtnhtml;
if(writeperms=="true"){ if(writeperms=="true"){
var savebtnhtml = '<button id="editor_save">'+t('files_texteditor','Save')+'</button>'; var editorcontrols = '<button id="editor_save">'+t('files_texteditor','Save')+'</button><div class="separator"></div><button id="gotolinebtn">Go to line:</button><input type="text" id="gotolineval">';
} }
var html = '<button id="editor_close">X</button>'; var html = '<button id="editor_close">X</button>';
$('#controls').append(html); $('#controls').append(html);
$('#editorbar').fadeIn('slow'); $('#editorbar').fadeIn('slow');
var breadcrumbhtml = '<div class="crumb svg" id="breadcrumb_file" style="background-image:url(&quot;../core/img/breadcrumb.png&quot;)"><p>'+filename+'</p></div>'; var breadcrumbhtml = '<div class="crumb svg" id="breadcrumb_file" style="background-image:url(&quot;../core/img/breadcrumb.png&quot;)"><p>'+filename+'</p></div>';
$('.actions').before(breadcrumbhtml).before(savebtnhtml); $('.actions').before(breadcrumbhtml).before(editorcontrols);
}); });
} }
function bindControlEvents(){ function bindControlEvents(){
$("#editor_save").die('click',doFileSave).live('click',doFileSave); $("#editor_save").die('click',doFileSave).live('click',doFileSave);
$('#editor_close').die('click',hideFileEditor).live('click',hideFileEditor); $('#editor_close').die('click',hideFileEditor).live('click',hideFileEditor);
$('#gotolinebtn').die('click', goToLine).live('click', goToLine);
} }
// returns true or false if the editor is in view or not
function editorIsShown(){ function editorIsShown(){
// Not working as intended. Always returns true. // Not working as intended. Always returns true.
return is_editor_shown; return is_editor_shown;
} }
// Moves the editor view to the line number speificed in #gotolineval
function goToLine(){
// Go to the line specified
window.aceEditor.gotoLine($('#gotolineval').val());
}
// Tries to save the file.
function doFileSave(){ function doFileSave(){
if(editorIsShown()){ if(editorIsShown()){
// Get file path // Get file path
@ -110,10 +120,12 @@ function doFileSave(){
} }
}; };
// Gives the editor focus
function giveEditorFocus(){ function giveEditorFocus(){
window.aceEditor.focus(); window.aceEditor.focus();
}; };
// Loads the file editor. Accepts two parameters, dir and filename.
function showFileEditor(dir,filename){ function showFileEditor(dir,filename){
if(!editorIsShown()){ if(!editorIsShown()){
// Loads the file editor and display it. // Loads the file editor and display it.
@ -154,11 +166,17 @@ function showFileEditor(dir,filename){
} }
} }
// Fades out the editor.
function hideFileEditor(){ function hideFileEditor(){
// Fade out controls // Fade out controls
$('#editor_close').fadeOut('slow'); $('#editor_close').fadeOut('slow');
// Fade out the save button // Fade out the save button
$('#editor_save').fadeOut('slow'); $('#editor_save').fadeOut('slow');
// Goto line items
$('#gotolinebtn').fadeOut('slow');
$('#gotolineval').fadeOut('slow');
// Fade out separators
$('.separator').fadeOut('slow');
// Fade out breadcrumb // Fade out breadcrumb
$('#breadcrumb_file').fadeOut('slow', function(){ $(this).remove();}); $('#breadcrumb_file').fadeOut('slow', function(){ $(this).remove();});
// Fade out editor // Fade out editor
@ -177,6 +195,7 @@ function hideFileEditor(){
// Keyboard Shortcuts // Keyboard Shortcuts
var ctrlBtn = false; var ctrlBtn = false;
// returns true if ctrl+s or cmd+s is being pressed
function checkForSaveKeyPress(e){ function checkForSaveKeyPress(e){
if(e.which == 17 || e.which == 91) ctrlBtn=true; if(e.which == 17 || e.which == 91) ctrlBtn=true;
if(e.which == 83 && ctrlBtn == true) { if(e.which == 83 && ctrlBtn == true) {
@ -187,6 +206,7 @@ function checkForSaveKeyPress(e){
} }
} }
// resizes the editor window
$(window).resize(function() { $(window).resize(function() {
setEditorSize(); setEditorSize();
}); });
@ -213,7 +233,7 @@ $(document).ready(function(){
showFileEditor(dir,file); showFileEditor(dir,file);
}); });
} }
// Binds the file save and close editor events // Binds the file save and close editor events, and gotoline button
bindControlEvents(); bindControlEvents();
// Binds the save keyboard shortcut events // Binds the save keyboard shortcut events