- feature: save/restore main window layout

- feature: hide/show left panel
 - feature: double click editor title to maximize/restore it
 - fix: editor not updated when parser done
This commit is contained in:
royqh1979 2021-09-02 19:36:16 +08:00
parent 9ee608891c
commit 805533664f
5 changed files with 217 additions and 29 deletions

View File

@ -382,6 +382,12 @@ void Editor::wheelEvent(QWheelEvent *event) {
void Editor::focusInEvent(QFocusEvent *event) void Editor::focusInEvent(QFocusEvent *event)
{ {
SynEdit::focusInEvent(event); SynEdit::focusInEvent(event);
if (mParser) {
connect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo();
@ -391,6 +397,13 @@ void Editor::focusInEvent(QFocusEvent *event)
void Editor::focusOutEvent(QFocusEvent *event) void Editor::focusOutEvent(QFocusEvent *event)
{ {
SynEdit::focusOutEvent(event); SynEdit::focusOutEvent(event);
if (mParser) {
disconnect(mParser.get(),
&CppParser::onEndParsing,
this,
&SynEdit::invalidate);
}
pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo();

View File

@ -34,9 +34,10 @@ MainWindow::MainWindow(QWidget *parent)
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
mSearchDialog(nullptr), mSearchDialog(nullptr),
mQuitting(false), mQuitting(false),
mMessageControlChanged(false), mOpenClosingBottomPanel(false),
mTabMessagesTogglingState(false), mOpenClosingLeftPanel(false),
mCheckSyntaxInBack(false) mCheckSyntaxInBack(false),
mClosing(false)
{ {
ui->setupUi(this); ui->setupUi(this);
// status bar // status bar
@ -288,11 +289,26 @@ void MainWindow::applySettings()
void MainWindow::applyUISettings() void MainWindow::applyUISettings()
{ {
openCloseMessageSheet(false);
mPreviousHeight = 250;
const Settings::UI& settings = pSettings->ui(); const Settings::UI& settings = pSettings->ui();
restoreGeometry(settings.mainWindowGeometry()); restoreGeometry(settings.mainWindowGeometry());
restoreState(settings.mainWindowState()); restoreState(settings.mainWindowState());
//we can show/hide left/bottom panels here, cause mainwindow layout is not calculated
// ui->tabMessages->setCurrentIndex(settings.bottomPanelIndex());
// if (settings.bottomPanelOpenned()) {
// mBottomPanelHeight = settings.bottomPanelHeight();
// openCloseBottomPanel(true);
// } else {
// openCloseBottomPanel(false);
// mBottomPanelHeight = settings.bottomPanelHeight();
// }
// ui->tabInfos->setCurrentIndex(settings.leftPanelIndex());
// if (settings.leftPanelOpenned()) {
// mLeftPanelWidth = settings.leftPanelWidth();
// openCloseLeftPanel(true);
// } else {
// openCloseLeftPanel(false);
// mLeftPanelWidth = settings.leftPanelWidth();
// }
} }
QFileSystemWatcher *MainWindow::fileSystemWatcher() QFileSystemWatcher *MainWindow::fileSystemWatcher()
@ -612,7 +628,7 @@ bool MainWindow::compile(bool rebuild)
mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename()); mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename());
} }
updateCompileActions(); updateCompileActions();
openCloseMessageSheet(true); openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput); ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput);
updateAppTitle(); updateAppTitle();
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild); mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
@ -929,19 +945,19 @@ void MainWindow::debug()
void MainWindow::showSearchPanel() void MainWindow::showSearchPanel()
{ {
openCloseMessageSheet(true); openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabSearch); ui->tabMessages->setCurrentWidget(ui->tabSearch);
} }
void MainWindow::openCloseMessageSheet(bool open) void MainWindow::openCloseBottomPanel(bool open)
{ {
// if Assigned(fReportToolWindow) then // if Assigned(fReportToolWindow) then
// Exit; // Exit;
if (mTabMessagesTogglingState) if (mOpenClosingBottomPanel)
return; return;
mTabMessagesTogglingState = true; mOpenClosingBottomPanel = true;
auto action = finally([this]{ auto action = finally([this]{
mTabMessagesTogglingState = false; mOpenClosingBottomPanel = false;
}); });
// Switch between open and close // Switch between open and close
if (open) { if (open) {
@ -949,12 +965,12 @@ void MainWindow::openCloseMessageSheet(bool open)
int tabHeight = ui->tabMessages->tabBar()->height(); int tabHeight = ui->tabMessages->tabBar()->height();
ui->tabMessages->setMinimumHeight(tabHeight+5); ui->tabMessages->setMinimumHeight(tabHeight+5);
int totalSize = sizes[0] + sizes[1]; int totalSize = sizes[0] + sizes[1];
sizes[1] = mPreviousHeight; sizes[1] = mBottomPanelHeight;
sizes[0] = std::max(1,totalSize - sizes[1]); sizes[0] = std::max(1,totalSize - sizes[1]);
ui->splitterMessages->setSizes(sizes); ui->splitterMessages->setSizes(sizes);
} else { } else {
QList<int> sizes = ui->splitterMessages->sizes(); QList<int> sizes = ui->splitterMessages->sizes();
mPreviousHeight = sizes[1]; mBottomPanelHeight = sizes[1];
int totalSize = sizes[0] + sizes[1]; int totalSize = sizes[0] + sizes[1];
int tabHeight = ui->tabMessages->tabBar()->height(); int tabHeight = ui->tabMessages->tabBar()->height();
ui->tabMessages->setMinimumHeight(tabHeight); ui->tabMessages->setMinimumHeight(tabHeight);
@ -962,11 +978,43 @@ void MainWindow::openCloseMessageSheet(bool open)
sizes[0] = std::max(1,totalSize - sizes[1]); sizes[0] = std::max(1,totalSize - sizes[1]);
ui->splitterMessages->setSizes(sizes); ui->splitterMessages->setSizes(sizes);
} }
mBottomPanelOpenned = open;
QSplitterHandle* handle = ui->splitterMessages->handle(1); QSplitterHandle* handle = ui->splitterMessages->handle(1);
handle->setEnabled(open); handle->setEnabled(open);
int idxClose = ui->tabMessages->indexOf(ui->tabClose); int idxClose = ui->tabMessages->indexOf(ui->tabClose);
ui->tabMessages->setTabVisible(idxClose,open); ui->tabMessages->setTabVisible(idxClose,open);
mTabMessagesTogglingState = false; }
void MainWindow::openCloseLeftPanel(bool open)
{
if (mOpenClosingLeftPanel)
return;
mOpenClosingLeftPanel = true;
auto action = finally([this]{
mOpenClosingLeftPanel = false;
});
// Switch between open and close
if (open) {
QList<int> sizes = ui->splitterInfos->sizes();
int tabWidth = ui->tabInfos->tabBar()->width();
ui->tabInfos->setMinimumWidth(tabWidth+5);
int totalSize = sizes[0] + sizes[1];
sizes[0] = mLeftPanelWidth;
sizes[1] = std::max(1,totalSize - sizes[0]);
ui->splitterInfos->setSizes(sizes);
} else {
QList<int> sizes = ui->splitterInfos->sizes();
mLeftPanelWidth = sizes[0];
int totalSize = sizes[0] + sizes[1];
int tabWidth = ui->tabInfos->tabBar()->width();
ui->tabInfos->setMinimumWidth(tabWidth);
sizes[0] = tabWidth;
sizes[1] = std::max(1,totalSize - sizes[0]);
ui->splitterInfos->setSizes(sizes);
}
mLeftPanelOpenned = open;
QSplitterHandle* handle = ui->splitterInfos->handle(1);
handle->setEnabled(open);
} }
void MainWindow::prepareDebugger() void MainWindow::prepareDebugger()
@ -984,7 +1032,8 @@ void MainWindow::prepareDebugger()
ui->tabInfos->setCurrentWidget(ui->tabWatch); ui->tabInfos->setCurrentWidget(ui->tabWatch);
ui->tabMessages->setCurrentWidget(ui->tabDebug); ui->tabMessages->setCurrentWidget(ui->tabDebug);
ui->debugViews->setCurrentWidget(ui->tabDebugConsole); ui->debugViews->setCurrentWidget(ui->tabDebugConsole);
openCloseMessageSheet(true); openCloseBottomPanel(true);
openCloseLeftPanel(true);
// Reset watch vars // Reset watch vars
@ -1138,7 +1187,7 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index) void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
{ {
Editor* editor = mEditorList->getEditor(index); Editor* editor = mEditorList->getEditor(index,ui->EditorTabsLeft);
mEditorList->closeEditor(editor); mEditorList->closeEditor(editor);
} }
@ -1164,7 +1213,14 @@ void MainWindow::closeEvent(QCloseEvent *event) {
Settings::UI& settings = pSettings->ui(); Settings::UI& settings = pSettings->ui();
settings.setMainWindowState(saveState()); settings.setMainWindowState(saveState());
settings.setMainWindowGeometry(saveGeometry()); settings.setMainWindowGeometry(saveGeometry());
pSettings->ui().save(); settings.setBottomPanelHeight(mBottomPanelHeight);
settings.setBottomPanelIndex(ui->tabMessages->currentIndex());
settings.setBottomPanelOpenned(mBottomPanelOpenned);
settings.setLeftPanelWidth(mLeftPanelWidth);
settings.setLeftPanelIndex(ui->tabInfos->currentIndex());
settings.setLeftPanelOpenned(mLeftPanelOpenned);
settings.save();
if (!mEditorList->closeAll(false)) { if (!mEditorList->closeAll(false)) {
event->ignore(); event->ignore();
return ; return ;
@ -1175,6 +1231,27 @@ void MainWindow::closeEvent(QCloseEvent *event) {
return; return;
} }
void MainWindow::showEvent(QShowEvent *event)
{
const Settings::UI& settings = pSettings->ui();
ui->tabMessages->setCurrentIndex(settings.bottomPanelIndex());
if (settings.bottomPanelOpenned()) {
mBottomPanelHeight = settings.bottomPanelHeight();
openCloseBottomPanel(true);
} else {
openCloseBottomPanel(false);
mBottomPanelHeight = settings.bottomPanelHeight();
}
ui->tabInfos->setCurrentIndex(settings.leftPanelIndex());
if (settings.leftPanelOpenned()) {
mLeftPanelWidth = settings.leftPanelWidth();
openCloseLeftPanel(true);
} else {
openCloseLeftPanel(false);
mLeftPanelWidth = settings.leftPanelWidth();
}
}
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
@ -1258,13 +1335,12 @@ void MainWindow::onCompileFinished()
// and (ResourceOutput.Items.Count = 0) // and (ResourceOutput.Items.Count = 0)
// and devData.AutoCloseProgress // and devData.AutoCloseProgress
) { ) {
openCloseMessageSheet(false); openCloseBottomPanel(false);
// Or open it if there is anything to show // Or open it if there is anything to show
} else { } else {
if (ui->tableIssues->count() > 0) { if (ui->tableIssues->count() > 0) {
if (ui->tabMessages->currentIndex() != i) { if (ui->tabMessages->currentIndex() != i) {
ui->tabMessages->setCurrentIndex(i); ui->tabMessages->setCurrentIndex(i);
mMessageControlChanged = false;
} }
// end else if (ResourceOutput.Items.Count > 0) then begin // end else if (ResourceOutput.Items.Count > 0) then begin
// if MessageControl.ActivePage <> ResSheet then begin // if MessageControl.ActivePage <> ResSheet then begin
@ -1272,7 +1348,7 @@ void MainWindow::onCompileFinished()
// fMessageControlChanged := False; // fMessageControlChanged := False;
// end; // end;
// end; // end;
openCloseMessageSheet(true); openCloseBottomPanel(true);
} }
} }
@ -1544,7 +1620,7 @@ void MainWindow::on_actionConvert_to_UTF_8_triggered()
void MainWindow::on_tabMessages_tabBarClicked(int index) void MainWindow::on_tabMessages_tabBarClicked(int index)
{ {
if (index == ui->tabMessages->currentIndex()) { if (index == ui->tabMessages->currentIndex()) {
openCloseMessageSheet(!ui->splitterMessages->handle(1)->isEnabled()); openCloseBottomPanel(!mBottomPanelOpenned);
} }
} }
@ -1552,9 +1628,9 @@ void MainWindow::on_tabMessages_currentChanged(int index)
{ {
int idxClose = ui->tabMessages->indexOf(ui->tabClose); int idxClose = ui->tabMessages->indexOf(ui->tabClose);
if (index == idxClose) { if (index == idxClose) {
openCloseMessageSheet(false); openCloseBottomPanel(false);
} else { } else {
openCloseMessageSheet(true); openCloseBottomPanel(true);
} }
} }
@ -1949,3 +2025,47 @@ void MainWindow::on_actionForward_triggered()
updateCaretActions(); updateCaretActions();
} }
void MainWindow::on_tabInfos_tabBarClicked(int index)
{
if (index == ui->tabInfos->currentIndex()) {
openCloseLeftPanel(!mLeftPanelOpenned);
}
}
void MainWindow::on_splitterInfos_splitterMoved(int, int)
{
QList<int> sizes = ui->splitterMessages->sizes();
mLeftPanelWidth = sizes[0];
}
void MainWindow::on_splitterMessages_splitterMoved(int, int)
{
QList<int> sizes = ui->splitterMessages->sizes();
mBottomPanelHeight = sizes[1];
}
void MainWindow::on_EditorTabsLeft_tabBarDoubleClicked(int index)
{
if (mLeftPanelOpenned || mBottomPanelOpenned ) {
openCloseBottomPanel(false);
openCloseLeftPanel(false);
} else {
openCloseBottomPanel(true);
openCloseLeftPanel(true);
}
}
void MainWindow::on_actionClose_triggered()
{
mClosing = true;
Editor* e = mEditorList->getEditor();
if (e) {
mEditorList->closeEditor(e);
}
}

