-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAction.EditText.js
78 lines (72 loc) · 2.43 KB
/
Action.EditText.js
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
/*
* This file is part of Min.
*
* Min is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Min 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Min. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Richard Pospesel, Kevin Hart, Lei Hu, Siyu Zhu, David Stalnaker,
* Christopher Sasarak, Robert LiVolsi, Awelemdy Orakwue, and Richard Zanibbi
* (Document and Pattern Recognition Lab, RIT)
*/
/*
Defines a command object to undo/redo text additions to the canvas via keyboard.
*/
EditText = function(in_text_segment)
{
this.text_segment = in_text_segment;
this.previous_text = String(in_text_segment.text);
this.current_text = "";
}
EditText.prototype.Undo = function()
{
this.text_segment.text = this.previous_text;
var context = Editor.contexts[2];
this.text_segment.text_width = context.measureText(this.text_segment.text).width;
this.text_segment.size.x = this.text_segment.text_width;
this.text_segment.update_extents();
}
EditText.prototype.set_current_text = function(in_text)
{
this.current_text = new String(in_text);
}
EditText.prototype.shouldKeep = function()
{
if(this.text_segment.text == this.previous_text)
return false;
return true;
}
EditText.prototype.Apply = function()
{
this.text_segment.text = this.current_text;
var context = Editor.contexts[2];
this.text_segment.text_width = context.measureText(this.text_segment.text).width;
this.text_segment.size.x = this.text_segment.text_width;
this.text_segment.update_extents();
}
EditText.prototype.toXML = function()
{
var sb = new StringBuilder();
sb.append("<Action type=\"edit_text\" instanceID=\"");
sb.append(String(this.text_segment.instance_id));
sb.append("\" newText=\"");
sb.append(this.current_text);
sb.append("\" oldText=\"");
sb.append(this.previous_text);
sb.append("\"/>");
return sb.toString();
// return "<Action type=\"edit_text\" " + \>";
}
EditText.prototype.toString = function()
{
return "EditText";
}