Skip to content

Commit fa0fb89

Browse files
committed
feat(api)!: 新增脚本 url 对象;优化程序;
1 parent b98ba86 commit fa0fb89

23 files changed

+1753
-1090
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ set(SCRIPT_ADDON_SRC
460460
src/scriptaddon/scriptqstring.cpp
461461
src/scriptaddon/scriptqdictionary.h
462462
src/scriptaddon/scriptqdictionary.cpp
463+
src/scriptaddon/scripturl.h
464+
src/scriptaddon/scripturl.cpp
463465
src/scriptaddon/scriptregex.h
464466
src/scriptaddon/scriptregex.cpp
465467
src/scriptaddon/scriptcolor.h

TestPlugin/readertestform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void ReaderTestForm::on_btnStatus_clicked() {
8282
QStringLiteral("[Status]") % lf %
8383
QStringLiteral("isCurrentDocEditing: ") %
8484
(isCurrentDocEditing() ? strue : sfalse) % lf %
85-
QStringLiteral("currentDocFile: ") % currentDocFile() % lf %
85+
QStringLiteral("currentDocFile: ") % currentDocFileName() % lf %
8686
QStringLiteral("isReadOnly: ") % (isReadOnly() ? strue : sfalse) % lf %
8787
QStringLiteral("isKeepSize: ") % (isKeepSize() ? strue : sfalse) % lf %
8888
QStringLiteral("isLocked: ") % (isLocked() ? strue : sfalse) % lf %

WingPlugin

lang/en_US/winghex_en_US.ts

Lines changed: 345 additions & 345 deletions
Large diffs are not rendered by default.

lang/zh_CN/winghex_zh_CN.ts

Lines changed: 345 additions & 345 deletions
Large diffs are not rendered by default.

lang/zh_TW/winghex_zh_TW.ts

Lines changed: 345 additions & 345 deletions
Large diffs are not rendered by default.

src/class/aspreprocesser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(
3939
"__AS_MATH__", "__AS_WEAKREF__", "__AS_COROUTINE__", "__AS_FILE__",
4040
"__AS_FILESYSTEM__", "__WING_STRING__", "__WING_COLOR__", "__WING_JSON__",
4141
"__WING_REGEX__", "__WING_DICTIONARY__", "__WING_PRINT_VAR__",
42-
"__WING_PRINT_LN__", "__WING_CLIPBOARD__"}));
42+
"__WING_PRINT_LN__", "__WING_CLIPBOARD__", "__WING_URL__"}));
4343

4444
AsPreprocesser::AsPreprocesser(asIScriptEngine *engine) : engine(engine) {
4545
Q_ASSERT(engine);

src/class/astype_evaluator.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,67 @@ class asIDBCharTypeEvaluator : public asIDBObjectTypeEvaluator {
227227
}
228228
};
229229

