@@ -46,28 +46,15 @@ EditDialog::EditDialog(MainWindow *mainWindow, QWidget *parent)
46
46
buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
47
47
connect (buttonBox, &QDialogButtonBox::accepted, this , [&]() {
48
48
if (promptTextEdit->document ()->isModified ()) { // If there are changes in the text
49
-
50
- QMessageBox::StandardButton reply = QMessageBox::question (this , " Save changes?" , " Do you want to save the changes to a new text file?" ,
51
- QMessageBox::Yes | QMessageBox::No);
52
- if (reply == QMessageBox::Yes) { // If the user wants to save the changes
53
- // Save the text to a new file
54
- QString modelPath = m_mainWindow->getModelPath ();
55
- QString fileName = QFileDialog::getSaveFileName (this , " Save Text File" , modelPath, " Text files (*.txt)" );
56
- if (!fileName.isEmpty ()) { // If the user has selected a valid file name
57
- QFile file (fileName);
58
- if (file.open (QIODevice::WriteOnly | QIODevice::Text)) {
59
- QTextStream stream (&file);
60
- stream << promptTextEdit->toPlainText ();
61
- file.close ();
62
- }
63
- }
64
- }
49
+ saveNewPrompts ();
50
+ // promptComboBox->clear();
51
+ // populateComboBox();
65
52
}
66
53
67
54
// Send the updated prompt to mainwindow.
55
+ promptIndex = promptComboBox->currentIndex ();
68
56
emit sendPrompt (promptTextEdit->toPlainText ());
69
- promptComboBox->clear ();
70
- populateComboBox ();
57
+
71
58
72
59
this ->accept (); // Accept the dialog
73
60
});
@@ -103,6 +90,49 @@ EditDialog::EditDialog(MainWindow *mainWindow, QWidget *parent)
103
90
modelComboBox->setCurrentIndex (0 );
104
91
}
105
92
93
+ void EditDialog::saveNewPrompts (){
94
+ QMessageBox::StandardButton reply = QMessageBox::question (this , " Save changes?" , " Do you want to save the changes to a new text file?" ,
95
+ QMessageBox::Yes | QMessageBox::No);
96
+ if (reply == QMessageBox::Yes) { // If the user wants to save the changes
97
+ // Save the text to a new file
98
+ QString modelPath = m_mainWindow->getModelPath ();
99
+ QString fullPath = QFileDialog::getSaveFileName (this , " Save Text File" , modelPath, " Text files (*.txt)" );
100
+ if (!fullPath.isEmpty ()) { // If the user has selected a valid file name
101
+ QFile file (fullPath);
102
+ if (file.open (QIODevice::WriteOnly | QIODevice::Text)) {
103
+ QTextStream stream (&file);
104
+ stream << promptTextEdit->toPlainText ();
105
+ file.close ();
106
+
107
+ // Add a new item to the end of the combobox
108
+ QFileInfo fileInfo (fullPath);
109
+ QString fileName = fileInfo.fileName ();
110
+
111
+ int samePrompt = -1 ;
112
+ for (int i = 0 ; i < promptComboBox->count (); ++i) {
113
+ QString itemText = promptComboBox->itemText (i);
114
+
115
+ // Compare the item text with the filename
116
+ if (itemText == fileName) {
117
+ // Item with the same filename exists in the combobox
118
+ samePrompt = i;
119
+ }
120
+ }
121
+
122
+ if (samePrompt >= 0 )
123
+ {
124
+ promptComboBox->setCurrentIndex (samePrompt);
125
+ }
126
+ else
127
+ {
128
+ promptComboBox->addItem (fileName);
129
+ promptComboBox->setCurrentIndex (promptComboBox->count () - 1 );
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+
106
136
void EditDialog::initAzureSetting ()
107
137
{
108
138
QStringList defaultVoices = {
@@ -164,10 +194,10 @@ void EditDialog::populateComboBox()
164
194
int modelIndex = m_mainWindow->getModelIndex ();
165
195
166
196
QDir directory (modelPath);
167
- QStringList txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Time );
197
+ QStringList txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Name );
168
198
169
199
initPrompts (modelIndex);
170
- txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Time );
200
+ txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Name );
171
201
172
202
173
203
for (int i = 0 ; i < txtFiles.size (); ++i)
@@ -192,12 +222,12 @@ QString EditDialog::parsePrompt(QString txtFileName)
192
222
return text;
193
223
}
194
224
195
- void EditDialog::loadPrompts (int promptIndex )
225
+ void EditDialog::loadPrompts (int idx )
196
226
{
197
227
QString modelPath = m_mainWindow->getModelPath ();
198
228
QDir directory (modelPath);
199
- QStringList txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Time );
200
- QString promptFileName = txtFiles.at (promptIndex );
229
+ QStringList txtFiles = directory.entryList (QStringList () << " *.txt" , QDir::Files, QDir::Name );
230
+ QString promptFileName = txtFiles.at (idx );
201
231
QString text = parsePrompt (modelPath + promptFileName);
202
232
203
233
promptTextEdit->clear ();
@@ -263,7 +293,7 @@ void EditDialog::initPrompts(int modelIndex)
263
293
}
264
294
265
295
QString str;
266
- rules.append (" ### Instruction ### \n You are Albert Einstein and you know everything. \n " );
296
+ rules.append (" You are Albert Einstein and you know everything. \n " );
267
297
268
298
str = " Your reply must be in JSON format with the following keys: Expression, Motion, Content \n " ;
269
299
rules.append (str);
0 commit comments