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

Implement multi-tab feature in TabManager class #2955

Open
wants to merge 36 commits into
base: master
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7502652
Implement multi-tab feature in TabManager class
RomitKumar May 26, 2019
8086470
Integrate support for legacy and scintilla editor along
RomitKumar May 28, 2019
c9b76a7
Implement pre-available editing features for each tab
RomitKumar May 28, 2019
cfa32da
remove support for legacy editor
RomitKumar May 29, 2019
1ad0f53
corrected keyboard shortcut for zoom-in and zoom-out
RomitKumar May 29, 2019
a60542f
undoState and windowModified updates for each tab
RomitKumar May 30, 2019
0b1427d
Correct stl export and parameterWidget enable state behaviour
RomitKumar Jun 1, 2019
a2a0da5
update to enable Scintilla Editor in travis check
RomitKumar Jun 1, 2019
cb2d2d6
Customizer widget disables on changing tab
RomitKumar Jun 1, 2019
b7e4d80
animation stops on changing tab
RomitKumar Jun 1, 2019
6bc13c5
remove commented lines
RomitKumar Jun 1, 2019
23129ba
Extended Find, Find and Replace behaviour for multi-tab
RomitKumar Jun 4, 2019
d594980
Removed support for single file QScintilla Editor
RomitKumar Jun 6, 2019
396d75b
Add the feature of New Tab
RomitKumar Jun 9, 2019
ee26a80
Correct the new tab implementation
RomitKumar Jun 9, 2019
486562d
Implement open file in new tab
RomitKumar Jun 9, 2019
232844b
Recent file and examples open in new tab
RomitKumar Jun 9, 2019
0ea2735
Handle file drop for multi-tab
RomitKumar Jun 9, 2019
c73a63a
Implement close confirmation dialog for unsaved tab and window
RomitKumar Jun 9, 2019
6a0a1d1
Changed behaviour of option in file menu
RomitKumar Jun 11, 2019
e3ff4d9
Corrected open behaviour for file drops
RomitKumar Jun 11, 2019
0e92308
Code cleanup, renaming of function and variable names
RomitKumar Jun 13, 2019
cdaee5e
Cleanup of Code
RomitKumar Jun 13, 2019
b0c95e8
Implement the feature of Save All
RomitKumar Jun 14, 2019
35e3fe0
Parameter Widget enabled on file load
RomitKumar Jun 14, 2019
acc3123
Recent File and example open in empty tab
RomitKumar Jun 14, 2019
087359f
Tab Header spans whole width of screen
RomitKumar Jun 16, 2019
c59df44
Update openscad.pro file
RomitKumar Jun 16, 2019
fd93e57
Add Tab Header in ToolBar
RomitKumar Jun 17, 2019
a50fd61
Corrected the opening of tab in toolbar
RomitKumar Jun 17, 2019
689292c
Undocked editor contains tab header toolbar
RomitKumar Jun 17, 2019
dff9b9b
Tab tool bar hidden for single tab
RomitKumar Jun 21, 2019
12c605f
Corrected implementation of opening of file in empty editor tab
RomitKumar Jul 13, 2019
30085ff
Corrected interpretation of ampersand in file name
RomitKumar Jul 13, 2019
a99d689
Merge branch 'master' into multi-tab
RomitKumar Jul 14, 2019
606f743
initialized tabCount variable
RomitKumar Jul 20, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Code cleanup, renaming of function and variable names

  • Loading branch information...
RomitKumar committed Jun 13, 2019
commit 0e923084003f16c1050aa6ea3ff04c25f0efec52
@@ -137,8 +137,8 @@ public slots:
void actionSave();