View File

@ -127,7 +127,8 @@ private:
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();
bool debugInferiorhasBreakpoint(); bool debugInferiorhasBreakpoint();
void setupActions(); void setupActions();
void openCloseMessageSheet(bool open); void openCloseBottomPanel(bool open);
void openCloseLeftPanel(bool open);
void prepareDebugger(); void prepareDebugger();
void doAutoSave(Editor *e); void doAutoSave(Editor *e);
void buildContextMenus(); void buildContextMenus();
@ -244,6 +245,16 @@ private slots:
void on_actionForward_triggered(); void on_actionForward_triggered();
void on_tabInfos_tabBarClicked(int index);
void on_splitterInfos_splitterMoved(int pos, int index);
void on_splitterMessages_splitterMoved(int pos, int index);
void on_EditorTabsLeft_tabBarDoubleClicked(int index);
void on_actionClose_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;
@ -272,20 +283,26 @@ private:
PSearchResultTreeViewDelegate mSearchViewDelegate; PSearchResultTreeViewDelegate mSearchViewDelegate;
ClassBrowserModel mClassBrowserModel; ClassBrowserModel mClassBrowserModel;
bool mMessageControlChanged;
bool mTabMessagesTogglingState;
bool mCheckSyntaxInBack; bool mCheckSyntaxInBack;
int mPreviousHeight; bool mOpenClosingBottomPanel;
int mBottomPanelHeight;
bool mBottomPanelOpenned;
bool mOpenClosingLeftPanel;
int mLeftPanelWidth;
bool mLeftPanelOpenned;
PCompileSuccessionTask mCompileSuccessionTask; PCompileSuccessionTask mCompileSuccessionTask;
QTimer mAutoSaveTimer; QTimer mAutoSaveTimer;
CaretList mCaretList; CaretList mCaretList;
bool mClosing = false;
// QWidget interface // QWidget interface
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent* event) override;
}; };
extern MainWindow* pMainWindow; extern MainWindow* pMainWindow;

