Skip to content

Commit

Permalink
add simple fileexplorer to docks
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Apr 1, 2024
1 parent 4160496 commit 495a49a
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 5 deletions.
62 changes: 62 additions & 0 deletions images-ng/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions images-ng/folder_R90.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<file>images-ng/extend.svg</file>
<file>images-ng/focusedhand.svg</file>
<file>images-ng/folder-cloud.svg</file>
<file>images-ng/folder_R90.svg</file>
<file>images-ng/folder.svg</file>
<file>images-ng/font_emph48.svg</file>
<file>images-ng/font_textbf48.svg</file>
<file>images-ng/font_textit48.svg</file>
Expand Down
43 changes: 38 additions & 5 deletions src/texstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,20 @@ void Texstudio::setupDockWidgets()
symbolListModel->setDarkmode(darkMode);
symbolWidget->reloadData();
}
// setup a dock widget with a file explorer
dock=findChild<QDockWidget *>("explorer",Qt::FindDirectChildrenOnly);
if(!dock){
fileView=new QTreeView();
fileExplorerModel = new QFileSystemModel(this);
fileExplorerModel->setRootPath(QDir::currentPath());
fileView->setModel(fileExplorerModel);
fileView->setColumnHidden(1,true);
fileView->setColumnHidden(2,true);
fileView->setColumnHidden(3,true);
fileView->setRootIndex(fileExplorerModel->index(QDir::currentPath()));
connect(fileView,&QAbstractItemView::doubleClicked,this,&Texstudio::openFromExplorer);
addDock("explorer", "folder_R90",tr("Files"), fileView);
}

addTagList("brackets", getRealIconFile("leftright_R90"), tr("Left/Right Brackets"), "brackets_tags.xml");
addTagList("pstricks", getRealIconFile("pstricks_R90"), tr("PSTricks Commands"), "pstricks_tags.xml");
Expand Down Expand Up @@ -1833,14 +1847,22 @@ void Texstudio::currentEditorChanged()
#ifdef INTERNAL_TERMINAL
outputView->getTerminalWidget()->setCurrentFileName(getCurrentFileName());
#endif
if (!currentEditorView()) return;
LatexEditorView *edView = currentEditorView();
if (!edView) return;
if (configManager.watchedMenus.contains("main/view/documents"))
updateToolBarMenu("main/view/documents");
editorSpellerChanged(currentEditorView()->getSpeller());
currentEditorView()->lastUsageTime = QDateTime::currentDateTime();
currentEditorView()->checkRTLLTRLanguageSwitching();
editorSpellerChanged(edView->getSpeller());
edView->lastUsageTime = QDateTime::currentDateTime();
edView->checkRTLLTRLanguageSwitching();

// update global toc
updateTOCs();
// set dock file explorer to current file, root to root document folder
LatexDocument *doc=edView->getDocument();
QFileInfo fi=doc->getFileInfo();
const QString rootDir=fi.absoluteDir().path();
fileExplorerModel->setRootPath(rootDir);
fileView->setRootIndex(fileExplorerModel->index(rootDir));
}

/*!
Expand Down Expand Up @@ -5231,7 +5253,18 @@ void Texstudio::insertBib()
insertTag(tag, 0, 1);
outputView->setMessage(QString("The argument to \\bibliography refers to the bib file (without extension)\n") +
"which should contain your database in BibTeX format.\n" +
"TeXstudio inserts automatically the base name of the TeX file");
"TeXstudio inserts automatically the base name of the TeX file");
}
/*!
* \brief open file which was double clicked in the file explorer (dock)
* \param index
*/
void Texstudio::openFromExplorer(const QModelIndex &index)
{
QFileInfo fi = fileExplorerModel->fileInfo(index);
if (fi.isFile() && fi.isReadable()) {
openExternalFile(fi.absoluteFilePath());
}
}

void Texstudio::quickTabular(const QMimeData *d)
Expand Down
4 changes: 4 additions & 0 deletions src/texstudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "help.h"

#include <QProgressDialog>
#include <QFileSystemModel>

/*!
* \file texstudio.h
Expand Down Expand Up @@ -163,6 +164,8 @@ private slots:
QAction *m_toggleDocksAction;
SymbolListModel *symbolListModel;
SymbolWidget *symbolWidget;
QTreeView *fileView; ///< file explorer in docks
QFileSystemModel *fileExplorerModel = nullptr;
QString hiddenLeftPanelWidgets;
QMap<QString, QString> m_dockIcons;
QList<QDockWidget*> m_docksOrder;
Expand Down Expand Up @@ -435,6 +438,7 @@ protected slots:
void insertTextFromAction();
void insertFromTagList(QListWidgetItem *item);
void insertBib();
void openFromExplorer(const QModelIndex &index);
void closeEnvironment();

void insertBibEntryFromAction();
Expand Down

0 comments on commit 495a49a

Please sign in to comment.