Show error if an incorrect URL passed to CelestiaCore::goToUrl

pull/643/head
Hleb Valoshka 2020-03-06 16:18:40 +03:00
parent 154c06e0a7
commit f67b331f02
5 changed files with 28 additions and 22 deletions

View File

@ -4242,11 +4242,15 @@ void CelestiaCore::notifyWatchers(int property)
}
void CelestiaCore::goToUrl(const string& urlStr)
bool CelestiaCore::goToUrl(const string& urlStr)
{
Url url(urlStr, this);
url.goTo();
notifyWatchers(RenderFlagsChanged | LabelFlagsChanged);
bool ret = url.goTo();
if (ret)
notifyWatchers(RenderFlagsChanged | LabelFlagsChanged);
else
fatalError(_("Invalid URL"));
return ret;
}

View File

@ -189,7 +189,7 @@ class CelestiaCore // : public Watchable<CelestiaCore>
// URLs and history navigation
void setStartURL(std::string url);
void goToUrl(const std::string& urlStr);
bool goToUrl(const std::string& urlStr);
void addToHistory();
void back();
void forward();

View File

@ -743,7 +743,7 @@ void CelestiaAppWindow::slotCopyURL()
Url url(appState, Url::CurrentVersion);
QApplication::clipboard()->setText(url.getAsString().c_str());
m_appCore->flash(QString(_("Copied URL")).toStdString());
m_appCore->flash(_("Copied URL"));
}
@ -752,8 +752,8 @@ void CelestiaAppWindow::slotPasteURL()
QString urlText = QApplication::clipboard()->text();
if (!urlText.isEmpty())
{
m_appCore->goToUrl(urlText.toStdString());
m_appCore->flash(QString(_("Pasting URL")).toStdString());
if (m_appCore->goToUrl(urlText.toStdString()))
m_appCore->flash(_("Pasting URL"));
}
}

View File

@ -754,19 +754,19 @@ static std::string getBodyName(Universe* universe, Body* body)
}
void Url::goTo()
bool Url::goTo()
{
Selection sel;
if (urlStr.empty())
return false;
if (urlStr == "")
return;
Simulation *sim = appCore->getSimulation();
Renderer *renderer = appCore->getRenderer();
std::string::size_type pos;
sim->update(0.0);
switch(type) {
switch(type)
{
case Absolute:// Intentional Fall-Through
case Relative:
sim->setFrame(ref.getCoordinateSystem(), ref.getRefObject(), ref.getTargetObject());
@ -776,15 +776,15 @@ void Url::goTo()
sim->setPauseState(pauseState);
appCore->setLightDelayActive(lightTimeDelay);
if (selectedStr != "")
if (!selectedStr.empty())
{
pos = 0;
while(pos != std::string::npos)
while (pos != std::string::npos)
{
pos = selectedStr.find(":", pos + 1);
if (pos != std::string::npos) selectedStr[pos]='/';
if (pos != std::string::npos) selectedStr[pos] = '/';
}
sel = sim->findObjectFromPath(selectedStr);
auto sel = sim->findObjectFromPath(selectedStr);
sim->setSelection(sel);
}
else
@ -792,15 +792,15 @@ void Url::goTo()
sim->setSelection(Selection());
}
if (trackedStr != "")
if (!trackedStr.empty())
{
pos = 0;
while(pos != std::string::npos)
while (pos != std::string::npos)
{
pos = trackedStr.find(":", pos + 1);
if (pos != std::string::npos) trackedStr[pos]='/';
if (pos != std::string::npos) trackedStr[pos] = '/';
}
sel = sim->findObjectFromPath(trackedStr);
auto sel = sim->findObjectFromPath(trackedStr);
sim->setTrackedObject(sel);
}
else
@ -842,7 +842,8 @@ void Url::goTo()
}
else
{
switch(type) {
switch(type)
{
case Absolute:
sim->setTime((double) date);
sim->setObserverPosition(coord);
@ -855,6 +856,7 @@ void Url::goTo()
break;
}
}
return true;
}

View File

@ -70,7 +70,7 @@ public:
std::string getAsString() const;
std::string getName() const;
void goTo();
bool goTo();
static const unsigned int CurrentVersion;