Skip to content

Commit d2a5c56

Browse files
Copy tab full path to a clipboard command. Startup action (load last project or empty environment).
1 parent b1b9e34 commit d2a5c56

6 files changed

Lines changed: 56 additions & 13 deletions

File tree

src/Application.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ Application::Application(int& argc, char** argv)
5555
splash->finish(_mainWindow);
5656
delete splash;
5757
}
58+
59+
// Perform a startup action
60+
const auto action = _settings->getEntryValue("global/app/startup_action").toInt();
61+
switch (action)
62+
{
63+
case 1: _mainWindow->openMostRecentProject(); break;
64+
default: break; // 0: empty environment
65+
}
5866
}
5967

6068
Application::~Application()
@@ -154,17 +162,26 @@ void Application::createSettingsEntries()
154162
// General settings
155163

156164
auto catGlobal = _settings->createCategory("global", "Global");
157-
auto secUndoRedo = catGlobal->createSection("undo", "Undo and Redo");
165+
auto secApp = catGlobal->createSection("app", "Application");
166+
167+
SettingsEntryPtr entry(new SettingsEntry(*secApp, "startup_action", 1, "On startup, load",
168+
"What to show when an application started",
169+
"combobox", false, 1, { {0, "Empty environment"}, {1, "Most recent project"} }));
170+
secApp->addEntry(std::move(entry));
158171

159172
// By default we limit the undo stack to 500 undo commands, should be enough and should
160-
// avoid memory drainage. keep in mind that every tabbed editor has it's own undo stack,
173+
// avoid memory drainage. Keep in mind that every tabbed editor has it's own undo stack,
161174
// so the overall command limit is number_of_tabs * 500!
162-
SettingsEntryPtr entry(new SettingsEntry(*secUndoRedo, "limit", 500, "Limit (number of steps)",
163-
"Puts a limit on every tabbed editor's undo stack. You can undo at most the number of times specified here.",
164-
"int", true, 1));
165-
secUndoRedo->addEntry(std::move(entry));
175+
entry.reset(new SettingsEntry(*secApp, "undo_limit", 500, "Undo history size",
176+
"Puts a limit on every tabbed editor's undo stack. You can undo at most the number of times specified here.",
177+
"int", true, 1));
178+
secApp->addEntry(std::move(entry));
179+
180+
entry.reset(new SettingsEntry(*secApp, "copy_path_os_separators", true, "Copy path with OS-specific separators",
181+
"When copy a file path to clipboard, will convert forward slashes (/) to OS-specific separators",
182+
"checkbox", false, 1));
183+
secApp->addEntry(std::move(entry));
166184

167-
auto secApp = catGlobal->createSection("app", "Application");
168185
entry.reset(new SettingsEntry(*secApp, "show_splash", true, "Show splash screen",
169186
"Show the splash screen on startup",
170187
"checkbox", false, 1));

src/editors/EditorBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ EditorBase::EditorBase(/*compatibilityManager, */ const QString& filePath, bool
2828
auto&& settings = qobject_cast<Application*>(qApp)->getSettings();
2929

3030
undoStack = new QUndoStack(this);
31-
undoStack->setUndoLimit(settings->getEntryValue("global/undo/limit").toInt());
31+
undoStack->setUndoLimit(settings->getEntryValue("global/app/undo_limit").toInt());
3232
undoStack->setClean();
3333

3434
connect(undoStack, &QUndoStack::canUndoChanged, [this](bool available)

src/editors/layout/LayoutVisualMode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,9 @@ void LayoutVisualMode::takeScreenshot()
552552
const auto action = settings->getEntryValue("cegui/screenshots/after_save_action").toInt();
553553
switch (action)
554554
{
555-
// TODO: https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
556-
case 0: QDesktopServices::openUrl(QUrl::fromLocalFile(dir.path())); break;
555+
case 0: Utils::showInGraphicalShell(filePath); break;
557556
case 1: QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); break;
558-
default: break;
557+
default: break; // 2: do nothing
559558
}
560559
}
561560
}

src/ui/MainWindow.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "src/ui/FileSystemBrowser.h"
3535
#include "src/ui/UndoViewer.h"
3636
#include "QtnProperty/PropertyWidget.h"
37+
#include <qclipboard.h>
3738

