File: CommandTree.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 35,764 kB
  • ctags: 26,929
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (127 lines) | stat: -rw-r--r-- 3,895 bytes parent folder | download | duplicates (6)
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
#if !JAVA
/*
 * CommandTree.cs
 * Copyright © 2009-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.
 */
using System;

namespace org.kbinani.cadencii {

#if TREECOM
    /// <summary>
    /// 分岐可能なコマンド履歴
    /// </summary>
    public partial class EditorManager {
        private ICommand s_root;
        private ICommand s_current = null;
        public VsqFileEx m_vsq = null;

        public EditorManager() {
            ID = org.kbinani.misc.getmd5( DateTime.Now.ToBinary().ToString() );
            s_root = new CadenciiCommand( Boare.Lib.Vsq.VsqCommand.generateCommandRoot() );
        }

        public VsqFileEx VsqFile {
            get {
                return m_vsq;
            }
        }

        public boolean IsRedoAvailable {
            get {
                if ( s_current == null ) {
                    return false;
                } else {
                    if ( s_current.Child.Count > 0 ) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        }

        public void ClearCommandBuffer() {
            s_root.Child.Clear();
            s_current = null;
        }

        public boolean IsUndoAvailable {
            get {
                if ( s_current != null ) {
                    if ( Object.ReferenceEquals( s_root, s_current ) ) {
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            }
        }

        /*public static ICommand[] GetAvailableRedoCommand() {
            
        }

        public static ICommand[] GetAvailableUndoCommand() {
        }*/

        public void Redo() {
            Redo( 0 );
        }

        public void Redo( int index ) {
            if ( s_current.Child.Count > 0 ) {
                ICommand run = s_current.Child[index];
                ICommand rev = VsqFile.executeCommand( run );
                rev.Parent = s_current;
                for ( int i = 0; i < run.Child.Count; i++ ) {
                    run.Child[i].Parent = rev;
                    rev.Child.Add( run.Child[i] );
                }
                s_current.Child[index] = rev;
                s_current = run;
            }
        }

        public void Undo() {
            ICommand run = s_current;
            ICommand rev = VsqFile.executeCommand( run );
            for ( int i = 0; i < s_current.Child.Count; i++ ) {
                s_current.Child[i].Parent = rev;
                rev.Child.Add( s_current.Child[i] );
            }
            rev.Parent = s_current.Parent;
            for ( int i = 0; i < s_current.Parent.Child.Count; i++ ) {
                if ( Object.ReferenceEquals( s_current, s_current.Parent.Child[i] ) ) {
                    s_current.Parent.Child[i] = rev;
                    break;
                }
            }
            s_current = s_current.Parent;
        }

        public void Register( ICommand command ) {
            if ( s_current == null ) {
                s_root.Child.Add( command );
                command.Parent = s_root;
            } else {
                s_current.Child.Insert( 0, command );
                command.Parent = s_current;
            }
            s_current = command;
        }
    }
#endif
}
#endif