1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* EditHistory.cs
* Copyright © 2011 kbinani
*
* This file is part of org.kbinani.cadencii.
*
* org.kbinani.cadencii is free software; you can redistribute it and/or
* modify it under the terms of the GPLv3 License.
*
* org.kbinani.cadencii is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.cadencii;
import java.util.*;
#else
using org.kbinani.java.util;
namespace org
{
namespace kbinani
{
namespace cadencii
{
#endif
/// <summary>
/// 編集操作の履歴を管理するModel
/// </summary>
public class EditHistoryModel
{
private static Vector<ICommand> mCommands = new Vector<ICommand>();
private static int mCommandIndex = -1;
/// <summary>
/// ヒストリーに編集履歴を登録する
/// </summary>
/// <param name="command">登録する履歴</param>
public void register( ICommand command )
{
if( mCommandIndex == mCommands.size() - 1 ) {
// 新しいコマンドバッファを追加する場合
mCommands.add( command );
mCommandIndex = mCommands.size() - 1;
} else {
// 既にあるコマンドバッファを上書きする場合
mCommands.set( mCommandIndex + 1, command );
for( int i = mCommands.size() - 1; i >= mCommandIndex + 2; i-- ) {
mCommands.removeElementAt( i );
}
mCommandIndex++;
}
}
/// <summary>
/// 編集履歴を消去する
/// </summary>
public void clear()
{
mCommands.clear();
mCommandIndex = -1;
}
/// <summary>
/// UNDO用のヒストリーを取得できるかどうか調べる
/// </summary>
/// <returns>UNDO用のヒストリーを取得できる場合trueを,そうでなければfalseを返す</returns>
public bool hasUndoHistory()
{
if( mCommands.size() > 0 && 0 <= mCommandIndex && mCommandIndex < mCommands.size() ) {
return true;
} else {
return false;
}
}
/// <summary>
/// REDO用のヒストリーを取得できるかどうか調べる
/// </summary>
/// <returns>REDO用のヒストリーを取得できる場合trueを,そうでなければfalseを返す</returns>
public bool hasRedoHistory()
{
if( mCommands.size() > 0 && 0 <= mCommandIndex + 1 && mCommandIndex + 1 < mCommands.size() ) {
return true;
} else {
return false;
}
}
/// <summary>
/// UNDO用のコマンドを取得する
/// </summary>
/// <returns></returns>
public ICommand getUndo()
{
return mCommands.get( mCommandIndex );
}
/// <summary>
/// REDO用のコマンドを取得する
/// </summary>
/// <returns></returns>
public ICommand getRedo()
{
return mCommands.get( mCommandIndex + 1 );
}
/// <summary>
/// UNDO処理後に発生したコマンドを登録する
/// </summary>
/// <param name="command"></param>
public void registerAfterUndo( ICommand command )
{
mCommands.set( mCommandIndex, command );
mCommandIndex--;
}
/// <summary>
/// REDO処理後に発生したコマンドを登録する
/// </summary>
/// <param name="command"></param>
public void registerAfterRedo( ICommand command )
{
mCommands.set( mCommandIndex + 1, command );
mCommandIndex++;
}
}
#if !JAVA
}
}
}
#endif
|