- implement: files view

This commit is contained in:
royqh1979@gmail.com 2021-10-22 15:02:54 +08:00
parent d2ca199024
commit 7a5b6b8efc
11 changed files with 626 additions and 355 deletions

View File

@ -11,6 +11,7 @@ Version 0.7.0
- enhancement: autosave/load bookmarks
- enhancement: autosave/load breakpoints
- enhancement: autosave/load watches
- implement: files view
Version 0.6.8
- enhancement: add link to cppreference in the help menu

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -495,6 +495,7 @@ void Editor::focusInEvent(QFocusEvent *event)
this,
&SynEdit::invalidate);
}
pMainWindow->updateAppTitle();
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
@ -511,7 +512,6 @@ void Editor::focusOutEvent(QFocusEvent *event)
&SynEdit::invalidate);
}
//pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->functionTip()->hide();

View File

@ -153,6 +153,9 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
editor = getEditor();
pMainWindow->updateClassBrowserForEditor(editor);
}
if (pageCount()==0) {
pMainWindow->updateAppTitle();
}
return true;
}
@ -283,6 +286,7 @@ bool EditorList::closeAll(bool force) {
return false;
}
}
pMainWindow->updateAppTitle();
return true;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

After

Width:  |  Height:  |  Size: 285 B

View File

