diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d0c74bb..c3cb2b6 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,13 +14,12 @@ Stick to the conventions defined in other components as closely as possible. * Utilize the same commenting structure * Use underscores in namespaces instead of interCaps -* Use intend with 4 spaces in your code -* Use single quotes for parameternames and double quotes for strings +* Use intend with a tab character in your code * When working with the editor utilize the `active` object whenever possible instead of going direct to the `editor` **Javascript Formatting** -In order to maintain a consistant code structure to the code across the application please follow the wordpress standard, or run any changes through JSBeautifier (http://jsbeautifier.org/) with the settings below. +In order to maintain a consistant code structure to the code across the application please follow the wordpress standard, or run any changes through [JSBeautifier] (http://jsbeautifier.org/) with the settings below. { "indent_size": "1", @@ -45,4 +44,4 @@ If you have questions, please ask. Submit an issue or [contact us directly](mail **PHP Formatting** -In order to maintain a consistant code structure we follow PSR2 standards. +In order to maintain a consistant code structure we follow WordPress standards. diff --git a/components/autosave/init.js b/components/autosave/init.js index b6084e1..a6cfba9 100755 --- a/components/autosave/init.js +++ b/components/autosave/init.js @@ -33,6 +33,8 @@ // Allows relative `this.path` linkage auto_save_trigger: null, + content: null, + editor: null, invalid_states: [ "", " ", null, undefined ], path: curpath, saving: false, @@ -44,7 +46,8 @@ init: async function() { - codiad.auto_save.settings.autosave = await codiad.settings.get_option( 'codiad.settings.autosave' ); + let _this = codiad.auto_save; + _this.settings.autosave = await codiad.settings.get_option( 'codiad.settings.autosave' ); // Check if the auto save setting is true or false // Also check to see if the editor is any of the invalid states @@ -83,7 +86,35 @@ console.log( 'Auto save Enabled' ); } - this.auto_save_trigger = setInterval( this.auto_save, 256 ); + + let content = codiad.editor.getContent(); + + if( ! codiad.active.getPath() == null && ! codiad.auto_save.invalid_states.includes( content ) ) { + + this.content = content; + } + + /* Subscribe to know when a file is being closed. */ + amplify.subscribe( 'active.onClose', function( path ) { + + let _this = codiad.auto_save; + _this.editor.removeEventListener( "change", _this.change ); + }); + + /* Subscribe to know when a file become active. */ + amplify.subscribe( 'active.onFocus', function( path ) { + + let _this = codiad.auto_save; + + if( ! _this.editor == null && path == _this.editor.getSession().path ) { + + return; + } + + _this.editor = codiad.editor.getActive(); + _this.content = codiad.editor.getContent(); + _this.editor.addEventListener( "change", _this.auto_save ); + }); }, /** @@ -95,34 +126,61 @@ auto_save: function() { - if( this.settings.toggle == false || this.settings.autosave == false || codiad.auto_save.invalid_states.includes( codiad.editor.getContent() ) ) { - - return; - } - - this.saving = true; - - if ( codiad.active.getPath() == null ) { - - this.saving = false; - return; - } - + let _this = codiad.auto_save; + _this.saving = true; let tabs = document.getElementsByClassName( "tab-item" ); let path = codiad.active.getPath(); let content = codiad.editor.getContent(); + if( _this.settings.toggle == false || _this.settings.autosave == false || codiad.auto_save.invalid_states.includes( content ) ) { + + _this.saving = false; + return; + } + + if( path == null ) { + + _this.saving = false; + return; + } + + if( _this.verbose ) { + + console.log( content, _this.content ); + } + + if( content == _this.content ) { + + var session = codiad.active.sessions[path]; + if( typeof session != 'undefined' ) { + + session.untainted = content; + session.serverMTime = session.serverMTime; + if ( session.listThumb ) { + + session.listThumb.removeClass('changed'); + } + + if ( session.tabThumb ) { + + session.tabThumb.removeClass('changed'); + } + } + return; + } + /* - this code caused issues even though it is the proper way to save something. + _this code caused issues even though it is the proper way to save something. Whenever in collaboration, the server constantly gave a wrong file version error. let path = codiad.active.getPath(); codiad.active.save( path, false ); - this.saving = false; + _this.saving = false; */ + _this.content = content; codiad.active.save; codiad.filemanager.saveFile( path, content, localStorage.removeItem( path ), false ); var session = codiad.active.sessions[path]; @@ -140,7 +198,7 @@ session.tabThumb.removeClass('changed'); } } - this.saving = false; + _this.saving = false; }, reload_interval: async function() { diff --git a/components/filemanager/init.js b/components/filemanager/init.js index 8af9a43..77bf518 100755 --- a/components/filemanager/init.js +++ b/components/filemanager/init.js @@ -562,6 +562,9 @@ if(type == 'file') { codiad.filemanager.openFile(createPath, true); } + + codiad.filemanager.rescan( path ); + /* Notify listeners. */ amplify.publish('filemanager.onCreate', {createPath: createPath, path: path, shortName: shortName, type: type}); } @@ -608,6 +611,8 @@ } else { // No conflicts; proceed... _this.processPasteNode(path,false); } + + codiad.filemanager.rescan( path ); } }, @@ -672,7 +677,7 @@ // Change any active files codiad.active.rename(path, newPath); codiad.modal.unload(); - + codiad.filemanager.rescan( parentPath ); /* Notify listeners. */ amplify.publish('filemanager.onRename', {path: path, newPath: newPath, parentPath: parentPath }); } diff --git a/components/project/class.project.php b/components/project/class.project.php index 8ea88df..a6d3d14 100755 --- a/components/project/class.project.php +++ b/components/project/class.project.php @@ -269,6 +269,7 @@ class Project extends Common { $query = "SELECT * FROM projects WHERE name=? AND path=? AND ( owner=? OR owner='nobody' );"; $bind_variables = array( $old_name, $path, $_SESSION["user"] ); $return = $sql->query( $query, $bind_variables, array() ); + $pass = false; if( ! empty( $return ) ) { @@ -279,14 +280,17 @@ class Project extends Common { if( $return > 0 ) { echo( formatJSEND( "success", "Renamed " . htmlentities( $old_name ) . " to " . htmlentities( $new_name ) ) ); + $pass = true; } else { - echo( formatJSEND( "error", "Error renaming project." ) ); + exit( formatJSEND( "error", "Error renaming project." ) ); } } else { echo( formatJSEND( "error", "Error renaming project, could not find specified project." ) ); } + + return $pass; } ////////////////////////////////////////////////////////////////// @@ -469,13 +473,11 @@ class Project extends Common { $revised_array[] = array( "name" => $data['name'], "path" => $data['path'] ); } else { - $this->rename_project( $data['name'], $_GET['project_name'], $data['path'] ); + $rename = $this->rename_project( $data['name'], $_GET['project_name'], $data['path'] ); } } $revised_array[] = $this->projects[] = array( "name" => $_GET['project_name'], "path" => $this->path ); - // Response - echo formatJSEND("success", null); } ////////////////////////////////////////////////////////////////// diff --git a/components/project/init.js b/components/project/init.js index ab9b40f..e396251 100755 --- a/components/project/init.js +++ b/components/project/init.js @@ -275,8 +275,13 @@ ////////////////////////////////////////////////////////////////// loadSide: async function() { + this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.SideExpaned" ) == "true" ); $( '.sb-projects-content' ).load( this.dialog + '?action=sidelist&trigger='+ await codiad.settings.get_option( 'codiad.editor.fileManagerTrigger' ) ); - this._sideExpanded = true; + + if ( ! this._sideExpanded ) { + + this.projectsCollapse(); + } }, ////////////////////////////////////////////////////////////////// @@ -318,6 +323,7 @@ projectsExpand: function() { this._sideExpanded = true; + codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded ); $( '#side-projects' ).css( 'height', 276 + 'px' ); $( '.project-list-title' ).css( 'right', 0 ); $( '.sb-left-content' ).css( 'bottom', 276 + 'px' ); @@ -329,6 +335,7 @@ projectsCollapse: function() { this._sideExpanded = false; + codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded ); $( '#side-projects' ).css( 'height', 33 + 'px' ); $( '.project-list-title' ).css( 'right', 0 ); $( '.sb-left-content' ).css( 'bottom', 33 + 'px' ); diff --git a/components/settings/dialog.php b/components/settings/dialog.php index 7ef3439..4712ca7 100755 --- a/components/settings/dialog.php +++ b/components/settings/dialog.php @@ -63,7 +63,7 @@ - +