small fixes
This commit is contained in:
@@ -26,6 +26,16 @@
|
||||
|
||||
QFileInfo projectfs_menu_target;
|
||||
|
||||
enum ItemType {
|
||||
itProject = 1,
|
||||
itFile,
|
||||
itDir
|
||||
};
|
||||
|
||||
const int roleFullPath = Qt::UserRole;
|
||||
const int roleItemType = Qt::UserRole + 1;
|
||||
const int roleIsDir = Qt::UserRole + 2;
|
||||
|
||||
|
||||
ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) {
|
||||
setupUi(this);
|
||||
@@ -40,9 +50,14 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
||||
actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
||||
actionCopy_name->setIcon(Utils::Icons::COPY.icon());
|
||||
actionCopy_path->setIcon(Utils::Icons::COPY.icon());
|
||||
popup_menu.addActions(QList<QAction*>() << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal);
|
||||
popup_menu.addSeparator();
|
||||
popup_menu.addActions(QList<QAction*>() << actionCopy_name << actionCopy_path);
|
||||
QAction * sep = new QAction();
|
||||
sep->setSeparator(true);
|
||||
//this_actions << sep;
|
||||
this_actions << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal;
|
||||
//sep = new QAction();
|
||||
//sep->setSeparator(true);
|
||||
this_actions << sep;
|
||||
this_actions << actionCopy_name << actionCopy_path;
|
||||
proj_plug = 0;
|
||||
//connect(ProjectExplorer::ProjectTree::instance(), SIGNAL(subtreeChanged(ProjectExplorer::FolderNode*)), this, SLOT(projectsChanged()));
|
||||
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), this, SLOT(startupProjectChanged()));
|
||||
@@ -88,8 +103,9 @@ void ProjectFilesystemWidget::createTree(QTreeWidgetItem * ti, const QString & d
|
||||
QTreeWidgetItem * ni = new QTreeWidgetItem();
|
||||
ni->setText(0, nit);
|
||||
ni->setIcon(0, Core::FileIconProvider::icon(i));
|
||||
ni->setData(0, Qt::UserRole, i.absoluteFilePath());
|
||||
ni->setData(0, Qt::UserRole + 1, i.isDir());
|
||||
ni->setData(0, roleFullPath, i.absoluteFilePath());
|
||||
ni->setData(0, roleItemType, i.isDir() ? itDir : itFile);
|
||||
ni->setData(0, roleIsDir, i.isDir());
|
||||
item_map[i.absoluteFilePath()] = ni;
|
||||
if (i.isDir()) {
|
||||
createTree(ni, dir + QDir::separator() + i.fileName());
|
||||
@@ -105,7 +121,7 @@ bool ProjectFilesystemWidget::filterTree(QTreeWidgetItem * ti, const QString & f
|
||||
for (int i = 0; i < ti->childCount(); ++i) {
|
||||
QTreeWidgetItem * ci = ti->child(i);
|
||||
QString cit = ci->text(0);
|
||||
if (ci->data(0, Qt::UserRole + 1).toBool()) {
|
||||
if (ci->data(0, roleIsDir).toBool()) {
|
||||
if (!filterTree(ci, filter)) {
|
||||
ci->setHidden(true);
|
||||
continue;
|
||||
@@ -137,12 +153,12 @@ void ProjectFilesystemWidget::filter() {
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::rememberExpanded(QTreeWidgetItem * ti) {
|
||||
//QMessageBox::information(0, ti->data(0, Qt::UserRole).toString(), QString::number(ti->childCount()));
|
||||
//QMessageBox::information(0, ti->data(0, roleFullPath).toString(), QString::number(ti->childCount()));
|
||||
for (int i = 0; i < ti->childCount(); ++i) {
|
||||
QTreeWidgetItem * ci = ti->child(i);
|
||||
if (ci->data(0, Qt::UserRole + 1).toBool()) {
|
||||
if (ci->data(0, roleIsDir).toBool()) {
|
||||
if (ci->isExpanded())
|
||||
last_expanded << ci->data(0, Qt::UserRole).toString();
|
||||
last_expanded << ci->data(0, roleFullPath).toString();
|
||||
rememberExpanded(ci);
|
||||
}
|
||||
}
|
||||
@@ -152,8 +168,8 @@ void ProjectFilesystemWidget::rememberExpanded(QTreeWidgetItem * ti) {
|
||||
void ProjectFilesystemWidget::restoreExpanded(QTreeWidgetItem * ti) {
|
||||
for (int i = 0; i < ti->childCount(); ++i) {
|
||||
QTreeWidgetItem * ci = ti->child(i);
|
||||
if (ci->data(0, Qt::UserRole + 1).toBool()) {
|
||||
if (last_expanded.contains(ci->data(0, Qt::UserRole).toString()))
|
||||
if (ci->data(0, roleIsDir).toBool()) {
|
||||
if (last_expanded.contains(ci->data(0, roleFullPath).toString()))
|
||||
ci->setExpanded(true);
|
||||
restoreExpanded(ci);
|
||||
}
|
||||
@@ -195,8 +211,9 @@ void ProjectFilesystemWidget::projectsChanged() {
|
||||
ri->setIcon(0, QIcon(logo.fileName()));
|
||||
else
|
||||
ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
||||
ri->setData(0, Qt::UserRole, dir);
|
||||
ri->setData(0, Qt::UserRole + 1, true);
|
||||
ri->setData(0, roleFullPath, dir);
|
||||
ri->setData(0, roleIsDir, true);
|
||||
ri->setData(0, roleItemType, itProject);
|
||||
createTree(ri, dir);
|
||||
tree->addTopLevelItem(ri);
|
||||
}
|
||||
@@ -241,7 +258,7 @@ void ProjectFilesystemWidget::startupProjectChanged() {
|
||||
QTreeWidgetItem * ti = tree->topLevelItem(i);
|
||||
ti->setFont(0, f);
|
||||
if (!sp) continue;
|
||||
if (sp->projectDirectory().toString() == ti->data(0, Qt::UserRole).toString())
|
||||
if (sp->projectDirectory().toString() == ti->data(0, roleFullPath).toString())
|
||||
ti->setFont(0, bf);
|
||||
}
|
||||
}
|
||||
@@ -249,8 +266,8 @@ void ProjectFilesystemWidget::startupProjectChanged() {
|
||||
|
||||
void ProjectFilesystemWidget::on_tree_itemDoubleClicked(QTreeWidgetItem * item, int) {
|
||||
if (!item) return;
|
||||
QString afp = item->data(0, Qt::UserRole).toString();
|
||||
bool dir = item->data(0, Qt::UserRole + 1).toBool();
|
||||
QString afp = item->data(0, roleFullPath).toString();
|
||||
bool dir = item->data(0, roleIsDir).toBool();
|
||||
if (dir) return;
|
||||
if (afp.isEmpty()) return;
|
||||
Core::EditorManager::openEditor(afp);
|
||||
@@ -268,7 +285,7 @@ void ProjectFilesystemWidget::on_tree_itemClicked(QTreeWidgetItem * item, int co
|
||||
setExtVariable();
|
||||
return;
|
||||
}
|
||||
projectfs_menu_target = QFileInfo(item->data(0, Qt::UserRole).toString());
|
||||
projectfs_menu_target = QFileInfo(item->data(0, roleFullPath).toString());
|
||||
setExtVariable();
|
||||
}
|
||||
|
||||
@@ -281,10 +298,25 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint &
|
||||
setExtVariable();
|
||||
return;
|
||||
}
|
||||
projectfs_menu_target = QFileInfo(item->data(0, Qt::UserRole).toString());
|
||||
projectfs_menu_target = QFileInfo(item->data(0, roleFullPath).toString());
|
||||
setExtVariable();
|
||||
actionOpen_here->setEnabled(!projectfs_menu_target.isDir());
|
||||
actionOpen_external->setEnabled(!projectfs_menu_target.isDir());
|
||||
popup_menu.clear();
|
||||
|
||||
/*if (item->data(0, roleItemType).toInt() == itProject) {
|
||||
QString proj_path = item->data(0, roleFullPath).toString();
|
||||
ProjectExplorer::Project * project = Utils::findOrDefault(ProjectExplorer::SessionManager::projects(),
|
||||
[proj_path](const ProjectExplorer::Project * p) {return p->containerNode()->path() == proj_path;});
|
||||
//ProjectExplorer::ProjectTree::instance()->setCurrent
|
||||
|
||||
QMenu * contextMenu = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT)->menu();
|
||||
//contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu();
|
||||
//contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
|
||||
popup_menu.addActions(contextMenu->actions());
|
||||
}*/
|
||||
|
||||
popup_menu.addActions(this_actions);
|
||||
popup_menu.popup(tree->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ protected:
|
||||
bool in_proc, need_rebuild;
|
||||
ExtensionSystem::IPlugin * proj_plug;
|
||||
QMenu popup_menu;
|
||||
QList<QAction*> this_actions;
|
||||
QMap<QString, QTreeWidgetItem*> item_map;
|
||||
QSet<QString> last_expanded;
|
||||
FilterDialog filter_dialog;
|
||||
|
||||
Reference in New Issue
Block a user