@ -207,10 +207,14 @@ MainWindow::MainWindow(QWidget *parent)
ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false);
//files view
ui->treeFiles->setModel(&mFileSystemModel);
mFileSystemModel.setRootPath(pSettings->environment().currentFolder());
ui->treeFiles->setRootIndex(mFileSystemModel.index(pSettings->environment().currentFolder()));
mFileSystemModel.setReadOnly(true);
setFilesViewRoot(pSettings->environment().currentFolder());
for (int i=1;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->hideColumn(i);
}
//class browser
ui->classBrowser->setModel(&mClassBrowserModel);
@ -322,6 +326,8 @@ void MainWindow::updateEditorActions()
ui->actionAdd_bookmark->setEnabled(false);
ui->actionRemove_Bookmark->setEnabled(false);
ui->actionModify_Bookmark_Description->setEnabled(false);
ui->actionLocate_in_Files_View->setEnabled(false);
} else {
ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true);
@ -362,6 +368,8 @@ void MainWindow::updateEditorActions()
ui->actionAdd_bookmark->setEnabled(e->lines()->count()>0 && !e->hasBookmark(line));
ui->actionRemove_Bookmark->setEnabled(e->hasBookmark(line));
ui->actionModify_Bookmark_Description->setEnabled(e->hasBookmark(line));
ui->actionLocate_in_Files_View->setEnabled(!e->isNew());
}
updateCompileActions();
@ -2047,6 +2055,7 @@ void MainWindow::buildContextMenus()
//toolbar for class browser
mClassBrowserToolbar = new QWidget();
{
QVBoxLayout* layout = dynamic_cast<QVBoxLayout*>( ui->tabStructure->layout());
layout->insertWidget(0,mClassBrowserToolbar);
QHBoxLayout* hlayout = new QHBoxLayout();
@ -2067,13 +2076,92 @@ void MainWindow::buildContextMenus()
toolButton->setDefaultAction(mClassBrowser_Show_Inherited);
hlayout->addWidget(toolButton);
hlayout->addStretch();
}
//menu for statusbar
mFileEncodingStatus->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mFileEncodingStatus,&QWidget::customContextMenuRequested,
this, &MainWindow::onFileEncodingContextMenu);
//
//menu for files view
ui->treeFiles->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treeFiles,&QWidget::customContextMenuRequested,
this, &MainWindow::onFilesViewContextMenu);
mFilesView_Open = createActionFor(
tr("Open in Editor"),
ui->treeFiles);
connect(mFilesView_Open, &QAction::triggered,
[this]() {
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
Editor *editor=mEditorList->getEditorByFilename(path);
if (editor)
editor->activate();
}
});
mFilesView_OpenWithExternal = createActionFor(
tr("Open in External Program"),
ui->treeFiles);
connect(mFilesView_OpenWithExternal, &QAction::triggered,
[this]() {
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
});
mFilesView_OpenInTerminal = createActionFor(
tr("Open in Terminal"),
ui->treeFiles);
mFilesView_OpenInTerminal->setIcon(ui->actionOpen_Terminal->icon());
connect(mFilesView_OpenInTerminal, &QAction::triggered,
[this]() {
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo fileInfo(path);
openShell(fileInfo.path(),"cmd.exe");
}
});
mFilesView_OpenInExplorer = createActionFor(
tr("Open in Windows Explorer"),
ui->treeFiles);
mFilesView_OpenInExplorer->setIcon(ui->actionOpen_Containing_Folder->icon());
connect(mFilesView_OpenInExplorer, &QAction::triggered,
[this]() {
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo info(path);
if (info.isFile()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode));
} else if (info.isDir()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(path),QUrl::TolerantMode));
}
}
});
//toolbar for files view
mFilesViewToolbar = new QWidget();
{
QVBoxLayout* layout = dynamic_cast<QVBoxLayout*>( ui->tabFiles->layout());
layout->insertWidget(0,mFilesViewToolbar);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(2,2,2,2);
mFilesViewToolbar->setLayout(hlayout);
QToolButton * toolButton;
toolButton = new QToolButton;
toolButton->setDefaultAction(ui->actionOpen_Folder);
toolButton->setFixedSize(32,32);
hlayout->addWidget(toolButton);
toolButton = new QToolButton;
toolButton->setDefaultAction(ui->actionLocate_in_Files_View);
toolButton->setFixedSize(32,32);
hlayout->addWidget(toolButton);
hlayout->addStretch();
}
}
void MainWindow::buildEncodingMenu()
@ -2345,6 +2433,26 @@ void MainWindow::onFileEncodingContextMenu(const QPoint &pos)
mMenuEncoding->exec(mFileEncodingStatus->mapToGlobal(pos));
}
void MainWindow::onFilesViewContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(ui->actionOpen_Folder);
menu.addSeparator();
menu.addAction(mFilesView_Open);
menu.addAction(mFilesView_OpenWithExternal);
menu.addSeparator();
menu.addAction(mFilesView_OpenInTerminal);
menu.addAction(mFilesView_OpenInExplorer);
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
QFileInfo info(path);
mFilesView_Open->setEnabled(info.isFile());
mFilesView_OpenWithExternal->setEnabled(info.isFile());
mFilesView_OpenInTerminal->setEnabled(!path.isEmpty());
mFilesView_OpenInExplorer->setEnabled(!path.isEmpty());
menu.exec(ui->treeFiles->mapToGlobal(pos));
}
void MainWindow::onShowInsertCodeSnippetMenu()
{
mMenuInsertCodeSnippet->clear();
@ -2407,7 +2515,7 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal);
menu.addAction(ui->actionLocate_in_Files_View);
menu.addSeparator();
menu.addAction(ui->actionReformat_Code);
menu.addSeparator();
@ -2443,6 +2551,7 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
menu.addAction(ui->actionRemove_Bookmark);
menu.addAction(ui->actionModify_Bookmark_Description);
}
ui->actionLocate_in_Files_View->setEnabled(!editor->isNew());
ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line));
ui->actionAdd_bookmark->setEnabled(
line>=0 && editor->lines()->count()>0
@ -2477,6 +2586,7 @@ void MainWindow::onEditorTabContextMenu(QTabWidget* tabWidget, const QPoint &pos
menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal);
menu.addAction(ui->actionLocate_in_Files_View);
menu.addSeparator();
menu.addAction(ui->actionMove_To_Other_View);
menu.addSeparator();
@ -2485,7 +2595,10 @@ void MainWindow::onEditorTabContextMenu(QTabWidget* tabWidget, const QPoint &pos
tabWidget==ui->EditorTabsRight
|| tabWidget->count()>1
);
Editor * editor = dynamic_cast<Editor *>(tabWidget->widget(index));
if (editor ) {
ui->actionLocate_in_Files_View->setEnabled(!editor->isNew());
}
menu.exec(tabBar->mapToGlobal(pos));
}
@ -2754,6 +2867,9 @@ void MainWindow::closeEvent(QCloseEvent *event) {
settings.setLeftPanelIndex(ui->tabInfos->currentIndex());
settings.setLeftPanelOpenned(mLeftPanelOpenned);
settings.save();
//save current folder ( for files view )
pSettings->environment().save();
try {
mBookmarkModel->save(includeTrailingPathDelimiter(pSettings->dirs().config())
+DEV_BOOKMARK_FILE);
@ -4343,6 +4459,15 @@ void MainWindow::showSearchReplacePanel(bool show)
mSearchResultTreeModel->setSelectable(show);
}
void MainWindow::setFilesViewRoot(const QString &path)
{
mFileSystemModel.setRootPath(path);
ui->treeFiles->setRootIndex(mFileSystemModel.index(path));
pSettings->environment().setCurrentFolder(path);
ui->txtFilesPath->setText(path);
ui->txtFilesPath->setCursorPosition(1);
}
Ui::MainWindow *MainWindow::mainWidget() const
{
return ui;
@ -4546,3 +4671,39 @@ void MainWindow::on_actionModify_Bookmark_Description_triggered()
}
}
void MainWindow::on_actionLocate_in_Files_View_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor) {
QString fileDir = extractFileDir(editor->filename());
if (!fileDir.isEmpty()) {
setFilesViewRoot(fileDir);
ui->treeFiles->setCurrentIndex(mFileSystemModel.index(editor->filename()));
}
}
}
void MainWindow::on_treeFiles_doubleClicked(const QModelIndex &index)
{
QString filepath = mFileSystemModel.filePath(index);
QFileInfo file(filepath);
if (file.isFile()) {
Editor * editor = mEditorList->getEditorByFilename(filepath);
if (editor) {
editor->activate();
}
}
}
void MainWindow::on_actionOpen_Folder_triggered()
{
QString folder = QFileDialog::getExistingDirectory(this,tr("Open Folder"),
pSettings->environment().currentFolder());
if (!folder.isEmpty()) {
setFilesViewRoot(folder);
}
}

