Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial prototype for multi-file feature #2949

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -18,6 +18,8 @@
#include <QElapsedTimer>
#include <QTime>
#include <QIODevice>
#include <QTabWidget>
#include <QObject>
#include "input/InputDriver.h"

class MainWindow : public QMainWindow, public Ui::MainWindow, public InputEventHandler
@@ -132,6 +134,7 @@ private slots:

private slots:
void actionNew();
void actionNewTab();
void actionOpen();
void actionOpenRecent();
void actionOpenExample();
@@ -208,6 +211,9 @@ private slots:
void actionCopyViewport();
void actionFlushCaches();

void currentTabChanged(int);
void closeTab(int);

public:
void viewModeActionsUncheck();
void setCurrentOutput();
@@ -311,6 +317,7 @@ public slots:
void clearExportPaths(); // clear exports paths when main file is changed by open, new, etc.
QString exportPath(const char *suffix); // look up the last export path and generate one if not found
int last_parser_error_pos; // last highlighted error position
QTabWidget *filetab;

signals:
void highlightError(int);
@@ -337,3 +344,26 @@ class GuiLocker
private:
static unsigned int gui_locked;
};




class SignalDispatcher : public QObject
{
Q_OBJECT

public:
~SignalDispatcher();
void updateActiveEditor(EditorInterface *);

static SignalDispatcher *inst();
static void create();

private:
SignalDispatcher(){};
EditorInterface *activeEditor;
static SignalDispatcher *instance;

private slots:
void indentSelection();
};
@@ -304,6 +304,7 @@
<addaction name="fileActionExportImage"/>
</widget>
<addaction name="fileActionNew"/>
<addaction name="fileActionNewTab"/>
<addaction name="fileActionOpen"/>
<addaction name="menuOpenRecent"/>
<addaction name="menuExamples"/>
@@ -648,6 +649,18 @@
<string>Ctrl+N</string>
</property>
</action>
<action name="fileActionNewTab">
<!-- <property name="icon">
<iconset resource="../openscad.qrc">
<normaloff>:/images/blackNew.png</normaloff>:/images/blackNew.png</iconset>
</property> -->
<property name="text">
<string>New Tab</string>
</property>
<!-- <property name="shortcut">
<string>Ctrl+N</string>
</property> -->
</action>
<action name="fileActionOpen">
<property name="icon">
<iconset resource="../openscad.qrc">
@@ -97,6 +97,7 @@
#include <QSettings> //Include QSettings for direct operations on settings arrays
#include "QSettingsCached.h"
#include <QSound>
#include <QTabWidget>

#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
#include <QTextDocument>
@@ -212,6 +213,9 @@ MainWindow::MainWindow(const QString &filename)
#endif
editor = new LegacyEditor(editorDockContents);

SignalDispatcher::create();
SignalDispatcher::inst()->updateActiveEditor(editor);

Preferences::create(editor->colorSchemes());
connect(Preferences::inst()->ButtonConfig, SIGNAL(inputMappingChanged()), InputDriverManager::instance(), SLOT(onInputMappingUpdated()), Qt::UniqueConnection);
connect(Preferences::inst()->AxisConfig, SIGNAL(inputMappingChanged()), InputDriverManager::instance(), SLOT(onInputMappingUpdated()), Qt::UniqueConnection);
@@ -226,7 +230,17 @@ MainWindow::MainWindow(const QString &filename)
}
#endif

editorDockContents->layout()->addWidget(editor);
filetab = new QTabWidget();
filetab->setTabsClosable(true);
filetab->setMovable(true);
editorDockContents->layout()->addWidget(filetab);

connect(filetab, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
connect(filetab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));


filetab->addTab(editor, "tab");
filetab->setCurrentWidget(editor);

setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
@@ -316,6 +330,7 @@ MainWindow::MainWindow(const QString &filename)