230+
class asIDBUrlTypeEvaluator : public asIDBObjectTypeEvaluator {
231+
public:
232+
virtual void Evaluate(asIDBVariable::Ptr var) const override {
233+
auto &dbg = var->dbg;
234+
auto &cache = *dbg.cache;
235+
auto ctx = cache.ctx;
236+
auto type = ctx->GetEngine()->GetTypeInfoById(var->address.typeId);
237+
if (type == nullptr) {
238+
return;
239+
}
240+
var->typeName = cache.GetTypeNameFromType(var->address.typeId);
241+
var->expandable = true;
242+
243+
const QUrl *s = var->address.ResolveAs<const QUrl>();
244+
var->value = fmt::format("url<\"{}\">", s->fileName().toStdString());
245+
}
246+
247+
virtual void Expand(asIDBVariable::Ptr var) const override {
248+
auto &dbg = var->dbg;
249+
auto &cache = *dbg.cache;
250+
auto ctx = cache.ctx;
251+
auto type = ctx->GetEngine()->GetTypeInfoByName("string");
252+
if (type == nullptr) {
253+
return;
254+
}
255+
auto typeID = type->GetTypeId();
256+
const QUrl *s = var->address.ResolveAs<const QUrl>();
257+
258+
{
259+
// scheme
260+
auto child = var->CreateChildVariable(
261+
"[scheme]", {}, cache.GetTypeNameFromType({typeID, asTM_NONE}));
262+
child->evaluated = true;
263+
child->value = fmt::format("\"{}\"", s->scheme().toStdString());
264+
}
265+
{
266+
// authority
267+
auto child = var->CreateChildVariable(
268+
"[authority]", {},
269+
cache.GetTypeNameFromType({typeID, asTM_NONE}));
270+
child->evaluated = true;
271+
child->value = fmt::format("\"{}\"", s->authority().toStdString());
272+
}
273+
{
274+
// path
275+
auto child = var->CreateChildVariable(
276+
"[path]", {}, cache.GetTypeNameFromType({typeID, asTM_NONE}));
277+
child->evaluated = true;
278+
child->value = fmt::format("\"{}\"", s->path().toStdString());
279+
}
280+
{
281+
// fileName
282+
auto child = var->CreateChildVariable(
283+
"[fileName]", {},
284+
cache.GetTypeNameFromType({typeID, asTM_NONE}));
285+
child->evaluated = true;
286+
child->value = fmt::format("\"{}\"", s->fileName().toStdString());
287+
}
288+
}
289+
};
290+
230291
class asIDBColorTypeEvaluator : public asIDBObjectTypeEvaluator {
231292
public:
232293
virtual void Evaluate(asIDBVariable::Ptr var) const override {

src/class/aswingcache.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ asWingCache::asWingCache(asDebugger &dbg, asIScriptContext *ctx)
3333
registerEvaluator<asIDBDictionaryTypeEvaluator>(engine, "dictionary");
3434
registerEvaluator<asIDBAnyTypeEvaluator>(engine, "any");
3535
registerEvaluator<asIDBColorTypeEvaluator>(engine, "color");
36+
registerEvaluator<asIDBUrlTypeEvaluator>(engine, "url");
3637
registerEvaluator<asIDBRegExTypeEvaluator>(engine, "regex::exp");
3738
registerEvaluator<asIDBRegMatchTypeEvaluator>(engine, "regex::match");
3839
registerEvaluator<asIDBJsonDocumentTypeEvaluator>(engine,

src/class/pluginsystem.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ bool PluginSystem::isCurrentDocEditing(const QObject *sender) {
557557
return pluginCurrentEditor(plg) != nullptr;
558558
}
559559

560-
QString PluginSystem::currentDocFile(const QObject *sender) {
560+
QUrl PluginSystem::currentDocFile(const QObject *sender) {
561561
auto plg = checkPluginAndReport(sender, __func__);
562562
if (plg == nullptr) {
563563
return {};
@@ -570,6 +570,45 @@ QString PluginSystem::currentDocFile(const QObject *sender) {
570570
return {};
571571
}
572572

573+
QString PluginSystem::currentDocFileName(const QObject *sender) {
574+
auto plg = checkPluginAndReport(sender, __func__);
575+
if (plg == nullptr) {
576+
return {};
577+
}
578+
579+
auto e = pluginCurrentEditor(plg);
580+
if (e) {
581+
return e->currentDocFileName(this);
582+
}
583+
return {};
584+
}
585+
586+
QUrl PluginSystem::currentDocWorkSpace(const QObject *sender) {
587+
auto plg = checkPluginAndReport(sender, __func__);
588+
if (plg == nullptr) {
589+
return {};
590+
}
591+
592+
auto e = pluginCurrentEditor(plg);
593+
if (e) {
594+
return e->currentDocWorkSpace(this);
595+
}
596+
return {};
597+
}
598+
599+
QString PluginSystem::currentDocWorkSpaceName(const QObject *sender) {
600+
auto plg = checkPluginAndReport(sender, __func__);
601+
if (plg == nullptr) {
602+
return {};
603+
}
604+
605+
auto e = pluginCurrentEditor(plg);
606+
if (e) {
607+
return e->currentDocWorkSpaceName(this);
608+
}
609+
return {};
610+
}
611+
573612
bool PluginSystem::isReadOnly(const QObject *sender) {
574613
auto plg = checkPluginAndReport(sender, __func__);
575614
if (plg == nullptr) {
@@ -2223,7 +2262,7 @@ ErrFile PluginSystem::exportCurrent(const QObject *sender,
22232262
}
22242263

22252264
if (view) {
2226-
auto ws = _win->m_views.value(view);
2265+
auto ws = view->workSpaceName();
22272266
return view->save(ws, savename, true,
22282267
EditorView::SaveWorkSpaceAttr::AutoWorkSpace);
22292268
}
@@ -2246,7 +2285,7 @@ ErrFile PluginSystem::saveCurrent(const QObject *sender) {
22462285
}
22472286

22482287
if (view) {
2249-
auto ws = _win->m_views.value(view);
2288+
auto ws = view->workSpaceName();
22502289
return view->save(ws, {}, false,
22512290
EditorView::SaveWorkSpaceAttr::AutoWorkSpace);
22522291
}

0 commit comments

Comments
 (0)