using System; using System.Collections.Generic; using System.Windows.Forms; using com.andoutomo.kybernetes.control; using com.andoutomo.kybernetes.data.DAO; using System.Drawing; namespace com.andoutomo.kybernetes.view { public partial class BaseForm : Form { public BaseForm() { InitializeComponent(); List initialText = new List(); initialText.Add("#####################################################"); initialText.Add("# " + AppInfoContainer.Title + " " + AppInfoContainer.Description); initialText.Add("# Version " + AppInfoContainer.VersionNo); initialText.Add("# " + AppInfoContainer.CopyRight); initialText.Add("# "); initialText.Add("#####################################################"); addMultiText(initialText); addPrompt(); history = new CmdHistory(); this.Text = AppInfoContainer.Title + " " + AppInfoContainer.Description; Echo = true; } private CmdHistory history; /// /// カテゴリ設定ダイアログを表示します。 /// /// internal void invokeCategSettingDialog(List arg) { CategorySetting categSetting = new CategorySetting(); categSetting.StartPosition = FormStartPosition.CenterParent; categSetting.setCategoryList(arg); categSetting.ShowDialog(); } /// /// バージョン情報を表示します /// internal void invokeCreditDialog() { Credit creditForm = new Credit(); creditForm.StartPosition = FormStartPosition.CenterParent; creditForm.ShowDialog(); } /// /// エクスポート用のファイルダイアログを開いて選択したファイルパスを返します。 /// /// internal string invokeExpDialog() { DialogResult result =this.expData.ShowDialog(); if (result == DialogResult.OK) { return this.expData.FileName; } else { return string.Empty; } } /// /// ダンプ用のファイルダイアログを開いて選択したファイルパスを返します。 /// /// internal string invokeDmpDialog() { DialogResult result = this.dmpData.ShowDialog(); if (result == DialogResult.OK) { return this.dmpData.FileName; } return string.Empty; } /// /// タイムエリア設定画面を表示します。 /// /// internal void invokeTimeareaSettingDialog(List arg) { TimeAreaSetting setting = new TimeAreaSetting(); setting.StartPosition = FormStartPosition.CenterParent; setting.setTimeareaList(arg); setting.ShowDialog(); } /// /// コンソールに文字列を表示します。 /// /// 表示したい文字列 internal void addText(string args) { rConsole.AppendText(args + System.Environment.NewLine); KybernetesLogger.Log.trace(args); } /// /// コンソールに複数文章を追加します。 /// /// 追加したい文章群 internal void addMultiText(List messages) { foreach (string message in messages) { addText(message); } rConsole.AppendText(System.Environment.NewLine); } private void addPrompt() { rConsole.AppendText("> "); } internal int getPanelSize() { return this.pnlTask.Width; } /// /// コンソールをクリアします。 /// internal void clearText() { rConsole.Clear(); } private bool exitSwitch = false; internal bool ExitSwitch { set { exitSwitch = value; } } private int lastRow=17; /// /// パネルを追加します。 /// /// internal void addPanel(TaskData data) { Panel targetPanel = new PanelController(this).createRow(lastRow,data); pnlTask.Controls.Add(targetPanel); lastRow += targetPanel.Height-1; } /// /// パネルがダブルクリックされた時に対応します。IDをテキストボックスに転記します。 /// /// internal void AddIDToText(string data) { this.txtInput.Text += data + " "; txtInput.Focus(); this.txtInput.Select(this.txtInput.Text.Length, 0); } /// /// パネルをクリアします。 /// internal void clearPanel() { int dummy = pnlTask.Controls.Count; for (int h = dummy; h > 0; h--) { Control ctrl = pnlTask.Controls[h - 1]; for (int i = ctrl.Controls.Count; i > 0; i--) { ctrl.Controls[i - 1].Dispose(); } ctrl.Dispose(); } //pnlTask.Controls.Clear(); //先頭行は足す pnlTask.Controls.Add(new CaptionPanelController().createRow(this.pnlTask.Width)); lastRow = 17; } /// /// コマンド内容を表示するかどうかを決定します。 /// internal bool Echo { get; set; } /// /// コマンド入力を受け付けます。 /// /// /// private void txtInput_KeyDown(object sender, KeyEventArgs e) { int currentYPosition; int currentScrollHeight = this.pnlTask.Height - 20; switch (e.KeyCode) { case Keys.Enter: e.SuppressKeyPress = true; doCommand(); break; case Keys.Space: if (e.Control) { e.SuppressKeyPress = true; if (txtInput.ImeMode == ImeMode.Off) { txtInput.ImeMode = ImeMode.On; } else { txtInput.ImeMode = ImeMode.Off; } } break; case Keys.Escape: e.SuppressKeyPress = true; history.resetPosition(); txtInput.Clear(); break; case Keys.Up: e.SuppressKeyPress = true; txtInput.Text = history.prevCommand(); txtInput.Select(this.txtInput.Text.Length, 0); break; case Keys.Down: e.SuppressKeyPress = true; txtInput.Text = history.nextCommand(); txtInput.Select(this.txtInput.Text.Length, 0); break; case Keys.PageDown: currentYPosition = Math.Abs(this.pnlTask.AutoScrollPosition.Y); this.pnlTask.AutoScrollPosition = new Point(0, currentYPosition + currentScrollHeight); break; case Keys.PageUp: currentYPosition = Math.Abs(this.pnlTask.AutoScrollPosition.Y); this.pnlTask.AutoScrollPosition = new Point(0, currentYPosition - currentScrollHeight); break; } } /// /// コマンドを実行します /// private void doCommand() { rConsole.Focus(); if (Echo) { addText(txtInput.Text); } KybernetesLogger.Log.trace("[dispatch]" + txtInput.Text); CmdDispatcher dispatcher = CmdDispatcher.getDispatcher(this); string result = dispatcher.dispatch(txtInput.Text.Trim()); if (!string.IsNullOrEmpty(result)) { addText(result); } addPrompt(); if (!string.IsNullOrEmpty(txtInput.Text)) { history.stackCmd(txtInput.Text); } txtInput.Clear(); txtInput.ImeMode = ImeMode.Off; panelResize(); if (exitSwitch == true) { this.Close(); } txtInput.Focus(); } /// /// 文字入力ボックスを表示します。 /// /// /// internal string showInputBox(string prompt) { return this.showInputBox(prompt, string.Empty); } /// /// 文字入力ボックスを表示します。 /// /// /// /// internal string showInputBox(string prompt, string defaultData) { return showInputBox(prompt, defaultData, ImeMode.Off); } /// /// 文字入力ボックスを表示します。 /// /// /// /// /// internal string showInputBox(string prompt, string defaultData, ImeMode imeMode) { InputBox inputBox = new InputBox(prompt, defaultData); inputBox.StartPosition = FormStartPosition.CenterParent; inputBox.ImeMode = imeMode; inputBox.Owner = this; DialogResult res = inputBox.ShowDialog(); if (res == DialogResult.OK) { return InputDialogData; } return null; } /// /// 文字入力ボックスを表示します。 /// /// /// /// internal string showInputBox(string prompt, ImeMode imeMode) { return showInputBox(prompt, string.Empty, imeMode); } /// /// 文字入力ボックスを表示します。プロンプトなし版です。 /// /// internal string showInputBox() { return showInputBox(""); } /// /// プロンプトで指定した値を(プロンプトがここに)格納します。 /// internal string InputDialogData { private get; set; } /// /// ドロップダウン式リストを表示します。 /// /// /// internal string showDropBoxInputBox(List list,string prompt) { DropBoxInputBox inputBox = new DropBoxInputBox(prompt); inputBox.StartPosition = FormStartPosition.CenterParent; inputBox.setDropData(list); inputBox.Owner = this; DialogResult res = inputBox.ShowDialog(); if (res == DialogResult.OK) { return InputDialogData; } return null; } /// /// ドロップダウン式リストを表示します。デフォルト表示を追加しています。 /// /// /// /// /// internal string showDropBoxInputBox(List list, string prompt, string defaultData) { DropBoxInputBox inputBox = new DropBoxInputBox(prompt,defaultData); inputBox.StartPosition = FormStartPosition.CenterParent; inputBox.setDropData(list); inputBox.Owner = this; DialogResult res = inputBox.ShowDialog(); if (res == DialogResult.OK) { return InputDialogData; } return null; } /// /// マウスでコンソールをドラッグした時に、選択対象を入力ボックスに追加します。 /// /// /// private void rConsole_MouseUp(object sender, MouseEventArgs e) { txtInput.Text += rConsole.SelectedText.Trim(); txtInput.Focus(); //選択状態を解除する this.txtInput.Select(this.txtInput.Text.Length, 0); } /// /// ウィンドウ全体のサイズ変更時イベントハンドラです。 /// /// /// private void BaseForm_ResizeEnd(object sender, EventArgs e) { panelResize(); } /// /// タスクパネルの大きさ調整を行います。 /// 起動されるのは、ウィンドウ全体のサイズ変更時、及びコマンド実行時です。 /// private void panelResize() { pnlTask.Size = new Size(this.Size.Width - 420, this.Size.Height - 50); } } }