private slots:
void actionNew();
void actionOpen();
void actionNewWindow();
void actionOpenWindow();
void actionOpenRecent();
void actionOpenExample();
void clearRecentFiles();
@@ -303,14 +303,14 @@
<addaction name="separator"/>
<addaction name="fileActionExportImage"/>
</widget>
<addaction name="fileActionNewTab"/>
<addaction name="fileActionOpenTab"/>
<addaction name="fileActionNew"/>
<addaction name="fileActionOpen"/>
<addaction name="menuOpenRecent"/>
<addaction name="menuExamples"/>
<addaction name="fileActionReload"/>
<addaction name="separator"/>
<addaction name="fileActionNew"/>
<addaction name="fileActionOpen"/>
<addaction name="fileActionNewWindow"/>
<addaction name="fileActionOpenWindow"/>
<addaction name="fileActionClose"/>
<addaction name="separator"/>
<addaction name="fileActionSave"/>
@@ -456,8 +456,8 @@
</property>
<item>
<widget class="QToolBar" name="editortoolbar">
<addaction name="fileActionNewTab"/>
<addaction name="fileActionOpenTab"/>
<addaction name="fileActionNew"/>
<addaction name="fileActionOpen"/>
<addaction name="fileActionSave"/>
<addaction name="separator"/>
<addaction name="editActionUndo"/>
@@ -639,7 +639,7 @@
</layout>
</widget>
</widget>
<action name="fileActionNewTab">
<action name="fileActionNew">
<property name="icon">
<iconset resource="../openscad.qrc">
<normaloff>:/images/blackNew.png</normaloff>:/images/blackNew.png</iconset>
@@ -651,7 +651,7 @@
<string>Ctrl+N</string>
</property>
</action>
<action name="fileActionNew">
<action name="fileActionNewWindow">
<!-- <property name="icon">
<iconset resource="../openscad.qrc">
<normaloff>:/images/blackNew.png</normaloff>:/images/blackNew.png</iconset>
@@ -663,7 +663,7 @@
<string>Ctrl+N</string>
</property> -->
</action>
<action name="fileActionOpenTab">
<action name="fileActionOpen">
<property name="icon">
<iconset resource="../openscad.qrc">
<normaloff>:/images/Open-32.png</normaloff>:/images/Open-32.png</iconset>
@@ -675,7 +675,7 @@
<string>Ctrl+O</string>
</property>
</action>
<action name="fileActionOpen">
<action name="fileActionOpenWindow">
<!-- <property name="icon">
<iconset resource="../openscad.qrc">
<normaloff>:/images/Open-32.png</normaloff>:/images/Open-32.png</iconset>
@@ -56,7 +56,7 @@ public slots:
QSize initialSizeHint;

public:
bool contentsChangedState; // Set if the source code has changes since the last render (F6)
bool contentsRendered; // Set if the source code has changes since the last render (F6)
int findState;
QString filepath;
};
@@ -220,7 +220,7 @@ MainWindow::MainWindow(const QString &filename)
}

tabManager = new TabManager(this, filename);
editorDockContents->layout()->addWidget(tabManager->getTabObj());
editorDockContents->layout()->addWidget(tabManager->getTabWidget());

connect(Preferences::inst()->ButtonConfig, SIGNAL(inputMappingChanged()), InputDriverManager::instance(), SLOT(onInputMappingUpdated()), Qt::UniqueConnection);
connect(Preferences::inst()->AxisConfig, SIGNAL(inputMappingChanged()), InputDriverManager::instance(), SLOT(onInputMappingUpdated()), Qt::UniqueConnection);
@@ -299,10 +299,10 @@ MainWindow::MainWindow(const QString &filename)
connect(this->labelCompileResultMessage, SIGNAL(linkActivated(QString)), SLOT(showConsole()));

// File menu
connect(this->fileActionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
connect(this->fileActionNewTab, SIGNAL(triggered()), tabManager, SLOT(actionNewTab()));
connect(this->fileActionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
connect(this->fileActionOpenTab, SIGNAL(triggered()), tabManager, SLOT(actionOpenTab()));
connect(this->fileActionNewWindow, SIGNAL(triggered()), this, SLOT(actionNewWindow()));
connect(this->fileActionNew, SIGNAL(triggered()), tabManager, SLOT(actionNew()));
connect(this->fileActionOpenWindow, SIGNAL(triggered()), this, SLOT(actionOpenWindow()));
connect(this->fileActionOpen, SIGNAL(triggered()), tabManager, SLOT(actionOpen()));
connect(this->fileActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
connect(this->fileActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
connect(this->fileActionReload, SIGNAL(triggered()), this, SLOT(actionReload()));
@@ -476,8 +476,8 @@ MainWindow::MainWindow(const QString &filename)
Preferences* instance = Preferences::inst();
instance->ButtonConfig->init();

initActionIcon(fileActionNewTab, ":/images/blackNew.png", ":/images/Document-New-128.png");
initActionIcon(fileActionOpenTab, ":/images/Open-32.png", ":/images/Open-128.png");
initActionIcon(fileActionNew, ":/images/blackNew.png", ":/images/Document-New-128.png");
initActionIcon(fileActionOpen, ":/images/Open-32.png", ":/images/Open-128.png");
initActionIcon(fileActionSave, ":/images/Save-32.png", ":/images/Save-128.png");
initActionIcon(editActionZoomTextIn, ":/images/zoom-text-in.png", ":/images/zoom-text-in-white.png");
initActionIcon(editActionZoomTextOut, ":/images/zoom-text-out.png", ":/images/zoom-text-out-white.png");
@@ -977,7 +977,7 @@ void MainWindow::refreshDocument()
PRINTB("Loaded design '%s'.", activeEditor->filepath.toLocal8Bit().constData());
if (activeEditor->toPlainText() != text) {
activeEditor->setPlainText(text);
tabManager->setContentsChanged();
tabManager->setContentRenderState();
}
}
}
@@ -1350,7 +1350,7 @@ void MainWindow::compileCSG()
}
}

