- implement: when startup , open file provided by commmand line options

- implement: open files pasted by clipboard
This commit is contained in:
royqh1979@gmail.com 2021-10-04 20:05:24 +08:00
parent 0ae9b92924
commit b28d2d4ab4
6 changed files with 40 additions and 13 deletions

View File

@ -14,6 +14,8 @@ Version 0.6.0
- enhancement: refactor in project (using search symbol occurence and replace in files) - enhancement: refactor in project (using search symbol occurence and replace in files)
- fix: search in files - fix: search in files
- implement: register file associations - implement: register file associations
- implement: when startup , open file provided by commmand line options
- implement: open files pasted by clipboard
Version 0.5.0 Version 0.5.0
- enhancement: support C++ using type alias; - enhancement: support C++ using type alias;

View File

@ -98,10 +98,16 @@ int main(int argc, char *argv[])
MainWindow mainWindow; MainWindow mainWindow;
pMainWindow = &mainWindow; pMainWindow = &mainWindow;
if (pSettings->editor().autoLoadLastFiles()) if (app.arguments().count()>1) {
pMainWindow->loadLastOpens(); QStringList filesToOpen = app.arguments();
if (pMainWindow->editorList()->pageCount()==0) { filesToOpen.pop_front();
pMainWindow->newEditor(); pMainWindow->openFiles(filesToOpen);
} else {
if (pSettings->editor().autoLoadLastFiles())
pMainWindow->loadLastOpens();
if (pMainWindow->editorList()->pageCount()==0) {
pMainWindow->newEditor();
}
} }
mainWindow.show(); mainWindow.show();
int retCode = app.exec(); int retCode = app.exec();

View File

@ -2857,9 +2857,25 @@ void MainWindow::on_actionCopy_triggered()
void MainWindow::on_actionPaste_triggered() void MainWindow::on_actionPaste_triggered()
{ {
Editor * editor = mEditorList->getEditor(); QClipboard* clipboard = QGuiApplication::clipboard();
if (editor != NULL ) { const QMimeData* data = clipboard->mimeData();
editor->pasteFromClipboard(); if (!data)
return;
if (data->hasUrls()) {
QStringList filesToOpen;
foreach (const QUrl& url, data->urls()) {
QString s = url.toLocalFile();
if (!s.isEmpty()) {
filesToOpen.append(s);
}
}
if (!filesToOpen.isEmpty())
openFiles(filesToOpen);
} else {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
editor->pasteFromClipboard();
}
} }
} }

View File

@ -91,6 +91,8 @@ public:
void saveLastOpens(); void saveLastOpens();
void loadLastOpens(); void loadLastOpens();
void openFiles(const QStringList& files);
void newEditor(); void newEditor();
QPlainTextEdit* txtLocals(); QPlainTextEdit* txtLocals();
@ -154,7 +156,6 @@ private:
void prepareProjectForCompile(); void prepareProjectForCompile();
void closeProject(bool refreshEditor); void closeProject(bool refreshEditor);
void updateProjectView(); void updateProjectView();
void openFiles(const QStringList& files);
void openFile(const QString& filename); void openFile(const QString& filename);
void openProject(const QString& filename); void openProject(const QString& filename);
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();

View File

@ -191,7 +191,9 @@ QString Settings::Dirs::config(Settings::Dirs::DataType dataType) const
QString Settings::Dirs::executable() const QString Settings::Dirs::executable() const
{ {
return QApplication::instance()->applicationFilePath(); QString s = QApplication::instance()->applicationFilePath();
s.replace("/",QDir::separator());
return s;
} }
void Settings::Dirs::doSave() void Settings::Dirs::doSave()

View File

@ -69,7 +69,7 @@ void FileAssociationModel::updateAssociationStates()
"."+item->suffix, "."+item->suffix,
"DevCpp."+item->suffix, "DevCpp."+item->suffix,
item->name, item->name,
"open", "Open",
pSettings->dirs().executable()+" \"%1\"" pSettings->dirs().executable()+" \"%1\""
); );
item->defaultSelected = item->selected; item->defaultSelected = item->selected;
@ -111,7 +111,7 @@ void FileAssociationModel::saveAssociations()
PFileAssociationItem item = fileTypeDescriptions[fileType]; PFileAssociationItem item = fileTypeDescriptions[fileType];
ok = registerFileType(fileType, ok = registerFileType(fileType,
item->name, item->name,
"open", "Open",
pSettings->dirs().executable(), pSettings->dirs().executable(),
item->icon); item->icon);
} else { } else {
@ -167,7 +167,7 @@ bool FileAssociationModel::checkAssociation(const QString &extension, const QStr
if (result != ERROR_SUCCESS ) if (result != ERROR_SUCCESS )
return false; return false;
QString keyString = QString("%1\\shell\\%2\\command").arg(filetype).arg(verb); QString keyString = QString("%1\\Shell\\%2\\Command").arg(filetype).arg(verb);
QString value1,value2; QString value1,value2;
if (!readRegistry(HKEY_CLASSES_ROOT,keyString.toLocal8Bit(),value1)) if (!readRegistry(HKEY_CLASSES_ROOT,keyString.toLocal8Bit(),value1))
return false; return false;
@ -254,7 +254,7 @@ bool FileAssociationModel::registerFileType(const QString &filetype, const QStri
keyString.toLocal8Bit(), keyString.toLocal8Bit(),
value.toLocal8Bit())) value.toLocal8Bit()))
return false; return false;
keyString = QString("%1\\shell\\%2\\command").arg(filetype).arg(verb); keyString = QString("%1\\Shell\\%2\\Command").arg(filetype).arg(verb);
value = serverApp+" \"%1\""; value = serverApp+" \"%1\"";
if (!writeRegistry(HKEY_CLASSES_ROOT, if (!writeRegistry(HKEY_CLASSES_ROOT,
keyString.toLocal8Bit(), keyString.toLocal8Bit(),