diff --git a/components/active/class.active.php b/components/active/class.active.php index badf1c1..5b1237f 100644 --- a/components/active/class.active.php +++ b/components/active/class.active.php @@ -130,6 +130,20 @@ class Active extends Common { echo formatJSEND("success"); } + ////////////////////////////////////////////////////////////////// + // Remove All Files + ////////////////////////////////////////////////////////////////// + + public function RemoveAll(){ + foreach($this->actives as $active=>$data){ + if(is_array($data) && isset($data['username']) && $this->username==$data['username']){ + unset($this->actives[$active]); + } + } + saveJSON('active.php',$this->actives); + echo formatJSEND("success"); + } + ////////////////////////////////////////////////////////////////// // Mark File As Focused // All other files will be marked as non-focused. diff --git a/components/active/controller.php b/components/active/controller.php index 27f03fb..8adcef5 100755 --- a/components/active/controller.php +++ b/components/active/controller.php @@ -67,6 +67,15 @@ $Active->Remove(); } + ////////////////////////////////////////////////////////////////// + // Remove all active record + ////////////////////////////////////////////////////////////////// + + if($_GET['action']=='removeall'){ + $Active->username = $_SESSION['user']; + $Active->RemoveAll(); + } + ////////////////////////////////////////////////////////////////// // Mark file as focused ////////////////////////////////////////////////////////////////// diff --git a/components/active/init.js b/components/active/init.js index 71ca1dc..3540f17 100755 --- a/components/active/init.js +++ b/components/active/init.js @@ -458,11 +458,13 @@ var content = session.getValue(); var path = session.path; var handleSuccess = function(mtime){ - var session = codiad.active.sessions[path]; - session.untainted = newContent; - session.serverMTime = mtime; - if (session.listThumb) session.listThumb.removeClass('changed'); - if (session.tabThumb) session.tabThumb.removeClass('changed'); + var session = codiad.active.sessions[path]; + if(typeof session != 'undefined') { + session.untainted = newContent; + session.serverMTime = mtime; + if (session.listThumb) session.listThumb.removeClass('changed'); + if (session.tabThumb) session.tabThumb.removeClass('changed'); + } _this.removeDraft(path); } // Replicate the current content so as to avoid @@ -493,6 +495,19 @@ }); } }, + + ////////////////////////////////////////////////////////////////// + // Save all files + ////////////////////////////////////////////////////////////////// + + saveAll: function() { + var _this = this; + for(var session in _this.sessions) { + if (_this.sessions[session].listThumb.hasClass('changed')) { + codiad.active.save(session); + } + } + }, ////////////////////////////////////////////////////////////////// // Remove file @@ -510,6 +525,47 @@ this.close(path); } }, + + removeAll: function() { + var _this = this; + var changed = false; + + var opentabs = new Array(); + for(var session in _this.sessions) { + opentabs[session] = session; + if (_this.sessions[session].listThumb.hasClass('changed')) { + changed = true; + } + } + + if(changed) { + if(confirm('Found unsaved Files. Do you want to save them?')) { + _this.saveAll(); + } + } + + for(var tab in opentabs) { + var session = this.sessions[tab]; + + session.tabThumb.remove(); + _this.updateTabDropdownVisibility(); + + session.listThumb.remove(); + + /* Remove closed path from history */ + var history = []; + $.each(this.history, function(index) { + if(this != tab) history.push(this); + }) + this.history = history + + delete this.sessions[tab]; + this.removeDraft(tab); + } + codiad.editor.exterminate(); + $('#list-active-files').html(''); + $.get(this.controller + '?action=removeall'); + }, close: function(path) { /* Notify listeners. */ @@ -740,6 +796,7 @@ var menu = $('#dropdown-list-active-files'); var button = $('#tab-dropdown-button'); + var closebutton = $('#tab-close-button'); menu.appendTo($('body')); @@ -747,6 +804,11 @@ e.stopPropagation(); _this.toggleTabDropdownMenu(); }); + + closebutton.click(function(e) { + e.stopPropagation(); + _this.removeAll(); + }); }, showTabDropdownMenu: function() { @@ -862,7 +924,8 @@ var tabListWidth = $("#tab-list-active-files").width(); var dropdownWidth = $('#tab-dropdown').width(); - var room = window.innerWidth - lsbarWidth - rsbarWidth - dropdownWidth - width - 30; + var closeWidth = $('#tab-close').width(); + var room = window.innerWidth - lsbarWidth - rsbarWidth - dropdownWidth - closeWidth - width - 30; return (room < 0); }, @@ -886,6 +949,11 @@ // Be sure to hide the menu if it is opened. $('#dropdown-list-active-files').hide(); } + if ($('#tab-list-active-files li').length > 1) { + $('#tab-close').show(); + } else { + $('#tab-close').hide(); + } }, ////////////////////////////////////////////////////////////////// diff --git a/components/filemanager/download.php b/components/filemanager/download.php index 2b474ab..19f15d9 100755 --- a/components/filemanager/download.php +++ b/components/filemanager/download.php @@ -11,9 +11,9 @@ ////////////////////////////////////////////////////////////////// // Verify Session or Key ////////////////////////////////////////////////////////////////// - + checkSession(); - + ////////////////////////////////////////////////////////////////// // Check $_GET for incorrect chars or '..' for workspace ecape ////////////////////////////////////////////////////////////////// @@ -23,9 +23,9 @@ || preg_match('#^[\\\/]?$#i', trim($_GET['path'])) // download all Projects || preg_match('#[\:*?\"<>\|]#i', $_GET['path']) //illegal chars in filenames || strpos('..', $_GET['path']) !== false ){ // change directory up to escape Workspace - exit(''); + exit(''); } - + ////////////////////////////////////////////////////////////////// // Run Download ////////////////////////////////////////////////////////////////// @@ -36,36 +36,36 @@ //$filename = array_pop($filename) . "-" . date('Y.m.d') . ".tar.gz"; $filename = array_pop($filename) . "-" . date('Y.m.d'); $targetPath = DATA . '/'; - $dir = WORKSPACE . $_GET['path']; + $dir = WORKSPACE . '/' . $_GET['path']; if(!is_dir($dir)){ - exit(''); + exit(''); } - + ////////////////////////////////////////////////////////////////// // Check system() command and a non windows OS ////////////////////////////////////////////////////////////////// if(isAvailable('system') && stripos(PHP_OS, 'win') === false){ - # Execute the tar command and save file - $filename .= '.tag.gz'; - - system("tar -pczf ".$targetPath.$filename." ".$dir); - $download_file = $targetPath.$filename; + # Execute the tar command and save file + $filename .= '.tar.gz'; + + system("tar -pczf ".$targetPath.$filename." ".$dir); + $download_file = $targetPath.$filename; }elseif(extension_loaded('zip')){ //Check if zip-Extension is availiable - //build zipfile - require_once 'class.dirzip.php'; - - $filename .= '.zip'; - $download_file = $targetPath.$filename; - DirZip::zipDir($dir, $targetPath .$filename); + //build zipfile + require_once 'class.dirzip.php'; + + $filename .= '.zip'; + $download_file = $targetPath.$filename; + DirZip::zipDir($dir, $targetPath .$filename); }else{ - exit(''); + exit(''); } }else{ $filename = explode("/",$_GET['path']); $filename = array_pop($filename); $download_file = WORKSPACE . $_GET['path']; } - + header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($filename)); diff --git a/components/right_bar.json b/components/right_bar.json index 82d2fff..e848640 100755 --- a/components/right_bar.json +++ b/components/right_bar.json @@ -4,6 +4,11 @@ "icon": "icon-install", "onclick": "codiad.active.save();" }, + { + "title": "Save All", + "icon": "icon-install", + "onclick": "codiad.active.saveAll();" + }, { "title": "break", "icon": null, diff --git a/index.php b/index.php index 28e3ccd..bbdcf8e 100755 --- a/index.php +++ b/index.php @@ -224,6 +224,9 @@ foreach ($allFiles as $fname){
+