void MainWindow::actionNew()
void MainWindow::actionNewWindow()
{
new MainWindow(QString());
// if (MainWindow::mdiMode) {
@@ -1365,7 +1365,7 @@ void MainWindow::actionNew()
// }
}

void MainWindow::actionOpen()
void MainWindow::actionOpenWindow()
{
auto fileInfo = UIUtils::openFile(this);
if (!fileInfo.exists()) {
@@ -2276,7 +2276,7 @@ void MainWindow::actionRenderDone(shared_ptr<const Geometry> root_geom)
}

renderedEditor = activeEditor;
activeEditor->contentsChangedState = false;
activeEditor->contentsRendered = true;
compileEnded();
}

@@ -2422,7 +2422,7 @@ bool MainWindow::canExport(unsigned int dim)
}

// editor has changed since last render
if (activeEditor->contentsChangedState) {
if (!activeEditor->contentsRendered) {
auto ret = QMessageBox::warning(this, "Application",
"The current tab has been modified since its last render (F6).\n"
"Do you really want to export the previous content?",
@@ -114,7 +114,7 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
scintillaLayout = new QVBoxLayout(this);
qsci = new QsciScintilla(this);

contentsChangedState = false;
contentsRendered = false;
findState = 0; //FIND_HIDDEN
filepath = "";

@@ -18,17 +18,17 @@ TabManager::TabManager(MainWindow *o, const QString &filename)
{
par = o;

tabobj = new QTabWidget();
tabobj->setTabsClosable(true);
tabobj->setMovable(true);
tabobj->setTabBarAutoHide(true);
connect(tabobj, SIGNAL(currentChanged(int)), this, SLOT(curChanged(int)));
connect(tabobj, SIGNAL(tabCloseRequested(int)), this, SLOT(closeRequested(int)));
tabWidget = new QTabWidget();
tabWidget->setTabsClosable(true);
tabWidget->setMovable(true);
tabWidget->setTabBarAutoHide(true);
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSwitched(int)));
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTabRequested(int)));

createTab(filename);

connect(tabobj, SIGNAL(currentChanged(int)), this, SLOT(stopAnimation()));
connect(tabobj, SIGNAL(currentChanged(int)), this, SLOT(updateFindState()));
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stopAnimation()));
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateFindState()));

connect(par, SIGNAL(highlightError(int)), this, SLOT(highlightError(int)));
connect(par, SIGNAL(unhighlightLastError()), this, SLOT(unhighlightLastError()));
@@ -46,16 +46,16 @@ TabManager::TabManager(MainWindow *o, const QString &filename)
connect(par->editActionUncomment, SIGNAL(triggered()), this, SLOT(uncommentSelection()));
}

QTabWidget *TabManager::getTabObj()
QTabWidget *TabManager::getTabWidget()
{
assert(tabobj != nullptr);
return tabobj;
assert(tabWidget != nullptr);
return tabWidget;
}

void TabManager::curChanged(int x)
void TabManager::tabSwitched(int x)
{
assert(tabobj != nullptr);
editor = (EditorInterface *)tabobj->widget(x);
assert(tabWidget != nullptr);
editor = (EditorInterface *)tabWidget->widget(x);
par->activeEditor = editor;

if(editor == par->customizerEditor)
@@ -73,30 +73,30 @@ void TabManager::curChanged(int x)
par->editorTopLevelChanged(par->editorDock->isFloating());
par->changedTopLevelConsole(par->consoleDock->isFloating());
par->parameterTopLevelChanged(par->parameterDock->isFloating());
par->setWindowTitle(tabobj->tabText(x));
par->setWindowTitle(tabWidget->tabText(x));
}

void TabManager::closeRequested(int x)
void TabManager::closeTabRequested(int x)
{
assert(tabobj != nullptr);
assert(tabWidget != nullptr);
if(!maybeSave(x))
return;

QWidget *temp = tabobj->widget(x);
QWidget *temp = tabWidget->widget(x);
editorList.remove((EditorInterface *)temp);
tabobj->removeTab(x);
tabWidget->removeTab(x);

// todo: popup dialog for saving of contents

delete temp;
}

void TabManager::actionNewTab()
void TabManager::actionNew()
{
createTab("");
}

