mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00

1. Handle directory rename correctly; 2. Handle file rename correctly; Signed-off-by: Le Tan <tamlokveer@gmail.com>
94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
#ifndef VFILELIST_H
|
|
#define VFILELIST_H
|
|
|
|
#include <QWidget>
|
|
#include <QJsonObject>
|
|
#include <QFileInfo>
|
|
#include <QDir>
|
|
#include "vnotebook.h"
|
|
#include "vconstants.h"
|
|
|
|
class QAction;
|
|
class VNote;
|
|
class QListWidget;
|
|
class QListWidgetItem;
|
|
class QPushButton;
|
|
class VEditArea;
|
|
|
|
class VFileList : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit VFileList(VNote *vnote, QWidget *parent = 0);
|
|
bool importFile(const QString &name);
|
|
inline void setEditArea(VEditArea *editArea);
|
|
|
|
signals:
|
|
void fileClicked(QJsonObject fileJson);
|
|
void fileDeleted(QJsonObject fileJson);
|
|
void fileCreated(QJsonObject fileJson);
|
|
void fileRenamed(const QString ¬ebook, const QString &oldPath,
|
|
const QString &newPath);
|
|
void directoryChanged(const QString ¬ebook, const QString &relativePath);
|
|
|
|
private slots:
|
|
void contextMenuRequested(QPoint pos);
|
|
void handleItemClicked(QListWidgetItem *currentItem);
|
|
void fileInfo();
|
|
|
|
public slots:
|
|
void setDirectory(QJsonObject dirJson);
|
|
void handleNotebookRenamed(const QVector<VNotebook> ¬ebooks, const QString &oldName,
|
|
const QString &newName);
|
|
void handleDirectoryRenamed(const QString ¬ebook, const QString &oldRelativePath,
|
|
const QString &newRelativePath);
|
|
void newFile();
|
|
void deleteFile();
|
|
|
|
private:
|
|
void setupUI();
|
|
void updateFileList();
|
|
QListWidgetItem *insertFileListItem(QJsonObject fileJson, bool atFront = false);
|
|
void removeFileListItem(QListWidgetItem *item);
|
|
void initActions();
|
|
bool isConflictNameWithExisting(const QString &name);
|
|
QListWidgetItem *createFileAndUpdateList(const QString &name);
|
|
void deleteFileAndUpdateList(QListWidgetItem *item);
|
|
void clearDirectoryInfo();
|
|
inline QString getDirectoryName();
|
|
void renameFile(QListWidgetItem *item, const QString &newName);
|
|
void convertFileType(const QString ¬ebook, const QString &fileRelativePath,
|
|
DocType oldType, DocType newType);
|
|
|
|
VNote *vnote;
|
|
QString notebook;
|
|
// Current directory's relative path
|
|
QString relativePath;
|
|
// Used for cache
|
|
QString rootPath;
|
|
|
|
VEditArea *editArea;
|
|
|
|
QListWidget *fileList;
|
|
|
|
// Actions
|
|
QAction *newFileAct;
|
|
QAction *deleteFileAct;
|
|
QAction *fileInfoAct;
|
|
};
|
|
|
|
inline QString VFileList::getDirectoryName()
|
|
{
|
|
if (relativePath.isEmpty()) {
|
|
return "";
|
|
}
|
|
return QFileInfo(QDir::cleanPath(relativePath)).fileName();
|
|
}
|
|
|
|
inline void VFileList::setEditArea(VEditArea *editArea)
|
|
{
|
|
this->editArea = editArea;
|
|
}
|
|
|
|
#endif // VFILELIST_H
|