-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSolidFileSaveCommand.cpp
More file actions
153 lines (121 loc) · 3.24 KB
/
Copy pathSolidFileSaveCommand.cpp
File metadata and controls
153 lines (121 loc) · 3.24 KB
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
#include "SolidFileSaveCommand.h"
#include "AliceIMainWindow.h"
#include "AliceIDocumentManager.h"
#include "AliceIDocument.h"
#include "AliceCommandParameter.h"
#include "AliceIOperation.h"
#include "SolidDesignerCommands.h"
using namespace alice;
using namespace sdr;
SolidFileSaveCommand::SolidFileSaveCommand() noexcept
{
}
const std::string_view& SolidFileSaveCommand::Id() const noexcept
{
return sdr::Cmd::FILE_SAVE;
}
bool SolidFileSaveCommand::IsSupported() const
{
//return (m_mainWindow != nullptr) && (m_docManager != nullptr);
return false;
}
bool SolidFileSaveCommand::IsVisible() const
{
return IsSupported();
}
bool SolidFileSaveCommand::IsEnabled() const
{
if (!IsSupported())
return false;
IDocument* doc = getActiveDocument_();
return (doc != nullptr);
}
std::string SolidFileSaveCommand::DisabledReason() const
{
//if (!m_mainWindow)
// return "Main window is not available.";
//if (!m_docManager)
// return "Document manager is not available.";
if (!getActiveDocument_())
return "There is no active document to save.";
return {};
}
std::unique_ptr<IOperation> SolidFileSaveCommand::Execute(const CommandParameter& param)
{
if (!IsEnabled())
return nullptr;
IDocument* doc = getActiveDocument_();
if (!doc)
return nullptr;
std::wstring path;
bool isSaveAs = false;
if (hasFilePath_(*doc)) {
// 已有路径:直接保存
path = getFilePath_(*doc);
isSaveAs = false;
}
else
{
path = showSaveAsDialog_(L"");
if (path.empty())
return nullptr;
isSaveAs = true;
}
const bool ok = saveDocument_(*doc, path, isSaveAs);
if (!ok)
{
}
// 保存文件通常不进 Undo/Redo
return nullptr;
}
IDocument* SolidFileSaveCommand::getActiveDocument_() const
{
//if (!m_docManager)
// return nullptr;
//return m_docManager->GetActiveDocument();
return nullptr;
}
bool SolidFileSaveCommand::hasFilePath_(IDocument& doc) const
{
//return doc.HasFilePath();
return false;
}
std::wstring SolidFileSaveCommand::getFilePath_(IDocument& doc) const
{
//return doc.GetFilePath();
return std::wstring();
}
std::wstring SolidFileSaveCommand::showSaveAsDialog_(const std::wstring& hintPath) const
{
//QWidget* parent = m_mainWindow ? m_mainWindow->AsQMainWindow() : nullptr;
//QString dir;
//QString suggested;
//if (!hintPath.empty()) {
// const QString qpath = QString::fromStdWString(hintPath);
// QFileInfo fi(qpath);
// dir = fi.absolutePath();
// suggested = fi.fileName();
//}
//const QString filter = QObject::tr("Alice Documents (*.alice);;" "All Files (*.*)");
//const QString file = QFileDialog::getSaveFileName(parent, QObject::tr("Save File"),
// dir.isEmpty() ? suggested : dir + QLatin1Char('/') + suggested,
// filter);
//if (file.isEmpty())
// return {};
//return file.toStdWString();
return std::wstring();
}
bool SolidFileSaveCommand::saveDocument_(IDocument& doc, const std::wstring& path, bool isSaveAs) const
{
//if (!m_docManager)
// return false;
//if (isSaveAs)
//{
// return m_docManager->SaveAs(doc, path); // TODO: 对齐你的 API
//}
//else
//{
// return m_docManager->Save(doc);
//}
return false;
}