void TabManager::actionOpenTab()
void TabManager::actionOpen()
{
auto fileInfo = UIUtils::openFile(par);
if (!fileInfo.exists()) {
@@ -118,7 +118,7 @@ void TabManager::createTab(const QString &filename)
{
assert(par != nullptr);

editor = new ScintillaEditor(tabobj);
editor = new ScintillaEditor(tabWidget);
par->activeEditor = editor;
editorList.insert(editor);

@@ -140,7 +140,7 @@ void TabManager::createTab(const QString &filename)

connect(editor, SIGNAL(contentsChanged()), this, SLOT(updateActionUndoState()));
connect(editor, SIGNAL(contentsChanged()), par, SLOT(animateUpdateDocChanged()));
connect(editor, SIGNAL(contentsChanged()), this, SLOT(setContentsChanged()));
connect(editor, SIGNAL(contentsChanged()), this, SLOT(setContentRenderState()));
// connect(editor, SIGNAL(modificationChanged(bool)), par, SLOT(setWindowModified(bool)));
connect(editor, SIGNAL(modificationChanged(bool)), this, SLOT(setTabModified(bool)));

@@ -159,13 +159,6 @@ void TabManager::createTab(const QString &filename)
par->updateRecentFileActions();
}

void TabManager::curContent()
{
std::cout << editor->toPlainText().toStdString() << std::endl << std::endl;

// todo: set window title
}

void TabManager::highlightError(int i)
{
editor->highlightError(i);
@@ -226,9 +219,9 @@ void TabManager::updateActionUndoState()
par->editActionUndo->setEnabled(editor->canUndo());
}

void TabManager::setContentsChanged() //since last render
void TabManager::setContentRenderState() //since last render
{
editor->contentsChangedState = true;//since last render
editor->contentsRendered = false; //since last render
if(editor == par->customizerEditor)
{
par->customizerEditor = nullptr;
@@ -268,8 +261,8 @@ void TabManager::setTabModified(bool mod)
fname += "*";
}

tabobj->setTabText(tabobj->currentIndex(), fname);
tabobj->setTabToolTip(tabobj->currentIndex(), fpath);
tabWidget->setTabText(tabWidget->currentIndex(), fname);
tabWidget->setTabToolTip(tabWidget->currentIndex(), fpath);
par->setWindowTitle(fname);
}

@@ -304,15 +297,15 @@ void TabManager::openFileTab(const QString &filename)
void TabManager::setTab(const QString &filename)
{
if (filename.isEmpty()) {
tabobj->addTab(editor, _("Untitled.scad"));
tabobj->setCurrentWidget(editor);
tabobj->setTabToolTip(tabobj->currentIndex(), _("Untitled.scad"));
tabWidget->addTab(editor, _("Untitled.scad"));
tabWidget->setCurrentWidget(editor);
tabWidget->setTabToolTip(tabWidget->currentIndex(), _("Untitled.scad"));
} else {
QFileInfo fileinfo(filename);
editor->filepath = fileinfo.absoluteFilePath();
tabobj->addTab(editor, fileinfo.fileName());
tabobj->setCurrentWidget(editor);
tabobj->setTabToolTip(tabobj->currentIndex(), fileinfo.filePath());
tabWidget->addTab(editor, fileinfo.fileName());
tabWidget->setCurrentWidget(editor);
tabWidget->setTabToolTip(tabWidget->currentIndex(), fileinfo.filePath());
par->parameterWidget->readFile(editor->filepath); ////////////////////////////////
QDir::setCurrent(fileinfo.dir().absolutePath());
// this->top_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
@@ -338,7 +331,7 @@ void TabManager::refreshDocument()
PRINTB("Loaded design '%s'.", editor->filepath.toLocal8Bit().constData());
if (editor->toPlainText() != text) {
editor->setPlainText(text);
setContentsChanged(); // since last render; should not be here
setContentRenderState(); // since last render; should not be here
}
}
}
@@ -347,7 +340,7 @@ void TabManager::refreshDocument()

bool TabManager::maybeSave(int x)
{
EditorInterface *edt = (EditorInterface *)tabobj->widget(x);
EditorInterface *edt = (EditorInterface *)tabWidget->widget(x);
if (edt->isContentModified()) {
QMessageBox box(par);
box.setText(_("The document has been modified."));
@@ -13,7 +13,7 @@ class TabManager: public QObject

public:
TabManager(MainWindow *o, const QString &filename);
QTabWidget *getTabObj();
QTabWidget *getTabWidget();
EditorInterface *editor;

void createTab(const QString &filename);
@@ -29,14 +29,14 @@ class TabManager: public QObject

private:
MainWindow *par;
QTabWidget *tabobj;
QTabWidget *tabWidget;
QSet<EditorInterface *> editorList;

bool maybeSave(int);

private slots:
void curChanged(int);
void closeRequested(int);
void tabSwitched(int);
void closeTabRequested(int);

private slots:
void highlightError(int);
@@ -56,9 +56,8 @@ private slots:
void updateFindState();

public slots:
void actionNewTab();
void actionOpenTab();
void curContent();
void setContentsChanged(); // since last render
void actionNew();
void actionOpen();
void setContentRenderState(); // since last render
void setTabModified(bool);
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.