-
Notifications
You must be signed in to change notification settings - Fork 15
/
dirview.cpp
155 lines (125 loc) · 4.18 KB
/
dirview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
License: GPL-2
An electronic filing cabinet: scan, print, stack, arrange
Copyright (C) 2009 Simon Glass, [email protected]
.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in the /usr/share/common-licenses/GPL file.
*/
/*
dirview - directory viewer
*/
#include <QAction>
#include <QContextMenuEvent>
#include <QDebug>
#include <QDirModel>
#include <QHeaderView>
#include <QMenu>
#include "dirview.h"
#include "utils.h"
Dirview::Dirview (QWidget *parent)
: QTreeView (parent)
{
// _dir->setRootIsDecorated (false);
setColumnWidth (0, 400);
hideColumn (1);
hideColumn (2);
hideColumn (3);
header ()->hide ();
setDragDropMode (QAbstractItemView::DragDrop);
// _dir->setDropIndicatorShown (true); - defaults to this
setDragEnabled (true);
setAcceptDrops (true);
// We can't use shortcuts here as they conflict with main view
_search = new QAction ("&Search folder", this);
_search->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
_new = new QAction ("&New subdirectory", this);
_rename = new QAction ("&Rename", this);
_delete = new QAction ("&Delete", this);
_refresh = new QAction ("Re&fresh", this);
_add_recent = new QAction ("&Add to recent", this);
_add_repository = new QAction ("Add repository", this);
_remove_repository = new QAction ("Remove repository", this);
_refresh_cache = new QAction("Refresh cache", this);
addAction (_search);
addAction (_new);
addAction (_rename);
addAction (_delete);
addAction (_refresh);
addAction (_add_recent);
addAction (_add_repository);
addAction (_remove_repository);
addAction(_refresh_cache);
}
Dirview::~Dirview ()
{
}
void Dirview::selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
{
QModelIndexList list = selected.indexes ();
QTreeView::selectionChanged (selected, deselected);
if (list.size () == 1)
selectContextItem (list [0]);
}
void Dirview::selectContextItem (const QModelIndex &index)
{
_context = QPersistentModelIndex (index);
emit clicked(index);
}
void Dirview::contextMenuEvent (QContextMenuEvent * e)
{
QMenu *menu = new QMenu ();
selectContextItem (indexAt (e->pos ()));
menu->addAction (_search);
menu->addAction (_new);
menu->addAction (_rename);
menu->addAction (_delete);
menu->addAction (_refresh);
menu->addAction (_add_recent);
menu->addSeparator ();
menu->addAction (_add_repository);
menu->addAction (_remove_repository);
menu->addAction (_refresh_cache);
menu->exec (e->globalPos());
}
QString Dirview::menuGetPath (void)
{
return model ()->data (_context, QDirModel::FilePathRole).toString ();
}
QString Dirview::menuGetName (void)
{
return model ()->data (_context, QDirModel::FileNameRole).toString ();
}
// void Dirview::dragEnterEvent(QDragEnterEvent *event)
// {
// // if (event->mimeData()->hasFormat("text/plain"))
// event->acceptProposedAction();
// }
void Dirview::dropEvent (QDropEvent *event)
{
if (!utilDropSupported(event,
QStringList({"application/vnd.text.list", "text/uri-list"})))
return;
QTreeView::dropEvent (event);
/*FIXME: drop events seem to close up the list, so we open it again */
QModelIndex index = model ()->index (0, 0, QModelIndex ());
setExpanded (index, true);
}
QModelIndex Dirview::menuGetModelIndex(void)
{
// qDebug() << "menuGetModelIndex" << _context;
return _context;
}