Skip to content

Commit

Permalink
merge latest from main
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbreeze413 committed Jan 25, 2024
2 parents 1bbe43c + ea4c5d5 commit 5dafec5
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:

jobs:
triage:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
jobs:
increment-patch-version:
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Cancel previous
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ foedag_cmd.tcl
third_party/gtkwave_cmake/gtkwaveTCL.tar.gz
third_party/monaco-editor/monaco-editor-*.tgz
third_party/monaco-editor/monaco-editor
etc/monaco-editor/
21 changes: 2 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(third_party/tcl_cmake EXCLUDE_FROM_ALL)
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
if (USE_MONACO_EDITOR)
add_subdirectory(third_party/monaco-editor)
else()
add_subdirectory(third_party/QScintilla-2.13.1)
endif()
Expand All @@ -95,10 +96,6 @@ add_subdirectory(third_party/gtkwave_cmake)
add_subdirectory(third_party/scope_guard)
add_subdirectory(third_party/openocd_cmake)
add_subdirectory(third_party/openssl_cmake)
if (USE_MONACO_EDITOR)
add_subdirectory(third_party/monaco-editor)
endif()

add_subdirectory(tests/tclutils)
add_subdirectory(tests/unittest)
add_subdirectory(src/NewProject)
Expand Down Expand Up @@ -614,20 +611,6 @@ add_custom_command(TARGET foedag-bin POST_BUILD
${PROJECT_SOURCE_DIR}/tests/Arch
${CMAKE_CURRENT_BINARY_DIR}/share/foedag/Arch/)

if (USE_MONACO_EDITOR)
add_custom_command(TARGET foedag-bin POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/share/foedag/etc/monaco-editor/
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/third_party/monaco-editor/monaco-editor
${CMAKE_CURRENT_BINARY_DIR}/share/foedag/etc/monaco-editor/monaco-editor)

add_custom_command(TARGET foedag-bin POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/third_party/monaco-editor/monaco-editor.html
${CMAKE_CURRENT_BINARY_DIR}/share/foedag/etc/monaco-editor)

add_custom_command(TARGET foedag-bin POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/third_party/monaco-editor/qwebchannel.js
${CMAKE_CURRENT_BINARY_DIR}/share/foedag/etc/monaco-editor)
endif()

5 changes: 3 additions & 2 deletions src/MainWindow/MessagesTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ void MessagesTabWidget::onMessageClicked(const QTreeWidgetItem *item, int col) {
auto filePath = item->data(0, FilePathRole).toString();

auto line = item->data(col, LineNumberRole).toInt();
TextEditorForm::Instance()->OpenFileWithSelection(QString(filePath), line,
line);
// TODO RG-215 @volodymyrk
TextEditorForm::Instance()->OpenFileWithSelection(QString(filePath), line + 1,
line + 1);
}

} // namespace FOEDAG
6 changes: 6 additions & 0 deletions src/TextEditor/cpp_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Q_INVOKABLE void CPPEndPoint::fileLoaded() {
emit signalToCPP_FileLoaded();
}

void CPPEndPoint::fileFailedToLoad(QVariant file) {
m_fileLoaded = false;
qWarning() << "Failed to load file: " << file;
emit signalToCPP_FileLoaded();
}

