Refactored custom action process invocation into a separate function
FossilOrigin-Name: bf36bf1c733da77a39ab9a8b7c63b892c11ef93c
This commit is contained in:
parent
8b2137a58a
commit
30d6cf3da4
20
manifest
20
manifest
@ -1,5 +1,5 @@
|
||||
C Added\ssupport\sfor\s$FILE\s$FOLDER\sand\s$WORKSPACE\smacros\sin\scustom\saction\scommands
|
||||
D 2015-07-10T15:36:47.096
|
||||
C Refactored\scustom\saction\sprocess\sinvocation\sinto\sa\sseparate\sfunction\n
|
||||
D 2015-07-10T15:49:00.994
|
||||
F .travis.yml 77966888a81c4ceee1fcc79bce842c9667ad8a35
|
||||
F debian/changelog eb4304dfcb6bb66850ec740838090eb50ce1249b
|
||||
F debian/compat b6abd567fa79cbe0196d093a067271361dc6ca8b
|
||||
@ -219,12 +219,12 @@ F src/FileActionDialog.h 15db1650b3a13d70bc338371e4c033c66e3b79ce
|
||||
F src/FileTableView.cpp 5ddf8c391c9a3ac449ec61fb1db837b577afeec2
|
||||
F src/FileTableView.h 03e56d87c2d46411b9762b87f4d301619aaf18df
|
||||
F src/Fossil.cpp 0149ce9af91392bb51b87c700e7edd4f8a4aefe7
|
||||
F src/Fossil.h e706992b331385660d57df6a27e5418342c14e19
|
||||
F src/Fossil.h 02599a958e6c27ac5f15d52a813abd40b8f5b2f4
|
||||
F src/FslSettingsDialog.cpp 2531d3709f0eab66651671e3edead2ca720d07d5
|
||||
F src/FslSettingsDialog.h dfe2a61884a55a74cbb9206b6f6b482b979725e7
|
||||
F src/LoggedProcess.cpp 2a1e5c94bc1e57c8984563e66c210e43a14dc60c
|
||||
F src/LoggedProcess.h 85df7c635c807a5a0e8c4763f17a0752aaff7261
|
||||
F src/MainWindow.cpp ab8aa79742a0da21ce1d4ddbe894d523f5c7b7a5
|
||||
F src/MainWindow.cpp ad1e2f3dd64ea0774feb7c13371c02bfac9f3f4b
|
||||
F src/MainWindow.h 573ffe960044afb446505949da50e0fb5ec2f75f
|
||||
F src/RemoteDialog.cpp 8540cc5e2e41c4127ed8a028d84691604fa6ecac
|
||||
F src/RemoteDialog.h 5e0438c2bd7c79b1bb44bfbd58c2181b544a9e5d
|
||||
@ -236,10 +236,10 @@ F src/Settings.cpp 258d3f466f6a125ce2b8519d6d57a312cbc44a3f
|
||||
F src/Settings.h 02bee6bd1178dc456fc80b277edd0843e535649c
|
||||
F src/SettingsDialog.cpp b0d0bfc45534b7bed148776d4c3865a68d59ec15
|
||||
F src/SettingsDialog.h 5eb3ae2cbb00ab5544e1889860f5376f69fe47cd
|
||||
F src/Utils.cpp d53b1b92352e586a7c12a19ec6b109a9f095b7f1
|
||||
F src/Utils.h 011e4be3f94cd26be537299cd44ab9c135db44a5
|
||||
F src/Utils.cpp 876942a44202611d3c778c67f6d0a344e241a000
|
||||
F src/Utils.h 4613424aaeb6910689b5821a2dd44ca0b6dd301f
|
||||
F src/Workspace.cpp 7004c2c30f79d2e64691aa9b2c55ee72a84d978b
|
||||
F src/Workspace.h 7ae2e63196433ae34864d182e49e3a2f0726fb78
|
||||
F src/Workspace.h 0ab9b941a537134a7c43cfccee5299b8ccda143a
|
||||
F src/main.cpp d8c65ea5e54102e4989fef9fd8cfd4f13ef8a8f0
|
||||
F tools/git-push.sh 62cc58434cae5b7bcd6bd9d4cce8b08739f31cd7 x
|
||||
F tools/pack.sh d7f38a498c4e9327fecd6a6e5ac27be270d43008 x
|
||||
@ -252,7 +252,7 @@ F ui/MainWindow.ui 10181826a25056ed5aba2b23a7d110159be7c043
|
||||
F ui/RemoteDialog.ui 95a4750d972ed8c49bb10b95db91ff16cfe2dd0b
|
||||
F ui/RevisionDialog.ui 27c3b98c665fec014a50cbf3352c0627f75e68cd
|
||||
F ui/SettingsDialog.ui b5858067cdb16c3f132af4cf8332e4ad255c915c
|
||||
P 172938d454db50a53cd0e0435991a7fccea59ae7
|
||||
R f0292424de125969e84f6add7e808390
|
||||
P 381aa49e9b6b5d5424ee6dbd69d0890634d5bf08
|
||||
R a7fde02a076af76b8e8f49221c822309
|
||||
U kostas
|
||||
Z 655910e224b8a744950ce119d86fd60d
|
||||
Z 13ebcbf30d3401de44fb0e771c5a69f1
|
||||
|
@ -1 +1 @@
|
||||
381aa49e9b6b5d5424ee6dbd69d0890634d5bf08
|
||||
bf36bf1c733da77a39ab9a8b7c63b892c11ef93c
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user