Refactored Workspace common types into WorkspaceCommon.h
FossilOrigin-Name: f31360bcda14a4137f5aee56ed916c161bcee18d
This commit is contained in:
@@ -26,7 +26,7 @@ void Fossil::Init(UICallback *callback, const QString &exePath)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Fossil::WorkspaceState Fossil::getWorkspaceState()
|
||||
WorkspaceState Fossil::getWorkspaceState()
|
||||
{
|
||||
QStringList res;
|
||||
int exit_code = EXIT_FAILURE;
|
||||
|
@@ -7,18 +7,11 @@ class QStringList;
|
||||
#include <QUrl>
|
||||
#include "LoggedProcess.h"
|
||||
#include "Utils.h"
|
||||
|
||||
typedef QMap<QString, QString> stashmap_t;
|
||||
#include "WorkspaceCommon.h"
|
||||
|
||||
class Fossil
|
||||
{
|
||||
public:
|
||||
enum WorkspaceState
|
||||
{
|
||||
WORKSPACE_STATE_OK,
|
||||
WORKSPACE_STATE_NOTFOUND,
|
||||
WORKSPACE_STATE_OLDSCHEMA
|
||||
};
|
||||
|
||||
Fossil();
|
||||
void Init(UICallback *callback, const QString &exePath);
|
||||
|
@@ -533,7 +533,7 @@ void MainWindow::on_actionNewRepository_triggered()
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::on_actionCloseRepository_triggered()
|
||||
{
|
||||
if(getWorkspace().getState()!=Fossil::WORKSPACE_STATE_OK)
|
||||
if(getWorkspace().getState()!=WORKSPACE_STATE_OK)
|
||||
return;
|
||||
|
||||
if(QMessageBox::Yes !=DialogQuery(this, tr("Close Workspace"), tr("Are you sure you want to close this workspace?")))
|
||||
@@ -693,15 +693,15 @@ bool MainWindow::scanWorkspace()
|
||||
bool valid = true;
|
||||
|
||||
// Load repository info
|
||||
Fossil::WorkspaceState st = getWorkspace().getState();
|
||||
WorkspaceState st = getWorkspace().getState();
|
||||
QString status;
|
||||
|
||||
if(st==Fossil::WORKSPACE_STATE_NOTFOUND)
|
||||
if(st==WORKSPACE_STATE_NOTFOUND)
|
||||
{
|
||||
status = tr("No workspace detected.");
|
||||
valid = false;
|
||||
}
|
||||
else if(st==Fossil::WORKSPACE_STATE_OLDSCHEMA)
|
||||
else if(st==WORKSPACE_STATE_OLDSCHEMA)
|
||||
{
|
||||
status = tr("Old repository schema detected. Consider running 'fossil rebuild'");
|
||||
valid = false;
|
||||
@@ -1010,7 +1010,7 @@ void MainWindow::updateFileView()
|
||||
const QString &search_text = searchBox->text();
|
||||
|
||||
size_t item_id=0;
|
||||
for(Workspace::filemap_t::iterator it = getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
for(filemap_t::iterator it = getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
{
|
||||
const WorkspaceFile &e = *it.value();
|
||||
const QString &path = e.getPath();
|
||||
@@ -1323,7 +1323,7 @@ void MainWindow::getSelectionPaths(stringset_t &paths)
|
||||
// Select all workspace files that match the includeMask
|
||||
void MainWindow::getAllFilenames(QStringList &filenames, int includeMask)
|
||||
{
|
||||
for(Workspace::filemap_t::iterator it=getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
for(filemap_t::iterator it=getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
{
|
||||
const WorkspaceFile &e = *(*it);
|
||||
|
||||
@@ -1347,7 +1347,7 @@ void MainWindow::getDirViewSelection(QStringList &filenames, int includeMask, bo
|
||||
}
|
||||
|
||||
// Select the actual files form the selected directories
|
||||
for(Workspace::filemap_t::iterator it=getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
for(filemap_t::iterator it=getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
|
||||
{
|
||||
const WorkspaceFile &e = *(*it);
|
||||
|
||||
@@ -1403,7 +1403,7 @@ void MainWindow::getFileViewSelection(QStringList &filenames, int includeMask, b
|
||||
|
||||
QVariant data = getWorkspace().getFileModel().data(mi, Qt::UserRole+1);
|
||||
QString filename = data.toString();
|
||||
Workspace::filemap_t::iterator e_it = getWorkspace().getFiles().find(filename);
|
||||
filemap_t::iterator e_it = getWorkspace().getFiles().find(filename);
|
||||
Q_ASSERT(e_it!=getWorkspace().getFiles().end());
|
||||
const WorkspaceFile &e = *e_it.value();
|
||||
|
||||
@@ -2034,7 +2034,7 @@ void MainWindow::on_actionRenameFolder_triggered()
|
||||
}
|
||||
|
||||
// Collect the files to be moved
|
||||
Workspace::filelist_t files_to_move;
|
||||
filelist_t files_to_move;
|
||||
QStringList new_paths;
|
||||
QStringList operations;
|
||||
foreach(WorkspaceFile *r, getWorkspace().getFiles())
|
||||
|
@@ -274,7 +274,7 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
else
|
||||
add_missing = true;
|
||||
|
||||
Workspace::filemap_t::iterator it = getFiles().find(fname);
|
||||
filemap_t::iterator it = getFiles().find(fname);
|
||||
|
||||
WorkspaceFile *rf = 0;
|
||||
if(add_missing && it==getFiles().end())
|
||||
|
111
src/Workspace.h
111
src/Workspace.h
@@ -8,113 +8,9 @@
|
||||
#include <QMap>
|
||||
#include <QSettings>
|
||||
#include "Utils.h"
|
||||
#include "WorkspaceCommon.h"
|
||||
#include "Fossil.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// WorkspaceFile
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct WorkspaceFile
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
TYPE_UNKNOWN = 1<<0,
|
||||
TYPE_UNCHANGED = 1<<1,
|
||||
TYPE_EDITTED = 1<<2,
|
||||
TYPE_ADDED = 1<<3,
|
||||
TYPE_DELETED = 1<<4,
|
||||
TYPE_MISSING = 1<<5,
|
||||
TYPE_RENAMED = 1<<6,
|
||||
TYPE_CONFLICTED = 1<<7,
|
||||
TYPE_MERGED = 1<<8,
|
||||
TYPE_MODIFIED = TYPE_EDITTED|TYPE_ADDED|TYPE_DELETED|TYPE_MISSING|TYPE_RENAMED|TYPE_CONFLICTED|TYPE_MERGED,
|
||||
TYPE_REPO = TYPE_UNCHANGED|TYPE_MODIFIED,
|
||||
TYPE_ALL = TYPE_UNKNOWN|TYPE_REPO
|
||||
};
|
||||
|
||||
WorkspaceFile(const QFileInfo &info, Type type, const QString &repoPath)
|
||||
{
|
||||
FileInfo = info;
|
||||
FileType = type;
|
||||
FilePath = getRelativeFilename(repoPath);
|
||||
Path = FileInfo.absolutePath();
|
||||
|
||||
// Strip the workspace path from the path
|
||||
Q_ASSERT(Path.indexOf(repoPath)==0);
|
||||
Path = Path.mid(repoPath.length()+1);
|
||||
}
|
||||
|
||||
bool isType(Type t) const
|
||||
{
|
||||
return FileType == t;
|
||||
}
|
||||
|
||||
void setType(Type t)
|
||||
{
|
||||
FileType = t;
|
||||
}
|
||||
|
||||
Type getType() const
|
||||
{
|
||||
return FileType;
|
||||
}
|
||||
|
||||
QFileInfo getFileInfo() const
|
||||
{
|
||||
return FileInfo;
|
||||
}
|
||||
|
||||
const QString &getFilePath() const
|
||||
{
|
||||
return FilePath;
|
||||
}
|
||||
|
||||
QString getFilename() const
|
||||
{
|
||||
return FileInfo.fileName();
|
||||
}
|
||||
|
||||
const QString &getPath() const
|
||||
{
|
||||
return Path;
|
||||
}
|
||||
|
||||
QString getRelativeFilename(const QString &path)
|
||||
{
|
||||
QString abs_base_dir = QDir(path).absolutePath();
|
||||
|
||||
QString relative = FileInfo.absoluteFilePath();
|
||||
int index = relative.indexOf(abs_base_dir);
|
||||
if(index<0)
|
||||
return QString("");
|
||||
|
||||
return relative.right(relative.length() - abs_base_dir.length()-1);
|
||||
}
|
||||
|
||||
private:
|
||||
QFileInfo FileInfo;
|
||||
Type FileType;
|
||||
QString FilePath;
|
||||
QString Path;
|
||||
};
|
||||
|
||||
class Remote
|
||||
{
|
||||
public:
|
||||
Remote(const QString &_name, const QUrl &_url, bool _isDefault=false)
|
||||
: name(_name), url(_url), isDefault(_isDefault)
|
||||
{
|
||||
}
|
||||
|
||||
QString name;
|
||||
QUrl url;
|
||||
bool isDefault;
|
||||
|
||||
};
|
||||
|
||||
typedef QMap<QUrl, Remote> remote_map_t;
|
||||
typedef QMap<QString, WorkspaceFile::Type> pathstate_map_t;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Workspace
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -124,9 +20,6 @@ public:
|
||||
Workspace();
|
||||
~Workspace();
|
||||
|
||||
typedef QList<WorkspaceFile*> filelist_t;
|
||||
typedef QMap<QString, WorkspaceFile*> filemap_t;
|
||||
|
||||
void clearState();
|
||||
|
||||
Fossil & fossil() { return bridge; }
|
||||
@@ -176,7 +69,7 @@ public:
|
||||
return fossil().createRepository(repositoryPath);
|
||||
}
|
||||
|
||||
Fossil::WorkspaceState getState()
|
||||
WorkspaceState getState()
|
||||
{
|
||||
return fossil().getWorkspaceState();
|
||||
}
|
||||
|
129
src/WorkspaceCommon.h
Normal file
129
src/WorkspaceCommon.h
Normal file
@@ -0,0 +1,129 @@
|
||||
#ifndef WORKSPACECOMMON_H
|
||||
#define WORKSPACECOMMON_H
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QSet>
|
||||
#include <QMap>
|
||||
#include <QUrl>
|
||||
#include "Utils.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// WorkspaceState
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum WorkspaceState
|
||||
{
|
||||
WORKSPACE_STATE_OK,
|
||||
WORKSPACE_STATE_NOTFOUND,
|
||||
WORKSPACE_STATE_OLDSCHEMA
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// WorkspaceFile
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct WorkspaceFile
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
TYPE_UNKNOWN = 1<<0,
|
||||
TYPE_UNCHANGED = 1<<1,
|
||||
TYPE_EDITTED = 1<<2,
|
||||
TYPE_ADDED = 1<<3,
|
||||
TYPE_DELETED = 1<<4,
|
||||
TYPE_MISSING = 1<<5,
|
||||
TYPE_RENAMED = 1<<6,
|
||||
TYPE_CONFLICTED = 1<<7,
|
||||
TYPE_MERGED = 1<<8,
|
||||
TYPE_MODIFIED = TYPE_EDITTED|TYPE_ADDED|TYPE_DELETED|TYPE_MISSING|TYPE_RENAMED|TYPE_CONFLICTED|TYPE_MERGED,
|
||||
TYPE_REPO = TYPE_UNCHANGED|TYPE_MODIFIED,
|
||||
TYPE_ALL = TYPE_UNKNOWN|TYPE_REPO
|
||||
};
|
||||
|
||||
WorkspaceFile(const QFileInfo &info, Type type, const QString &repoPath)
|
||||
{
|
||||
FileInfo = info;
|
||||
FileType = type;
|
||||
FilePath = getRelativeFilename(repoPath);
|
||||
Path = FileInfo.absolutePath();
|
||||
|
||||
// Strip the workspace path from the path
|
||||
Q_ASSERT(Path.indexOf(repoPath)==0);
|
||||
Path = Path.mid(repoPath.length()+1);
|
||||
}
|
||||
|
||||
bool isType(Type t) const
|
||||
{
|
||||
return FileType == t;
|
||||
}
|
||||
|
||||
void setType(Type t)
|
||||
{
|
||||
FileType = t;
|
||||
}
|
||||
|
||||
Type getType() const
|
||||
{
|
||||
return FileType;
|
||||
}
|
||||
|
||||
QFileInfo getFileInfo() const
|
||||
{
|
||||
return FileInfo;
|
||||
}
|
||||
|
||||
const QString &getFilePath() const
|
||||
{
|
||||
return FilePath;
|
||||
}
|
||||
|
||||
QString getFilename() const
|
||||
{
|
||||
return FileInfo.fileName();
|
||||
}
|
||||
|
||||
const QString &getPath() const
|
||||
{
|
||||
return Path;
|
||||
}
|
||||
|
||||
QString getRelativeFilename(const QString &path)
|
||||
{
|
||||
QString abs_base_dir = QDir(path).absolutePath();
|
||||
|
||||
QString relative = FileInfo.absoluteFilePath();
|
||||
int index = relative.indexOf(abs_base_dir);
|
||||
if(index<0)
|
||||
return QString("");
|
||||
|
||||
return relative.right(relative.length() - abs_base_dir.length()-1);
|
||||
}
|
||||
|
||||
private:
|
||||
QFileInfo FileInfo;
|
||||
Type FileType;
|
||||
QString FilePath;
|
||||
QString Path;
|
||||
};
|
||||
|
||||
class Remote
|
||||
{
|
||||
public:
|
||||
Remote(const QString &_name, const QUrl &_url, bool _isDefault=false)
|
||||
: name(_name), url(_url), isDefault(_isDefault)
|
||||
{
|
||||
}
|
||||
|
||||
QString name;
|
||||
QUrl url;
|
||||
bool isDefault;
|
||||
|
||||
};
|
||||
|
||||
typedef QMap<QUrl, Remote> remote_map_t;
|
||||
typedef QMap<QString, WorkspaceFile::Type> pathstate_map_t;
|
||||
typedef QList<WorkspaceFile*> filelist_t;
|
||||
typedef QMap<QString, WorkspaceFile*> filemap_t;
|
||||
typedef QMap<QString, QString> stashmap_t;
|
||||
|
||||
|
||||
#endif // WORKSPACECOMMON_H
|
Reference in New Issue
Block a user