* * Libreria para interactuar con Textmate, inspirada en la de Duane Johnson (duane.johnson@gmail.com) http://syncpeople.com/ */ class TM { // TextMate shell script exit codes. // See /Applications/TextMate.app/Contents/SharedSupport/Support/lib/bash_init.sh for a comprehensive list function exit_discard() { exit(200); } function exit_replace_text() { exit(201); } function exit_replace_document() { exit(202); } function exit_insert_text() { exit(203); } function exit_insert_snippet() { exit(204); } function exit_show_html() { exit(205); } function exit_show_tool_tip() { exit(206); } function exit_create_new_document() { exit(207); } function open_url($url='') { shell_exec('open "'.$url.'"'); } // Open a file in textmate using the txmt:// protocol. Uses 0-based line and column indices. function open($filename, $line_nubmer=null, $column_number = null) { $options = array(); $options[] = "url=file://$filename"; if($line_number) $options[] = "line=".($line_nubmer+1); if($column_number) $options[] = "line=".($column_number+1); TM::open_url("txmt://open?".join("&",$options)); } // Switching away from and then back to TextMate will automatically cause it to refresh the project drawer function refresh_project_drawer() { shell_exec("osascript -e 'tell application \"Dock\" to activate'; osascript -e 'tell application \"TextMate\" to activate'"); } function selected_text() { return TM::env('selected_text'); } // Make line_number 0-base index function line_number() { return TM::env('line_number') - 1; } // Make line_number 0-base index function column_number() { return TM::env('column_number') - 1; } function project_directory() { return TM::env('project_directory'); } function env($var) { return @$_ENV['TM_'.strtoupper($var)]; } function cocoa_dialog_command() { return TM::env('support_path')."/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog"; } // See http://cocoadialog.sourceforge.net/documentation.html for documentation function cocoa_dialog($command, $options = array()) { $options_list = array(); foreach($options as $option => $value) { if($value) { if(is_bool($value) && $value) { $options_list[] = '--'.$option; } else { $value = is_array($value) ? '"'.join('" "',$value).'"': '"'.$value.'"'; $options_list[] = '--'.$option.' '.$value; } } } $res = shell_exec('"'.TM::cocoa_dialog_command().'" '.$command.' '.join(' ',$options_list)); return explode("\n",$res); } function bubble($text, $options = array()) { $options = array_merge(array('debug'=>true, 'title' => 'Message','text'=>$text),$options); return TM::cocoa_dialog('bubble', $options); } function message($text, $options = array()) { $options = array_merge(array('title' => 'Message','informative-text'=>$text,'button1'=>'Ok'),$options); $res = TM::cocoa_dialog('msgbox', $options); return $res[0] == '1'; } function textbox($informative_text, $text, $options = array()) { $options = array_merge(array('title' => 'Message','informative-text'=>$informative_text, 'text'=>$text,'button1'=>'Ok'),$options); $res = TM::cocoa_dialog('textbox', $options); return $res[0] == '1'; } function message_yes_no_cancel($text,$informative_text = '', $options = array()) { $options = array_merge(array('title' => 'Message', 'informative-text'=>$informative_text, 'text'=>$text),$options); $res = TM::cocoa_dialog('yesno-msgbox', $options); return $res[0] == '1'; } function message_ok_cancel($text,$informative_text = '', $options = array()) { $options = array_merge(array('title' => 'Message', 'informative-text'=>$informative_text, 'text'=>$text),$options); $res = TM::cocoa_dialog('ok-msgbox', $options); return $res[0] == '1'; } function input($text, $default_text = "", $options = array()) { $options = array_merge(array('title' => 'Input','informative-text'=>$text,'text'=>$default_text),$options); $res = TM::cocoa_dialog('standard-inputbox', $options); if($res[0] == '1') return $res[1]; return null; } function choose($text,$choises = array('none'),$options = array()) { $options = array_merge(array('title' => 'Choose','text'=>$text,'items'=>$choises,'button1' => 'Ok', 'button2' => 'Cancel'),$options); $res = TM::cocoa_dialog('dropdown', $options); if($res[0] == '1') return $choises[$res[1]]; return null; } function progressbar($options = array(),$percent=-1) { return new progressbar($options,$percent); } } class progressbar { function progressbar($options = array(),$percent=-1) { $option = array('title' => 'progressbar','text'=>'progressbar'); if($percent>=0) { $option['percent'] = $percent; $indeterminate = ''; } else $indeterminate = '--indeterminate '; $options = array_merge($option,$options); $options_list = array(); foreach($options as $option => $value) $options_list[] = '--'.$option.' "'.$value.'"'; $this->handle = popen('"'.TM::cocoa_dialog_command().'" progressbar '.$indeterminate.join(' ',$options_list), "w+"); } function write($text='',$percent=null) { $text = $percent ? $percent.' '.$text."\n" : '0 '.$text; fputs($this->handle,$text); } function close() { sleep(1); pclose($this->handle); } } ?>