View File

@ -751,7 +751,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>946</width> <width>946</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -765,6 +765,9 @@
<addaction name="actionSaveAs"/> <addaction name="actionSaveAs"/>
<addaction name="actionSaveAll"/> <addaction name="actionSaveAll"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionClose"/>
<addaction name="actionClose_All"/>
<addaction name="separator"/>
<addaction name="actionExit"/> <addaction name="actionExit"/>
</widget> </widget>
<widget class="QMenu" name="menuTools"> <widget class="QMenu" name="menuTools">
@ -834,12 +837,18 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionReformat_Code"/> <addaction name="actionReformat_Code"/>
</widget> </widget>
<widget class="QMenu" name="menuWindow">
<property name="title">
<string>Window</string>
</property>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
<addaction name="menuSearch"/> <addaction name="menuSearch"/>
<addaction name="menuCode"/> <addaction name="menuCode"/>
<addaction name="menuExecute"/> <addaction name="menuExecute"/>
<addaction name="menuTools"/> <addaction name="menuTools"/>
<addaction name="menuWindow"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolbarMain"> <widget class="QToolBar" name="toolbarMain">
@ -1426,6 +1435,32 @@
<string>Ctrl+Alt+Right</string> <string>Ctrl+Alt+Right</string>
</property> </property>
</action> </action>
<action name="actionClose">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/010-closefl.png</normalon>
</iconset>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
<action name="actionClose_All">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/009-closeall.png</normalon>
</iconset>
</property>
<property name="text">
<string>Close All</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+W</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -3663,9 +3663,10 @@ void Settings::UI::doSave()
saveValue("main_window_geometry",mMainWindowGeometry); saveValue("main_window_geometry",mMainWindowGeometry);
saveValue("bottom_panel_openned",mBottomPanelOpenned); saveValue("bottom_panel_openned",mBottomPanelOpenned);
saveValue("bottom_panel_height",mBottomPanelHeight); saveValue("bottom_panel_height",mBottomPanelHeight);
saveValue() saveValue("bottom_panel_index",mBottomPanelIndex);
saveValue("left_panel_openned",mLeftPanelOpenned); saveValue("left_panel_openned",mLeftPanelOpenned);
saveValue("left_panel_width",mLeftPanelWidth); saveValue("left_panel_width",mLeftPanelWidth);
saveValue("left_panel_index",mLeftPanelIndex);
} }
void Settings::UI::doLoad() void Settings::UI::doLoad()
@ -3674,6 +3675,8 @@ void Settings::UI::doLoad()
mMainWindowGeometry = value("main_window_geometry",QByteArray()).toByteArray(); mMainWindowGeometry = value("main_window_geometry",QByteArray()).toByteArray();
mBottomPanelOpenned = boolValue("bottom_panel_openned",false); mBottomPanelOpenned = boolValue("bottom_panel_openned",false);
mBottomPanelHeight = intValue("bottom_panel_height",220); mBottomPanelHeight = intValue("bottom_panel_height",220);
mBottomPanelIndex = intValue("bottom_panel_index",0);
mLeftPanelOpenned = boolValue("left_panel_openned",true); mLeftPanelOpenned = boolValue("left_panel_openned",true);
mLeftPanelWidth = intValue("left_panel_width",250); mLeftPanelWidth = intValue("left_panel_width",250);
mLeftPanelIndex = intValue("left_panel_index",2);
} }