ui: file not up to date display

* the codeview now displays a hatched background for a filename when the file's content has changed or the file does not exist anymore.
* added TimePoint class to encapsulate boost.
This commit is contained in:
malte_langkabel
2015-11-03 10:29:29 +01:00
parent 42ab36fbad
commit a524a7a71c
18 changed files with 161 additions and 20 deletions
+2
View File
@@ -302,6 +302,8 @@ add_files(
utility/ConfigManager.cpp
utility/ConfigManager.h
utility/Property.h
utility/TimePoint.cpp
utility/TimePoint.h
utility/types.h
utility/utility.cpp
utility/utility.h
@@ -121,6 +121,7 @@ void CodeController::handleMessage(MessageShowFile* message)
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(message->filePath);
params.code = textAccess->getText();
params.modificationTime = m_storageAccess->getFileModificationTime(message->filePath);
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath.str());
getView()->showCodeFile(params);
@@ -194,6 +195,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
CodeView::CodeSnippetParams params;
params.locationFile = file;
params.refCount = file->getUnscopedStartTokenLocationCount();
params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath());
params.isCollapsed = true;
snippets.push_back(params);
@@ -259,6 +261,8 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
params.refCount = file->getUnscopedStartTokenLocationCount();
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
params.endLineNumber = std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath());
std::shared_ptr<TokenLocationFile> tempFile =
m_storageAccess->getTokenLocationsForLinesInFile(file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
+2
View File
@@ -5,6 +5,7 @@
#include "component/view/View.h"
#include "data/location/TokenLocationFile.h"
#include "utility/TimePoint.h"
#include "utility/types.h"
class CodeController;
@@ -26,6 +27,7 @@ public:
std::string code;
Id titleId;
TimePoint modificationTime;
std::shared_ptr<TokenLocationFile> locationFile;
+6
View File
@@ -5,6 +5,7 @@
#include "utility/file/FileSystem.h"
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
@@ -1219,6 +1220,11 @@ std::shared_ptr<TextAccess> Storage::getFileContent(const FilePath& filePath) co
return m_sqliteStorage.getFileContentByPath(filePath.str());
}
TimePoint Storage::getFileModificationTime(const FilePath& filePath) const
{
return TimePoint(m_sqliteStorage.getFileByPath(filePath.str()).modificationTime);
}
Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool defined, bool distinct)
{
std::vector<Id> nameIds = addNameHierarchyElements(nameHierarchy);
+1 -2
View File
@@ -161,8 +161,7 @@ public:
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
virtual TimePoint getFileModificationTime(const FilePath& filePath) const;
private:
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool defined, bool distinct = false);
+2
View File
@@ -17,6 +17,7 @@ class TextAccess;
class TokenLocation;
class TokenLocationCollection;
class TokenLocationFile;
class TimePoint;
class StorageAccess
{
@@ -56,6 +57,7 @@ public:
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const = 0;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
virtual TimePoint getFileModificationTime(const FilePath& filePath) const = 0;
};
#endif // STORAGE_ACCESS_H
@@ -6,6 +6,7 @@
#include "utility/logging/logging.h"
#include "utility/file/FileInfo.h"
#include "utility/TimePoint.h"
StorageAccessProxy::StorageAccessProxy()
: m_subject(nullptr)
@@ -243,3 +244,13 @@ std::shared_ptr<TextAccess> StorageAccessProxy::getFileContent(const FilePath& f
return nullptr;
}
TimePoint StorageAccessProxy::getFileModificationTime(const FilePath& filePath) const
{
if (hasSubject())
{
return m_subject->getFileModificationTime(filePath);
}
return TimePoint(boost::posix_time::not_a_date_time);
}
+1
View File
@@ -47,6 +47,7 @@ public:
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
virtual TimePoint getFileModificationTime(const FilePath& filePath) const;
private:
StorageAccess* m_subject;
+21
View File
@@ -0,0 +1,21 @@
#include "TimePoint.h"
TimePoint::TimePoint()
: m_time(boost::posix_time::not_a_date_time)
{
}
TimePoint::TimePoint(boost::posix_time::ptime t)
: m_time(t)
{
}
//TimePoint::TimePoint(time_t t)
//{
// needs an implementation
//}
TimePoint::TimePoint(std::string s)
{
m_time = boost::posix_time::time_from_string(s);
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef TIME_POINT_H
#define TIME_POINT_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimePoint
{
public:
TimePoint();
TimePoint(boost::posix_time::ptime t);
//TimePoint(time_t t);
TimePoint(std::string s);
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
inline bool operator<(const TimePoint& rhs){ return m_time < rhs.m_time; }
inline bool operator>(const TimePoint& rhs){ return m_time > rhs.m_time; }
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_POINT_H
+11
View File
@@ -94,6 +94,17 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
return files;
}
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
{
boost::posix_time::ptime lastWriteTime;
if (FileSystem::exists(filePath.str()))
{
std::time_t t = boost::filesystem::last_write_time(filePath.path());
lastWriteTime = boost::posix_time::from_time_t(t);
}
return TimePoint(lastWriteTime);
}
std::string FileSystem::getTimeStringNow() // TODO: move to utility
{
return boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time());
+2
View File
@@ -5,6 +5,7 @@
#include <vector>
#include "utility/file/FileInfo.h"
#include "utility/TimePoint.h"
class FileSystem
{
@@ -19,6 +20,7 @@ public:
static std::vector<FileInfo> getFileInfosFromPaths(
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions);
static TimePoint getLastWriteTime(const FilePath& filePath);
static std::string getTimeStringNow();
static std::vector<FilePath> getSubDirectories(const FilePath& path);