mirror of https://github.com/xevidos/codiad.git
Fixed issue with sessions not timing out on firefox and removed CodeSettings from default plugins due to errors.
This commit is contained in:
parent
d824926299
commit
e3b4c0df98
|
@ -26,6 +26,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 and using travis CI to validate a proper formatting.
|
||||
|
||||
[![Build Status](https://travis-ci.org/Codiad/Codiad.svg?branch=master)](https://travis-ci.org/Codiad/Codiad)
|
||||
In order to maintain a consistant code structure we follow PSR2 standards.
|
||||
|
|
18
README.md
18
README.md
|
@ -1 +1,17 @@
|
|||
Custom versions of codiad.
|
||||
This is the Telaaedifex team's custom version of Codiad. Codiad is a web-based IDE framework with a small footprint and minimal requirements.
|
||||
|
||||
Codiad was built with simplicity in mind, allowing for fast, interactive development without the massive overhead of some of the larger desktop editors. That being said even users of IDE's such as Eclipse, NetBeans and Aptana are finding Codiad's simplicity to be a huge benefit. While simplicity was key, we didn't skimp on features and have a team of dedicated developer actively adding more.
|
||||
|
||||
For more information on the project please check out the check out the Wiki.
|
||||
|
||||
Distributed under the MIT-Style License. See LICENSE.txt file for more information.
|
||||
|
||||
When you see a ? in front of a task that means it is a possibility but we aren't sure we will add it yet.
|
||||
|
||||
Task List:
|
||||
|
||||
Add ability to hide cursors when in collaboration mode.
|
||||
? Add ability to see what people are highlighting in collaboration mode.
|
||||
Add mobile compatibility.
|
||||
|
||||
Clean up update script.
|
|
@ -87,10 +87,14 @@
|
|||
}
|
||||
|
||||
//Set a Session Name
|
||||
session_name(md5(BASE_PATH));
|
||||
session_name( md5( BASE_PATH ) );
|
||||
session_save_path( SESSIONS_PATH );
|
||||
session_start();
|
||||
|
||||
if(!defined('SESSION_ID')){
|
||||
define("SESSION_ID", session_id());
|
||||
}
|
||||
|
||||
//Check for external authentification
|
||||
if(defined('AUTH_PATH')){
|
||||
require_once(AUTH_PATH);
|
||||
|
@ -162,6 +166,7 @@
|
|||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
public static function checkSession(){
|
||||
|
||||
// Set any API keys
|
||||
$api_keys = array();
|
||||
// Check API Key or Session Authentication
|
||||
|
@ -173,6 +178,7 @@
|
|||
exit('{"status":"error","message":"Authentication Error<script>window.location.href = window.location.protocol + `' . "//" . Common::getConstant('BASE_URL') . '`</script>"}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Get JSON
|
||||
|
|
|
@ -50,29 +50,31 @@ class User
|
|||
$users = getJSON('users.php');
|
||||
foreach ($users as $user) {
|
||||
if ($user['username']==$this->username && $user['password']==$this->password) {
|
||||
|
||||
$this->checkDuplicateSessions();
|
||||
|
||||
|
||||
$pass = true;
|
||||
$_SESSION['id'] = SESSION_ID;
|
||||
$_SESSION['user'] = $this->username;
|
||||
$_SESSION['lang'] = $this->lang;
|
||||
$_SESSION['theme'] = $this->theme;
|
||||
$_SESSION['login_session'] = true;
|
||||
$_SESSION["login_session"] = true;
|
||||
|
||||
if ($user['project']!='') {
|
||||
$_SESSION['project'] = $user['project'];
|
||||
}
|
||||
|
||||
$this->checkDuplicateSessions( $this->username );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($pass) {
|
||||
|
||||
echo formatJSEND("success", array("username"=>$this->username));
|
||||
} else {
|
||||
echo formatJSEND("error", "Incorrect Username or Password");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**S
|
||||
* Check duplicate sessions
|
||||
*
|
||||
* This function checks to see if the user is currently logged in
|
||||
|
@ -81,16 +83,18 @@ class User
|
|||
* users at the same time.
|
||||
*/
|
||||
|
||||
public function checkDuplicateSessions() {
|
||||
|
||||
public static function checkDuplicateSessions( $username ) {
|
||||
|
||||
//ini_set('display_errors', 1);
|
||||
//ini_set('display_startup_errors', 1);
|
||||
//error_reporting(E_ALL);
|
||||
session_write_close();
|
||||
$all_sessions = array();
|
||||
session_save_path( SESSIONS_PATH );
|
||||
session_start();
|
||||
$sessions = glob( SESSIONS_PATH . "/*" );
|
||||
$this_session = session_id();
|
||||
$username = "xevidos";
|
||||
session_id( SESSION_ID );
|
||||
// session_save_path( SESSIONS_PATH );
|
||||
|
||||
foreach($sessions as $session) {
|
||||
foreach( $sessions as $session ) {
|
||||
|
||||
//echo var_dump( $session ) . "\n\n";
|
||||
|
||||
|
@ -98,33 +102,28 @@ class User
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
$session = str_replace( "sess_", "", $session );
|
||||
$session = str_replace( SESSIONS_PATH . "/", "", $session );
|
||||
$session = str_replace( SESSIONS_PATH . "/", "", $session );
|
||||
//This skips temp files that aren't sessions
|
||||
if( strpos( $session, "." ) == false ) {
|
||||
|
||||
if ( $session == $this_session ) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
session_save_path( SESSIONS_PATH );
|
||||
session_id( $session );
|
||||
session_start();
|
||||
//echo var_dump( $_SESSION ) . "\n\n";
|
||||
if ( ( isset( $_SESSION["user"] ) && $_SESSION["user"] == $username && ( isset( $_SESSION['lang'] ) && isset( $_SESSION['theme'] ) ) && isset( $_SESSION['login_session'] ) && $_SESSION['login_session'] == true ) || empty( $_SESSION ) ) {
|
||||
$_SESSION["id"] = $session;
|
||||
array_push( $all_sessions, $_SESSION );
|
||||
|
||||
if ( isset( $_SESSION["user"] ) && $_SESSION["user"] === $username && isset( $_SESSION["login_session"] ) && $_SESSION["login_session"] === true && SESSION_ID !== session_id() ) {
|
||||
|
||||
session_unset();
|
||||
session_destroy();
|
||||
session_destroy();
|
||||
} else {
|
||||
|
||||
session_abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
//echo '{"status":"error","message":"' . print_r( $all_sessions ) . '"}';
|
||||
|
||||
session_id( $this_session );
|
||||
session_id( SESSION_ID );
|
||||
session_start();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
"name": "codiad/codiad",
|
||||
"type": "application",
|
||||
"keywords": ["ide","development","environment","editor"],
|
||||
"homepage": "http://codiad.telaaedifex.com",
|
||||
"license": "MIT",
|
||||
"description": "Codiad is a web-based IDE framework with a small footprint and minimal requirements. The system is still early in development, and while it has been proven extremely stable please be sure have a backup system if you use it in any production work.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Isaac Brown @xevidos",
|
||||
"email": "xevidos@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Kent Safranski @fluidbyte",
|
||||
"email": "kent@fluidbyte.net"
|
||||
},
|
||||
{
|
||||
"name": "@tholum"
|
||||
},
|
||||
{
|
||||
"name": "@lorefnon"
|
||||
},
|
||||
{
|
||||
"name": "@tablatronix"
|
||||
},
|
||||
{
|
||||
"name": "@Flolagale"
|
||||
},
|
||||
{
|
||||
"name": "@Verdier"
|
||||
},
|
||||
{
|
||||
"name": "Danny Morabito @newsocialifecom",
|
||||
"email": "codiad@newsocialife.com"
|
||||
},
|
||||
{
|
||||
"name": "@daeks"
|
||||
},
|
||||
{
|
||||
"name": "@holblin"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require":
|
||||
{
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"require-dev":
|
||||
{
|
||||
"phing/phing": "2.*",
|
||||
"squizlabs/php_codesniffer": "*"
|
||||
},
|
||||
"extra":
|
||||
{
|
||||
"installer-paths":
|
||||
{
|
||||
"apps/{$name}": ["codiad/codiad"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#CodeSettings
|
||||
|
||||
Create your own keybindings
|
||||
|
||||
##Installation
|
||||
|
||||
- Download the zip file and unzip it to your plugin folder.
|
||||
|
||||
##Example
|
||||
|
||||
![Example](http://andrano.de/Plugins/img/settings_dialog.jpg "Example")
|
||||
![Example](http://andrano.de/Plugins/img/settings.jpg "Example")
|
File diff suppressed because it is too large
Load Diff
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Codiad & Andr3as, distributed
|
||||
* as-is and without warranty under the MIT License.
|
||||
* See http://opensource.org/licenses/MIT for more information.
|
||||
* This information must remain intact.
|
||||
*/
|
||||
include_once('../../common.php');
|
||||
|
||||
class settings {
|
||||
|
||||
public function load() {
|
||||
$this->existDir();
|
||||
return json_encode(getJSON($this->getFileName(), "config"));
|
||||
}
|
||||
|
||||
public function open() {
|
||||
$this->existDir();
|
||||
$msg = array();
|
||||
$msg['content'] = json_encode(getJSON($this->getFileName(), "config"));
|
||||
$msg['name'] = basename($this->getFileName(), ".php").".json";
|
||||
$msg['mtime'] = filemtime($this->getFilePath());
|
||||
if ($msg['content'] !== false) {
|
||||
$msg['status'] = "success";
|
||||
} else {
|
||||
$msg['status'] = "error";
|
||||
$msg['message'] = "Failed to open file!";
|
||||
}
|
||||
return json_encode($msg);
|
||||
}
|
||||
|
||||
public function save($content) {
|
||||
$this->existDir();
|
||||
saveJSON($this->getFileName(), json_decode($content), "config");
|
||||
return '{"status":"success","message":"Settings saved!"}';
|
||||
}
|
||||
|
||||
public function existDir() {
|
||||
if(!file_exists($this->getFilePath())) {
|
||||
saveJSON($this->getFileName(), array(), "config");
|
||||
}
|
||||
}
|
||||
|
||||
public function getFilePath() {
|
||||
return DATA."/config/".get_called_class().".".$_SESSION['user'].".php";
|
||||
}
|
||||
|
||||
public function getFileName() {
|
||||
return basename($this->getFilePath());
|
||||
}
|
||||
|
||||
static public function getWorkspacePath($path) {
|
||||
if (strpos($path, "/") === 0) {
|
||||
//Unix absolute path
|
||||
return $path;
|
||||
}
|
||||
if (strpos($path, ":/") !== false) {
|
||||
//Windows absolute path
|
||||
return $path;
|
||||
}
|
||||
if (strpos($path, ":\\") !== false) {
|
||||
//Windows absolute path
|
||||
return $path;
|
||||
}
|
||||
return "../../workspace/".$path;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) Codiad & Andr3as, distributed
|
||||
* as-is and without warranty under the MIT License.
|
||||
* See [root]/license.md for more information. This information must remain intact.
|
||||
*/
|
||||
error_reporting(0);
|
||||
|
||||
require_once('../../common.php');
|
||||
require_once('class.settings.php');
|
||||
|
||||
checkSession();
|
||||
|
||||
|
||||
switch($_GET['action']) {
|
||||
|
||||
case 'open':
|
||||
$settings = new settings();
|
||||
echo $settings->open();
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
$settings = new settings();
|
||||
if (isset($_POST['content'])) {
|
||||
echo $settings->save($_POST['content']);
|
||||
} else {
|
||||
echo '{"status":"error","message":"Missing Parameters!"}';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'load':
|
||||
$settings = new settings();
|
||||
echo $settings->load();
|
||||
break;
|
||||
|
||||
case 'saveCommands':
|
||||
if (isset($_POST['commands'])) {
|
||||
$result = file_put_contents("default.commands.json", $_POST['commands']);
|
||||
if ($result === false) {
|
||||
echo '{"status":"error","message":"Failed to save default commands!"}';
|
||||
} else {
|
||||
echo '{"status":"success","message":"Commands saved."}';
|
||||
}
|
||||
} else {
|
||||
echo '{"status":"error","message":"Missing Parameters!"}';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
echo '{"status":"error","message":"No Type"}';
|
||||
break;
|
||||
}
|
||||
?>
|
File diff suppressed because one or more lines are too long
|
@ -1,59 +0,0 @@
|
|||
<!--
|
||||
Copyright (c) Codiad & Andr3as, distributed
|
||||
as-is and without warranty under the MIT License.
|
||||
See http://opensource.org/licenses/MIT for more information.
|
||||
This information must remain intact.
|
||||
-->
|
||||
<form id="hotkey">
|
||||
<?php
|
||||
if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
} else {
|
||||
$action = "show";
|
||||
}
|
||||
|
||||
switch($action) {
|
||||
case "show":
|
||||
?>
|
||||
<label>CodeSettings</label>
|
||||
<div id="hotkey_div">
|
||||
<table id="hotkey_list">
|
||||
<tr>
|
||||
<td>Command name</td>
|
||||
<td>Win keybinding</td>
|
||||
<td>Mac keybinging</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<button onclick="codiad.CodeSettings.add(); return false;">Add new binding</button>
|
||||
<button onclick="codiad.CodeSettings.edit(); return false;">Expert settings</button>
|
||||
<button onclick="codiad.CodeSettings.help(); return false;">Help</button>
|
||||
<script>
|
||||
codiad.CodeSettings.show();
|
||||
</script>
|
||||
<?php
|
||||
break;
|
||||
case "help":
|
||||
?>
|
||||
<label>CodeSettings - Help</label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Command name:</td>
|
||||
<td>Name of the Command</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Win/Mac keybinding:</td>
|
||||
<td>Keys given by its name divided by dash</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example:</td>
|
||||
<td>CompletePlus Ctrl-Space</td>
|
||||
</tr>
|
||||
</table><button onclick="codiad.CodeSettings.showDialog(); return false;">Close</button>
|
||||
<?php
|
||||
break;
|
||||
default:
|
||||
}
|
||||
?>
|
||||
</form>
|
|
@ -1,444 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) Codiad & Andr3as, distributed
|
||||
* as-is and without warranty under the MIT License.
|
||||
* See http://opensource.org/licenses/MIT for more information.
|
||||
* This information must remain intact.
|
||||
*/
|
||||
|
||||
(function(global, $){
|
||||
|
||||
var codiad = global.codiad,
|
||||
scripts = document.getElementsByTagName('script'),
|
||||
path = scripts[scripts.length-1].src.split('?')[0],
|
||||
curpath = path.split('/').slice(0, -1).join('/')+'/';
|
||||
|
||||
$(function() {
|
||||
codiad.CodeSettings.init();
|
||||
});
|
||||
|
||||
codiad.CodeSettings = {
|
||||
|
||||
path: curpath,
|
||||
file: "",
|
||||
open: false,
|
||||
redo: false,
|
||||
settings: null,
|
||||
template: "",
|
||||
commands: null,
|
||||
entries: 0,
|
||||
|
||||
init: function() {
|
||||
var _this = this;
|
||||
this.$pSave = this.saveExpert.bind(this);
|
||||
this.$cSave = codiad.active.save.bind(this);
|
||||
//Load keymap
|
||||
this.load();
|
||||
//Load template
|
||||
$.get(this.path+"template.html", function(html){
|
||||
_this.template = html;
|
||||
});
|
||||
$.getScript(this.path+"beautify.js");
|
||||
//Load default commands
|
||||
$.getJSON(this.path+"default.commands.json", function(json){
|
||||
_this.commands = json;
|
||||
});
|
||||
//Set keymap
|
||||
amplify.subscribe("active.onOpen", function(path){
|
||||
//Overwrite save commands
|
||||
var manager = codiad.editor.getActive().commands;
|
||||
manager.addCommand({
|
||||
name: 'Save',
|
||||
bindKey: "Ctrl-S",
|
||||
exec: function () {
|
||||
codiad.active.save();
|
||||
}
|
||||
});
|
||||
_this.setKeys();
|
||||
if (_this.open && path === _this.file && _this.redo) {
|
||||
_this.addCommands();
|
||||
}
|
||||
if (codiad.editor.getActive() !== null) {
|
||||
_this.commands = codiad.editor.getActive().commands.byName;
|
||||
}
|
||||
//Save current existing commands
|
||||
setTimeout(function(){
|
||||
$.post(_this.path+"controller.php?action=saveCommands", {commands: JSON.stringify(_this.commands)}, function(data){
|
||||
var json = JSON.parse(data);
|
||||
if (json.status == "error") {
|
||||
codiad.message.error(json.message);
|
||||
}
|
||||
});
|
||||
}, 10);
|
||||
});
|
||||
amplify.subscribe("active.onFocus", function(path){
|
||||
if (_this.open) {
|
||||
if (path === _this.file) {
|
||||
_this.addCommands();
|
||||
} else {
|
||||
_this.restoreCommands();
|
||||
}
|
||||
}
|
||||
});
|
||||
amplify.subscribe("active.onClose", function(path){
|
||||
if (_this.file === path) {
|
||||
_this.open = false;
|
||||
}
|
||||
});
|
||||
|
||||
amplify.subscribe('settings.dialog.save', function(){
|
||||
if ($('#hotkey_div').length > 0) {
|
||||
_this.saveDialog();
|
||||
}
|
||||
});
|
||||
//Live feature
|
||||
$('.command_name').live("change", function(){
|
||||
var line = $(this).attr('data-line');
|
||||
var name = $(this).val();
|
||||
var com = _this.commands[name].bindKey;
|
||||
if (typeof(com.win) != 'undefined') {
|
||||
$('.command_win[data-line="'+line+'"]').val(com.win);
|
||||
} else {
|
||||
if (!$.isPlainObject(com) && !$.isArray(com)) {
|
||||
$('.command_win[data-line="'+line+'"]').val(com);
|
||||
}
|
||||
}
|
||||
if (typeof(com.win) != 'undefined') {
|
||||
$('.command_mac[data-line="'+line+'"]').val(com.mac);
|
||||
} else {
|
||||
if (!$.isPlainObject(com) && !$.isArray(com)) {
|
||||
$('.command_mac[data-line="'+line+'"]').val(com);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
$('.command_win').live("change", function(){
|
||||
_this.onCommandChange(this);
|
||||
});
|
||||
$('.command_mac').live("change", function(){
|
||||
_this.onCommandChange(this);
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Show dialog
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
showDialog: function() {
|
||||
codiad.settings.show(this.path.replace(location.toString(), "") + '/dialog.php');
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Load current settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
load: function() {
|
||||
var _this = this;
|
||||
$.getJSON(this.path+"controller.php?action=load", function(json){
|
||||
_this.settings = json || {};
|
||||
_this.settings.keys = json.keys || {};
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Set keybindings of settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
setKeys: function() {
|
||||
var _this = this;
|
||||
setTimeout(function(){
|
||||
if (codiad.editor.getActive() !== null) {
|
||||
var manager = codiad.editor.getActive().commands;
|
||||
//var command;
|
||||
for (var i = 0; i < _this.settings.keys.length; i++) {
|
||||
var element = _this.settings.keys[i];
|
||||
if (typeof(manager.byName[element.name]) != 'undefined') {
|
||||
manager.addCommand({
|
||||
name: element.name,
|
||||
bindKey: element.bindKey,
|
||||
exec: manager.byName[element.name].exec
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 50);
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Open file for expert settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
edit: function() {
|
||||
var _this = this;
|
||||
//Open file and load currrent settings
|
||||
$.getJSON(this.path+"controller.php?action=open", function(json){
|
||||
if (json.status !== "error") {
|
||||
var opt = {
|
||||
"indent_size": codiad.editor.settings.tabSize,
|
||||
"indent_char": " ",
|
||||
"indent_with_tabs": !codiad.editor.settings.softTabs
|
||||
};
|
||||
_this.content = json.content;
|
||||
json.content = js_beautify(json.content, opt);
|
||||
_this.file = json.name;
|
||||
_this.open = true;
|
||||
codiad.modal.unload();
|
||||
codiad.active.open(json.name, json.content, json.mtime, false, true);
|
||||
} else {
|
||||
codiad.message.error(json.message);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Save expert settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
saveExpert: function() {
|
||||
var _this = this;
|
||||
var content = codiad.editor.getContent();
|
||||
try {
|
||||
this.settings = JSON.parse(content);
|
||||
} catch (e) {
|
||||
codiad.message.error("Error: "+e);
|
||||
return false;
|
||||
}
|
||||
this.save();
|
||||
return true;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Save dialog settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
saveDialog: function() {
|
||||
var buf = [];
|
||||
var line;
|
||||
$('.command_line').each(function(i, item){
|
||||
var obj = {"name": "","bindKey": {"win": "","mac": ""}};
|
||||
line = $(item).attr("data-line");
|
||||
obj.name = $('.command_name[data-line="'+line+'"]').val();
|
||||
obj.bindKey.win = $('.command_win[data-line="'+line+'"]').val();
|
||||
obj.bindKey.mac = $('.command_mac[data-line="'+line+'"]').val();
|
||||
buf.push(obj);
|
||||
});
|
||||
if ($.isArray(this.settings)) {
|
||||
this.settings = {};
|
||||
}
|
||||
this.settings.keys = buf;
|
||||
this.save();
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Save current user settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
save: function() {
|
||||
var _this = this;
|
||||
var content = this.settings;
|
||||
content = JSON.stringify(content);
|
||||
$.post(this.path+"controller.php?action=save", {"content": content}, function(data){
|
||||
var json = JSON.parse(data);
|
||||
if (json.status !== "error") {
|
||||
$('li[data-path="'+_this.file+'"]').removeClass('changed');
|
||||
_this.load();
|
||||
_this.setKeys();
|
||||
codiad.message.success(json.message);
|
||||
} else {
|
||||
codiad.message.error(json.message);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Change save command for expert settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
addCommands: function() {
|
||||
if (codiad.editor.getActive() === null) {
|
||||
return false;
|
||||
}
|
||||
var manager = codiad.editor.getActive().commands;
|
||||
try {
|
||||
manager.commands.Save.exec = this.$pSave;
|
||||
this.redo = false;
|
||||
} catch (e) {
|
||||
this.redo = true;
|
||||
}
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Restore save command after expert settings
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
restoreCommands: function() {
|
||||
if (codiad.editor.getActive() === null) {
|
||||
return false;
|
||||
}
|
||||
var manager = codiad.editor.getActive().commands;
|
||||
try {
|
||||
manager.commands.Save.exec = this.$cSave;
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Display commands in dialog
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
show: function() {
|
||||
var _this = this;
|
||||
$.each(this.settings.keys, function(i, item){
|
||||
_this.addEntry(item.name, item.bindKey.win, item.bindKey.mac);
|
||||
});
|
||||
$('#hotkey_div').css('max-height', function(){
|
||||
return 0.6*window.innerHeight + "px";
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Add new command
|
||||
//
|
||||
// Parameter
|
||||
//
|
||||
// name - {String} - Name of command
|
||||
// win - {String} - Command for win
|
||||
// mac - {String} - Command for mac
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
addEntry: function(name, win, mac) {
|
||||
var coms = this.getCommands();
|
||||
if (coms === false) {
|
||||
return false;
|
||||
}
|
||||
var template = this.template;
|
||||
var option = "";
|
||||
for (var i = 0; i < coms.length; i++) {
|
||||
if (coms[i].name == name) {
|
||||
option += "<option selected>"+coms[i].name+"</option>";
|
||||
} else {
|
||||
option += "<option>"+coms[i].name+"</option>";
|
||||
}
|
||||
}
|
||||
template = template.replace("__options__", option);
|
||||
template = template.replace("__win__", win);
|
||||
template = template.replace("__mac__", mac);
|
||||
template = template.replace(new RegExp("__line__", "g"), this.entries++);
|
||||
$('#hotkey_list').append(template);
|
||||
this.setDelete();
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Add new empty command
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
add: function() {
|
||||
this.addEntry("","","");
|
||||
$('.command_name:last').trigger('change');
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Activate delete button
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
setDelete: function(){
|
||||
$('.command_remove').click(function(){
|
||||
var line = $(this).attr("data-line");
|
||||
$('.command_line[data-line="'+line+'"]').remove();
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get current commands or a fallback
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
getCommands: function() {
|
||||
var commands;
|
||||
if (codiad.editor.getActive() === null) {
|
||||
if (this.commands === null) {
|
||||
codiad.message.error("Open file to display all commands!");
|
||||
return false;
|
||||
} else {
|
||||
commands = this.commands;
|
||||
}
|
||||
} else {
|
||||
commands = codiad.editor.getActive().commands.byName;
|
||||
}
|
||||
|
||||
var buf = [];
|
||||
$.each(commands, function(i, item){
|
||||
buf.push(item);
|
||||
});
|
||||
buf.sort(function(a,b){
|
||||
var newBuf = [a.name,b.name];
|
||||
if (a === b) {
|
||||
return 0;
|
||||
}
|
||||
newBuf.sort();
|
||||
if (newBuf[0] === a.name) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
return buf;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Display help command
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
help: function() {
|
||||
codiad.modal.load(400, this.path+"dialog.php?action=help");
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Check if command is already used
|
||||
//
|
||||
// Parameter
|
||||
//
|
||||
// field - {jQuery objcet} - Field to check
|
||||
//
|
||||
//////////////////////////////////////////////////////////
|
||||
onCommandChange: function(field) {
|
||||
var type = 'win';
|
||||
if ($(field).hasClass('.command_mac')) {
|
||||
type = 'mac';
|
||||
}
|
||||
var value = $(field).val();
|
||||
if (this.commands === null) {
|
||||
return false;
|
||||
}
|
||||
var com;
|
||||
$.each(this.commands, function(i, item){
|
||||
if (typeof(item.bindKey) == 'undefined') {
|
||||
return;
|
||||
}
|
||||
if (typeof(item.bindKey[type]) == 'undefined') {
|
||||
com = item.bindKey;
|
||||
} else {
|
||||
com = item.bindKey[type];
|
||||
}
|
||||
if (value === com) {
|
||||
codiad.message.notice("Command already used!");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
})(this, jQuery);
|
|
@ -1,16 +0,0 @@
|
|||
[{ "author" : "Andr3as",
|
||||
"version": "0.3.2",
|
||||
"name" : "CodeSettings",
|
||||
"url" : "https://github.com/Andr3as/Codiad-CodeSettings",
|
||||
"exclude" : "",
|
||||
"rightbar" : [{
|
||||
"action" : "codiad.CodeSettings.showDialog();",
|
||||
"icon" : "icon-keyboard",
|
||||
"title" : "CodeSettings"
|
||||
}],
|
||||
"config": [{
|
||||
"file": "dialog.php",
|
||||
"icon": "icon-keyboard",
|
||||
"title": "CodeSettings"
|
||||
}]
|
||||
}]
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"keys": [
|
||||
{ "name": "CodeDate",
|
||||
"bindKey": {
|
||||
"win": "Ctrl-6",
|
||||
"mac": "Command-6"}
|
||||
},
|
||||
{ "name": "CompletePlus",
|
||||
"bindKey": "Ctrl-Space"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#hotkey_div {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
#hotkey_list td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.command_win, .command_mac{
|
||||
//width: 100px;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<tr class="command_line" data-line="__line__">
|
||||
<td>
|
||||
<select class="command_name" style="width: 140px;" data-line="__line__" >
|
||||
__options__
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="command_win" value="__win__" data-line="__line__" >
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="command_mac" value="__mac__" data-line="__line__" >
|
||||
</td>
|
||||
<td>
|
||||
<button data-line="__line__" class="btn-left command_remove">X</button>
|
||||
</td>
|
||||
</tr>
|
Loading…
Reference in New Issue