2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-06 23:10:57 +08:00
|
|
|
#include "mainwindow.h"
|
2021-04-08 10:29:21 +08:00
|
|
|
#include "settings.h"
|
2021-04-11 21:33:08 +08:00
|
|
|
#include "systemconsts.h"
|
2021-04-13 22:17:18 +08:00
|
|
|
#include "utils.h"
|
2021-04-06 23:10:57 +08:00
|
|
|
#include <QApplication>
|
2021-04-12 00:00:29 +08:00
|
|
|
#include <QDir>
|
|
|
|
#include <QTranslator>
|
2021-04-13 22:17:18 +08:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QMessageBox>
|
2021-04-15 11:18:14 +08:00
|
|
|
#include <QStringList>
|
2021-10-07 00:25:11 +08:00
|
|
|
#include <QAbstractNativeEventFilter>
|
2022-01-24 18:37:16 +08:00
|
|
|
#include <QDesktopWidget>
|
2021-11-05 11:48:46 +08:00
|
|
|
#include <QDir>
|
2022-01-26 21:36:31 +08:00
|
|
|
#include <QScreen>
|
2023-10-21 13:38:12 +08:00
|
|
|
#include <QLockFile>
|
2021-04-24 15:57:45 +08:00
|
|
|
#include "common.h"
|
2021-06-18 21:48:40 +08:00
|
|
|
#include "colorscheme.h"
|
2021-06-24 16:05:19 +08:00
|
|
|
#include "iconsmanager.h"
|
2021-09-04 11:37:04 +08:00
|
|
|
#include "autolinkmanager.h"
|
2022-09-26 14:54:28 +08:00
|
|
|
#include <qt_utils/charsetinfo.h>
|
2021-08-13 11:18:42 +08:00
|
|
|
#include "parser/parserutils.h"
|
2021-10-03 09:57:19 +08:00
|
|
|
#include "editorlist.h"
|
2022-02-24 17:33:19 +08:00
|
|
|
#include "widgets/choosethemedialog.h"
|
|
|
|
#include "thememanager.h"
|
2022-03-01 22:03:54 +08:00
|
|
|
|
2021-12-25 18:09:50 +08:00
|
|
|
#ifdef Q_OS_WIN
|
2022-02-28 22:40:09 +08:00
|
|
|
#include <QTemporaryFile>
|
2021-10-07 00:25:11 +08:00
|
|
|
#include <windows.h>
|
2022-02-28 22:40:09 +08:00
|
|
|
#include <psapi.h>
|
|
|
|
#include <QSharedMemory>
|
|
|
|
#include <QBuffer>
|
2022-03-01 22:03:54 +08:00
|
|
|
#include <winuser.h>
|
|
|
|
|
|
|
|
#include "widgets/cpudialog.h"
|
2021-12-24 23:18:20 +08:00
|
|
|
#endif
|
2021-10-07 00:25:11 +08:00
|
|
|
|
2022-02-28 22:40:09 +08:00
|
|
|
QString getSettingFilename(const QString& filepath, bool& firstRun);
|
2021-12-25 18:09:50 +08:00
|
|
|
#ifdef Q_OS_WIN
|
2021-10-07 00:25:11 +08:00
|
|
|
class WindowLogoutEventFilter : public QAbstractNativeEventFilter {
|
|
|
|
|
|
|
|
// QAbstractNativeEventFilter interface
|
|
|
|
public:
|
|
|
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
|
|
|
};
|
2022-10-02 13:29:51 +08:00
|
|
|
|
2023-10-21 13:38:12 +08:00
|
|
|
#ifndef WM_DPICHANGED
|
|
|
|
# define WM_DPICHANGED 0x02e0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WM_APP_OPEN_FILE (WM_APP + 6736 /* “OPEN” on dial pad */)
|
|
|
|
static_assert(WM_APP_OPEN_FILE < 0xc000);
|
|
|
|
|
2022-02-28 22:40:09 +08:00
|
|
|
HWND prevAppInstance = NULL;
|
|
|
|
BOOL CALLBACK GetPreviousInstanceCallback(HWND hwnd, LPARAM param){
|
|
|
|
BOOL result = TRUE;
|
|
|
|
WCHAR buffer[4098];
|
|
|
|
HINSTANCE hWindowModule = (HINSTANCE)GetWindowLongPtr(hwnd,GWLP_HINSTANCE);
|
|
|
|
|
|
|
|
if (hWindowModule==0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
DWORD processID;
|
|
|
|
|
|
|
|
// Get the ID of the process that created this window
|
|
|
|
GetWindowThreadProcessId(hwnd,&processID);
|
|
|
|
if (processID==0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Get the process associated with the ID
|
|
|
|
HANDLE hWindowProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
|
|
|
|
if (hWindowProcess == 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Get its module filename
|
|
|
|
if (GetModuleFileNameExW(hWindowProcess, hWindowModule, buffer, sizeof(buffer)) == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
CloseHandle(hWindowProcess); // not needed anymore
|
|
|
|
WCHAR * compareFilename=(WCHAR*)param;
|
|
|
|
QString s1=QString::fromWCharArray(compareFilename);
|
|
|
|
QString s2=QString::fromWCharArray(buffer);
|
|
|
|
|
|
|
|
//Is from the "same" application?
|
|
|
|
if (QString::compare(s1,s2,PATH_SENSITIVITY)==0) {
|
|
|
|
//found, stop EnumWindows loop
|
|
|
|
prevAppInstance = hwnd;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND getPreviousInstance() {
|
|
|
|
WCHAR buffer[4098];
|
|
|
|
//ShowMessage('ERROR_ALREADY_EXISTS');
|
|
|
|
// Store our own module filename
|
|
|
|
if (GetModuleFileNameW(GetModuleHandle(NULL), buffer, sizeof(buffer)) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// If that's the case, walk all top level windows and find the previous instance
|
|
|
|
// At this point, the program that created the mutex might not have created its MainForm yet
|
|
|
|
if (EnumWindows(GetPreviousInstanceCallback, LPARAM(buffer))==0) {
|
|
|
|
return prevAppInstance;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-10-07 00:25:11 +08:00
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/, void *message, long *result){
|
2021-10-07 00:25:11 +08:00
|
|
|
MSG * pMsg = static_cast<MSG *>(message);
|
2021-12-13 16:38:22 +08:00
|
|
|
switch(pMsg->message) {
|
|
|
|
case WM_QUERYENDSESSION:
|
2021-10-07 00:48:05 +08:00
|
|
|
if (pMsg->lParam == 0
|
|
|
|
|| (pMsg->lParam & ENDSESSION_LOGOFF)) {
|
2021-10-07 00:25:11 +08:00
|
|
|
if (!pMainWindow->close()) {
|
|
|
|
*result = 0;
|
|
|
|
} else {
|
|
|
|
*result = 1;
|
|
|
|
}
|
2021-10-07 00:48:05 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-12-13 16:38:22 +08:00
|
|
|
break;
|
2022-02-20 22:36:12 +08:00
|
|
|
case WM_DPICHANGED:{
|
2022-03-01 22:03:54 +08:00
|
|
|
if (pMsg->hwnd == (HWND)pMainWindow->winId()) {
|
|
|
|
int oldDPI = screenDPI();
|
2022-10-10 18:05:18 +08:00
|
|
|
//postEvent takes the owner ship
|
2022-03-01 22:03:54 +08:00
|
|
|
QEvent * dpiEvent = new QEvent(DPI_CHANGED_EVENT);
|
|
|
|
qApp->postEvent(pMainWindow,dpiEvent);
|
|
|
|
setScreenDPI(HIWORD(pMsg->wParam));
|
|
|
|
int newDPI = screenDPI();
|
|
|
|
pMainWindow->updateDPI(oldDPI,newDPI);
|
|
|
|
} else if (pMainWindow->cpuDialog() &&
|
|
|
|
(HWND)pMainWindow->cpuDialog()->winId() == pMsg->hwnd) {
|
|
|
|
int newDPI = HIWORD(pMsg->wParam);
|
|
|
|
pMainWindow->cpuDialog()->updateDPI(newDPI);
|
|
|
|
}
|
2021-12-13 19:10:16 +08:00
|
|
|
break;
|
2022-02-20 22:36:12 +08:00
|
|
|
}
|
2023-10-21 13:38:12 +08:00
|
|
|
case WM_APP_OPEN_FILE: {
|
2022-02-28 22:40:09 +08:00
|
|
|
QSharedMemory sharedMemory("RedPandaCpp/openfiles");
|
|
|
|
if (sharedMemory.attach()) {
|
|
|
|
QBuffer buffer;
|
|
|
|
QDataStream in(&buffer);
|
|
|
|
QStringList files;
|
|
|
|
sharedMemory.lock();
|
|
|
|
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
|
|
|
|
buffer.open(QBuffer::ReadOnly);
|
|
|
|
in >> files;
|
|
|
|
sharedMemory.unlock();
|
2022-03-21 18:06:47 +08:00
|
|
|
if (pMainWindow->isMinimized()) {
|
|
|
|
pMainWindow->showNormal();
|
|
|
|
}
|
2022-02-28 22:40:09 +08:00
|
|
|
pMainWindow->openFiles(files);
|
|
|
|
sharedMemory.detach();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sendFilesToInstance() {
|
|
|
|
HWND prevInstance = getPreviousInstance();
|
|
|
|
if (prevInstance != NULL) {
|
|
|
|
QSharedMemory sharedMemory("RedPandaCpp/openfiles");
|
|
|
|
QBuffer buffer;
|
|
|
|
buffer.open(QBuffer::ReadWrite);
|
|
|
|
QDataStream out(&buffer);
|
|
|
|
QStringList filesToOpen = qApp->arguments();
|
|
|
|
filesToOpen.pop_front();
|
|
|
|
out<<filesToOpen;
|
|
|
|
int size = buffer.size();
|
|
|
|
if (sharedMemory.create(size)) {
|
|
|
|
sharedMemory.lock();
|
|
|
|
char *to = (char*)sharedMemory.data();
|
|
|
|
const char *from = buffer.data().data();
|
|
|
|
memcpy(to, from, qMin(sharedMemory.size(), size));
|
|
|
|
sharedMemory.unlock();
|
2023-10-21 13:38:12 +08:00
|
|
|
SendMessage(prevInstance,WM_APP_OPEN_FILE,0,0);
|
2022-02-28 22:40:09 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-07 00:25:11 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-24 23:18:20 +08:00
|
|
|
#endif
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2022-02-23 13:17:57 +08:00
|
|
|
QString getSettingFilename(const QString& filepath, bool& firstRun) {
|
2021-04-15 11:18:14 +08:00
|
|
|
QString filename;
|
|
|
|
if (filepath.isEmpty()) {
|
|
|
|
if (isGreenEdition()) {
|
2021-04-20 22:24:33 +08:00
|
|
|
filename = includeTrailingPathDelimiter(QApplication::applicationDirPath()) +
|
|
|
|
"config/" + APP_SETTSINGS_FILENAME;
|
2021-04-15 11:18:14 +08:00
|
|
|
} else {
|
2021-04-20 22:24:33 +08:00
|
|
|
filename =includeTrailingPathDelimiter(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[0])
|
|
|
|
+ APP_SETTSINGS_FILENAME;
|
2021-04-15 11:18:14 +08:00
|
|
|
}
|
2021-04-13 22:17:18 +08:00
|
|
|
} else {
|
|
|
|
filename = filepath;
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
QFileInfo fileInfo(filename);
|
2022-02-23 13:17:57 +08:00
|
|
|
firstRun = !fileInfo.exists();
|
2021-04-15 11:18:14 +08:00
|
|
|
QDir dir(fileInfo.absoluteDir());
|
2021-04-13 22:17:18 +08:00
|
|
|
if (!dir.exists()) {
|
|
|
|
if (!dir.mkpath(dir.absolutePath())) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr, QObject::tr("Error"),
|
2021-04-13 22:17:18 +08:00
|
|
|
QString(QObject::tr("Can't create configuration folder %1")).arg(dir.absolutePath()));
|
2021-08-30 18:07:55 +08:00
|
|
|
return "";
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileInfo.exists() && !fileInfo.isWritable()) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr, QObject::tr("Error"),
|
2021-04-15 11:18:14 +08:00
|
|
|
QString(QObject::tr("Can't write to configuration file %1")).arg(filename));
|
|
|
|
|
2021-08-30 18:07:55 +08:00
|
|
|
return "";
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
2021-08-30 18:07:55 +08:00
|
|
|
return filename;
|
2021-04-13 22:17:18 +08:00
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2022-02-24 17:33:19 +08:00
|
|
|
void setTheme(const QString& theme) {
|
|
|
|
pSettings->environment().setTheme(theme);
|
|
|
|
ThemeManager themeManager;
|
|
|
|
PAppTheme appTheme = themeManager.theme(theme);
|
|
|
|
if (appTheme && !appTheme->defaultColorScheme().isEmpty()) {
|
|
|
|
pSettings->editor().setColorScheme(appTheme->defaultColorScheme());
|
|
|
|
pSettings->editor().save();
|
|
|
|
}
|
|
|
|
if (appTheme && !appTheme->defaultIconSet().isEmpty()) {
|
|
|
|
pSettings->environment().setIconSet(appTheme->defaultIconSet());
|
|
|
|
}
|
|
|
|
pSettings->environment().save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:10:57 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2023-07-03 14:06:26 +08:00
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
// Make title bar and palette follow system-wide dark mode setting on recent Windows releases.
|
2023-09-22 08:05:05 +08:00
|
|
|
// Use freetype as the fontengine
|
|
|
|
qputenv("QT_QPA_PLATFORM", "windows:darkmode=2:fontengine=freetype");
|
2023-07-03 14:06:26 +08:00
|
|
|
#endif
|
|
|
|
|
2023-09-05 19:14:08 +08:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
// in macOS GUI apps, `/usr/local/bin` is not in PATH by default
|
|
|
|
// follow the Unix way by prepending it to `/usr/bin`
|
|
|
|
{
|
|
|
|
QStringList pathList = getExecutableSearchPaths();
|
|
|
|
if (!pathList.contains("/usr/local/bin")) {
|
|
|
|
auto idxUsrBin = pathList.indexOf("/usr/bin");
|
|
|
|
if (idxUsrBin >= 0)
|
|
|
|
pathList.insert(idxUsrBin, "/usr/local/bin");
|
|
|
|
else
|
|
|
|
pathList.append("/usr/local/bin");
|
|
|
|
}
|
|
|
|
QString newPath = pathList.join(PATH_SEPARATOR);
|
|
|
|
qputenv("PATH", newPath.toUtf8());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
QApplication app(argc, argv);
|
2023-03-11 08:32:52 +08:00
|
|
|
|
2023-03-11 07:49:47 +08:00
|
|
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2023-03-11 08:32:52 +08:00
|
|
|
|
2023-10-21 13:38:12 +08:00
|
|
|
QLockFile lockFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock");
|
2022-02-28 22:40:09 +08:00
|
|
|
{
|
|
|
|
bool firstRun;
|
|
|
|
QString settingFilename = getSettingFilename(QString(), firstRun);
|
|
|
|
bool openInSingleInstance = false;
|
|
|
|
if (!settingFilename.isEmpty() && !firstRun) {
|
2022-03-04 19:04:45 +08:00
|
|
|
QSettings envSetting(settingFilename,QSettings::IniFormat);
|
|
|
|
envSetting.beginGroup(SETTING_ENVIRONMENT);
|
|
|
|
openInSingleInstance = envSetting.value("open_files_in_single_instance",false).toBool();
|
2022-02-28 22:40:09 +08:00
|
|
|
} else if (!settingFilename.isEmpty() && firstRun)
|
|
|
|
openInSingleInstance = false;
|
2022-10-17 23:23:05 +08:00
|
|
|
if (app.arguments().contains("-ns")) {
|
|
|
|
openInSingleInstance = false;
|
|
|
|
} else if (app.arguments().contains("-s"))
|
|
|
|
openInSingleInstance = true;
|
2022-02-28 22:40:09 +08:00
|
|
|
if (openInSingleInstance) {
|
2022-03-01 22:03:54 +08:00
|
|
|
int openCount = 0;
|
2022-02-28 22:40:09 +08:00
|
|
|
while (true) {
|
2023-10-21 13:41:53 +08:00
|
|
|
if (lockFile.tryLock(100))
|
2022-02-28 22:40:09 +08:00
|
|
|
break;
|
2022-03-01 22:03:54 +08:00
|
|
|
openCount++;
|
|
|
|
if (openCount>100)
|
|
|
|
break;
|
2022-02-28 22:40:09 +08:00
|
|
|
}
|
|
|
|
|
2022-03-01 22:03:54 +08:00
|
|
|
if (app.arguments().length()>=2 && openCount<100) {
|
2022-02-28 22:40:09 +08:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (sendFilesToInstance()) {
|
2023-10-21 13:38:12 +08:00
|
|
|
lockFile.unlock();
|
2022-02-28 22:40:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-30 18:07:55 +08:00
|
|
|
//Translation must be loaded first
|
2023-01-25 10:51:59 +08:00
|
|
|
QTranslator trans,transQt,transUtils;
|
2022-02-23 13:17:57 +08:00
|
|
|
bool firstRun;
|
|
|
|
QString settingFilename = getSettingFilename(QString(), firstRun);
|
2021-11-05 11:48:46 +08:00
|
|
|
if (!isGreenEdition()) {
|
|
|
|
QDir::setCurrent(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0]);
|
|
|
|
}
|
2022-02-28 22:40:09 +08:00
|
|
|
if (settingFilename.isEmpty()) {
|
2023-10-21 13:38:12 +08:00
|
|
|
lockFile.unlock();
|
2021-08-30 18:07:55 +08:00
|
|
|
return -1;
|
2022-02-28 22:40:09 +08:00
|
|
|
}
|
2022-03-12 17:37:53 +08:00
|
|
|
QString language;
|
2021-08-30 18:07:55 +08:00
|
|
|
{
|
2021-08-30 19:52:38 +08:00
|
|
|
QSettings languageSetting(settingFilename,QSettings::IniFormat);
|
|
|
|
languageSetting.beginGroup(SETTING_ENVIRONMENT);
|
2022-03-12 17:37:53 +08:00
|
|
|
language = languageSetting.value("language",QLocale::system().name()).toString();
|
2021-11-18 21:25:28 +08:00
|
|
|
|
2022-01-28 18:18:34 +08:00
|
|
|
if (trans.load("RedPandaIDE_"+language,":/i18n/")) {
|
2021-11-17 09:41:44 +08:00
|
|
|
app.installTranslator(&trans);
|
2021-11-18 21:25:28 +08:00
|
|
|
}
|
2023-01-25 10:51:59 +08:00
|
|
|
if (transUtils.load("qt_utils_"+language,":/i18n/")) {
|
|
|
|
app.installTranslator(&transUtils);
|
|
|
|
}
|
2021-11-18 21:25:28 +08:00
|
|
|
if (transQt.load("qt_"+language,":/translations")) {
|
|
|
|
app.installTranslator(&transQt);
|
|
|
|
}
|
2021-08-30 18:07:55 +08:00
|
|
|
}
|
2021-04-24 15:57:45 +08:00
|
|
|
qRegisterMetaType<PCompileIssue>("PCompileIssue");
|
|
|
|
qRegisterMetaType<PCompileIssue>("PCompileIssue&");
|
2021-08-01 01:06:43 +08:00
|
|
|
qRegisterMetaType<QVector<int>>("QVector<int>");
|
2021-11-25 09:05:45 +08:00
|
|
|
qRegisterMetaType<QHash<int,QString>>("QHash<int,QString>");
|
2021-04-24 15:57:45 +08:00
|
|
|
|
2021-08-07 14:08:51 +08:00
|
|
|
initParser();
|
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
try {
|
2021-04-13 22:17:18 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
SystemConsts systemConsts;
|
|
|
|
pSystemConsts = &systemConsts;
|
2022-10-10 18:05:18 +08:00
|
|
|
CharsetInfoManager charsetInfoManager(language);
|
|
|
|
pCharsetInfoManager=&charsetInfoManager;
|
|
|
|
|
|
|
|
//We must use smarter point here, to manually control it's lifetime:
|
|
|
|
// when restore default settings, it must be destoyed before we remove all setting files.
|
|
|
|
auto settings = std::make_unique<Settings>(settingFilename);
|
2021-06-20 09:27:37 +08:00
|
|
|
//load settings
|
2022-10-10 18:05:18 +08:00
|
|
|
pSettings = settings.get();
|
2022-02-23 13:17:57 +08:00
|
|
|
if (firstRun) {
|
|
|
|
pSettings->compilerSets().findSets();
|
|
|
|
pSettings->compilerSets().saveSets();
|
|
|
|
}
|
|
|
|
pSettings->load();
|
2022-02-24 17:33:19 +08:00
|
|
|
if (firstRun) {
|
|
|
|
//set theme
|
|
|
|
ChooseThemeDialog themeDialog;
|
2023-07-03 14:06:26 +08:00
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
// Qt's default style on Windows is not good.
|
|
|
|
themeDialog.hideAutoFollowSystemTheme();
|
|
|
|
#endif
|
2022-02-24 17:33:19 +08:00
|
|
|
themeDialog.exec();
|
|
|
|
switch (themeDialog.theme()) {
|
2023-07-03 14:06:26 +08:00
|
|
|
case ChooseThemeDialog::Theme::AutoFollowSystem:
|
|
|
|
setTheme("system");
|
|
|
|
break;
|
2022-02-24 17:33:19 +08:00
|
|
|
case ChooseThemeDialog::Theme::Dark:
|
|
|
|
setTheme("dark");
|
|
|
|
break;
|
2023-07-03 14:06:26 +08:00
|
|
|
case ChooseThemeDialog::Theme::Light:
|
|
|
|
setTheme("default");
|
|
|
|
break;
|
2022-02-24 17:33:19 +08:00
|
|
|
default:
|
|
|
|
setTheme("default");
|
|
|
|
}
|
2022-07-28 14:03:18 +08:00
|
|
|
|
|
|
|
pSettings->editor().setDefaultFileCpp(themeDialog.language()==ChooseThemeDialog::Language::CPlusPlus);
|
|
|
|
pSettings->editor().save();
|
|
|
|
|
2022-02-26 19:42:50 +08:00
|
|
|
//auto detect git in path
|
2023-08-08 14:41:23 +08:00
|
|
|
#ifdef ENABLE_VCS
|
2022-02-26 19:42:50 +08:00
|
|
|
pSettings->vcs().detectGitInPath();
|
2023-08-08 14:41:23 +08:00
|
|
|
#endif
|
2022-02-24 17:33:19 +08:00
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
//Color scheme settings must be loaded after translation
|
2022-10-10 18:05:18 +08:00
|
|
|
ColorManager colorManager;
|
|
|
|
pColorManager = &colorManager;
|
|
|
|
IconsManager iconsManager;
|
|
|
|
pIconsManager = &iconsManager;
|
|
|
|
AutolinkManager autolinkManager;
|
|
|
|
pAutolinkManager = &autolinkManager;
|
2021-09-04 19:27:44 +08:00
|
|
|
try {
|
|
|
|
pAutolinkManager->load();
|
|
|
|
} catch (FileError e) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
QObject::tr("Can't load autolink settings"),
|
|
|
|
e.reason(),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
MainWindow mainWindow;
|
|
|
|
pMainWindow = &mainWindow;
|
2022-03-11 20:51:33 +08:00
|
|
|
#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR < 15
|
|
|
|
setScreenDPI(qApp->primaryScreen()->logicalDotsPerInch());
|
|
|
|
#else
|
|
|
|
if (mainWindow.screen())
|
|
|
|
setScreenDPI(mainWindow.screen()->logicalDotsPerInch());
|
|
|
|
#endif
|
|
|
|
mainWindow.show();
|
2021-10-04 20:05:24 +08:00
|
|
|
if (app.arguments().count()>1) {
|
|
|
|
QStringList filesToOpen = app.arguments();
|
|
|
|
filesToOpen.pop_front();
|
|
|
|
pMainWindow->openFiles(filesToOpen);
|
|
|
|
} else {
|
|
|
|
if (pSettings->editor().autoLoadLastFiles())
|
|
|
|
pMainWindow->loadLastOpens();
|
2022-10-09 22:19:18 +08:00
|
|
|
if (pMainWindow->editorList()->pageCount()==0 && !pMainWindow->project()) {
|
2021-10-04 20:05:24 +08:00
|
|
|
pMainWindow->newEditor();
|
|
|
|
}
|
2021-10-03 09:57:19 +08:00
|
|
|
}
|
2022-03-10 20:28:01 +08:00
|
|
|
|
|
|
|
//reset default open folder
|
|
|
|
QDir::setCurrent(pSettings->environment().defaultOpenFolder());
|
|
|
|
|
2022-03-11 20:51:33 +08:00
|
|
|
pMainWindow->setFilesViewRoot(pSettings->environment().currentFolder());
|
|
|
|
|
2021-12-25 18:09:50 +08:00
|
|
|
#ifdef Q_OS_WIN
|
2021-10-07 00:25:11 +08:00
|
|
|
WindowLogoutEventFilter filter;
|
|
|
|
app.installNativeEventFilter(&filter);
|
2021-12-24 23:18:20 +08:00
|
|
|
#endif
|
2023-10-21 13:38:12 +08:00
|
|
|
if (lockFile.isLocked()) {
|
|
|
|
lockFile.unlock();
|
2022-03-11 20:51:33 +08:00
|
|
|
}
|
2022-03-29 18:06:24 +08:00
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
int retCode = app.exec();
|
2021-10-08 20:01:29 +08:00
|
|
|
if (mainWindow.shouldRemoveAllSettings()) {
|
2022-12-05 12:04:48 +08:00
|
|
|
QString configDir = pSettings->dirs().config();
|
2021-10-09 09:09:05 +08:00
|
|
|
settings.release();
|
|
|
|
delete pSettings;
|
2021-10-08 20:01:29 +08:00
|
|
|
QDir dir(configDir);
|
|
|
|
dir.removeRecursively();
|
|
|
|
}
|
2021-06-20 09:27:37 +08:00
|
|
|
return retCode;
|
|
|
|
} catch (BaseError e) {
|
2023-10-21 13:38:12 +08:00
|
|
|
lockFile.unlock();
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(nullptr,QApplication::tr("Error"),e.reason());
|
2021-06-21 22:01:35 +08:00
|
|
|
return -1;
|
2021-06-20 09:27:37 +08:00
|
|
|
}
|
2021-04-06 23:10:57 +08:00
|
|
|
}
|