#include "base/rebase.hpp"
#include "dialogoptions.hpp"
#include "ui_dialogoptions.h"
+#include "math.h"
+#include <QFileDialog>
+/**
+ * Constructor.
+ *
+ * @param handlers the current list of the context menu handlers
+ * @param parent the widget parent
+ */
DialogOptions::DialogOptions(ContextHandlerList& handlers, QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogOptions),
connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(add()));
connect(ui->pushButtonDel, SIGNAL(clicked()), this, SLOT(del()));
connect(ui->pushButtonDown, SIGNAL(clicked()), this, SLOT(down()));
+ connect(ui->pushButtonSelectProgram, SIGNAL(clicked()), this,
+ SLOT(selectProgram()));
connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int,int)));
+ connect(ui->tableWidget, SIGNAL(cellActivated(int,int)), this, SLOT(cellEntered(int,int)));
for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++)
m_fileTypes.append(ui->comboBoxFileType->itemText(ix));
for (int ix = 0; ix < ui->comboBoxDirMode->count(); ix++)
*/
void DialogOptions::del(){
int count = ui->tableWidget->rowCount() - 1;
- for (int row = m_selectedRow; row < count; row++){
+ int start = m_selectedRow;
+ if (start == 0)
+ start = 1;
+ for (int row = start; row < count; row++){
swapRows(row, row - 1);
}
ui->tableWidget->setRowCount(count);
}
}
+/**
+ * Handles the event "pushed button select program file".
+ */
+void DialogOptions::selectProgram(){
+ QString file = QFileDialog::getOpenFileName(NULL, tr("Select Program File"),
+ ui->comboBoxProgram->currentText());
+ if (!file.isEmpty())
+ ui->comboBoxProgram->setCurrentText(file);
+}
/**
* Handles the event "pushed button up".
*/
void cellEntered(int row, int column);
void del();
void down();
+ void selectProgram();
void up();
private:
void currentToTable(int row);
</column>
<column>
<property name="text">
- <string>Current Directory</string>
+ <string>Directory Mode</string>
</property>
</column>
<item row="0" column="1">
SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(handleTableContextMenu(const QPoint&)));
ContextHandler* handler = new ContextHandler();
- handler->m_text = "kedit";
- handler->m_program = "/usr/bin/kate";
- handler->m_arguments = "${full}";
- handler->m_directoryMode = ContextHandler::DM_UNDEF;
- handler->m_fileType = ContextHandler::FT_FILE;
- m_contextHandlers.list().append(handler);
- handler = new ContextHandler();
- handler->m_text = "bash";
- handler->m_program = "/usr/bin/konsole";
- handler->m_arguments = "${full}";
- handler->m_directoryMode = ContextHandler::DM_TO_FILE;
- handler->m_fileType = ContextHandler::FT_DIR;
- m_contextHandlers.list().append(handler);
}
/**
for (int ix = 0; ix < m_list.size(); ix++){
ContextHandler* handler = m_list.at(ix);
value = handler->m_text + "\t" + handler->m_program + "\t"
+ + handler->m_arguments + "\t"
+ QString::number(handler->m_fileType) + "\t"
+ QString::number(handler->m_directoryMode);
storage.store(name, value, ix);
}
}
+ContextHandler* createHandlerIfExists(const QString& file,
+ ContextHandler::FileType fileType = ContextHandler::FT_FILE){
+ QFileInfo info(file);
+ ContextHandler* handler = NULL;
+ if (info.exists()){
+ handler = new ContextHandler;
+ handler->m_text = ReQStringUtil::nodeOf(file);
+ handler->m_program = file;
+ handler->m_arguments = fileType;
+ handler->m_directoryMode = fileType == ContextHandler::FT_FILE
+ ? ContextHandler::DM_TO_PARENT
+ : ContextHandler::DM_TO_FILE;
+ }
+ return handler;
+}
+
/**
* Reads the list from the storage.
*
int ix = -1;
QString value;
QStringList cols;
+ ContextHandler* handler;
while (true){
ix++;
value = storage.restore(name, ix);
if (value.isEmpty())
break;
cols = value.split('\t');
- if (cols.size() != 5)
- break;
- ContextHandler* handler = new ContextHandler;
+ if (cols.size() < 3)
+ continue;
+ handler = new ContextHandler;
handler->m_text = cols.at(0);
handler->m_program = cols.at(1);
handler->m_arguments = cols.at(2);
- handler->m_fileType = ContextHandler::FileType(
- 1 + atol(cols.at(3).toUtf8().constData()));
- handler->m_directoryMode = ContextHandler::DirMode(
- 1 + atol(cols.at(4).toUtf8().constData()));
+ const char* sValue = cols.at(3).toUtf8().constData();
+ handler->m_fileType = ContextHandler::FileType(atol(sValue));
+ sValue = cols.at(4).toUtf8().constData();
+ handler->m_directoryMode = ContextHandler::DirMode(atol(sValue));
m_list.append(handler);
}
+ if (m_list.size() == 0){
+#if defined __linux__
+ handler = createHandlerIfExists("/usr/bin/kate");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/geany");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/kwrite");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/gedit");
+ if (handler != NULL)
+ m_list.append(handler);
+ handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR);
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR);
+ if (handler != NULL)
+ m_list.append(handler);
+#elif defined __WIN32__
+ handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe");
+ if (handler == NULL)
+ m_contextHandlers.list().append(handler);
+ handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR);
+ if (handler == NULL)
+ m_list.append(handler);
+
+#endif
+ }
}
/**
return found ? ix - start : 0;
}
+/**
+ * Extracts the node of a filename.
+ *
+ * The node is the filename without path.
+ *
+ * @param filename the filename (with or without path)
+ * @return the node of <code>filename</code>
+ */
+ReString ReQStringUtil::nodeOf(const ReString& filename){
+ QString rc;
+
+ int index = filename.lastIndexOf('/');
+ if (index >= 0)
+ rc = filename.mid(index + 1);
+ else{
+#if defined __WIN32__
+ index = filename.lastIndexOf('\\');
+ if (index < 0)
+ rc = filename;
+ else
+ rc = filename.mid(index + 1);
+#endif
+ }
+ return rc;
+}
+
/**
* Appends a relative path to base directory name (absolute or relative).
*
return path;
#endif
}
+ static ReString nodeOf(const ReString& filename);
static QString pathAppend(const QString& base, const QString& path);
static bool replacePlaceholders(QString& text,
const QMap <QString, QString>& placeholders, QString* error);