Folder state generation and propagation now happens during workspace scan.
FossilOrigin-Name: 309756d79851ed8606d748fb226b2eab3d2276a8
This commit is contained in:
@@ -62,25 +62,38 @@ struct WorkspaceItem
|
||||
TYPE_REMOTE,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_DEFAULT,
|
||||
STATE_CLEAN,
|
||||
STATE_MODIFIED,
|
||||
STATE_UNKNOWN
|
||||
};
|
||||
|
||||
|
||||
WorkspaceItem()
|
||||
: Type(TYPE_UNKNOWN)
|
||||
, State(STATE_DEFAULT)
|
||||
{
|
||||
}
|
||||
|
||||
WorkspaceItem(int type, const QString &value)
|
||||
: Type(type), Value(value)
|
||||
WorkspaceItem(int type, const QString &value, int state=STATE_DEFAULT)
|
||||
: Type(type), State(state), Value(value)
|
||||
{
|
||||
}
|
||||
|
||||
WorkspaceItem(const WorkspaceItem &other)
|
||||
{
|
||||
Type = other.Type;
|
||||
State = other.State;
|
||||
Value = other.Value;
|
||||
}
|
||||
|
||||
int Type;
|
||||
int State;
|
||||
QString Value;
|
||||
|
||||
|
||||
operator QVariant() const
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
@@ -703,7 +716,7 @@ void MainWindow::scanWorkspace()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static void addPathToTree(QStandardItem &root, const QString &path, const QIcon &folderDefaultIcon, const QIcon &folderIconClean, const QIcon &folderIconDirty, const pathstate_map_t &pathState)
|
||||
static void addPathToTree(QStandardItem &root, const QString &path, const QIcon &iconDefault, const QIcon &iconClean, const QIcon &iconDirty, const QIcon &iconUnknown, const pathstate_map_t &pathState)
|
||||
{
|
||||
QStringList dirs = path.split('/');
|
||||
QStandardItem *parent = &root;
|
||||
@@ -729,7 +742,7 @@ static void addPathToTree(QStandardItem &root, const QString &path, const QIcon
|
||||
|
||||
if(!found) // Generate it
|
||||
{
|
||||
const QIcon *icon = &folderDefaultIcon;
|
||||
int state = WorkspaceItem::STATE_DEFAULT;
|
||||
|
||||
pathstate_map_t::const_iterator state_it = pathState.find(fullpath);
|
||||
if(state_it != pathState.end())
|
||||
@@ -737,34 +750,27 @@ static void addPathToTree(QStandardItem &root, const QString &path, const QIcon
|
||||
WorkspaceFile::Type type = state_it.value();
|
||||
|
||||
if(type & (WorkspaceFile::TYPE_MODIFIED))
|
||||
icon = &folderIconDirty;
|
||||
state = WorkspaceItem::STATE_MODIFIED;
|
||||
else if(type == WorkspaceFile::TYPE_UNKNOWN)
|
||||
state = WorkspaceItem::STATE_UNKNOWN;
|
||||
else
|
||||
icon = &folderIconClean;
|
||||
state = WorkspaceItem::STATE_CLEAN;
|
||||
}
|
||||
|
||||
QStandardItem *child = new QStandardItem(*icon, dir);
|
||||
child->setData(WorkspaceItem(WorkspaceItem::TYPE_FOLDER, fullpath), ROLE_WORKSPACE_ITEM);
|
||||
QStandardItem *child = new QStandardItem(dir);
|
||||
child->setData(WorkspaceItem(WorkspaceItem::TYPE_FOLDER, fullpath, state), ROLE_WORKSPACE_ITEM);
|
||||
|
||||
if(state == WorkspaceItem::STATE_CLEAN)
|
||||
child->setIcon(iconClean);
|
||||
else if(state == WorkspaceItem::STATE_MODIFIED)
|
||||
child->setIcon(iconDirty);
|
||||
else if(state == WorkspaceItem::STATE_UNKNOWN)
|
||||
child->setIcon(iconUnknown);
|
||||
else
|
||||
child->setIcon(iconDefault);
|
||||
|
||||
parent->appendRow(child);
|
||||
parent = child;
|
||||
|
||||
// Update icons of parents
|
||||
if(icon != &folderDefaultIcon) // Default Icon is not inherited by parent
|
||||
{
|
||||
QStandardItem *p = parent;
|
||||
while(p && p != &root) // Ascend parents except the root node
|
||||
{
|
||||
const QIcon &parent_icon = p->icon();
|
||||
|
||||
// Dirty is inherited
|
||||
if(icon == &folderIconDirty)
|
||||
p->setIcon(*icon);
|
||||
// Clean is inherited if not dirty
|
||||
else if(icon == &folderIconClean && (&parent_icon != &folderIconDirty))
|
||||
p->setIcon(*icon);
|
||||
|
||||
p = p->parent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fullpath += '/';
|
||||
@@ -811,7 +817,7 @@ void MainWindow::updateWorkspaceView()
|
||||
if(dir.isEmpty())
|
||||
continue;
|
||||
|
||||
addPathToTree(*workspace, dir, getInternalIcon(":icons/icon-item-folder"), getInternalIcon(":icons/icons/Folder Generic Green-01.png"), getInternalIcon(":icons/icons/Folder Generic Red-01.png"), getWorkspace().getPathState());
|
||||
addPathToTree(*workspace, dir, getInternalIcon(":icons/icon-item-folder"), getInternalIcon(":icons/icons/Folder Generic Green-01.png"), getInternalIcon(":icons/icons/Folder Generic Red-01.png"), getInternalIcon(":icons/icons/Folder Generic Silver-01.png"), getWorkspace().getPathState());
|
||||
}
|
||||
|
||||
// Expand root folder
|
||||
|
@@ -22,7 +22,7 @@ void Workspace::clearState()
|
||||
|
||||
getFiles().clear();
|
||||
getPaths().clear();
|
||||
getPathState().clear();
|
||||
pathState.clear();
|
||||
stashMap.clear();
|
||||
branchList.clear();
|
||||
tags.clear();
|
||||
@@ -149,6 +149,12 @@ bool Workspace::scanDirectory(QFileInfoList &entries, const QString& dirPath, co
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool StringLengthDescending(const QString &l, const QString &r)
|
||||
{
|
||||
return l.length() > r.length();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModified, bool scanUnchanged, const QString &ignoreGlob, UICallback &uiCallback, bool &operationAborted)
|
||||
{
|
||||
@@ -168,6 +174,8 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
|
||||
clearState();
|
||||
|
||||
QStringList paths;
|
||||
|
||||
operationAborted = false;
|
||||
|
||||
uiCallback.beginProcess("");
|
||||
@@ -196,9 +204,22 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
if(filename == FOSSIL_CHECKOUT1 || filename == FOSSIL_CHECKOUT2 || (!fossil().getRepositoryFile().isEmpty() && QFileInfo(fullpath) == QFileInfo(fossil().getRepositoryFile())))
|
||||
continue;
|
||||
|
||||
WorkspaceFile *rf = new WorkspaceFile(*it, WorkspaceFile::TYPE_UNKNOWN, wkdir);
|
||||
WorkspaceFile::Type type = WorkspaceFile::TYPE_UNKNOWN;
|
||||
|
||||
WorkspaceFile *rf = new WorkspaceFile(*it, type, wkdir);
|
||||
const QString &path = rf->getPath();
|
||||
getFiles().insert(rf->getFilePath(), rf);
|
||||
getPaths().insert(rf->getPath());
|
||||
getPaths().insert(path);
|
||||
|
||||
// Add or merge file state into directory state
|
||||
pathstate_map_t::iterator state_it = pathState.find(path);
|
||||
if(state_it != pathState.end())
|
||||
state_it.value() = static_cast<WorkspaceFile::Type>(state_it.value() | type);
|
||||
else
|
||||
{
|
||||
pathState.insert(path, type);
|
||||
paths.append(path); // keep path in list for depth sort
|
||||
}
|
||||
}
|
||||
}
|
||||
uiCallback.endProcess();
|
||||
@@ -206,7 +227,6 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
uiCallback.beginProcess(QObject::tr("Updating..."));
|
||||
|
||||
// Update Files and Directories
|
||||
|
||||
for(QStringList::iterator line_it=res.begin(); line_it!=res.end(); ++line_it)
|
||||
{
|
||||
QString line = (*line_it).trimmed();
|
||||
@@ -281,12 +301,42 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
getPaths().insert(path);
|
||||
|
||||
// Add or merge file state into directory state
|
||||
pathstate_map_t::iterator state_it = getPathState().find(path);
|
||||
if(state_it != getPathState().end())
|
||||
pathstate_map_t::iterator state_it = pathState.find(path);
|
||||
if(state_it != pathState.end())
|
||||
state_it.value() = static_cast<WorkspaceFile::Type>(state_it.value() | type);
|
||||
else
|
||||
getPathState().insert(path, type);
|
||||
{
|
||||
pathState.insert(path, type);
|
||||
paths.append(path); // keep path in list for depth sort
|
||||
}
|
||||
}
|
||||
|
||||
// Sort paths, so that children (longer path) are before parents (shorter path)
|
||||
std::sort(paths.begin(), paths.end(), StringLengthDescending);
|
||||
foreach(const QString &p, paths)
|
||||
{
|
||||
pathstate_map_t::iterator state_it = pathState.find(p);
|
||||
Q_ASSERT(state_it != pathState.end());
|
||||
WorkspaceFile::Type state = state_it.value();
|
||||
|
||||
// Propagate child dir state to parents
|
||||
QString parent_path = p;
|
||||
while(!parent_path.isEmpty())
|
||||
{
|
||||
// Extract parent path
|
||||
int sep_index = parent_path.lastIndexOf(PATH_SEPARATOR);
|
||||
if(sep_index>=0)
|
||||
parent_path = parent_path.left(sep_index);
|
||||
else
|
||||
parent_path = "";
|
||||
|
||||
// Merge path of child to parent
|
||||
pathstate_map_t::iterator state_it = pathState.find(parent_path);
|
||||
if(state_it != pathState.end())
|
||||
state_it.value() = static_cast<WorkspaceFile::Type>(state_it.value() | state);
|
||||
else
|
||||
pathState.insert(parent_path, state);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the repository needs integration
|
||||
|
Reference in New Issue
Block a user