Display a system icon for a custom actions
Refactored Icon cache Refactored custom command spawning FossilOrigin-Name: 2dabf7d89cfa79d1ce278c7b083761be5f54a691
This commit is contained in:
@@ -1000,12 +1000,8 @@ void MainWindow::updateFileView()
|
||||
getWorkspace().getFileModel().setItem(item_id, COLUMN_STATUS, status);
|
||||
|
||||
QFileInfo finfo = e.getFileInfo();
|
||||
QString icon_type = iconProvider.type(finfo);
|
||||
|
||||
if(!iconCache.contains(icon_type))
|
||||
iconCache.insert(icon_type, iconProvider.icon(finfo));
|
||||
|
||||
const QIcon *icon = &iconCache[icon_type];
|
||||
const QIcon *icon = &getInternalFileIcon(finfo);
|
||||
|
||||
QStandardItem *filename_item = 0;
|
||||
getWorkspace().getFileModel().setItem(item_id, COLUMN_PATH, new QStandardItem(path));
|
||||
@@ -2114,13 +2110,22 @@ QMenu * MainWindow::createPopupMenu()
|
||||
//------------------------------------------------------------------------------
|
||||
const QIcon &MainWindow::getInternalIcon(const char* name)
|
||||
{
|
||||
if(iconCache.contains(name))
|
||||
return iconCache[name];
|
||||
if(!iconCache.contains(name))
|
||||
iconCache.insert(name, QIcon(name));
|
||||
|
||||
iconCache.insert(name, QIcon(name));
|
||||
return iconCache[name];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const QIcon &MainWindow::getInternalFileIcon(const QFileInfo &finfo)
|
||||
{
|
||||
QString icon_type = iconProvider.type(finfo);
|
||||
|
||||
if(!iconCache.contains(icon_type))
|
||||
iconCache.insert(icon_type, iconProvider.icon(finfo));
|
||||
|
||||
return iconCache[icon_type];
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::on_actionCreateStash_triggered()
|
||||
{
|
||||
@@ -2824,6 +2829,16 @@ void MainWindow::updateCustomActions()
|
||||
action->setVisible(cust_act.IsValid());
|
||||
action->setText(cust_act.Description);
|
||||
|
||||
if(!cust_act.IsValid())
|
||||
continue;
|
||||
|
||||
// Attempt to extract an icon
|
||||
QString cmd, extra_params;
|
||||
SplitCommandLine(cust_act.Command, cmd, extra_params);
|
||||
QFileInfo fi(cmd);
|
||||
if(fi.isFile())
|
||||
action->setIcon(getInternalFileIcon(fi));
|
||||
|
||||
if(cust_act.IsActive(ACTION_CONTEXT_FILES))
|
||||
{
|
||||
ui->fileTableView->addAction(action);
|
||||
|
@@ -62,6 +62,7 @@ private:
|
||||
void setBusy(bool busy);
|
||||
virtual QMenu *createPopupMenu();
|
||||
const QIcon& getInternalIcon(const char *name);
|
||||
const QIcon& getInternalFileIcon(const QFileInfo &finfo);
|
||||
|
||||
enum ViewMode
|
||||
{
|
||||
|
@@ -476,39 +476,45 @@ QString UrlToStringNoCredentials(const QUrl& url)
|
||||
return url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SpawnExternalProcess(QObject *processParent, const QString& command, const QStringList& fileList, const stringset_t& pathSet, const QString &workspaceDir, UICallback &uiCallback)
|
||||
void SplitCommandLine(const QString &commandLine, QString &command, QString &extraParams)
|
||||
{
|
||||
QStringList params;
|
||||
|
||||
// Process command string
|
||||
QString cmd = command;
|
||||
Q_ASSERT(!cmd.isEmpty());
|
||||
command = commandLine;
|
||||
Q_ASSERT(!command.isEmpty());
|
||||
|
||||
// Split command from embedded params
|
||||
QString extra_params;
|
||||
extraParams.clear();
|
||||
|
||||
// Command ends after first space
|
||||
QChar cmd_char_end = ' ';
|
||||
int start = 0;
|
||||
|
||||
// ...unless it is a quoted command
|
||||
if(cmd[0]=='"')
|
||||
if(command[0]=='"')
|
||||
{
|
||||
cmd_char_end = '"';
|
||||
start = 1;
|
||||
}
|
||||
|
||||
int cmd_end = cmd.indexOf(cmd_char_end, start);
|
||||
int cmd_end = command.indexOf(cmd_char_end, start);
|
||||
if(cmd_end != -1)
|
||||
{
|
||||
extra_params = cmd.mid(cmd_end+1);
|
||||
cmd = cmd.left(cmd_end);
|
||||
extraParams = command.mid(cmd_end+1);
|
||||
command = command.left(cmd_end);
|
||||
}
|
||||
|
||||
cmd = cmd.trimmed();
|
||||
extra_params = extra_params.trimmed();
|
||||
command = command.trimmed();
|
||||
extraParams = extraParams.trimmed();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SpawnExternalProcess(QObject *processParent, const QString& command, const QStringList& fileList, const stringset_t& pathSet, const QString &workspaceDir, UICallback &uiCallback)
|
||||
{
|
||||
QStringList params;
|
||||
|
||||
QString cmd, extra_params;
|
||||
SplitCommandLine(command, cmd, extra_params);
|
||||
|
||||
// Push all additional params, except those containing macros
|
||||
QString macro_file;
|
||||
|
@@ -61,6 +61,7 @@ bool KeychainDelete(QObject* parent, const QUrl& url);
|
||||
QString HashString(const QString &str);
|
||||
QString UrlToStringDisplay(const QUrl &url);
|
||||
QString UrlToStringNoCredentials(const QUrl& url);
|
||||
void SplitCommandLine(const QString &commandLine, QString &command, QString &extraParams);
|
||||
bool SpawnExternalProcess(QObject *processParent, const QString& command, const QStringList& fileList, const stringset_t& pathSet, const QString &workspaceDir, UICallback &uiCallback);
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
|
Reference in New Issue
Block a user