Q_INVOKABLE void CPPEndPoint::openLink(QVariant linkURI) {
// use Qt to open the link:
QDesktopServices::openUrl(QUrl(linkURI.toString()));
Expand Down
1 change: 1 addition & 0 deletions src/TextEditor/cpp_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CPPEndPoint : public QObject {

// Monaco Editor JS will call this once the file has been loaded
Q_INVOKABLE void fileLoaded();
Q_INVOKABLE void fileFailedToLoad(QVariant file);

// Monaco Editor JS will call this to request opening any link from the editor
// content
Expand Down
11 changes: 7 additions & 4 deletions src/TextEditor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ void Editor::markLineWarning(int line) {
}

void Editor::selectLines(int lineFrom, int lineTo) {
m_scintilla->setSelection(lineFrom, 0, lineTo,
m_scintilla->lineLength(lineTo));
m_scintilla->setSelection(lineFrom - 1, 0, lineTo - 1,
m_scintilla->lineLength(lineTo - 1));
// VISIBLE_STRICT policy makes sure line is in the middle of the screen.
// VISIBLE_SLOP, on the other hand, just makess sure line is visible
m_scintilla->SendScintilla(QsciScintilla::SCI_SETVISIBLEPOLICY,
QsciScintilla::VISIBLE_STRICT);
m_scintilla->ensureLineVisible(lineFrom);
m_scintilla->ensureLineVisible(lineFrom - 1);
}

void Editor::clearMarkers() { m_scintilla->markerDeleteAll(ERROR_MARKER); }
Expand Down Expand Up @@ -294,7 +294,8 @@ void Editor::InitScintilla(int iFileType) {

void Editor::SetScintillaText(QString strFileName) {
QFile file(strFileName);
if (!file.open(QFile::ReadOnly)) {
m_fileLoaded = file.open(QFile::ReadOnly);
if (!m_fileLoaded) {
return;
}

Expand All @@ -316,3 +317,5 @@ void Editor::UpdateToolBarStates() {
m_actCopy->setEnabled(m_scintilla->hasSelectedText());
m_actDelete->setEnabled(m_scintilla->hasSelectedText());
}

bool Editor::fileLoaded() const { return m_fileLoaded; }
2 changes: 2 additions & 0 deletions src/TextEditor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Editor : public QWidget {
void clearMarkers();
void reload();
void selectLines(int lineFrom, int lineTo);
bool fileLoaded() const;

signals:
void EditorModificationChanged(bool m);
Expand Down Expand Up @@ -93,6 +94,7 @@ class Editor : public QWidget {
static constexpr int MIN_MARGIN_WIDTH{4};
static constexpr int MARGIN_INDEX{0};
int m_marginWidth{MIN_MARGIN_WIDTH};
bool m_fileLoaded{false};
};

} // namespace FOEDAG
Expand Down
8 changes: 6 additions & 2 deletions src/TextEditor/monaco_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <QWebEngineSettings>
#include <QWebEngineView>
#include <QWidget>
#include <QLoggingCategory>

#include "Main/Foedag.h"
#include "Main/ToolContext.h"
Expand Down Expand Up @@ -47,7 +46,10 @@ using namespace FOEDAG;

Editor::Editor(QString strFileName, int iFileType, QWidget* parent)
: QWidget(parent) {
m_strFileName = strFileName;
QFileInfo info{strFileName};
// path should be absolute since monaco editor can't open file relative to
// std::filesystem::current_path()
m_strFileName = info.absoluteFilePath();
m_closeAfterSave = false;

QVBoxLayout* monacoTextEditorVBoxLayout = new QVBoxLayout();
Expand Down Expand Up @@ -165,6 +167,8 @@ void Editor::selectLines(int lineFrom, int lineTo) {
emit m_CPPEndPointObject->signalToJS_SetHighlightSelection(lineFrom, lineTo);
}

bool Editor::fileLoaded() const { return m_CPPEndPointObject->m_fileLoaded; }

void Editor::clearMarkers() {
emit m_CPPEndPointObject->signalToJS_ClearHighlightError();
emit m_CPPEndPointObject->signalToJS_ClearHighlightWarning();
Expand Down
1 change: 1 addition & 0 deletions src/TextEditor/monaco_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Editor : public QWidget {
void clearMarkers();
void reload();
void selectLines(int lineFrom, int lineTo);
bool fileLoaded() const;

signals:
void EditorModificationChanged(bool m);
Expand Down
8 changes: 4 additions & 4 deletions src/TextEditor/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void FOEDAG::registerTextEditorCommands(QWidget* editor,
Tcl_AppendResult(interp, qPrintable(msg), (char*)nullptr);
return TCL_ERROR;
}
editor->SlotOpenFile(file);
return TCL_OK;
auto res = editor->SlotOpenFile(file);
return (res == 0) ? TCL_OK : TCL_ERROR;
};
session->TclInterp()->registerCmd(
"openfile", openfile, static_cast<void*>(editor), nullptr /*deleteProc*/);
Expand All @@ -72,8 +72,8 @@ void TextEditor::ClosetextEditor() { TextEditorForm::Instance()->hide(); }

QWidget* TextEditor::GetTextEditor() { return TextEditorForm::Instance(); }

void TextEditor::SlotOpenFile(const QString& strFileName) {
TextEditorForm::Instance()->OpenFile(strFileName);
int TextEditor::SlotOpenFile(const QString& strFileName) {
return TextEditorForm::Instance()->OpenFile(strFileName);
}

void TextEditor::SlotOpenFileWithLine(const QString& strFileName, int line) {
Expand Down
2 changes: 1 addition & 1 deletion src/TextEditor/text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TextEditor : public QWidget {
void FileChanged(const QString &);

public slots:
void SlotOpenFile(const QString &strFileName);
int SlotOpenFile(const QString &strFileName);
void SlotOpenFileWithLine(const QString &strFileName, int line);

private slots:
Expand Down
3 changes: 2 additions & 1 deletion src/TextEditor/text_editor_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int TextEditorForm::OpenFile(const QString &strFileName) {
m_fileWatcher.addPath(strFileName);
editor->SetFileWatcher(&m_fileWatcher);

return ret;
return editor->fileLoaded() ? 0 : -1;
}

int TextEditorForm::OpenFileWithLine(const QString &strFileName, int line,
Expand All @@ -133,6 +133,7 @@ int TextEditorForm::OpenFileWithSelection(const QString &strFileName,
int res = OpenFile(strFileName);
if (res == 0) {
auto pair = m_map_file_tabIndex_editor.value(strFileName);
pair.second->clearMarkers();
pair.second->selectLines(lineFrom, lineTo);
} else
return -1;
Expand Down
30 changes: 24 additions & 6 deletions third_party/monaco-editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,45 @@ cmake_minimum_required(VERSION 3.15)
set(MONACO_EDITOR_VERSION 0.45.0)

# download the monaco editor tgz, extract it, and rename the dir from 'package' to 'monaco-editor'
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/third_party/monaco-editor/monaco-editor-${MONACO_EDITOR_VERSION}.tgz)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor-${MONACO_EDITOR_VERSION}.tgz)
message("Downloading monaco-editor tgz package: " ${MONACO_EDITOR_VERSION} " ...")
file(DOWNLOAD
https://registry.npmjs.org/monaco-editor/-/monaco-editor-${MONACO_EDITOR_VERSION}.tgz
${CMAKE_SOURCE_DIR}/third_party/monaco-editor/monaco-editor-${MONACO_EDITOR_VERSION}.tgz
${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor-${MONACO_EDITOR_VERSION}.tgz
)
endif()

if(NOT EXISTS ${CMAKE_SOURCE_DIR}/third_party/monaco-editor/monaco-editor/)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor/)
message("Extracting monaco-editor tgz package: " ${MONACO_EDITOR_VERSION} " ...")
execute_process(
COMMAND_ECHO
STDOUT
COMMAND
tar -xf ${CMAKE_SOURCE_DIR}/third_party/monaco-editor/monaco-editor-${MONACO_EDITOR_VERSION}.tgz
tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor-${MONACO_EDITOR_VERSION}.tgz
RESULT_VARIABLE result
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}/third_party/monaco-editor
${CMAKE_CURRENT_SOURCE_DIR}
)
if(result AND NOT result EQUAL 0)
message(FATAL_ERROR "monaco editor extraction failed!")
endif()
file(RENAME ${CMAKE_SOURCE_DIR}/third_party/monaco-editor/package ${CMAKE_SOURCE_DIR}/third_party/monaco-editor/monaco-editor)
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/package ${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor)
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/etc/monaco-editor/
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor
${CMAKE_SOURCE_DIR}/etc/monaco-editor/monaco-editor
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/monaco-editor.html
${CMAKE_SOURCE_DIR}/etc/monaco-editor
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/qwebchannel.js
${CMAKE_SOURCE_DIR}/etc/monaco-editor
)

17 changes: 12 additions & 5 deletions third_party/monaco-editor/monaco-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@
var text = rawFile.responseText;

setMonacoEditorModelWithFile(filepath, text);
} else {
window.cppEndPoint.fileFailedToLoad(filepath);
}
} else {
window.cppEndPoint.fileFailedToLoad(filepath);
}
}
rawFile.send(null);
Expand All @@ -147,7 +151,10 @@

setMonacoEditorModelWithFile(filepath, text);
})
.catch((e) => console.error(e));
.catch((e) => {
console.error(e);
window.cppEndPoint.fileFailedToLoad(filepath);
})
}

function setMonacoEditorModelWithFile(filepath, filecontent) {
Expand Down Expand Up @@ -281,9 +288,9 @@
// window.cppEndPoint.log("we got the signal: signalToJS_UpdateFilePath");

if(window.cppEndPoint.qtVersion[0] >= 6 &&
window.cppEndPoint.qtVersion[1] >= 0 &&
window.cppEndPoint.qtVersion[2] >= 0) {
// Qt 6.0.0+ has support FETCH API, so use that
window.cppEndPoint.qtVersion[1] >= 5 &&
window.cppEndPoint.qtVersion[2] >= 3) {
// Qt 6.5.3+ has support FETCH API, so use that
readFileFromPathUsingFetch(path);
}
else {
Expand Down Expand Up @@ -335,4 +342,4 @@

</body>

</html>
</html>

0 comments on commit 5dafec5

Please sign in to comment.