aboutsummaryrefslogtreecommitdiff
path: root/js/document/views/code.js
blob: 66d1c70210a6c717446be0e1651bb17cd927e545 (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

////////////////////////////////////////////////////////////////////////
//
var Montage = 			require("montage/core/core").Montage,
	Component = 		require("montage/ui/component").Component,
	BaseDocumentView = 	require("js/document/views/base").BaseDocumentView;
////////////////////////////////////////////////////////////////////////
//	
var CodeDocumentView = exports.CodeDocumentView = Montage.create(BaseDocumentView, {
	////////////////////////////////////////////////////////////////////
	//
	hasTemplate: {
		enumerable: false,
        value: false
    },

    ////////////////////////////////////////////////////////////////////
    //
    _editor: {
        value: null
    },
    ////////////////////////////////////////////////////////////////////
    //
    editor: {
        get: function() {return this._editor;},
        set: function(value) {this._editor= value;}
    },
    ////////////////////////////////////////////////////////////////////
    //
    _textArea: {
        value: null
    },
    ////////////////////////////////////////////////////////////////////
    //
    textArea: {
        get: function() {return this._textArea;},
        set: function(value) {this._textArea= value;}
    },
    ////////////////////////////////////////////////////////////////////
    //
    _textViewContainer: {
        value: null
    },
    ////////////////////////////////////////////////////////////////////
    //
    textViewContainer: {
        get: function() {return this._textViewContainer;},
        set: function(value) {this._textViewContainer= value;}
    },
    ////////////////////////////////////////////////////////////////////
    //

    /**
     * Public method
     */
    initialize:{
        value: function(parentContainer){
            //create contianer
            this.textViewContainer = document.createElement("div");
            //this.textViewContainer.id = "codemirror_" + uuid;
            this.textViewContainer.style.display = "block";
            parentContainer.appendChild(this.textViewContainer);

            //create text area
            this.textArea = this.createTextAreaElement();
        }
    },

    /**
     * Public method
     * Creates a textarea element which will contain the content of the opened text document.
     */
    createTextAreaElement: {
        value: function() {
            var textArea = document.createElement("textarea");
//            textArea.id = "code";
//            textArea.name = "code";
            this.textViewContainer.appendChild(textArea);

            return textArea;
        }
    },
    ////////////////////////////////////////////////////////////////////
    //
    /**
     * Public method
     * Creates a new instance of a code editor
     */
    initializeTextView: {
        value: function(file, textDocument) {
            var type;

            if(this.activeDocument) {
                //need to hide only if another document was open before
//                this.application.ninja.documentController._hideCurrentDocument();
//                this.hideOtherDocuments(doc.uuid);
            }

            switch(file.extension) {
                case  "css" :
                    type = "css";
                    break;
                case "js" :
                    type = "javascript";
                    break;
                case "html" :
                    type = "htmlmixed";
                    break;
                case "json" :
                    type = "javascript";
                    break;
                case "php" :
                    type = "php";
                    break;
                case "pl" :
                    type = "perl";
                    break;
                case "py" :
                    type = "python";
                    break;
                case "rb" :
                    type = "ruby";
                    break;
                case "xml" :
                    type = "xml";
                    break;
            }
            this.textViewContainer.style.display="block";

            this.editor = this.application.ninja.codeEditorController.createEditor(this, type, file.extension, textDocument);
            this.editor.hline = this.editor.setLineClass(0, "activeline");


        }
    },
    ////////////////////////////////////////////////////////////////////
    //
    show: {
        value: function (callback) {
            this.textViewContainer.style.display = "block";
            //
            if (callback) callback();
        }
    },
    ////////////////////////////////////////////////////////////////////
    //
    hide: {
        value: function (callback) {
            this.textViewContainer.style.display = "none";
            //
            if (callback) callback();
        }
    },
    ////////////////////////////////////////////////////////////////////
    //
    applyTheme:{
        value:function(themeClass){
            //Todo: change for bucket structure of documents
            this.textViewContainer.className = "codeViewContainer "+themeClass;
        }
    }
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
});
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////