Keep Url objects instead of pointer in history

pull/928/head
Hleb Valoshka 2021-03-03 22:35:21 +02:00
parent 332840fdd1
commit f5f8770f7f
2 changed files with 12 additions and 16 deletions

View File

@ -4441,17 +4441,13 @@ bool CelestiaCore::goToUrl(const string& urlStr)
void CelestiaCore::addToHistory()
{
Url* url = new Url(this);
if (!history.empty() && historyCurrent < history.size() - 1)
{
// truncating history to current position
while (historyCurrent != history.size() - 1)
{
delete history.back();
history.pop_back();
}
}
history.push_back(url);
history.emplace_back(this);
historyCurrent = history.size() - 1;
notifyWatchers(HistoryChanged);
}
@ -4468,7 +4464,7 @@ void CelestiaCore::back()
historyCurrent = history.size()-1;
}
historyCurrent--;
history[historyCurrent]->goTo();
history[historyCurrent].goTo();
notifyWatchers(HistoryChanged|RenderFlagsChanged|LabelFlagsChanged);
}
@ -4478,29 +4474,29 @@ void CelestiaCore::forward()
if (history.size() == 0) return;
if (historyCurrent == history.size()-1) return;
historyCurrent++;
history[historyCurrent]->goTo();
history[historyCurrent].goTo();
notifyWatchers(HistoryChanged|RenderFlagsChanged|LabelFlagsChanged);
}
const vector<Url*>& CelestiaCore::getHistory() const
const vector<Url>& CelestiaCore::getHistory() const
{
return history;
}
vector<Url*>::size_type CelestiaCore::getHistoryCurrent() const
vector<Url>::size_type CelestiaCore::getHistoryCurrent() const
{
return historyCurrent;
}
void CelestiaCore::setHistoryCurrent(vector<Url*>::size_type curr)
void CelestiaCore::setHistoryCurrent(vector<Url>::size_type curr)
{
if (curr >= history.size()) return;
if (historyCurrent == history.size()) {
addToHistory();
}
historyCurrent = curr;
history[curr]->goTo();
history[curr].goTo();
notifyWatchers(HistoryChanged|RenderFlagsChanged|LabelFlagsChanged);
}

View File

@ -195,9 +195,9 @@ class CelestiaCore // : public Watchable<CelestiaCore>
void addToHistory();
void back();
void forward();
const std::vector<Url*>& getHistory() const;
std::vector<Url*>::size_type getHistoryCurrent() const;
void setHistoryCurrent(std::vector<Url*>::size_type curr);
const std::vector<Url>& getHistory() const;
std::vector<Url>::size_type getHistoryCurrent() const;
void setHistoryCurrent(std::vector<Url>::size_type curr);
// event processing methods
void charEntered(const char*, int modifiers = 0);
@ -479,8 +479,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
ContextMenuHandler* contextMenuHandler{ nullptr };
TextDisplayHandler* textDisplayHandler{ nullptr };
std::vector<Url*> history;
std::vector<Url*>::size_type historyCurrent{ 0 };
std::vector<Url> history;
std::vector<Url>::size_type historyCurrent{ 0 };
std::string startURL;
std::list<View*> views;