/* ---------------------------------------------------------------------- * MocaScript File * $Id: openPeggyPad.ms,v 1.3 2004/07/05 14:06:03 nzawa Exp nzawa $ * * [Title] * Peggy Padでファイルを開くスクリプト * * [Description] * Peggyで編集中のファイルをPeggy Padで開くスクリプトです。 * 他にもメモファイルを開くなどの機能があります。 * * [Remarks] * OpenMemoFileを使うにはスクリプト変数MemoFileに、 * 既に存在するテキストファイルのパスを指定して下さい。 * * * Copyright (c) 2004 Nzawa * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * ----------------------------------------------------------------------*/ ///////////////////////////////////////////////////////////////////////////// // コマンド宣言 #command Menu "メニュー表示(&D)" #command OpenCurrentView "編集中のファイル(&F)" #command OpenCurrentViewCP "編集中のファイル(カーソル位置復元)(&C)" #command OpenSelectedProjectItem "選択されたプロジェクトアイテム(&P)" #command OpenNewFile "新規作成(&N)" #command OpenMemoFile "メモファイル(&M)" ///////////////////////////////////////////////////////////////////////////// // 設定 var PeggyPad = "C:\\Program Files\\Anchor\\PeggyPad\\PeggyPad.exe"; var MemoFile = "E:\\MN_Documents\\Memo.txt"; ///////////////////////////////////////////////////////////////////////////// // コマンド処理 setStatusText(); // ステータスバーの初期化 switchCommand(command); // コマンド処理用関数呼出し ///////////////////////////////////////////////////////////////////////////// // コマンド処理用関数 function switchCommand ( cmd ) { switch ( cmd ) { case "Menu": displayMenu(); break; case "OpenCurrentView": openCurrentView(); break; case "OpenCurrentViewCP": openCurrentView(true); break; case "OpenSelectedProjectItem": openSelectedProjectItem(); break; case "OpenNewFile": startPeggyPad(); setStatusText("新規ファイルを Peggy Pad で開きました。"); break; case "OpenMemoFile": if ( MemoFile ) { startPeggyPad(MemoFile); setStatusText("メモファイル " + MemoFile + " を Peggy Pad で開きました。"); } else { error("メモファイルが指定されていません。"); } break; default: error("コマンド " + command + " は未定義です。"); } return; } ///////////////////////////////////////////////////////////////////////////// // メニューを表示 function displayMenu () { var choice; choice = popupMenu([ ["編集中のファイル(&F)", "OpenCurrentView", false, "編集中のファイルを Peggy Pad で開く"], ["編集中のファイル(カーソル位置復元)(&C)", "OpenCurrentViewCP", false, "編集中のファイルを Peggy Pad で開く (カーソル位置も復元)"], ["選択されたプロジェクトアイテム(&P)", "OpenSelectedProjectItem", false, "選択されているプロジェクトアイテムを Peggy Pad で開く"], ["新規作成(&N)", "OpenNewFile", false, "新規ファイルを Peggy Pad で開く"], ["メモファイル(&M)", "OpenMemoFile", false, "メモファイルを Peggy Pad で開く"] ]); if ( choice ) switchCommand(choice); return; } ///////////////////////////////////////////////////////////////////////////// // 編集中のファイルをPeggy Padで開く function openCurrentView ( restoreCP ) { var filepath, line, index, modified; if ( !view ) error("編集中のファイルがありません。"); line = CP.line; index = CP.index + 1; filepath = getFilePath(); if ( !filepath ) error("編集中のファイルを取得出来ません。"); if ( isModified() ) { if ( messageBox("ファイルが変更されています。変更を無視して開きますか?", MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2) == IDYES ) { modified = true; } else { setWarningStatusText("ファイルが変更されていたので処理を中止しました。"); return; } } if ( restoreCP ) startPeggyPad(filepath, line, index, true); else startPeggyPad(filepath, line, index); if ( !modified ) setStatusText("編集中のファイル " + filepath + " を Peggy Pad で開きました。"); else setWarningStatusText("編集中のファイル " + filepath + " を Peggy Pad で開きました。 (変更無視)"); return; } ///////////////////////////////////////////////////////////////////////////// // 選択されているプロジェクトアイテムをPeggy Padで開く function openSelectedProjectItem () { var item, filepath; if ( !project ) error("プロジェクトが開かれていません。"); item = project.selected; if ( !(item instanceof FileItem) ) error("プロジェクトアイテム " + item + " はファイルではありません。"); filepath = item.path; startPeggyPad(filepath); setStatusText("プロジェクトアイテム " + filepath + " を Peggy Pad で開きました。"); return; } ///////////////////////////////////////////////////////////////////////////// // Peggy Padを起動する関数 function startPeggyPad ( file, line, index, withLOption ) { var param; if ( withLOption ) param = "-L" + line + "." + index + " " + file; else param = file; shellExecute("open", PeggyPad, param); return; }