3839
// FIXME QTBUG: Qt 5.13.0 text rendering in OpenGL breaks on QOpenGLWidget delete
3940
#include <qopenglwidget.h>
@@ -604,6 +605,7 @@ void MainWindow::slot_tabBarCustomContextMenuRequested(const QPoint& pos)
604605
menu->addAction(ui->actionCloseOtherTabs);
605606
menu->addAction(ui->actionCloseAllTabs);
606607
menu->addSeparator();
608+
menu->addAction(ui->actionTabCopyFullPath);
607609
menu->addAction(ui->actionOpenContainingFolder);
608610

609611
/*
@@ -662,6 +664,7 @@ void MainWindow::on_tabs_currentChanged(int index)
662664
ui->actionSaveAs->setEnabled(hasEditor);
663665
ui->actionCloseTab->setEnabled(hasEditor);
664666
ui->actionCloseOtherTabs->setEnabled(hasEditor);
667+
ui->actionTabCopyFullPath->setEnabled(hasEditor);
665668
ui->actionOpenContainingFolder->setEnabled(hasEditor);
666669

667670
if (currentEditor)
@@ -770,6 +773,18 @@ void MainWindow::on_actionCloseAllTabs_triggered()
770773
}
771774
}
772775

776+
void MainWindow::on_actionTabCopyFullPath_triggered()
777+
{
778+
if (auto editor = getEditorForTab(ui->tabs->currentWidget()))
779+
{
780+
auto path = editor->getFilePath();
781+
auto&& settings = qobject_cast<Application*>(qApp)->getSettings();
782+
if (settings->getEntryValue("global/app/copy_path_os_separators").toBool())
783+
path = QDir::toNativeSeparators(path);
784+
QApplication::clipboard()->setText(path);
785+
}
786+
}
787+
773788
void MainWindow::on_actionOpenContainingFolder_triggered()
774789
{
775790
if (auto editor = getEditorForTab(ui->tabs->currentWidget()))
@@ -988,6 +1003,14 @@ void MainWindow::on_actionOpenFile_triggered()
9881003
openEditorTab(fileName);
9891004
}
9901005

1006+
void MainWindow::openMostRecentProject()
1007+
{
1008+
QStringList items;
1009+
recentlyUsedProjects->getRecentlyUsed(items);
1010+
if (!items.empty() && QFileInfo(items[0]).exists() && confirmProjectClosing(false))
1011+
loadProject(items[0]);
1012+
}
1013+
9911014
void MainWindow::openRecentProject(const QString& path)
9921015
{
9931016
if (QFileInfo(path).exists())

src/ui/MainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class MainWindow : public QMainWindow
3535
QToolBar* createToolbar(const QString& name);
3636
QToolBar* getToolbar(const QString& name) const;
3737

38+
void openMostRecentProject();
39+
3840
// Common actions
3941
QAction* getActionCut() const;
4042
QAction* getActionCopy() const;
@@ -83,6 +85,7 @@ private slots:
8385
void on_actionCloseTab_triggered();
8486
void on_actionCloseOtherTabs_triggered();
8587
void on_actionCloseAllTabs_triggered();
88+
void on_actionTabCopyFullPath_triggered();
8689
void on_actionOpenContainingFolder_triggered();
8790
void on_actionPreviousTab_triggered();
8891
void on_actionNextTab_triggered();

ui/MainWindow.ui

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@
200200
<addaction name="separator"/>
201201
<addaction name="actionCloseOtherTabs"/>
202202
<addaction name="actionCloseAllTabs"/>
203-
<addaction name="separator"/>
204-
<addaction name="actionOpenContainingFolder"/>
205203
</widget>
206204
<widget class="QMenu" name="menuEditor">
207205
<property name="enabled">
@@ -721,6 +719,9 @@
721719
</property>
722720
</action>
723721
<action name="actionTabCopyFullPath">
722+
<property name="enabled">
723+
<bool>false</bool>
724+
</property>
724725
<property name="text">
725726
<string>Copy Full Path</string>
726727
</property>

0 commit comments

Comments
 (0)