mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
single click in file list to open file in current tab
This commit is contained in:
parent
97721f3e92
commit
30c69fc148
@ -192,6 +192,9 @@ close_before_external_editor=true
|
|||||||
; Each item is in the form "Name:Color"
|
; Each item is in the form "Name:Color"
|
||||||
custom_colors=White:#FFFFFF,LightGrey:#EEEEEE
|
custom_colors=White:#FFFFFF,LightGrey:#EEEEEE
|
||||||
|
|
||||||
|
; Single click to open a file then close previous tab
|
||||||
|
single_click_close_previous_tab=true
|
||||||
|
|
||||||
[web]
|
[web]
|
||||||
; Location and configuration for Mathjax
|
; Location and configuration for Mathjax
|
||||||
mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML
|
mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML
|
||||||
|
@ -287,6 +287,9 @@ void VConfigManager::initialize()
|
|||||||
|
|
||||||
m_stylesToInlineWhenCopied = getConfigFromSettings("web",
|
m_stylesToInlineWhenCopied = getConfigFromSettings("web",
|
||||||
"styles_to_inline_when_copied").toStringList().join(",");
|
"styles_to_inline_when_copied").toStringList().join(",");
|
||||||
|
|
||||||
|
m_singleClickClosePreviousTab = getConfigFromSettings("global",
|
||||||
|
"single_click_close_previous_tab").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::initSettings()
|
void VConfigManager::initSettings()
|
||||||
|
@ -438,6 +438,8 @@ public:
|
|||||||
bool getMenuBarChecked() const;
|
bool getMenuBarChecked() const;
|
||||||
void setMenuBarChecked(bool p_checked);
|
void setMenuBarChecked(bool p_checked);
|
||||||
|
|
||||||
|
bool getSingleClickClosePreviousTab() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Look up a config from user and default settings.
|
// Look up a config from user and default settings.
|
||||||
QVariant getConfigFromSettings(const QString §ion, const QString &key) const;
|
QVariant getConfigFromSettings(const QString §ion, const QString &key) const;
|
||||||
@ -835,6 +837,9 @@ private:
|
|||||||
// The string containing styles to inline when copied in edit mode.
|
// The string containing styles to inline when copied in edit mode.
|
||||||
QString m_stylesToInlineWhenCopied;
|
QString m_stylesToInlineWhenCopied;
|
||||||
|
|
||||||
|
// Single click to open file and then close previous tab.
|
||||||
|
bool m_singleClickClosePreviousTab;
|
||||||
|
|
||||||
// The name of the config file in each directory, obsolete.
|
// The name of the config file in each directory, obsolete.
|
||||||
// Use c_dirConfigFile instead.
|
// Use c_dirConfigFile instead.
|
||||||
static const QString c_obsoleteDirConfigFile;
|
static const QString c_obsoleteDirConfigFile;
|
||||||
@ -2036,4 +2041,9 @@ inline void VConfigManager::setMenuBarChecked(bool p_checked)
|
|||||||
{
|
{
|
||||||
setConfigToSettings("global", "menu_bar_checked", p_checked);
|
setConfigToSettings("global", "menu_bar_checked", p_checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VConfigManager::getSingleClickClosePreviousTab() const
|
||||||
|
{
|
||||||
|
return m_singleClickClosePreviousTab;
|
||||||
|
}
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
@ -313,11 +313,6 @@ int VEditWindow::insertEditTab(int p_index, VFile *p_file, QWidget *p_page)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VEditWindow::appendEditTab(VFile *p_file, QWidget *p_page)
|
|
||||||
{
|
|
||||||
return insertEditTab(count(), p_file, p_page);
|
|
||||||
}
|
|
||||||
|
|
||||||
int VEditWindow::openFile(VFile *p_file, OpenFileMode p_mode)
|
int VEditWindow::openFile(VFile *p_file, OpenFileMode p_mode)
|
||||||
{
|
{
|
||||||
qDebug() << "open" << p_file->getName();
|
qDebug() << "open" << p_file->getName();
|
||||||
@ -326,6 +321,7 @@ int VEditWindow::openFile(VFile *p_file, OpenFileMode p_mode)
|
|||||||
if (idx > -1) {
|
if (idx > -1) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = openFileInTab(p_file, p_mode);
|
idx = openFileInTab(p_file, p_mode);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -459,8 +455,9 @@ int VEditWindow::openFileInTab(VFile *p_file, OpenFileMode p_mode)
|
|||||||
// Connect the signals.
|
// Connect the signals.
|
||||||
connectEditTab(editor);
|
connectEditTab(editor);
|
||||||
|
|
||||||
int idx = appendEditTab(p_file, editor);
|
// Insert right after current tab.
|
||||||
return idx;
|
// VFileList will depends on this behavior.
|
||||||
|
return insertEditTab(currentIndex() + 1, p_file, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int VEditWindow::findTabByFile(const VFile *p_file) const
|
int VEditWindow::findTabByFile(const VFile *p_file) const
|
||||||
@ -990,7 +987,7 @@ bool VEditWindow::addEditTab(QWidget *p_widget)
|
|||||||
// Connect the signals.
|
// Connect the signals.
|
||||||
connectEditTab(editor);
|
connectEditTab(editor);
|
||||||
|
|
||||||
int idx = appendEditTab(editor->getFile(), editor);
|
int idx = insertEditTab(currentIndex() + 1, editor->getFile(), editor);
|
||||||
setCurrentIndex(idx);
|
setCurrentIndex(idx);
|
||||||
updateTabStatus(idx);
|
updateTabStatus(idx);
|
||||||
return true;
|
return true;
|
||||||
|
@ -149,8 +149,9 @@ private:
|
|||||||
void initTabActions();
|
void initTabActions();
|
||||||
void setupCornerWidget();
|
void setupCornerWidget();
|
||||||
void removeEditTab(int p_index);
|
void removeEditTab(int p_index);
|
||||||
|
|
||||||
int insertEditTab(int p_index, VFile *p_file, QWidget *p_page);
|
int insertEditTab(int p_index, VFile *p_file, QWidget *p_page);
|
||||||
int appendEditTab(VFile *p_file, QWidget *p_page);
|
|
||||||
int openFileInTab(VFile *p_file, OpenFileMode p_mode);
|
int openFileInTab(VFile *p_file, OpenFileMode p_mode);
|
||||||
|
|
||||||
QString generateTooltip(const VFile *p_file) const;
|
QString generateTooltip(const VFile *p_file) const;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "vfilelist.h"
|
#include "vfilelist.h"
|
||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
#include "dialog/vnewfiledialog.h"
|
#include "dialog/vnewfiledialog.h"
|
||||||
@ -30,11 +32,31 @@ const QString VFileList::c_cutShortcutSequence = "Ctrl+X";
|
|||||||
const QString VFileList::c_pasteShortcutSequence = "Ctrl+V";
|
const QString VFileList::c_pasteShortcutSequence = "Ctrl+V";
|
||||||
|
|
||||||
VFileList::VFileList(QWidget *parent)
|
VFileList::VFileList(QWidget *parent)
|
||||||
: QWidget(parent), VNavigationMode()
|
: QWidget(parent),
|
||||||
|
VNavigationMode(),
|
||||||
|
m_itemClicked(NULL),
|
||||||
|
m_fileToCloseInSingleClick(NULL)
|
||||||
{
|
{
|
||||||
setupUI();
|
setupUI();
|
||||||
initShortcuts();
|
initShortcuts();
|
||||||
initActions();
|
initActions();
|
||||||
|
|
||||||
|
m_clickTimer = new QTimer(this);
|
||||||
|
m_clickTimer->setSingleShot(true);
|
||||||
|
m_clickTimer->setInterval(QApplication::doubleClickInterval());
|
||||||
|
// When timer timeouts, we need to close the previous tab to simulate the
|
||||||
|
// effect as opening file in current tab.
|
||||||
|
connect(m_clickTimer, &QTimer::timeout,
|
||||||
|
this, [this]() {
|
||||||
|
m_itemClicked = NULL;
|
||||||
|
VFile *file = m_fileToCloseInSingleClick;
|
||||||
|
m_fileToCloseInSingleClick = NULL;
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
editArea->closeFile(file, false);
|
||||||
|
fileList->setFocus();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFileList::setupUI()
|
void VFileList::setupUI()
|
||||||
@ -613,18 +635,62 @@ QListWidgetItem* VFileList::findItem(const VNoteFile *p_file)
|
|||||||
|
|
||||||
void VFileList::handleItemClicked(QListWidgetItem *p_item)
|
void VFileList::handleItemClicked(QListWidgetItem *p_item)
|
||||||
{
|
{
|
||||||
activateItem(p_item);
|
Q_ASSERT(p_item);
|
||||||
|
|
||||||
fileList->setFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VFileList::activateItem(QListWidgetItem *p_item)
|
|
||||||
{
|
|
||||||
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
|
||||||
if (modifiers != Qt::NoModifier) {
|
if (modifiers != Qt::NoModifier) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clickTimer->stop();
|
||||||
|
if (m_itemClicked) {
|
||||||
|
// Timer will not trigger.
|
||||||
|
if (m_itemClicked == p_item) {
|
||||||
|
// Double clicked.
|
||||||
|
m_itemClicked = NULL;
|
||||||
|
m_fileToCloseInSingleClick = NULL;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Handle previous clicked item as single click.
|
||||||
|
m_itemClicked = NULL;
|
||||||
|
if (m_fileToCloseInSingleClick) {
|
||||||
|
editArea->closeFile(m_fileToCloseInSingleClick, false);
|
||||||
|
m_fileToCloseInSingleClick = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pending @p_item.
|
||||||
|
bool singleClickClose = g_config->getSingleClickClosePreviousTab();
|
||||||
|
if (singleClickClose) {
|
||||||
|
VFile *file = getVFile(p_item);
|
||||||
|
Q_ASSERT(file);
|
||||||
|
if (editArea->isFileOpened(file)) {
|
||||||
|
// File already opened.
|
||||||
|
activateItem(p_item, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current tab which will be closed if click timer timeouts.
|
||||||
|
VEditTab *tab = editArea->getCurrentTab();
|
||||||
|
if (tab) {
|
||||||
|
m_fileToCloseInSingleClick = tab->getFile();
|
||||||
|
} else {
|
||||||
|
m_fileToCloseInSingleClick = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate it.
|
||||||
|
activateItem(p_item, true);
|
||||||
|
|
||||||
|
if (singleClickClose) {
|
||||||
|
m_itemClicked = p_item;
|
||||||
|
m_clickTimer->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VFileList::activateItem(QListWidgetItem *p_item, bool p_restoreFocus)
|
||||||
|
{
|
||||||
if (!p_item) {
|
if (!p_item) {
|
||||||
emit fileClicked(NULL);
|
emit fileClicked(NULL);
|
||||||
return;
|
return;
|
||||||
@ -633,6 +699,10 @@ void VFileList::activateItem(QListWidgetItem *p_item)
|
|||||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||||
fileList->update();
|
fileList->update();
|
||||||
emit fileClicked(getVFile(p_item), g_config->getNoteOpenMode());
|
emit fileClicked(getVFile(p_item), g_config->getNoteOpenMode());
|
||||||
|
|
||||||
|
if (p_restoreFocus) {
|
||||||
|
fileList->setFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFileList::importFiles(const QStringList &p_files, QString *p_errMsg)
|
bool VFileList::importFiles(const QStringList &p_files, QString *p_errMsg)
|
||||||
@ -859,7 +929,23 @@ void VFileList::keyPressEvent(QKeyEvent *p_event)
|
|||||||
if (p_event->key() == Qt::Key_Return) {
|
if (p_event->key() == Qt::Key_Return) {
|
||||||
QListWidgetItem *item = fileList->currentItem();
|
QListWidgetItem *item = fileList->currentItem();
|
||||||
if (item) {
|
if (item) {
|
||||||
activateItem(item);
|
VFile *fileToClose = NULL;
|
||||||
|
if (!(p_event->modifiers() & Qt::ControlModifier)) {
|
||||||
|
VFile *file = getVFile(item);
|
||||||
|
Q_ASSERT(file);
|
||||||
|
if (!editArea->isFileOpened(file)) {
|
||||||
|
VEditTab *tab = editArea->getCurrentTab();
|
||||||
|
if (tab) {
|
||||||
|
fileToClose = tab->getFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
activateItem(item, false);
|
||||||
|
if (fileToClose) {
|
||||||
|
editArea->closeFile(fileToClose, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class VEditArea;
|
|||||||
class QFocusEvent;
|
class QFocusEvent;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class VFileList : public QWidget, public VNavigationMode
|
class VFileList : public QWidget, public VNavigationMode
|
||||||
{
|
{
|
||||||
@ -162,7 +163,7 @@ private:
|
|||||||
// Init Open With menu.
|
// Init Open With menu.
|
||||||
void initOpenWithMenu();
|
void initOpenWithMenu();
|
||||||
|
|
||||||
void activateItem(QListWidgetItem *p_item);
|
void activateItem(QListWidgetItem *p_item, bool p_restoreFocus = false);
|
||||||
|
|
||||||
VEditArea *editArea;
|
VEditArea *editArea;
|
||||||
QListWidget *fileList;
|
QListWidget *fileList;
|
||||||
@ -190,6 +191,12 @@ private:
|
|||||||
// Context sub-menu of Open With.
|
// Context sub-menu of Open With.
|
||||||
QMenu *m_openWithMenu;
|
QMenu *m_openWithMenu;
|
||||||
|
|
||||||
|
QTimer *m_clickTimer;
|
||||||
|
|
||||||
|
QListWidgetItem *m_itemClicked;
|
||||||
|
|
||||||
|
VFile *m_fileToCloseInSingleClick;
|
||||||
|
|
||||||
static const QString c_infoShortcutSequence;
|
static const QString c_infoShortcutSequence;
|
||||||
static const QString c_copyShortcutSequence;
|
static const QString c_copyShortcutSequence;
|
||||||
static const QString c_cutShortcutSequence;
|
static const QString c_cutShortcutSequence;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user