View File

@ -192,6 +192,7 @@ private:
void scanActiveProject(bool parse=false);
void includeOrSkipDirs(const QStringList& dirs, bool skip);
void showSearchReplacePanel(bool show);
void setFilesViewRoot(const QString& path);
private slots:
void onAutoSaveTimeout();
@ -206,6 +207,7 @@ private slots:
void onClassBrowserContextMenu(const QPoint& pos);
void onDebugConsoleContextMenu(const QPoint& pos);
void onFileEncodingContextMenu(const QPoint& pos);
void onFilesViewContextMenu(const QPoint& pos);
void onShowInsertCodeSnippetMenu();
@ -420,6 +422,12 @@ private slots:
void on_actionModify_Bookmark_Description_triggered();
void on_actionLocate_in_Files_View_triggered();
void on_treeFiles_doubleClicked(const QModelIndex &index);
void on_actionOpen_Folder_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;
@ -511,9 +519,6 @@ private:
QAction * mFilesView_OpenWithExternal;
QAction * mFilesView_OpenInTerminal;
QAction * mFilesView_OpenInExplorer;
QAction * mFilesView_OnlyShowDevFiles;
QAction * mFilesView_LocateCurrent;
QWidget * mFilesViewToolbar;
//action for debug console

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>3</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -213,6 +213,9 @@
<string>Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
@ -226,7 +229,24 @@
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="treeFiles"/>
<widget class="QLineEdit" name="txtFilesPath">
<property name="frame">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="treeFiles">
<property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
@ -931,6 +951,7 @@
<string>File</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionOpen_Folder"/>
<addaction name="separator"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
@ -1965,6 +1986,24 @@
<string>Modify Bookmark Description</string>
</property>
</action>
<action name="actionLocate_in_Files_View">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/046-Locate.png</normaloff>:/icons/images/newlook24/046-Locate.png</iconset>
</property>
<property name="text">
<string>Locate in Files View</string>
</property>
</action>
<action name="actionOpen_Folder">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/053-open.png</normaloff>:/icons/images/newlook24/053-open.png</iconset>
</property>
<property name="text">
<string>Open Folder</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -2619,6 +2619,9 @@ void Settings::Environment::doLoad()
mInterfaceFontSize = intValue("interface font size",10);
mLanguage = stringValue("language", QLocale::system().name());
mCurrentFolder = stringValue("current_folder",QDir::currentPath());
if (!fileExists(mCurrentFolder)) {
mCurrentFolder = QDir::currentPath();
}
}
int Settings::Environment::interfaceFontSize() const

View File

@ -748,7 +748,7 @@ QString parseMacros(const QString &s)
QString result = s;
Editor *e = pMainWindow->editorList()->getEditor();
result.replace("<DEFAULT>", QDir().absolutePath());
result.replace("<DEFAULT>", QDir::currentPath());
result.replace("<DEVCPP>", pSettings->dirs().executable());
result.replace("<DEVCPPVERSION>", DEVCPP_VERSION);
result.replace("<EXECPATH>", pSettings->dirs().app());