OSDN Git Service

[denncoCreator] fixed a crash issue.
[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     if (cell)
37         d_attacher = DCCodeEditorScriptManager::createCustomScriptAttacher(this, cell);
38 }
39
40 void DCEditScriptFolder::attach(DCCellCode *cellCode)
41 {
42     deattach();
43     if (cellCode)
44         d_attacher = DCCodeEditorScriptManager::createCellCodeScriptAttacher(this, cellCode);
45 }
46
47 void DCEditScriptFolder::deattach()
48 {
49     if (d_attacher)
50     {
51         delete d_attacher;
52         d_attacher = NULL;
53     }
54 }
55
56 QString DCEditScriptFolder::getCurrentScript(bool forceReload)
57 {
58     if (d_attacher)
59     {
60         return d_attacher->getCurrentScript(forceReload);
61     }
62     return "";
63 }
64 bool DCEditScriptFolder::getIsModified() const
65 {
66     if (d_attacher)
67     {
68         return d_attacher->getIsModified();
69     }
70     return false;
71 }
72
73 bool DCEditScriptFolder::getIsFileModifiedByExternalEditor() const
74 {
75     if (d_attacher)
76     {
77         return d_attacher->getIsFileModifiedByExternalEditor();
78     }
79     return false;
80 }
81
82 qint64 DCEditScriptFolder::getLoadedTime() const
83 {
84     if (d_attacher)
85     {
86         return d_attacher->getLoadedTime();
87     }
88     return 0;
89 }
90
91 void DCEditScriptFolder::setScript(const QString& newScript)
92 {
93     if (d_attacher)
94     {
95         d_attacher->setScript(newScript);
96     }
97 }
98
99 bool DCEditScriptFolder::saveScript()
100 {
101     if (d_attacher)
102     {
103         return d_attacher->saveScript();
104     }
105     return false;
106 }
107
108 void DCEditScriptFolder::callbackScriptChanged()
109 {
110     emit scriptChanged();
111 }
112
113 void DCEditScriptFolder::callbackModificationStatusChanged(bool modified)
114 {
115     emit modificationStatusChanged(modified);
116 }
117
118 void DCEditScriptFolder::callbackFileModifiedByExternalEditor(qint64 notifiedTime)
119 {
120     emit fileModifiedByExternalEditor(notifiedTime);
121 }