// File menu
connect(this->fileActionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
connect(this->fileActionNewTab, SIGNAL(triggered()), this, SLOT(actionNewTab()));
connect(this->fileActionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
connect(this->fileActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
connect(this->fileActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
@@ -354,7 +369,7 @@ MainWindow::MainWindow(const QString &filename)
connect(this->editActionCopy, SIGNAL(triggered()), editor, SLOT(copy()));
connect(this->editActionPaste, SIGNAL(triggered()), editor, SLOT(paste()));
connect(this->editActionCopyViewport, SIGNAL(triggered()), this, SLOT(actionCopyViewport()));
connect(this->editActionIndent, SIGNAL(triggered()), editor, SLOT(indentSelection()));
connect(this->editActionIndent, SIGNAL(triggered()), SignalDispatcher::inst(), SLOT(indentSelection()));
connect(this->editActionUnindent, SIGNAL(triggered()), editor, SLOT(unindentSelection()));
connect(this->editActionComment, SIGNAL(triggered()), editor, SLOT(commentSelection()));
connect(this->editActionUncomment, SIGNAL(triggered()), editor, SLOT(uncommentSelection()));
@@ -1417,6 +1432,69 @@ void MainWindow::actionNew()
}
}

void MainWindow::actionNewTab()
{
// todo: new tab must be created
#ifdef USE_SCINTILLA_EDITOR
if (useScintilla) {
editor = new ScintillaEditor(editorDockContents);
}
else
#endif
editor = new LegacyEditor(editorDockContents);


Preferences::create(editor->colorSchemes());

connect(editor, SIGNAL(previewRequest()), this, SLOT(actionRenderPreview()));
connect(Preferences::inst(), SIGNAL(editorConfigChanged()), editor, SLOT(applySettings()));
connect(Preferences::inst(), SIGNAL(editorConfigChanged()), editor, SLOT(applySettings()));

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Preferences::inst()->fireEditorConfigChanged(); // it seems to highlight current line and set indentation space
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int)));
connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError()));

// Edit menu
connect(this->editActionUndo, SIGNAL(triggered()), editor, SLOT(undo()));
connect(editor, SIGNAL(contentsChanged()), this, SLOT(updateActionUndoState()));
connect(this->editActionRedo, SIGNAL(triggered()), editor, SLOT(redo()));
connect(this->editActionRedo_2, SIGNAL(triggered()), editor, SLOT(redo()));
connect(this->editActionCut, SIGNAL(triggered()), editor, SLOT(cut()));
connect(this->editActionCopy, SIGNAL(triggered()), editor, SLOT(copy()));
connect(this->editActionPaste, SIGNAL(triggered()), editor, SLOT(paste()));

//connect(this->editActionIndent, SIGNAL(triggered()), editor, SLOT(indentSelection()));
connect(this->editActionUnindent, SIGNAL(triggered()), editor, SLOT(unindentSelection()));
connect(this->editActionComment, SIGNAL(triggered()), editor, SLOT(commentSelection()));
connect(this->editActionUncomment, SIGNAL(triggered()), editor, SLOT(uncommentSelection()));
connect(this->editActionZoomTextIn, SIGNAL(triggered()), editor, SLOT(zoomIn()));
connect(this->editActionZoomTextOut, SIGNAL(triggered()), editor, SLOT(zoomOut()));

connect(editor, SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
connect(editor, SIGNAL(contentsChanged()), this, SLOT(setContentsChanged()));
connect(editor, SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));

connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)),
editor, SLOT(initFont(const QString&,uint)));

connect(Preferences::inst(), SIGNAL(syntaxHighlightChanged(const QString&)),
editor, SLOT(setHighlightScheme(const QString&)));
connect(Preferences::inst(), SIGNAL(colorSchemeChanged(const QString&)),
this, SLOT(setColorScheme(const QString&)));

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Preferences::inst()->apply(); // it seems to set the colour scheme and design of editor... but how??
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



filetab->addTab(editor, "tab");
filetab ->setCurrentWidget(editor);
}

void MainWindow::actionOpen()
{
auto fileInfo = UIUtils::openFile(this);
@@ -2655,6 +2733,22 @@ void MainWindow::viewModePreview()
}
}

void MainWindow::currentTabChanged(int i)
{
editor = (EditorInterface *)filetab->widget(i);
SignalDispatcher::inst()->updateActiveEditor(editor);
}

void MainWindow::closeTab(int i)
{
QWidget *temp = filetab->widget(i);
filetab->removeTab(i);

// todo: popup dialog for saving contents

delete temp;
}

#endif /* ENABLE_OPENCSG */

#ifdef ENABLE_CGAL
@@ -3207,3 +3301,37 @@ QString MainWindow::exportPath(const char *suffix) {
}
return path;
}





SignalDispatcher *SignalDispatcher::instance = nullptr;

SignalDispatcher::~SignalDispatcher()
{
SignalDispatcher::instance = nullptr;
}

void SignalDispatcher::create()
{
instance = new SignalDispatcher();
}

void SignalDispatcher::updateActiveEditor(EditorInterface *editor)
{
activeEditor = editor;
}

void SignalDispatcher::indentSelection()
{
assert(SignalDispatcher::instance != nullptr);
assert(activeEditor != nullptr);
activeEditor->indentSelection();
}

SignalDispatcher *SignalDispatcher::inst() {
assert(SignalDispatcher::instance != nullptr);

return SignalDispatcher::instance;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.