/// <summary> /// ファイルを保存する /// </summary> /// <param name="editor">保存するエディタ</param> /// <param name="fileName">ファイル名</param> public void SaveFile(IEditorDocContent editor, string fileName) { editor.SaveFile(fileName); //保存する if (editor is EditorForm) { ((EditorForm)editor).TextEditor.ParseFile(); //構文解析開始 } }
/// <summary> /// 現在アクティブなタブ以外を全て閉じる /// </summary> /// <returns></returns> public bool CloseFileOtherAll() { IEditorDocContent editor = ActiveDocument; if (editor == null) { //現在アクティブなエディタがないので何もせずに終了 return(true); } //現在アクティブなエディタの位置を取得する int docLen = 0; IDockContent[] docList = m_mainPanel.Documents; int activeEditorIndex = 0; for (int i = 0; i < docList.Length; i++) { if (editor == docList[i]) { activeEditorIndex = i; } if (docList[i] is IEditorDocContent) { docLen++; } } //ドッキングウィンドウからエディタを検索する for (int i = 0; i < docList.Length; i++) { if (i != activeEditorIndex) //アクティブだったエディタではないとき { if (docList[i] is IEditorDocContent) { //エディタを閉じる editor = (IEditorDocContent)docList[i]; editor.ActivateForm(); editor.CloseForm(); if (editor.IsClosed == false) { //閉じることができなかったので失敗を返す return(false); } } } } //すべて閉じれたので成功を返す return(true); }
/// <summary> /// エディタを閉じる /// 未保存の時は保存するかどうかのダイアログを表示する /// エディタを閉じるのに成功したらtrueを返す /// </summary> public bool CloseFile() { IEditorDocContent editor = ActiveDocument; if (editor == null) { //閉じるエディタがないので何もせずに終了 return(true); } //現在アクティブなエディタの位置を取得する int docLen = 0; IDockContent[] docList = m_mainPanel.Documents; int activeEditorIndex = 0; for (int i = 0; i < docList.Length; i++) { if (editor == docList[i]) { activeEditorIndex = i; } if (docList[i] is IEditorDocContent) { docLen++; } } //閉じる editor.CloseForm(); if (editor.IsClosed == true) { if (docLen > 1) //自分とこれからアクティブにする個数分だけ存在するとき { //閉じるエディタの一つ前の位置をアクティブにする int index = 0; if (activeEditorIndex == 0) { //前がいないので一つ後ろを指定する index = 1; } else { //一つ前を指定する index = activeEditorIndex - 1; } ((IEditorDocContent)docList[index]).ActivateForm(); } } return(editor.IsClosed); }
/// <summary> /// ファイルを開く /// </summary> /// <param name="filePath">開くファイルのパス</param> public IEditorDocContent LoadFile(string filePath) { if (File.Exists(filePath) == false) { util.Msgbox.Error(filePath + "\nファイルが見つかりませんでした。"); return(null); } GlobalStatus.EnvOption.HistoryFile.Add(filePath); //履歴に追加する //ドッキングウィンドウからエディタすべて探索する IDockContent[] docList = m_mainPanel.Documents; foreach (IDockContent doc in docList) { if (doc is IEditorDocContent) { if (filePath == ((IEditorDocContent)doc).FileName) { //すでに開いているときはファイルを読み込まずにそれをアクティブにする ((IEditorDocContent)doc).ActivateForm(); return((IEditorDocContent)doc); } } } //タブの生成と読み込み IEditorDocContent nweDoc = null; if (FileType.GetKrkrType(filePath) == FileType.KrkrType.Screen) { ScreenMakerForm screen = new ScreenMakerForm(); screen.LoadFile(filePath); screen.Show(m_mainPanel); nweDoc = screen; } else { EditorForm editor = createEditorForm(); ConvertEncoding(filePath); //文字コード調整 editor.LoadFile(filePath); //ファイル読み込み SetOption(editor.TextEditor); //エディタオプションのセット editor.TextEditor.LoadBookmarkFormList(); //ブックマークのセット editor.Show(m_mainPanel); //表示する GlobalStatus.FormManager.MainForm.UpdateStatusBar(editor.TextEditor); editor.TextEditor.UpdateFolding(); //折りたたみのセット editor.TextEditor.ActiveTextArea.Focus(); //フォーカスをセットする nweDoc = editor; } return(nweDoc); }
/// <summary> /// 名前をつけて保存する(保存エディタ指定) /// </summary> /// <param name="editor">保存するエディタオブジェクト</param> public void SaveFileAs(IEditorDocContent editor) { //保存先選択ダイアログを表示する SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "名前をつけて保存"; saveDialog.Filter = "KAGシナリオファイル (*.ks)|*.ks|TJSファイル (*.tjs)|*.tjs|テキストファイル (*.txt)|*.txt|すべてのファイル (*.*)|*.*"; saveDialog.InitialDirectory = GlobalStatus.Project.DirPath; if (saveDialog.ShowDialog() == DialogResult.OK) { //指定したパスで保存する this.SaveFile(editor, saveDialog.FileName); if (editor is EditorForm) { SetOption(((EditorForm)editor).TextEditor); //エディタオプションのセット } } }
/// <summary> /// 上書き保存する(保存エディタ指定) /// </summary> /// <param name="editor">保存するエディタオブジェクト</param> public void SaveFile(IEditorDocContent editor) { if (editor == null) { //保存するエディタがないので何もしない return; } Debug.WriteLine("SaveFile: FileName=" + editor.FileName); if (File.Exists(editor.FileName)) { //ファイルが存在するため上書き保存する this.SaveFile(editor, editor.FileName); } else { //ファイルがまだ作成されていないため、名前をつけて保存する this.SaveFileAs(editor); } }
/// <summary> /// すべてのエディタを閉じる /// すべて閉じたらtrueを返す /// </summary> public bool CloseFileAll() { //ドッキングウィンドウからエディタを検索する IDockContent[] docList = m_mainPanel.Documents; foreach (IDockContent doc in docList) { if (doc is IEditorDocContent) { //エディタを閉じる IEditorDocContent editor = (IEditorDocContent)doc; editor.ActivateForm(); editor.CloseForm(); if (editor.IsClosed == false) { //閉じることができなかったので失敗を返す return(false); } } } //すべて閉じれたので成功を返す return(true); }