Linux bookmarks move up and down
step
Read the bookmark file, divide it into QStringList, click the right-click menu to get the serial number, exchange the serial number, and write the bookmark file.
(int, int) is outdated, (int, int) is replaced.
Bookmark file path
const QString filepath_bookmark = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/gtk-3.0/bookmarks";
Move up
connect(action_bookmark_move_up, &QAction::triggered, [=](){ QTreeWidgetItem *TWI = ui->treeWidget_nav->currentItem(); int index = TWI_bookmark->indexOfChild(TWI); QFile file(filepath_bookmark); if ((QFile::ReadWrite)) { QTextStream TS(&file); QString s = (); QStringList SL = ("\n"); (index, index - 1); s = ""; for (int i=0; i<(); i++) { s += (i); if (i < () - 1) s += "\n"; } (0); TS << s; (); } });
Move down
- Change swap -1 to +1, the others are the same.
connect(action_bookmark_move_down, &QAction::triggered, [=](){ QTreeWidgetItem *TWI = ui->treeWidget_nav->currentItem(); int index = TWI_bookmark->indexOfChild(TWI); QFile file(filepath_bookmark); if ((QFile::ReadWrite)) { QTextStream TS(&file); QString s = (); QStringList SL = ("\n"); (index, index + 1); s = ""; for (int i=0; i<(); i++) { s += (i); if (i < () - 1) s += "\n"; } (0); TS << s; (); } });
Monitor bookmark file changes to update bookmark tree
QFileSystemWatcher is triggered only once
- Baidu AI answered:
- It can only be triggered once. If it needs to be triggered continuously, you need to add the path again after processing the trigger.
const QString filepath_bookmark = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/gtk-3.0/bookmarks"; QFileSystemWatcher *watcher = new QFileSystemWatcher; watcher->addPath(filepath_bookmark); connect(watcher, &QFileSystemWatcher::fileChanged, [=]{ genBookmark(); watcher->addPath(filepath_bookmark); });
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.