ホーム > アーカイブ > 2007年12月3日のアーカイブ

2007年12月3日のアーカイブ

MocaScript – よく使う機能を関数にまとめた

[`evernote` not found]
[`grow` not found]
[`livedoor` not found]
[`yahoo` not found]
Delicious にシェア
このエントリーをはてなブックマークに追加

/***********************************************
 * 文字列操作
 ***********************************************/
/**
 * 文字列をダブルクォーテーションで囲む
 * @var    string path
 * @return string
 */
function addQuote ( path ) {
	return '"' + path.replace(/"/g, '""') + '"';
}
/**
 * 文字列両端のダブルクォーテーションを削除する
 * @var     string path
 * @return string
 */
function trimQuote ( path ) {
	return path.replace(/^"??(.*)"??$/, '$1').replace(/""/g, '"');
}
/**
 * 文字列末尾のパスセパレータを削除する
 * @var     string path
 * @return string
 */
function rtrimPath ( path ) {
	return path.replace(/[\s\\\/]+$/, '');
}
/**
 * パス文字列からフォルダ名を取り出す
 * @var     string path
 * @return string foldername
 */
function dirname ( path ) {
	return path.replace(/[\\\/]([^\\\/]+)$/, '');
}
/**
 * パス文字列からファイル名を取り出す
 * @var     string path
 * @return string filename
 */
function basename ( path ) {
	return path.replace(/^.*[\\\/]/, '');
}
/**
 * カンマ区切りの文字列を配列に分解する
 * @var     string line 
 * @return array
 */
function splitcsv ( line ) {
	return line.split(/\s*,\s*/);
}

/***********************************************
 * ファイル&フォルダー操作
 ***********************************************/
/**
 * テンポラリフォルダのパスを得る
 * @return string path
 */
function getTempPath () {
	var path = getenv('TEMP');
	if (!File.isFolder(path))
		path = getenv('TMP');
	return path;
}
/**
 * コマンドプロンプトを開く
 * @var string path
 */
function openShell ( path ) {
	if (File.isFile(path))
		path = dirname(path);
	if (!File.isFolder(path))
		path = getcwd();
	shellExecute('open', 'cmd.exe', null, path);
}
/**
 * フォルダを開く
 * @var string path
 */
function openFolder ( path ) {
	if (File.isFile(path))
		path = dirname(path);
	if (!File.isFolder(path))
		path = getcwd();
	shellExecute('open', path, null, path);
}

/***********************************************
 * Peggy 操作
 ***********************************************/
/**
 * view が開かれていなければ終了する
 */ 
function hasView () {
	if (!view)
		error('ファイルが開かれていません');
}
/**
 * project が開かれていなければ終了する
 */ 
function hasProject () {
	if (!project)
		error('プロジェクトが開かれていません');
}
/**
 * フォーカスのある view または output から
 * 選択中の文字列を獲得する(Peggy ver 4.22以降)
 * @return string
 */
function getSelected () {
	switch (getFocusedWindowType()) {
	case 2:
		for (var n in output) {
			if (output[n].hasFocus())
				return output[n].getSelectedText();
		}
	case 1:
		return view.getSelectedText();
	}
	return '';
}
/**
 *  1行ダイアログを表示して入力された文字列を得る
 *  @var string title   ダイアログのタイトル
 *  @var string init    初期値(省略可)
 *  @var string prompt  接頭文字列(プロンプト)(省略可)
 */
function getInput ( title, init, prompt ) {
	if (!prompt)
		prompt = '>>';
	if (!init)
		init = '';
	var s = inputBox(title, 'パラメータを入力してください', [ prompt, init ]);
	return s[0].trim();
}
/**
 * 編集中のファイル(view)のフォルダを開く
 */
function openViewFolder () {
	hasView();
	openFolder(view.getFilePath());
}

/***********************************************
 * ユーティリティ
 ***********************************************/
/**
 * サービスコンソールを開く
 */
function openServiceConsole () {
	shellExecute('open', 'services.msc', '/s');
}
/**
 * ODBCコンソールを開く
 */
function openOdbcConsole () {
	shellExecute('open', 'odbcad32.exe');
}
/**
 * MocaScriptフォルダを開く
 */
function openMocaFolder () {
	openFolder(getShareFolder() + '\\script');
}
/**
 * URIをブラウズ
 * @var string uri
 */
function browse ( uri ) {
	shellExecute('open', uri);
}

ホーム > アーカイブ > 2007年12月3日のアーカイブ

Ad
Apache
MySQL
PHP
お気に入り
ん。。。。。。広告
アーカイブ
Ad

ページの上部に戻る