diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 6bd20429..1132ff3a 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -13,7 +13,15 @@ isEmpty(APP_VERSION) { APP_VERSION=1.1.0 } +macos: { + # This package needs to be installed via homebrew before we can compile it + INCLUDEPATH += \ + /opt/homebrew/opt/icu4c/include + QT += gui-private + + ICON = ../macos/RedPandaIDE.icns +} win32: VERSION = $${APP_VERSION}.0 else: VERSION = $${APP_VERSION} @@ -32,7 +40,7 @@ gcc { } msvc { -DEFINES += NOMINMAX + DEFINES += NOMINMAX } # You can make your code fail to compile if it uses deprecated APIs. @@ -424,6 +432,7 @@ unix: { settingsdialog/formatterpathwidget.ui \ settingsdialog/environmentprogramswidget.ui } + linux: { LIBS+= \ -lrt @@ -494,3 +503,16 @@ RESOURCES += qmake_qm_files RESOURCES += iconsets_files RESOURCES += theme_files RESOURCES += colorscheme_files + +macos: { + # Add needed executables into the main app bundle + bundled_executable.files = \ + $$OUT_PWD/../astyle/astyle \ + $$OUT_PWD/../consolepauser/consolepauser \ + $$OUT_PWD/../redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass + bundled_executable.path = Contents/MacOS + + # Also bundled templates + + QMAKE_BUNDLE_DATA += bundled_executable +} diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 0c1dc1bc..5befc097 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -54,6 +54,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), mFontDummy = QFont("Consolas",12); #elif defined(Q_OS_LINUX) mFontDummy = QFont("terminal",14); +#elif defined(Q_OS_MACOS) + mFontDummy = QFont("Menlo", 14); #else #error "Not supported!" #endif diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index a6e0792a..98902eb6 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -190,15 +190,21 @@ QString Settings::Dirs::appResourceDir() const return appDir(); #elif defined(Q_OS_LINUX) return includeTrailingPathDelimiter(PREFIX)+"share/"+APP_NAME; +#elif defined(Q_OS_MACOS) +// return QApplication::instance()->applicationDirPath(); + return ""; #endif } + QString Settings::Dirs::appLibexecDir() const { #ifdef Q_OS_WIN return appDir(); #elif defined(Q_OS_LINUX) return includeTrailingPathDelimiter(PREFIX)+"libexec/"+APP_NAME; +#elif defined(Q_OS_MACOS) + return QApplication::instance()->applicationDirPath(); #endif } @@ -1274,10 +1280,13 @@ void Settings::Editor::doLoad() mRightEdgeWidth = intValue("right_edge_width",80); mRightEdgeLineColor = colorValue("right_edge_line_color",Qt::yellow); - //Font + //Editor font #ifdef Q_OS_WIN mFontName = stringValue("font_name","consolas"); mNonAsciiFontName = stringValue("non_ascii_font_name","consolas"); +#elif defined(Q_OS_MACOS) + mFontName = stringValue("font_name","Menlo"); + mNonAsciiFontName = stringValue("non_ascii_font_name","PingFang SC"); #else mFontName = stringValue("font_name","Dejavu Sans Mono"); mNonAsciiFontName = stringValue("non_ascii_font_name","Dejavu Sans Mono"); @@ -2845,7 +2854,13 @@ void Settings::Environment::doLoad() QString defaultLocaleName = QLocale::system().name(); if (defaultLocaleName == "zh_CN") { QString fontName; +#ifdef Q_OS_WINDOWS fontName = "Microsoft Yahei"; +#elif defined(Q_OS_MACOS) + fontName = "PingFang SC"; +#elif defined(Q_OS_LINUX) + fontName = "Noto Sans CJK"; +#endif QFont font(fontName); if (font.exactMatch()) { defaultFontName = fontName; @@ -2874,6 +2889,10 @@ void Settings::Environment::doLoad() if (mTerminalPath.isEmpty()) mTerminalPath = stringValue("terminal_path","/usr/bin/x-terminal-emulator"); mAStylePath = includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"astyle"; +#elif defined(Q_OS_MACOS) + mTerminalPath = stringValue("terminal_path", + "/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal"); + mAStylePath = includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"astyle"; #endif mHideNonSupportFilesInFileView=boolValue("hide_non_support_files_file_view",true); mOpenFilesInSingleInstance = boolValue("open_files_in_single_instance",false); @@ -3222,6 +3241,8 @@ void Settings::Executor::doLoad() mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false); #ifdef Q_OS_WIN mCaseEditorFontName = stringValue("case_editor_font_name","consolas"); +#elif defined(Q_OS_MACOS) + mCaseEditorFontName = stringValue("case_editor_font_name", "Menlo"); #else mCaseEditorFontName = stringValue("case_editor_font_name","Dejavu Sans Mono"); #endif diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index a7c1ddec..8329f770 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -50,6 +50,21 @@ #define CLANG_PROGRAM "clang" #define CLANG_CPP_PROGRAM "clang++" #define LLDB_MI_PROGRAM "lldb-mi" +#elif defined(Q_OS_MACOS) +#define GCC_PROGRAM "gcc" +#define GPP_PROGRAM "g++" +#define GDB_PROGRAM "gdb" +#define GDB_SERVER_PROGRAM "gdbserver" +#define GDB32_PROGRAM "gdb32" +#define MAKE_PROGRAM "make" +#define WINDRES_PROGRAM "" +#define GPROF_PROGRAM "gprof" +#define CLEAN_PROGRAM "rm -rf" +#define CPP_PROGRAM "cpp" +#define GIT_PROGRAM "git" +#define CLANG_PROGRAM "clang" +#define CLANG_CPP_PROGRAM "clang++" +#define LLDB_MI_PROGRAM "lldb-mi" #else #error "Only support windows and linux now!" #endif @@ -85,7 +100,7 @@ # define DYNAMIC_LIB_EXT "dll" # define MAKEFILE_NAME "makefile.win" # define ALL_FILE_WILDCARD "*.*" -#elif defined(Q_OS_LINUX) +#elif defined(Q_OS_LINUX) || defined(Q_OS_MACOS) # define PATH_SENSITIVITY Qt::CaseSensitive # define PATH_SEPARATOR ":" # define LINE_BREAKER "\n" diff --git a/RedPandaIDE/widgets/darkfusionstyle.cpp b/RedPandaIDE/widgets/darkfusionstyle.cpp index 7618c9e3..9b38fb6f 100644 --- a/RedPandaIDE/widgets/darkfusionstyle.cpp +++ b/RedPandaIDE/widgets/darkfusionstyle.cpp @@ -27,6 +27,11 @@ #include #include "../settings.h" +#if defined(Q_OS_MACX) +#include +#include +#endif + #define BEGIN_STYLE_PIXMAPCACHE(a) \ QRect rect = option->rect; \ QPixmap internalPixmapCache; \ diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro index 69d942f4..a12b5844 100644 --- a/Red_Panda_CPP.pro +++ b/Red_Panda_CPP.pro @@ -5,14 +5,20 @@ SUBDIRS += \ astyle \ consolepauser +# Add the dependencies so that the RedPandaIDE project can add the depended programs +# into the main app bundle +RedPandaIDE.depends = astyle consolepauser + win32: { SUBDIRS += \ redpanda-win-git-askpass + RedPandaIDE.depends += redpanda-win-git-askpass } -linux: { +unix: { SUBDIRS += \ redpanda-git-askpass + RedPandaIDE.depends += redpanda-git-askpass } APP_NAME = RedPandaCPP @@ -20,7 +26,6 @@ APP_NAME = RedPandaCPP APP_VERSION = 1.1.0 linux: { - isEmpty(PREFIX) { PREFIX = /usr/local } @@ -44,7 +49,6 @@ linux: { desktop.path = $${PREFIX}/share/applications desktop.files += linux/redpandaide.desktop INSTALLS += desktop - } win32: { diff --git a/consolepauser/consolepauser.pro b/consolepauser/consolepauser.pro index 0ab409f6..6fcf7b56 100644 --- a/consolepauser/consolepauser.pro +++ b/consolepauser/consolepauser.pro @@ -19,10 +19,15 @@ SOURCES += \ unix: { SOURCES += \ main.unix.cpp - LIBS+= \ - -lrt } +# macOS does not provide rt library, only use it for Linux +linux: { +LIBS+= \ + -lrt +} + + CONFIG += lrelease CONFIG += embed_translations diff --git a/consolepauser/main.unix.cpp b/consolepauser/main.unix.cpp index 9861261a..a8712f97 100644 --- a/consolepauser/main.unix.cpp +++ b/consolepauser/main.unix.cpp @@ -109,7 +109,9 @@ int ExecuteCommand(vector& command,bool reInp) { if (result) { printf("Failed to start command %s %s!\n",path_to_command.c_str(), file.c_str()); printf("errno %d: %s\n",errno,strerror(errno)); - printf("current dir: %s",get_current_dir_name()); + char* current_dir = getcwd(nullptr, 0); + printf("current dir: %s",current_dir); + free(current_dir); exit(-1); } } else { diff --git a/macos/RedPandaIDE.icns b/macos/RedPandaIDE.icns new file mode 100644 index 00000000..1399029f Binary files /dev/null and b/macos/RedPandaIDE.icns differ diff --git a/macos/gen_macos_icns.sh b/macos/gen_macos_icns.sh new file mode 100755 index 00000000..0ad45aa2 --- /dev/null +++ b/macos/gen_macos_icns.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +input_icon="../RedPandaIDE/images/devcpp.png" +output_dir="RedPandaIDE.iconset" + +mkdir $output_dir + +sips -z 16 16 $input_icon --out "${output_dir}/icon_16x16.png" +sips -z 32 32 $input_icon --out "${output_dir}/icon_16x16@2x.png" +sips -z 32 32 $input_icon --out "${output_dir}/icon_32x32.png" +sips -z 64 64 $input_icon --out "${output_dir}/icon_32x32@2x.png" +sips -z 128 128 $input_icon --out "${output_dir}/icon_128x128.png" +sips -z 256 256 $input_icon --out "${output_dir}/icon_128x128@2x.png" +sips -z 256 256 $input_icon --out "${output_dir}/icon_256x256.png" +sips -z 512 512 $input_icon --out "${output_dir}/icon_256x256@2x.png" + +iconutil -c icns $output_dir + +rm -R $output_dir