Refactored and unified workspace path functions
FossilOrigin-Name: 5e89247bf2fa2cf6d5720ddf51e091319ab66459
This commit is contained in:
@@ -82,7 +82,7 @@ bool Fossil::openRepository(const QString& repositoryPath, const QString& worksp
|
||||
return false;
|
||||
|
||||
QString abspath = fi.absoluteFilePath();
|
||||
setCurrentWorkspace(workspacePath);
|
||||
setWorkspacePath(workspacePath);
|
||||
setRepositoryFile(abspath);
|
||||
|
||||
if(!runFossil(QStringList() << "open" << QuotePath(abspath)))
|
||||
@@ -111,7 +111,7 @@ bool Fossil::closeRepository()
|
||||
return false;
|
||||
|
||||
stopUI();
|
||||
setCurrentWorkspace("");
|
||||
setWorkspacePath("");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ bool Fossil::removeFiles(const QStringList& fileList, bool deleteLocal)
|
||||
{
|
||||
for(int i=0; i<fileList.size(); ++i)
|
||||
{
|
||||
QFileInfo fi(getCurrentWorkspace() + QDir::separator() + fileList[i]);
|
||||
QFileInfo fi(getWorkspacePath() + QDir::separator() + fileList[i]);
|
||||
if(fi.exists())
|
||||
QFile::remove(fi.filePath());
|
||||
}
|
||||
@@ -339,7 +339,7 @@ bool Fossil::renameFile(const QString &beforePath, const QString &afterPath, boo
|
||||
if(!runFossil(QStringList() << "mv" << QuotePath(beforePath) << QuotePath(afterPath)))
|
||||
return false;
|
||||
|
||||
QString wkdir = getCurrentWorkspace() + QDir::separator();
|
||||
QString wkdir = getWorkspacePath() + QDir::separator();
|
||||
|
||||
// Also rename the file
|
||||
if(renameLocal && !QFile::rename(wkdir+beforePath, wkdir+afterPath))
|
||||
@@ -720,7 +720,7 @@ bool Fossil::runFossilRaw(const QStringList &args, QStringList *output, int *exi
|
||||
log("<b>> fossil "+params+"</b><br>", true);
|
||||
}
|
||||
|
||||
QString wkdir = getCurrentWorkspace();
|
||||
QString wkdir = getWorkspacePath();
|
||||
|
||||
QString fossil = getFossilPath();
|
||||
|
||||
@@ -1079,7 +1079,7 @@ bool Fossil::startUI(const QString &httpPort)
|
||||
//fossilUI.setParent(parentWidget);
|
||||
|
||||
fossilUI.setProcessChannelMode(QProcess::MergedChannels);
|
||||
fossilUI.setWorkingDirectory(getCurrentWorkspace());
|
||||
fossilUI.setWorkingDirectory(getWorkspacePath());
|
||||
|
||||
log("<b>> fossil ui</b><br>", true);
|
||||
log(QObject::tr("Starting Fossil browser UI. Please wait.")+"\n");
|
||||
|
||||
12
src/Fossil.h
12
src/Fossil.h
@@ -40,7 +40,7 @@ public:
|
||||
{
|
||||
uiCallback = callback;
|
||||
fossilPath.clear();
|
||||
currentWorkspace.clear();
|
||||
workspacePath.clear();
|
||||
}
|
||||
|
||||
bool runFossil(const QStringList &args, QStringList *output=0, int runFlags=RUNFLAGS_NONE);
|
||||
@@ -50,14 +50,14 @@ public:
|
||||
|
||||
RepoStatus getRepoStatus();
|
||||
|
||||
void setCurrentWorkspace(const QString &workspace)
|
||||
void setWorkspacePath(const QString &workspace)
|
||||
{
|
||||
currentWorkspace = workspace;
|
||||
workspacePath = workspace;
|
||||
}
|
||||
|
||||
const QString &getCurrentWorkspace() const
|
||||
const QString &getWorkspacePath() const
|
||||
{
|
||||
return currentWorkspace;
|
||||
return workspacePath;
|
||||
}
|
||||
|
||||
const QString &getProjectName() const
|
||||
@@ -138,7 +138,7 @@ private:
|
||||
|
||||
bool operationAborted;
|
||||
UICallback *uiCallback;
|
||||
QString currentWorkspace;
|
||||
QString workspacePath;
|
||||
QString fossilPath; // The value from the settings
|
||||
QString repositoryFile;
|
||||
QString projectName;
|
||||
|
||||
@@ -321,19 +321,13 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const QString &MainWindow::getCurrentWorkspace()
|
||||
{
|
||||
return fossil().getCurrentWorkspace();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void MainWindow::setCurrentWorkspace(const QString &workspace)
|
||||
{
|
||||
if(!getWorkspace().switchWorkspace(workspace, *settings.GetStore()))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not change current directory to '%0'").arg(workspace), QMessageBox::Ok );
|
||||
else
|
||||
addWorkspaceHistory(fossil().getCurrentWorkspace());
|
||||
addWorkspaceHistory(getWorkspace().getPath());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -1169,7 +1163,7 @@ void MainWindow::updateSettings()
|
||||
{
|
||||
store->setArrayIndex(i);
|
||||
store->setValue("Path", workspaceHistory[i]);
|
||||
if(getCurrentWorkspace() == workspaceHistory[i])
|
||||
if(getWorkspace().getPath() == workspaceHistory[i])
|
||||
store->setValue("Active", true);
|
||||
else
|
||||
store->remove("Active");
|
||||
@@ -1500,7 +1494,7 @@ void MainWindow::on_actionOpenFile_triggered()
|
||||
|
||||
for(QStringList::iterator it = selection.begin(); it!=selection.end(); ++it)
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(getCurrentWorkspace()+QDir::separator()+*it));
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(getWorkspace().getPath()+QDir::separator()+*it));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1598,7 +1592,7 @@ void MainWindow::on_actionDelete_triggered()
|
||||
{
|
||||
for(int i=0; i<unknown_files.size(); ++i)
|
||||
{
|
||||
QFileInfo fi(getCurrentWorkspace() + QDir::separator() + unknown_files[i]);
|
||||
QFileInfo fi(getWorkspace().getPath() + QDir::separator() + unknown_files[i]);
|
||||
if(fi.exists())
|
||||
QFile::remove(fi.filePath());
|
||||
}
|
||||
@@ -1663,7 +1657,7 @@ void MainWindow::on_actionOpenContaining_triggered()
|
||||
QString target;
|
||||
|
||||
if(selection.empty())
|
||||
target = QDir::toNativeSeparators(getCurrentWorkspace());
|
||||
target = QDir::toNativeSeparators(getWorkspace().getPath());
|
||||
else
|
||||
{
|
||||
QFileInfo file_info(selection[0]);
|
||||
@@ -1909,7 +1903,7 @@ void MainWindow::on_workspaceTreeView_doubleClicked(const QModelIndex &index)
|
||||
|
||||
if(tv.Type==WorkspaceItem::TYPE_FOLDER || tv.Type==WorkspaceItem::TYPE_WORKSPACE)
|
||||
{
|
||||
QString target = getCurrentWorkspace() + PATH_SEPARATOR + tv.Value;
|
||||
QString target = getWorkspace().getPath() + PATH_SEPARATOR + tv.Value;
|
||||
QUrl url = QUrl::fromLocalFile(target);
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
@@ -2019,13 +2013,13 @@ void MainWindow::on_actionRenameFolder_triggered()
|
||||
// First ensure that the target directories exist, and if not make them
|
||||
for(int i=0; i<files_to_move.length(); ++i)
|
||||
{
|
||||
QString target_path = QDir::cleanPath(getCurrentWorkspace() + PATH_SEPARATOR + new_paths[i] + PATH_SEPARATOR);
|
||||
QString target_path = QDir::cleanPath(getWorkspace().getPath() + PATH_SEPARATOR + new_paths[i] + PATH_SEPARATOR);
|
||||
QDir target(target_path);
|
||||
|
||||
if(target.exists())
|
||||
continue;
|
||||
|
||||
QDir wkdir(getCurrentWorkspace());
|
||||
QDir wkdir(getWorkspace().getPath());
|
||||
Q_ASSERT(wkdir.exists());
|
||||
|
||||
log(tr("Creating folder '%0'").arg(target_path)+"\n");
|
||||
@@ -2244,7 +2238,7 @@ void MainWindow::onFileViewDragOut()
|
||||
|
||||
QList<QUrl> urls;
|
||||
foreach(QString f, filenames)
|
||||
urls.append(QUrl::fromLocalFile(getCurrentWorkspace()+QDir::separator()+f));
|
||||
urls.append(QUrl::fromLocalFile(getWorkspace().getPath()+QDir::separator()+f));
|
||||
|
||||
QMimeData *mime_data = new QMimeData;
|
||||
mime_data->setUrls(urls);
|
||||
@@ -2276,7 +2270,7 @@ void MainWindow::on_fileTableView_customContextMenuRequested(const QPoint &pos)
|
||||
|
||||
if(fnames.size()==1)
|
||||
{
|
||||
QString fname = getCurrentWorkspace() + PATH_SEPARATOR + fnames[0];
|
||||
QString fname = getWorkspace().getPath() + PATH_SEPARATOR + fnames[0];
|
||||
fname = QDir::toNativeSeparators(fname);
|
||||
if(ShowExplorerMenu((HWND)winId(), fname, gpos))
|
||||
refresh();
|
||||
@@ -2361,11 +2355,11 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
QString abspath = finfo.absoluteFilePath();
|
||||
|
||||
// Within the current workspace ?
|
||||
if(abspath.indexOf(getCurrentWorkspace())!=0)
|
||||
if(abspath.indexOf(getWorkspace().getPath())!=0)
|
||||
continue; // skip
|
||||
|
||||
// Remove workspace from full path
|
||||
QString wkpath = abspath.right(abspath.length()-getCurrentWorkspace().length()-1);
|
||||
QString wkpath = abspath.right(abspath.length()-getWorkspace().getPath().length()-1);
|
||||
|
||||
newfiles.append(wkpath);
|
||||
}
|
||||
@@ -2885,7 +2879,7 @@ void MainWindow::invokeCustomAction(int actionId)
|
||||
}
|
||||
}
|
||||
|
||||
const QString &wkdir = fossil().getCurrentWorkspace();
|
||||
const QString &wkdir = getWorkspace().getPath();
|
||||
|
||||
SpawnExternalProcess(this, cust_action.Command, file_selection, path_selection, wkdir, uiCallback);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ private:
|
||||
void applySettings();
|
||||
void updateSettings();
|
||||
void updateRevision(const QString& revision);
|
||||
const QString &getCurrentWorkspace();
|
||||
void setCurrentWorkspace(const QString &workspace);
|
||||
void log(const QString &text, bool isHTML=false);
|
||||
void setStatus(const QString &text);
|
||||
|
||||
@@ -32,7 +32,7 @@ void Workspace::clearState()
|
||||
//------------------------------------------------------------------------------
|
||||
void Workspace::storeWorkspace(QSettings &store)
|
||||
{
|
||||
QString workspace = fossil().getCurrentWorkspace();
|
||||
QString workspace = fossil().getWorkspacePath();
|
||||
if(workspace.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -66,7 +66,7 @@ bool Workspace::switchWorkspace(const QString& workspace, QSettings &store)
|
||||
clearState();
|
||||
remotes.clear();
|
||||
|
||||
fossil().setCurrentWorkspace("");
|
||||
fossil().setWorkspacePath("");
|
||||
if(workspace.isEmpty())
|
||||
return true;
|
||||
|
||||
@@ -75,7 +75,7 @@ bool Workspace::switchWorkspace(const QString& workspace, QSettings &store)
|
||||
if(!QDir::setCurrent(new_workspace))
|
||||
return false;
|
||||
|
||||
fossil().setCurrentWorkspace(new_workspace);
|
||||
fossil().setWorkspacePath(new_workspace);
|
||||
|
||||
// Load Remotes
|
||||
QString workspace_hash = HashString(QDir::toNativeSeparators(new_workspace));
|
||||
@@ -161,7 +161,7 @@ void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModifie
|
||||
{
|
||||
// Scan all workspace files
|
||||
QFileInfoList all_files;
|
||||
QString wkdir = fossil().getCurrentWorkspace();
|
||||
QString wkdir = fossil().getWorkspacePath();
|
||||
|
||||
if(wkdir.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -122,7 +122,6 @@ class Workspace
|
||||
{
|
||||
public:
|
||||
Workspace();
|
||||
|
||||
~Workspace();
|
||||
|
||||
typedef QList<WorkspaceFile*> filelist_t;
|
||||
@@ -133,6 +132,7 @@ public:
|
||||
Fossil & fossil() { return bridge; }
|
||||
const Fossil & fossil() const { return bridge; }
|
||||
|
||||
const QString & getPath() const { return fossil().getWorkspacePath(); }
|
||||
bool switchWorkspace(const QString &workspace, QSettings &store);
|
||||
void scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModified, bool scanUnchanged, const QString &ignoreGlob, UICallback &uiCallback, bool &operationAborted);
|
||||
|
||||
@@ -155,8 +155,7 @@ public:
|
||||
QUrl getRemoteDefault() const;
|
||||
Remote * findRemote(const QUrl& url);
|
||||
|
||||
|
||||
void storeWorkspace(QSettings &store);
|
||||
void storeWorkspace(QSettings &store);
|
||||
private:
|
||||
static bool scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool& abort, UICallback &uiCallback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user