add config insert_new_note_in_front

This commit is contained in:
Le Tan 2018-09-06 21:08:46 +08:00
parent 32991051a9
commit 3d188fa648
8 changed files with 46 additions and 7 deletions

View File

@ -255,6 +255,9 @@ smart_live_preview=3
; Support multiple keyboard layout
multiple_keyboard_layout=true
; Whether insert new note in front
insert_new_note_in_front=false
[editor]
; Auto indent as previous line
auto_indent=true

View File

@ -317,6 +317,9 @@ void VConfigManager::initialize()
m_multipleKeyboardLayout = getConfigFromSettings("global",
"multiple_keyboard_layout").toBool();
m_insertNewNoteInFront = getConfigFromSettings("global",
"insert_new_note_in_front").toBool();
initEditorConfigs();
}

View File

@ -558,6 +558,9 @@ public:
bool getMultipleKeyboardLayout() const;
bool getInsertNewNoteInFront() const;
void setInsertNewNoteInFront(bool p_enabled);
private:
// Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -1001,6 +1004,9 @@ private:
// Support multiple keyboard layout.
bool m_multipleKeyboardLayout;
// Whether insert new note in front.
bool m_insertNewNoteInFront;
// The name of the config file in each directory.
static const QString c_dirConfigFile;
@ -2576,4 +2582,19 @@ inline bool VConfigManager::getMultipleKeyboardLayout() const
{
return m_multipleKeyboardLayout;
}
inline bool VConfigManager::getInsertNewNoteInFront() const
{
return m_insertNewNoteInFront;
}
inline void VConfigManager::setInsertNewNoteInFront(bool p_enabled)
{
if (m_insertNewNoteInFront == p_enabled) {
return;
}
m_insertNewNoteInFront = p_enabled;
setConfigToSettings("global", "insert_new_note_in_front", m_insertNewNoteInFront);
}
#endif // VCONFIGMANAGER_H

View File

@ -289,7 +289,7 @@ bool VDirectory::containsFile(const VFile *p_file) const
return false;
}
VNoteFile *VDirectory::createFile(const QString &p_name)
VNoteFile *VDirectory::createFile(const QString &p_name, bool p_front)
{
Q_ASSERT(!p_name.isEmpty());
if (!open()) {
@ -312,11 +312,19 @@ VNoteFile *VDirectory::createFile(const QString &p_name)
true,
dateTime,
dateTime);
m_files.append(ret);
int idx = -1;
if (p_front) {
m_files.prepend(ret);
idx = 0;
} else {
m_files.append(ret);
idx = m_files.size() - 1;
}
if (!writeToConfig()) {
file.remove();
delete ret;
m_files.removeLast();
m_files.remove(idx);
return NULL;
}

View File

@ -37,7 +37,7 @@ public:
// If current dir or its sub-dir contains @p_file.
bool containsFile(const VFile *p_file) const;
VNoteFile *createFile(const QString &p_name);
VNoteFile *createFile(const QString &p_name, bool p_front);
// Remove the file in the config and m_files without deleting it in the disk.
// It won't change the parent of @p_file to enable it find its path.

View File

@ -349,7 +349,8 @@ void VFileList::newFile()
true);
VNewFileDialog dialog(tr("Create Note"), info, defaultName, m_directory, this);
if (dialog.exec() == QDialog::Accepted) {
VNoteFile *file = m_directory->createFile(dialog.getNameInput());
VNoteFile *file = m_directory->createFile(dialog.getNameInput(),
g_config->getInsertNewNoteInFront());
if (!file) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create note <span style=\"%1\">%2</span>.")
@ -998,6 +999,7 @@ void VFileList::pasteFiles(VDirectory *p_destDir,
fileName,
file,
p_isCut,
g_config->getInsertNewNoteInFront() ? 0 : -1,
&destFile,
&msg);
if (!ret) {

View File

@ -453,6 +453,7 @@ bool VNoteFile::copyFile(VDirectory *p_destDir,
const QString &p_destName,
VNoteFile *p_file,
bool p_isCut,
int p_idx,
VNoteFile **p_targetFile,
QString *p_errMsg)
{
@ -506,13 +507,13 @@ bool VNoteFile::copyFile(VDirectory *p_destDir,
if (p_isCut) {
srcDir->removeFile(p_file);
p_file->setName(p_destName);
if (p_destDir->addFile(p_file, -1)) {
if (p_destDir->addFile(p_file, p_idx)) {
destFile = p_file;
} else {
destFile = NULL;
}
} else {
destFile = p_destDir->addFile(p_destName, -1);
destFile = p_destDir->addFile(p_destName, p_idx);
// Copy tags to this file.
if (destFile) {
const QStringList &tags = p_file->getTags();

View File

@ -135,6 +135,7 @@ public:
const QString &p_destName,
VNoteFile *p_file,
bool p_isCut,
int p_idx,
VNoteFile **p_targetFile,
QString *p_errMsg = NULL);