OSDN Git Service

[denncoCreator] Implemented the functionality to check if editing script file is...
[dennco/denncoCreator.git] / Source / codeeditor / dceditscriptfolder.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on Dec-8, 2012.
18 //
19 #include "dceditscriptfolder.h"
20
21 #include "dccodeeditorscriptmanager.h"
22
23 DCEditScriptFolder::DCEditScriptFolder(QObject *parent) :
24     QObject(parent), d_attacher(NULL)
25 {
26 }
27
28 DCEditScriptFolder::~DCEditScriptFolder()
29 {
30     deattach();
31 }
32
33 void DCEditScriptFolder::attach(DCCell *cell)
34 {
35     deattach();
36     d_attacher = DCCodeEditorScriptManager::createCustomScriptAttacher(this, cell);
37 }
38
39 void DCEditScriptFolder::attach(DCCellCode *cellCode)
40 {
41     deattach();
42     d_attacher = DCCodeEditorScriptManager::createCellCodeScriptAttacher(this, cellCode);
43 }
44
45 void DCEditScriptFolder::deattach()
46 {
47     if (d_attacher)
48     {
49         delete d_attacher;
50         d_attacher = NULL;
51     }
52 }
53
54 QString DCEditScriptFolder::getCurrentScript(bool forceReload)
55 {
56     if (d_attacher)
57     {
58         return d_attacher->getCurrentScript(forceReload);
59     }
60     return "";
61 }
62 bool DCEditScriptFolder::getIsModified() const
63 {
64     if (d_attacher)
65     {
66         return d_attacher->getIsModified();
67     }
68     return false;
69 }
70
71 bool DCEditScriptFolder::getIsFileModifiedByExternalEditor() const
72 {
73     if (d_attacher)
74     {
75         return d_attacher->getIsFileModifiedByExternalEditor();
76     }
77     return false;
78 }
79
80 qint64 DCEditScriptFolder::getLoadedTime() const
81 {
82     if (d_attacher)
83     {
84         return d_attacher->getLoadedTime();
85     }
86     return 0;
87 }
88
89 void DCEditScriptFolder::setScript(const QString& newScript)
90 {
91     if (d_attacher)
92     {
93         d_attacher->setScript(newScript);
94     }
95 }
96
97 bool DCEditScriptFolder::saveScript()
98 {
99     if (d_attacher)
100     {
101         return d_attacher->saveScript();
102     }
103     return false;
104 }
105
106 void DCEditScriptFolder::callbackScriptChanged()
107 {
108     emit scriptChanged();
109 }
110
111 void DCEditScriptFolder::callbackModificationStatusChanged(bool modified)
112 {
113     emit modificationStatusChanged(modified);
114 }
115
116 void DCEditScriptFolder::callbackFileModifiedByExternalEditor(qint64 notifiedTime)
117 {
118     emit fileModifiedByExternalEditor(notifiedTime);
119 }