Skip to content

Commit 3e7ea1c

Browse files
author
brkgbr
committed
feat: Added a right click option to activity items to allow file observation features
Signed-off-by: brkgbr <[email protected]> Signed-off-by: brkgbr <->
1 parent 4cf818e commit 3e7ea1c

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

src/gui/tray/ActivityList.qml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ScrollView {
2626
}
2727

2828
signal openFile(string filePath)
29+
signal showInFileManager(int index)
2930
signal activityItemClicked(int index)
3031

3132
contentWidth: availableWidth
@@ -51,6 +52,14 @@ ScrollView {
5152
ListView {
5253
id: activityList
5354

55+
function openFileOrLink(index) {
56+
if (model.isCurrentUserFileActivity && model.openablePath) {
57+
openFile("file://" + model.openablePath);
58+
} else {
59+
activityItemClicked(index);
60+
}
61+
}
62+
5463
Accessible.role: Accessible.List
5564
Accessible.name: qsTr("Activity list")
5665

@@ -117,11 +126,25 @@ ScrollView {
117126

118127
forceActiveFocus();
119128
}
120-
onClicked: {
121-
if (model.isCurrentUserFileActivity && model.openablePath) {
122-
openFile("file://" + model.openablePath);
123-
} else {
124-
activityItemClicked(model.activityIndex)
129+
130+
MouseArea {
131+
anchors.fill: parent
132+
acceptedButtons: Qt.LeftButton | Qt.RightButton
133+
onClicked: (mouse)=> {
134+
switch (mouse.button) {
135+
case Qt.LeftButton:
136+
activityList.openFileOrLink(activityList.currentIndex)
137+
break;
138+
case Qt.RightButton:
139+
// We only want to allow the context menu for actual files
140+
if (model.showFileDetails) {
141+
contextMenu.x = mouse.x;
142+
contextMenu.y = mouse.y;
143+
contextMenu.selectedItem = activityList.currentIndex
144+
contextMenu.open();
145+
}
146+
break;
147+
}
125148
}
126149
}
127150
}
@@ -148,6 +171,26 @@ ScrollView {
148171
visible: !controlRoot.atYBeginning && controlRoot.contentHeight > controlRoot.height
149172
}
150173

174+
Menu {
175+
id: contextMenu
176+
property int selectedItem
177+
178+
MenuItem {
179+
text: qsTr("Open local file")
180+
onTriggered: {
181+
activityList.currentIndex = contextMenu.selectedItem
182+
activityList.openFileOrLink(contextMenu.selectedItem);
183+
}
184+
}
185+
MenuItem {
186+
text: qsTr("Show in file manager")
187+
onTriggered: {
188+
activityList.currentIndex = contextMenu.selectedItem
189+
showInFileManager(contextMenu.selectedItem);
190+
}
191+
}
192+
}
193+
151194
Column {
152195
id: placeholderColumn
153196
width: parent.width * 0.8

src/gui/tray/MainWindow.qml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,8 @@ ApplicationWindow {
486486
activeFocusOnTab: true
487487
model: activityModel
488488
onOpenFile: Qt.openUrlExternally(filePath);
489-
onActivityItemClicked: {
490-
model.slotTriggerDefaultAction(index)
491-
}
489+
onShowInFileManager: index => model.slotTriggerShowInFileManager(index)
490+
onActivityItemClicked: index => model.slotTriggerDefaultAction(index)
492491
Connections {
493492
target: activityModel
494493
function onInteractiveActivityReceived() {

src/gui/tray/activitylistmodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "caseclashfilenamedialog.h"
1818
#include "activitydata.h"
1919
#include "systray.h"
20+
#include "openfilemanager.h"
21+
#include "filesystem.h"
2022

2123
#include <QtCore>
2224
#include <QAbstractListModel>
@@ -862,6 +864,20 @@ void ActivityListModel::slotTriggerDismiss(const int activityIndex)
862864
emit sendNotificationRequest(activity._accName, Utility::concatUrlPath(accountState()->account()->url(), "ocs/v2.php/apps/notifications/api/v2/notifications/" + QString::number(activity._id)).toString(), deleteVerb, activityIndex);
863865
}
864866

867+
void ActivityListModel::slotTriggerShowInFileManager(const int activityIndex)
868+
{
869+
if (activityIndex < 0 || activityIndex >= _finalList.size()) {
870+
qCWarning(lcActivity) << "Couldn't trigger show in file manager at index" << activityIndex << "/ final list size:" << _finalList.size();
871+
return;
872+
}
873+
874+
const auto modelIndex = index(activityIndex);
875+
const auto path = data(modelIndex, PathRole).toString();
876+
if (FileSystem::fileExists(path)) {
877+
showInFileManager(path);
878+
}
879+
}
880+
865881
AccountState *ActivityListModel::accountState() const
866882
{
867883
return _accountState;

src/gui/tray/activitylistmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public slots:
120120
void slotTriggerDefaultAction(const int activityIndex);
121121
void slotTriggerAction(const int activityIndex, const int actionIndex);
122122
void slotTriggerDismiss(const int activityIndex);
123+
void slotTriggerShowInFileManager(const int activityIndex);
123124

124125
void addNotificationToActivityList(const OCC::Activity &activity);
125126
void addErrorToActivityList(const OCC::Activity &activity, const OCC::ActivityListModel::ErrorType type);

0 commit comments

Comments
 (0)