Browse Source

refine default new note name

Le Tan 5 years ago
parent
commit
b4818e617f

BIN
pics/main.png


BIN
src/data/core/translations/vnote_zh_CN.qm


+ 9 - 4
src/data/core/translations/vnote_zh_CN.ts

@@ -1391,25 +1391,30 @@
 <context>
     <name>vnotex::NewNoteDialog</name>
     <message>
-        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="36"/>
+        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="35"/>
         <source>New Note</source>
         <translation>新建笔记</translation>
     </message>
     <message>
-        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="63"/>
+        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="62"/>
         <source>Please specify a name for the note.</source>
         <translation>请为笔记指定一个名字。</translation>
     </message>
     <message>
-        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="68"/>
+        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="67"/>
         <source>Name conflicts with existing note.</source>
         <translation>名字和已有笔记冲突。</translation>
     </message>
     <message>
-        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="91"/>
+        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="90"/>
         <source>Failed to create note under (%1) in (%2) (%3).</source>
         <translation>无法在笔记本 (%2) 中文件夹 (%1) 下创建笔记 (%3)。</translation>
     </message>
+    <message>
+        <location filename="../../../widgets/dialogs/newnotedialog.cpp" line="113"/>
+        <source>note</source>
+        <translation>笔记</translation>
+    </message>
 </context>
 <context>
     <name>vnotex::NewNotebookDialog</name>

+ 7 - 5
src/widgets/dialogs/newnotedialog.cpp

@@ -6,21 +6,20 @@
 #include "notebook/node.h"
 #include "../widgetsfactory.h"
 #include <utils/pathutils.h>
+#include <utils/fileutils.h>
 #include "exception.h"
 #include "nodeinfowidget.h"
 #include <utils/widgetutils.h>
 
 using namespace vnotex;
 
-const QString NewNoteDialog::c_defaultNoteName = "new_note.md";
-
 NewNoteDialog::NewNoteDialog(Node *p_node, QWidget *p_parent)
     : ScrollDialog(p_parent)
 {
     Q_ASSERT(p_node && p_node->isLoaded());
     setupUI(p_node);
 
-    initDefaultValues();
+    initDefaultValues(p_node);
 
     m_infoWidget->getNameLineEdit()->setFocus();
 }
@@ -106,11 +105,14 @@ const QSharedPointer<Node> &NewNoteDialog::getNewNode() const
     return m_newNode;
 }
 
-void NewNoteDialog::initDefaultValues()
+void NewNoteDialog::initDefaultValues(const Node *p_node)
 {
     {
         auto lineEdit = m_infoWidget->getNameLineEdit();
-        lineEdit->setText(c_defaultNoteName);
+        auto defaultName = FileUtils::generateFileNameWithSequence(p_node->fetchAbsolutePath(),
+                                                                   tr("note"),
+                                                                   QStringLiteral("md"));
+        lineEdit->setText(defaultName);
         WidgetUtils::selectBaseName(lineEdit);
 
         validateInputs();

+ 1 - 3
src/widgets/dialogs/newnotedialog.h

@@ -33,13 +33,11 @@ namespace vnotex
 
         bool newNote();
 
-        void initDefaultValues();
+        void initDefaultValues(const Node *p_node);
 
         NodeInfoWidget *m_infoWidget = nullptr;
 
         QSharedPointer<Node> m_newNode;
-
-        static const QString c_defaultNoteName;
     };
 } // ns vnotex