mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Add open recent functionality to main_window_viewer
This commit is contained in:
parent
f1eada4a94
commit
5fb88482fb
@ -223,7 +223,7 @@ void MainWindowViewer::createActions()
|
|||||||
{
|
{
|
||||||
recentFileAction = new QAction(this);
|
recentFileAction = new QAction(this);
|
||||||
recentFileAction->setVisible(false);
|
recentFileAction->setVisible(false);
|
||||||
//QObject::connect(recentFileAction, SIGNAL(triggered()), this, SLOT(openRecent()));
|
QObject::connect(recentFileAction, &QAction::triggered, this, &MainWindowViewer::openRecent);
|
||||||
recentFilesActionList.append(recentFileAction);
|
recentFilesActionList.append(recentFileAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,6 +513,7 @@ void MainWindowViewer::createToolBars()
|
|||||||
#else
|
#else
|
||||||
QMenu * recentmenu = new QMenu("Open recent");
|
QMenu * recentmenu = new QMenu("Open recent");
|
||||||
recentmenu->addActions(recentFilesActionList);
|
recentmenu->addActions(recentFilesActionList);
|
||||||
|
refreshRecentFilesActionList();
|
||||||
|
|
||||||
QToolButton * tb = new QToolButton();
|
QToolButton * tb = new QToolButton();
|
||||||
tb->addAction(openAction);
|
tb->addAction(openAction);
|
||||||
@ -660,6 +661,48 @@ void MainWindowViewer::createToolBars()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindowViewer::refreshRecentFilesActionList()
|
||||||
|
{
|
||||||
|
QStringList recentFilePaths = Configuration::getConfiguration().openRecentList();
|
||||||
|
|
||||||
|
//TODO: Replace "5" with something configurable
|
||||||
|
int iteration = (recentFilePaths.size() < 5) ? recentFilePaths.size() : 5;
|
||||||
|
|
||||||
|
for (int i = 0; i < iteration; i++)
|
||||||
|
{
|
||||||
|
QString strippedName = QFileInfo(recentFilePaths.at(i)).fileName();
|
||||||
|
recentFilesActionList.at(i)->setText(strippedName);
|
||||||
|
recentFilesActionList.at(i)->setData(recentFilePaths.at(i));
|
||||||
|
recentFilesActionList.at(i)->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = iteration; i < 5; i++)
|
||||||
|
{
|
||||||
|
recentFilesActionList.at(i)->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindowViewer::openRecent()
|
||||||
|
{
|
||||||
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
if (action)
|
||||||
|
{
|
||||||
|
QFileInfo info1 (action->data().toString());
|
||||||
|
if (info1.exists())
|
||||||
|
{
|
||||||
|
if (info1.isFile())
|
||||||
|
{
|
||||||
|
openComicFromPath(action->data().toString());
|
||||||
|
}
|
||||||
|
else if (info1.isDir())
|
||||||
|
{
|
||||||
|
openFolderFromPath(action->data().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindowViewer::reloadOptions()
|
void MainWindowViewer::reloadOptions()
|
||||||
{
|
{
|
||||||
viewer->updateConfig(settings);
|
viewer->updateConfig(settings);
|
||||||
@ -764,6 +807,8 @@ void MainWindowViewer::openComic(QString pathFile)
|
|||||||
enableActions();
|
enableActions();
|
||||||
|
|
||||||
viewer->open(pathFile);
|
viewer->open(pathFile);
|
||||||
|
Configuration::getConfiguration().updateOpenRecentList(pathFile);
|
||||||
|
refreshRecentFilesActionList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowViewer::openFolder()
|
void MainWindowViewer::openFolder()
|
||||||
@ -788,6 +833,8 @@ void MainWindowViewer::openFolderFromPath(QString pathDir)
|
|||||||
enableActions();
|
enableActions();
|
||||||
|
|
||||||
viewer->open(pathDir);
|
viewer->open(pathDir);
|
||||||
|
Configuration::getConfiguration().updateOpenRecentList(pathDir);
|
||||||
|
refreshRecentFilesActionList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowViewer::openFolderFromPath(QString pathDir, QString atFileName)
|
void MainWindowViewer::openFolderFromPath(QString pathDir, QString atFileName)
|
||||||
|
@ -34,6 +34,7 @@ class EditShortcutsDialog;
|
|||||||
void open(QString path, ComicDB & comic, QList<ComicDB> & siblings);
|
void open(QString path, ComicDB & comic, QList<ComicDB> & siblings);
|
||||||
void open(QString path, qint64 comicId, qint64 libraryId);
|
void open(QString path, qint64 comicId, qint64 libraryId);
|
||||||
void openFolder();
|
void openFolder();
|
||||||
|
void openRecent();
|
||||||
void saveImage();
|
void saveImage();
|
||||||
void toggleToolBars();
|
void toggleToolBars();
|
||||||
void hideToolBars();
|
void hideToolBars();
|
||||||
@ -146,6 +147,7 @@ class EditShortcutsDialog;
|
|||||||
void setupUI();
|
void setupUI();
|
||||||
void createActions();
|
void createActions();
|
||||||
void createToolBars();
|
void createToolBars();
|
||||||
|
void refreshRecentFilesActionList();
|
||||||
void getSiblingComics(QString path,QString currentComic);
|
void getSiblingComics(QString path,QString currentComic);
|
||||||
|
|
||||||
//! Manejadores de evento:
|
//! Manejadores de evento:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user