Refactored custom action process invocation into a separate function
FossilOrigin-Name: bf36bf1c733da77a39ab9a8b7c63b892c11ef93c
This commit is contained in:
@@ -10,8 +10,6 @@ class QStringList;
|
||||
|
||||
typedef QMap<QString, QString> stashmap_t;
|
||||
|
||||
#define PATH_SEPARATOR "/"
|
||||
|
||||
enum RunFlags
|
||||
{
|
||||
RUNFLAGS_NONE = 0<<0,
|
||||
|
@@ -2791,112 +2791,17 @@ void MainWindow::on_actionCustomAction_triggered()
|
||||
CustomAction &cust_action = settings.GetCustomActions()[action_id];
|
||||
Q_ASSERT(cust_action.IsValid());
|
||||
|
||||
QStringList params;
|
||||
Q_ASSERT(!cust_action.Command.isEmpty());
|
||||
|
||||
// Process command string
|
||||
QString cmd = cust_action.Command;
|
||||
Q_ASSERT(!cmd.isEmpty());
|
||||
QStringList file_selection;
|
||||
if(cust_action.IsActive(ACTION_CONTEXT_FILES))
|
||||
getSelectionFilenames(file_selection, WorkspaceFile::TYPE_ALL);
|
||||
|
||||
// Split command from embedded params
|
||||
QString extra_params;
|
||||
|
||||
// Command ends after first space
|
||||
QChar cmd_char_end = ' ';
|
||||
int start = 0;
|
||||
|
||||
// ...unless it is a quoted command
|
||||
if(cmd[0]=='"')
|
||||
{
|
||||
cmd_char_end = '"';
|
||||
start = 1;
|
||||
}
|
||||
|
||||
int cmd_end = cmd.indexOf(cmd_char_end, start);
|
||||
if(cmd_end != -1)
|
||||
{
|
||||
extra_params = cmd.mid(cmd_end+1);
|
||||
cmd = cmd.left(cmd_end);
|
||||
}
|
||||
|
||||
cmd = cmd.trimmed();
|
||||
extra_params = extra_params.trimmed();
|
||||
|
||||
// Push all additional params, except those containing macros
|
||||
QStringList extra_param_list = extra_params.split(' ');
|
||||
QString macro_file;
|
||||
QString macro_folder;
|
||||
stringset_t path_selection;
|
||||
if(cust_action.IsActive(ACTION_CONTEXT_FOLDERS))
|
||||
getSelectionPaths(path_selection);
|
||||
|
||||
const QString &wkdir = fossil().getCurrentWorkspace();
|
||||
|
||||
foreach(const QString &p, extra_param_list)
|
||||
{
|
||||
if(p.indexOf("$FILE")!=-1)
|
||||
{
|
||||
macro_file = p;
|
||||
continue;
|
||||
}
|
||||
else if(p.indexOf("$FOLDER")!=-1)
|
||||
{
|
||||
macro_folder = p;
|
||||
continue;
|
||||
}
|
||||
else if(p.indexOf("$WORKSPACE")!=-1)
|
||||
{
|
||||
// Add in-place
|
||||
QString n = p;
|
||||
n.replace("$WORKSPACE", wkdir, Qt::CaseInsensitive);
|
||||
params.push_back(n);
|
||||
continue;
|
||||
}
|
||||
|
||||
params.push_back(p);
|
||||
}
|
||||
|
||||
// Build file params
|
||||
if(cust_action.IsActive(ACTION_CONTEXT_FILES))
|
||||
{
|
||||
QStringList file_selection;
|
||||
getSelectionFilenames(file_selection, WorkspaceFile::TYPE_ALL);
|
||||
foreach(const QString &f, file_selection)
|
||||
{
|
||||
QString path = QFileInfo(wkdir + PATH_SEPARATOR + f).absoluteFilePath();
|
||||
|
||||
// Apply macro
|
||||
if(!macro_file.isEmpty())
|
||||
{
|
||||
QString macro = macro_file;
|
||||
path = macro.replace("$FILE", path, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
params.append(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Build folder params
|
||||
if(cust_action.IsActive(ACTION_CONTEXT_FOLDERS))
|
||||
{
|
||||
stringset_t path_selection;
|
||||
getSelectionPaths(path_selection);
|
||||
foreach(const QString &f, path_selection)
|
||||
{
|
||||
QString path = QFileInfo(wkdir + PATH_SEPARATOR + f).absoluteFilePath();
|
||||
|
||||
// Apply macro
|
||||
if(!macro_folder.isEmpty())
|
||||
{
|
||||
QString macro = macro_folder;
|
||||
path = macro.replace("$FOLDER", path, Qt::CaseInsensitive);
|
||||
}
|
||||
params.append(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip action if nothing is available
|
||||
if(params.empty())
|
||||
return;
|
||||
|
||||
log("<b>"+cmd + " "+params.join(" ")+"</b><br>", true);
|
||||
|
||||
QProcess proc(this);
|
||||
proc.startDetached(cmd, params);
|
||||
SpawnExternalProcess(this, cust_action.Command, file_selection, path_selection, wkdir, uiCallback);
|
||||
}
|
||||
|
109
src/Utils.cpp
109
src/Utils.cpp
@@ -4,8 +4,9 @@
|
||||
#include <QFileDialog>
|
||||
#include <QEventLoop>
|
||||
#include <QUrl>
|
||||
#include "ext/qtkeychain/keychain.h"
|
||||
#include <QProcess>
|
||||
#include <QCryptographicHash>
|
||||
#include "ext/qtkeychain/keychain.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, const QString &query, QMessageBox::StandardButtons buttons)
|
||||
@@ -475,3 +476,109 @@ QString UrlToStringNoCredentials(const QUrl& url)
|
||||
return url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SpawnExternalProcess(QObject *procesParent, const QString& command, const QStringList& file_selection, const stringset_t& path_selection, const QString &wkdir, UICallback &ui)
|
||||
{
|
||||
QStringList params;
|
||||
|
||||
// Process command string
|
||||
QString cmd = command;
|
||||
Q_ASSERT(!cmd.isEmpty());
|
||||
|
||||
// Split command from embedded params
|
||||
QString extra_params;
|
||||
|
||||
// Command ends after first space
|
||||
QChar cmd_char_end = ' ';
|
||||
int start = 0;
|
||||
|
||||
// ...unless it is a quoted command
|
||||
if(cmd[0]=='"')
|
||||
{
|
||||
cmd_char_end = '"';
|
||||
start = 1;
|
||||
}
|
||||
|
||||
int cmd_end = cmd.indexOf(cmd_char_end, start);
|
||||
if(cmd_end != -1)
|
||||
{
|
||||
extra_params = cmd.mid(cmd_end+1);
|
||||
cmd = cmd.left(cmd_end);
|
||||
}
|
||||
|
||||
cmd = cmd.trimmed();
|
||||
extra_params = extra_params.trimmed();
|
||||
|
||||
// Push all additional params, except those containing macros
|
||||
QString macro_file;
|
||||
QString macro_folder;
|
||||
|
||||
if(!extra_params.isEmpty())
|
||||
{
|
||||
QStringList extra_param_list = extra_params.split(' ');
|
||||
|
||||
foreach(const QString &p, extra_param_list)
|
||||
{
|
||||
if(p.indexOf("$FILE")!=-1)
|
||||
{
|
||||
macro_file = p;
|
||||
continue;
|
||||
}
|
||||
else if(p.indexOf("$FOLDER")!=-1)
|
||||
{
|
||||
macro_folder = p;
|
||||
continue;
|
||||
}
|
||||
else if(p.indexOf("$WORKSPACE")!=-1)
|
||||
{
|
||||
// Add in-place
|
||||
QString n = p;
|
||||
n.replace("$WORKSPACE", wkdir, Qt::CaseInsensitive);
|
||||
params.push_back(n);
|
||||
continue;
|
||||
}
|
||||
|
||||
params.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Build file params
|
||||
foreach(const QString &f, file_selection)
|
||||
{
|
||||
QString path = QFileInfo(wkdir + PATH_SEPARATOR + f).absoluteFilePath();
|
||||
|
||||
// Apply macro
|
||||
if(!macro_file.isEmpty())
|
||||
{
|
||||
QString macro = macro_file;
|
||||
path = macro.replace("$FILE", path, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
params.append(path);
|
||||
}
|
||||
|
||||
|
||||
// Build folder params
|
||||
foreach(const QString &f, path_selection)
|
||||
{
|
||||
QString path = QFileInfo(wkdir + PATH_SEPARATOR + f).absoluteFilePath();
|
||||
|
||||
// Apply macro
|
||||
if(!macro_folder.isEmpty())
|
||||
{
|
||||
QString macro = macro_folder;
|
||||
path = macro.replace("$FOLDER", path, Qt::CaseInsensitive);
|
||||
}
|
||||
params.append(path);
|
||||
}
|
||||
|
||||
// Skip action if nothing is available
|
||||
if(params.empty())
|
||||
return false;
|
||||
|
||||
ui.logText("<b>"+cmd + " "+params.join(" ")+"</b><br>", true);
|
||||
|
||||
QProcess proc(procesParent);
|
||||
return proc.startDetached(cmd, params);
|
||||
}
|
||||
|
53
src/Utils.h
53
src/Utils.h
@@ -5,37 +5,16 @@
|
||||
#include <QMessageBox>
|
||||
#include <QMap>
|
||||
#include <QStandardItem>
|
||||
#include <QSet>
|
||||
|
||||
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))
|
||||
#define FOSSIL_CHECKOUT1 "_FOSSIL_"
|
||||
#define FOSSIL_CHECKOUT2 ".fslckout"
|
||||
#define FOSSIL_EXT "fossil"
|
||||
#define PATH_SEPARATOR "/"
|
||||
|
||||
typedef QSet<QString> stringset_t;
|
||||
|
||||
QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, const QString &query, QMessageBox::StandardButtons buttons = QMessageBox::Yes|QMessageBox::No);
|
||||
QString QuotePath(const QString &path);
|
||||
QStringList QuotePaths(const QStringList &paths);
|
||||
QString SelectExe(QWidget *parent, const QString &description);
|
||||
|
||||
|
||||
typedef QMap<QString, QModelIndex> name_modelindex_map_t;
|
||||
void GetStandardItemTextRecursive(QString &name, const QStandardItem &item, const QChar &separator='/');
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItem &item);
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel &model);
|
||||
bool KeychainSet(QObject* parent, const QUrl& url);
|
||||
bool KeychainGet(QObject* parent, QUrl& url);
|
||||
bool KeychainDelete(QObject* parent, const QUrl& url);
|
||||
QString HashString(const QString &str);
|
||||
QString UrlToStringDisplay(const QUrl &url);
|
||||
QString UrlToStringNoCredentials(const QUrl& url);
|
||||
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
void ParseProperties(QStringMap &properties, const QStringList &lines, QChar separator=' ');
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
bool ShowExplorerMenu(HWND hwnd, const QString &path, const QPoint &qpoint);
|
||||
#endif
|
||||
|
||||
class UICallback
|
||||
{
|
||||
@@ -65,4 +44,30 @@ private:
|
||||
UICallback *uiCallback;
|
||||
};
|
||||
|
||||
|
||||
QMessageBox::StandardButton DialogQuery(QWidget *parent, const QString &title, const QString &query, QMessageBox::StandardButtons buttons = QMessageBox::Yes|QMessageBox::No);
|
||||
QString QuotePath(const QString &path);
|
||||
QStringList QuotePaths(const QStringList &paths);
|
||||
QString SelectExe(QWidget *parent, const QString &description);
|
||||
|
||||
|
||||
typedef QMap<QString, QModelIndex> name_modelindex_map_t;
|
||||
void GetStandardItemTextRecursive(QString &name, const QStandardItem &item, const QChar &separator='/');
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItem &item);
|
||||
void BuildNameToModelIndex(name_modelindex_map_t &map, const QStandardItemModel &model);
|
||||
bool KeychainSet(QObject* parent, const QUrl& url);
|
||||
bool KeychainGet(QObject* parent, QUrl& url);
|
||||
bool KeychainDelete(QObject* parent, const QUrl& url);
|
||||
QString HashString(const QString &str);
|
||||
QString UrlToStringDisplay(const QUrl &url);
|
||||
QString UrlToStringNoCredentials(const QUrl& url);
|
||||
bool SpawnExternalProcess(QObject *procesParent, const QString &command, const QStringList &file_selection, const stringset_t &path_selection, const QString& wkdir, UICallback& ui);
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
void ParseProperties(QStringMap &properties, const QStringList &lines, QChar separator=' ');
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
bool ShowExplorerMenu(HWND hwnd, const QString &path, const QPoint &qpoint);
|
||||
#endif
|
||||
|
||||
#endif // UTILS_H
|
||||
|
@@ -97,9 +97,6 @@ private:
|
||||
QString Path;
|
||||
};
|
||||
|
||||
|
||||
typedef QSet<QString> stringset_t;
|
||||
|
||||
class Remote
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user