keep recent filenames from being absurdly long in the menu
This commit is contained in:
parent
7e6cf61b4c
commit
284a9b73b0
|
@ -1139,10 +1139,11 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||||
connect(actOpenROMArchive, &QAction::triggered, this, &MainWindow::onOpenFileArchive);
|
connect(actOpenROMArchive, &QAction::triggered, this, &MainWindow::onOpenFileArchive);
|
||||||
|
|
||||||
recentMenu = menu->addMenu("Open Recent");
|
recentMenu = menu->addMenu("Open Recent");
|
||||||
for(int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
if(strlen(Config::RecentROMList[i]) > 0)
|
char* item = Config::RecentROMList[i];
|
||||||
recentFileList.push_back(Config::RecentROMList[i]);
|
if (strlen(item) > 0)
|
||||||
|
recentFileList.push_back(item);
|
||||||
}
|
}
|
||||||
updateRecentFilesMenu();
|
updateRecentFilesMenu();
|
||||||
|
|
||||||
|
@ -1881,8 +1882,30 @@ void MainWindow::updateRecentFilesMenu()
|
||||||
|
|
||||||
for(int i = 0; i < recentFileList.size(); ++i)
|
for(int i = 0; i < recentFileList.size(); ++i)
|
||||||
{
|
{
|
||||||
QAction *actRecentFile_i = recentMenu->addAction(QString("%1. %2").arg(i+1).arg(recentFileList.at(i)));
|
QString item_full = recentFileList.at(i);
|
||||||
actRecentFile_i->setData(recentFileList.at(i));
|
QString item_display = item_full;
|
||||||
|
int itemlen = item_full.length();
|
||||||
|
const int maxlen = 100;
|
||||||
|
if (itemlen > maxlen)
|
||||||
|
{
|
||||||
|
int cut_start = 0;
|
||||||
|
while (item_full[cut_start] != '/' && item_full[cut_start] != '\\' &&
|
||||||
|
cut_start < itemlen)
|
||||||
|
cut_start++;
|
||||||
|
|
||||||
|
int cut_end = itemlen-1;
|
||||||
|
while (((item_full[cut_end] != '/' && item_full[cut_end] != '\\') ||
|
||||||
|
(cut_start+4+(itemlen-cut_end) < maxlen)) &&
|
||||||
|
cut_end > 0)
|
||||||
|
cut_end--;
|
||||||
|
|
||||||
|
item_display.truncate(cut_start+1);
|
||||||
|
item_display += "...";
|
||||||
|
item_display += item_full.remove(0, cut_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *actRecentFile_i = recentMenu->addAction(QString("%1. %2").arg(i+1).arg(item_display));
|
||||||
|
actRecentFile_i->setData(item_full);
|
||||||
connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile);
|
connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile);
|
||||||
|
|
||||||
if(i < 10)
|
if(i < 10)
|
||||||
|
|
Loading…
Reference in New Issue