mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 14:29:54 +08:00
NewNoteDialog: remember default file type
This commit is contained in:
parent
b3a385693c
commit
6ea5995c12
@ -132,7 +132,9 @@ const QVector<FileType> &FileTypeHelper::getAllFileTypes() const
|
|||||||
|
|
||||||
const FileType &FileTypeHelper::getFileType(int p_type) const
|
const FileType &FileTypeHelper::getFileType(int p_type) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(p_type < m_fileTypes.size());
|
if (p_type >= m_fileTypes.size()) {
|
||||||
|
p_type = FileType::Others;
|
||||||
|
}
|
||||||
return m_fileTypes[p_type];
|
return m_fileTypes[p_type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ void WidgetConfig::init(const QJsonObject &p_app,
|
|||||||
m_snippetPanelBuiltInSnippetsVisible = READBOOL(QStringLiteral("snippet_panel_builtin_snippets_visible"));
|
m_snippetPanelBuiltInSnippetsVisible = READBOOL(QStringLiteral("snippet_panel_builtin_snippets_visible"));
|
||||||
|
|
||||||
m_tagExplorerTwoColumnsEnabled = READBOOL(QStringLiteral("tag_explorer_two_columns_enabled"));
|
m_tagExplorerTwoColumnsEnabled = READBOOL(QStringLiteral("tag_explorer_two_columns_enabled"));
|
||||||
|
|
||||||
|
m_newNoteDefaultFileType = READINT(QStringLiteral("new_note_default_file_type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject WidgetConfig::toJson() const
|
QJsonObject WidgetConfig::toJson() const
|
||||||
@ -65,6 +67,7 @@ QJsonObject WidgetConfig::toJson() const
|
|||||||
writeStringList(obj,
|
writeStringList(obj,
|
||||||
QStringLiteral("main_window_keep_docks_expanding_content_area"),
|
QStringLiteral("main_window_keep_docks_expanding_content_area"),
|
||||||
m_mainWindowKeepDocksExpandingContentArea);
|
m_mainWindowKeepDocksExpandingContentArea);
|
||||||
|
obj[QStringLiteral("new_note_default_file_type")] = m_newNoteDefaultFileType;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,3 +190,13 @@ void WidgetConfig::setTagExplorerTwoColumnsEnabled(bool p_enabled)
|
|||||||
{
|
{
|
||||||
updateConfig(m_tagExplorerTwoColumnsEnabled, p_enabled, this);
|
updateConfig(m_tagExplorerTwoColumnsEnabled, p_enabled, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WidgetConfig::getNewNoteDefaultFileType() const
|
||||||
|
{
|
||||||
|
return m_newNoteDefaultFileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetConfig::setNewNoteDefaultFileType(int p_type)
|
||||||
|
{
|
||||||
|
updateConfig(m_newNoteDefaultFileType, p_type, this);
|
||||||
|
}
|
||||||
|
@ -54,6 +54,9 @@ namespace vnotex
|
|||||||
bool getTagExplorerTwoColumnsEnabled() const;
|
bool getTagExplorerTwoColumnsEnabled() const;
|
||||||
void setTagExplorerTwoColumnsEnabled(bool p_enabled);
|
void setTagExplorerTwoColumnsEnabled(bool p_enabled);
|
||||||
|
|
||||||
|
int getNewNoteDefaultFileType() const;
|
||||||
|
void setNewNoteDefaultFileType(int p_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_outlineAutoExpandedLevel = 6;
|
int m_outlineAutoExpandedLevel = 6;
|
||||||
|
|
||||||
@ -80,6 +83,8 @@ namespace vnotex
|
|||||||
|
|
||||||
// Whether enable two columns for tag explorer.
|
// Whether enable two columns for tag explorer.
|
||||||
bool m_tagExplorerTwoColumnsEnabled = false;
|
bool m_tagExplorerTwoColumnsEnabled = false;
|
||||||
|
|
||||||
|
int m_newNoteDefaultFileType = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +417,7 @@
|
|||||||
"//comment" : "Docks to ignore when expanding content area of main window",
|
"//comment" : "Docks to ignore when expanding content area of main window",
|
||||||
"main_window_keep_docks_expanding_content_area": ["OutlineDock.vnotex"],
|
"main_window_keep_docks_expanding_content_area": ["OutlineDock.vnotex"],
|
||||||
"snippet_panel_builtin_snippets_visible" : true,
|
"snippet_panel_builtin_snippets_visible" : true,
|
||||||
"tag_explorer_two_columns_enabled" : true
|
"tag_explorer_two_columns_enabled" : true,
|
||||||
|
"new_note_default_file_type" : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
#include "nodeinfowidget.h"
|
#include "nodeinfowidget.h"
|
||||||
#include <utils/widgetutils.h>
|
#include <utils/widgetutils.h>
|
||||||
#include <core/templatemgr.h>
|
#include <core/templatemgr.h>
|
||||||
|
#include <core/configmgr.h>
|
||||||
|
#include <core/widgetconfig.h>
|
||||||
#include <snippet/snippetmgr.h>
|
#include <snippet/snippetmgr.h>
|
||||||
|
#include <buffer/filetypehelper.h>
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
@ -105,6 +108,11 @@ void NewNoteDialog::acceptedButtonClicked()
|
|||||||
{
|
{
|
||||||
s_lastTemplate = m_templateComboBox->currentData().toString();
|
s_lastTemplate = m_templateComboBox->currentData().toString();
|
||||||
|
|
||||||
|
{
|
||||||
|
auto fileType = FileTypeHelper::getInst().getFileTypeByName(m_infoWidget->getFileType()).m_type;
|
||||||
|
ConfigMgr::getInst().getWidgetConfig().setNewNoteDefaultFileType(static_cast<int>(fileType));
|
||||||
|
}
|
||||||
|
|
||||||
if (validateInputs() && newNote()) {
|
if (validateInputs() && newNote()) {
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
@ -143,10 +151,15 @@ const QSharedPointer<Node> &NewNoteDialog::getNewNode() const
|
|||||||
void NewNoteDialog::initDefaultValues(const Node *p_node)
|
void NewNoteDialog::initDefaultValues(const Node *p_node)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
int defaultType = ConfigMgr::getInst().getWidgetConfig().getNewNoteDefaultFileType();
|
||||||
|
const auto &fileType = FileTypeHelper::getInst().getFileType(defaultType);
|
||||||
|
|
||||||
|
m_infoWidget->setFileType(fileType.m_typeName);
|
||||||
|
|
||||||
auto lineEdit = m_infoWidget->getNameLineEdit();
|
auto lineEdit = m_infoWidget->getNameLineEdit();
|
||||||
auto defaultName = FileUtils::generateFileNameWithSequence(p_node->fetchAbsolutePath(),
|
auto defaultName = FileUtils::generateFileNameWithSequence(p_node->fetchAbsolutePath(),
|
||||||
tr("note"),
|
tr("note"),
|
||||||
QStringLiteral("md"));
|
fileType.preferredSuffix());
|
||||||
lineEdit->setText(defaultName);
|
lineEdit->setText(defaultName);
|
||||||
WidgetUtils::selectBaseName(lineEdit);
|
WidgetUtils::selectBaseName(lineEdit);
|
||||||
}
|
}
|
||||||
|
@ -197,3 +197,16 @@ QFormLayout *NodeInfoWidget::getMainLayout() const
|
|||||||
{
|
{
|
||||||
return m_mainLayout;
|
return m_mainLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString NodeInfoWidget::getFileType() const
|
||||||
|
{
|
||||||
|
return m_fileTypeComboBox->currentData().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeInfoWidget::setFileType(const QString &p_typeName)
|
||||||
|
{
|
||||||
|
int idx = m_fileTypeComboBox->findData(p_typeName);
|
||||||
|
if (idx != -1) {
|
||||||
|
m_fileTypeComboBox->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -39,6 +39,9 @@ namespace vnotex
|
|||||||
// Allow upper level to add more widgets to the layout.
|
// Allow upper level to add more widgets to the layout.
|
||||||
QFormLayout *getMainLayout() const;
|
QFormLayout *getMainLayout() const;
|
||||||
|
|
||||||
|
QString getFileType() const;
|
||||||
|
void setFileType(const QString &p_typeName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void inputEdited();
|
void inputEdited();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user