Index: shell/mainwindow.h =================================================================== --- shell/mainwindow.h +++ shell/mainwindow.h @@ -94,7 +94,7 @@ void tabContextMenuRequested(Sublime::View* , QMenu* ) override; void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int tab) override; void dockBarContextMenuRequested(Qt::DockWidgetArea, const QPoint&) override; - void newTabRequested() override; + void newTabRequested(const QUrl& file) override; private Q_SLOTS: void updateCaption(); Index: shell/mainwindow.cpp =================================================================== --- shell/mainwindow.cpp +++ shell/mainwindow.cpp @@ -516,9 +516,12 @@ d->dockBarContextMenuRequested(area, position); } -void MainWindow::newTabRequested() +void MainWindow::newTabRequested(const QUrl& file = QUrl()) { - Sublime::MainWindow::newTabRequested(); + Sublime::MainWindow::newTabRequested(file); - d->fileNew(); + if (file.isEmpty()) + d->fileNew(); + else + d->fileOpen(file); } Index: shell/mainwindow_actions.cpp =================================================================== --- shell/mainwindow_actions.cpp +++ shell/mainwindow_actions.cpp @@ -189,6 +189,11 @@ Core::self()->documentControllerInternal()->openDocument(DocumentController::nextEmptyDocumentUrl()); } +void MainWindowPrivate::fileOpen(const QUrl& file) +{ + Core::self()->documentControllerInternal()->openDocument(file); +} + void MainWindowPrivate::viewAddNewToolView() { Core::self()->uiControllerInternal()->selectNewToolViewToAdd(m_mainWindow); Index: shell/mainwindow_p.h =================================================================== --- shell/mainwindow_p.h +++ shell/mainwindow_p.h @@ -85,6 +85,7 @@ //actions void fileNew(); + void fileOpen(const QUrl& fileName); void gotoNextWindow(); void gotoPreviousWindow(); Index: sublime/container.h =================================================================== --- sublime/container.h +++ sublime/container.h @@ -24,6 +24,7 @@ class QMenu; class QPaintEvent; +class QUrl; namespace Sublime { @@ -84,7 +85,7 @@ * space next to the tab bar. Typically, a new document should be * created. */ - void newTabRequested(); + void newTabRequested(const QUrl&); void tabContextMenuRequested(Sublime::View* view, QMenu* menu); /** * @p view The view represented by the tab that was hovered @@ -94,6 +95,9 @@ void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int idx); void tabDoubleClicked(Sublime::View* view); +public Q_SLOTS: + void reopenClosedFile(); + private Q_SLOTS: void widgetActivated(int idx); void documentTitleChanged(Sublime::Document* doc); @@ -108,6 +112,8 @@ private: Sublime::View* currentView() const; + void addToReopenQueue(QWidget* w); + struct ContainerPrivate * const d; }; Index: sublime/container.cpp =================================================================== --- sublime/container.cpp +++ sublime/container.cpp @@ -26,12 +26,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -120,7 +122,7 @@ } Q_SIGNALS: - void newTabRequested(); + void newTabRequested(const QUrl& file = QUrl()); private: Container* m_container; @@ -144,6 +146,7 @@ QToolButton* documentListButton; QMenu* documentListMenu; QHash documentListActionForView; + QQueue reopenFilesQueue; /** * Updates the context menu which is shown when @@ -356,6 +359,17 @@ emit requestClose(widget(idx)); } +void Container::addToReopenQueue(QWidget* w) +{ + if (auto view = viewForWidget(w)) { + auto urlDocument = qobject_cast(view->document()); + + if (urlDocument && !urlDocument->url().isEmpty()) { + d->reopenFilesQueue.enqueue(urlDocument->url()); + } + } +} + void Container::widgetActivated(int idx) { if (idx < 0) @@ -502,6 +516,9 @@ documentTitleChanged( view->document() ); } } + + addToReopenQueue(w); + View* view = d->viewForWidget.take(w); if (view) { @@ -608,6 +625,10 @@ } QAction* closeAllTabsAction = menu.addAction( QIcon::fromTheme(QStringLiteral("document-close")), i18n( "Close All Files" ) ); + menu.addSeparator(); + QAction* reopenClosedFileAction = menu.addAction( QIcon::fromTheme(QStringLiteral("document-open")), i18n( "Reopen Closed File" ) ); + reopenClosedFileAction->setEnabled(!d->reopenFilesQueue.isEmpty()); + QAction* triggered = menu.exec(senderWidget->mapToGlobal(pos)); if (triggered) { @@ -635,6 +656,8 @@ for ( int i = 0; i < count(); ++i ) { requestClose(widget(i)); } + } else if ( triggered == reopenClosedFileAction ) { + reopenClosedFile(); } else if( triggered == copyPathAction ) { auto view = viewForWidget( widget( currentTab ) ); auto urlDocument = qobject_cast( view->document() ); @@ -663,12 +686,20 @@ void Container::doubleClickTriggered(int tab) { if (tab == -1) { - emit newTabRequested(); + emit newTabRequested(QUrl()); } else { emit tabDoubleClicked(viewForWidget(widget(tab))); } } +void Container::reopenClosedFile() +{ + if (!d->reopenFilesQueue.isEmpty()) { + QUrl doc = d->reopenFilesQueue.dequeue(); + emit newTabRequested(doc); + } +} + void Container::documentListActionTriggered(QAction* action) { Sublime::View* view = action->data().value< Sublime::View* >(); Index: sublime/mainwindow.h =================================================================== --- sublime/mainwindow.h +++ sublime/mainwindow.h @@ -130,6 +130,8 @@ void viewAdded(Sublime::View*); /**Emitted when a view is going to be removed from the mainwindow.*/ void aboutToRemoveView(Sublime::View*); + /** Emitted when reopen closed file action is triggered.*/ + void reopenClosedFile(); protected: QWidget *statusBarLocation() const; @@ -138,7 +140,7 @@ virtual void tabDoubleClicked(Sublime::View* view); virtual void tabContextMenuRequested(Sublime::View*, QMenu*); virtual void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int tab); - virtual void newTabRequested(); + virtual void newTabRequested(const QUrl& file); /**Called whenever the user requests a context menu on a dockwidget bar. You can then e.g. add actions to add dockwidgets. Default implementation does nothing.**/ Index: sublime/mainwindow.cpp =================================================================== --- sublime/mainwindow.cpp +++ sublime/mainwindow.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -413,8 +414,9 @@ // do nothing } -void MainWindow::newTabRequested() +void MainWindow::newTabRequested(const QUrl& file = QUrl()) { + Q_UNUSED(file); } void MainWindow::dockBarContextMenuRequested(Qt::DockWidgetArea , const QPoint& ) Index: sublime/mainwindow_p.h =================================================================== --- sublime/mainwindow_p.h +++ sublime/mainwindow_p.h @@ -127,6 +127,7 @@ void focusEditor(); void selectNextDock(); void selectPreviousDock(); + void reopenClosedFile(); private: void restoreConcentrationMode(); Index: sublime/mainwindow_p.cpp =================================================================== --- sublime/mainwindow_p.cpp +++ sublime/mainwindow_p.cpp @@ -132,6 +132,12 @@ connect(action, &QAction::triggered, this, &MainWindowPrivate::selectPreviousDock); ac->addAction(QStringLiteral("select_previous_dock"), action); + action = new QAction(i18n("Reopen Closed File"), this); + ac->setDefaultShortcut(action, Qt::META | Qt::Key_T); + action->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); + connect(action, &QAction::triggered, this, &MainWindowPrivate::reopenClosedFile); + ac->addAction(QStringLiteral("reopen_closed_file"), action); + action = new KActionMenu(i18n("Tool Views"), this); ac->addAction(QStringLiteral("docks_submenu"), action); @@ -313,6 +319,11 @@ idealController->goPrevNextDock(IdealController::PrevDock); } +void MainWindowPrivate::reopenClosedFile() +{ + m_mainWindow->reopenClosedFile(); +} + Area::WalkerMode MainWindowPrivate::IdealToolViewCreator::operator() (View *view, Sublime::Position position) { if (!d->docks.contains(view)) @@ -388,6 +399,8 @@ d, &MainWindowPrivate::widgetCloseRequest, Qt::QueuedConnection); connect(container, &Container::newTabRequested, d->m_mainWindow, &MainWindow::newTabRequested); + connect(d->m_mainWindow, &MainWindow::reopenClosedFile, + container, &Container::reopenClosedFile); splitter->addWidget(container); } else