Skip to content

Commit 882066c

Browse files
committed
Workspace operations: Rename
1 parent 87c5b09 commit 882066c

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

src/NotepadNext/docks/FolderAsWorkspaceDock.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ FolderAsWorkspaceDock::FolderAsWorkspaceDock(QWidget *parent) :
3232
{
3333
ui->setupUi(this);
3434

35+
model->setReadOnly(false);
3536
ui->treeView->setModel(model);
3637
ui->treeView->header()->hideSection(1);
3738
ui->treeView->header()->hideSection(2);
@@ -42,6 +43,7 @@ FolderAsWorkspaceDock::FolderAsWorkspaceDock(QWidget *parent) :
4243
emit fileDoubleClicked(model->filePath(index));
4344
}
4445
});
46+
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &FolderAsWorkspaceDock::onCustomContextMenu);
4547

4648
ApplicationSettings settings;
4749
setRootPath(settings.get(rootPathSetting));
@@ -65,3 +67,41 @@ QString FolderAsWorkspaceDock::rootPath() const
6567
{
6668
return model->rootPath();
6769
}
70+
71+
void FolderAsWorkspaceDock::onCustomContextMenu(const QPoint &point)
72+
{
73+
QModelIndex index = ui->treeView->indexAt(point);
74+
if (!index.isValid()) {
75+
lastSelectedItem = model->index(0, 0);
76+
ui->menuEmpty->exec(ui->treeView->viewport()->mapToGlobal(point));
77+
return;
78+
}
79+
lastSelectedItem = index;
80+
if (model->isDir(index)) {
81+
ui->menuDirectory->exec(ui->treeView->viewport()->mapToGlobal(point));
82+
}
83+
else {
84+
ui->menuFile->exec(ui->treeView->viewport()->mapToGlobal(point));
85+
}
86+
}
87+
88+
void FolderAsWorkspaceDock::on_actionNewFile_triggered()
89+
{
90+
qInfo(Q_FUNC_INFO);
91+
}
92+
93+
void FolderAsWorkspaceDock::on_actionNewFolder_triggered()
94+
{
95+
qInfo(Q_FUNC_INFO);
96+
}
97+
98+
void FolderAsWorkspaceDock::on_actionRename_triggered()
99+
{
100+
ui->treeView->setCurrentIndex(lastSelectedItem);
101+
ui->treeView->edit(lastSelectedItem);
102+
}
103+
104+
void FolderAsWorkspaceDock::on_actionDelete_triggered()
105+
{
106+
qInfo(Q_FUNC_INFO);
107+
}

src/NotepadNext/docks/FolderAsWorkspaceDock.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define FOLDERASWORKSPACEDOCK_H
2222

2323
#include <QDockWidget>
24+
#include <QModelIndex>
2425

2526
namespace Ui {
2627
class FolderAsWorkspaceDock;
@@ -42,10 +43,19 @@ class FolderAsWorkspaceDock : public QDockWidget
4243
signals:
4344
void fileDoubleClicked(const QString &filePath);
4445

46+
private slots:
47+
void on_actionNewFile_triggered();
48+
void on_actionNewFolder_triggered();
49+
void on_actionRename_triggered();
50+
void on_actionDelete_triggered();
51+
52+
void onCustomContextMenu(const QPoint &point);
53+
4554
private:
4655
Ui::FolderAsWorkspaceDock *ui;
4756

4857
QFileSystemModel *model;
58+
QModelIndex lastSelectedItem;
4959
};
5060

5161
#endif // FOLDERASWORKSPACEDOCK_H

src/NotepadNext/docks/FolderAsWorkspaceDock.ui

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,81 @@
2727
<property name="bottomMargin">
2828
<number>0</number>
2929
</property>
30+
<item>
31+
<widget class="QMenu" name="menuFile">
32+
<property name="title">
33+
<string>File Menu</string>
34+
</property>
35+
<addaction name="actionRename"/>
36+
<addaction name="actionDelete"/>
37+
</widget>
38+
</item>
39+
<item>
40+
<widget class="QMenu" name="menuDirectory">
41+
<property name="title">
42+
<string>Folder Menu</string>
43+
</property>
44+
<addaction name="actionRename"/>
45+
<addaction name="actionDelete"/>
46+
<addaction name="separator"/>
47+
<addaction name="actionNewFolder"/>
48+
<addaction name="actionNewFile"/>
49+
</widget>
50+
</item>
51+
<item>
52+
<widget class="QMenu" name="menuEmpty">
53+
<property name="title">
54+
<string>Space Menu</string>
55+
</property>
56+
<addaction name="actionNewFolder"/>
57+
<addaction name="actionNewFile"/>
58+
</widget>
59+
</item>
3060
<item>
3161
<widget class="QTreeView" name="treeView">
62+
<property name="contextMenuPolicy">
63+
<enum>Qt::CustomContextMenu</enum>
64+
</property>
3265
<property name="frameShape">
3366
<enum>QFrame::NoFrame</enum>
3467
</property>
68+
<property name="editTriggers">
69+
<set>QAbstractItemView::EditKeyPressed</set>
70+
</property>
3571
<attribute name="headerVisible">
3672
<bool>false</bool>
3773
</attribute>
3874
</widget>
3975
</item>
4076
</layout>
4177
</widget>
78+
<action name="actionNewFile">
79+
<property name="icon">
80+
<iconset resource="../resources.qrc">
81+
<normaloff>:/icons/newfile.png</normaloff>:/icons/newfile.png</iconset>
82+
</property>
83+
<property name="text">
84+
<string>&amp;New File</string>
85+
</property>
86+
</action>
87+
<action name="actionNewFolder">
88+
<property name="text">
89+
<string>New &amp;Folder</string>
90+
</property>
91+
</action>
92+
<action name="actionRename">
93+
<property name="text">
94+
<string>&amp;Rename</string>
95+
</property>
96+
</action>
97+
<action name="actionDelete">
98+
<property name="text">
99+
<string>&amp;Delete</string>
100+
</property>
101+
</action>
42102
</widget>
43-
<resources/>
103+
<resources>
104+
<include location="../resources.qrc"/>
105+
</resources>
44106
<connections/>
45107
</ui>

0 commit comments

Comments
 (0)