void Plugin::handleRemoveTab (QWidget *widget) { auto tab = qobject_cast<ITabWidget*> (widget); if (!tab) return; auto recTab = qobject_cast<IRecoverableTab*> (widget); if (!recTab) return; const auto& recoverData = recTab->GetTabRecoverData (); if (recoverData.isEmpty ()) return; TabUncloseInfo info { { recoverData, GetSessionProps (widget) }, qobject_cast<IHaveRecoverableTabs*> (tab->ParentMultiTabs ()) }; const auto rootWM = Proxy_->GetRootWindowsManager (); const auto winIdx = rootWM->GetWindowForTab (tab); const auto tabIdx = rootWM->GetTabWidget (winIdx)->IndexOf (widget); info.RecInfo_.DynProperties_.append ({ "TabSessManager/Position", tabIdx }); const auto pos = std::find_if (UncloseAct2Data_.begin (), UncloseAct2Data_.end (), [&info] (const TabUncloseInfo& that) { return that.RecInfo_.Data_ == info.RecInfo_.Data_; }); if (pos != UncloseAct2Data_.end ()) { auto act = pos.key (); UncloseMenu_->removeAction (act); UncloseAct2Data_.erase (pos); delete act; } const auto& fm = UncloseMenu_->fontMetrics (); const QString& elided = fm.elidedText (recTab->GetTabRecoverName (), Qt::ElideMiddle, 300); QAction *action = new QAction (recTab->GetTabRecoverIcon (), elided, this); UncloseAct2Data_ [action] = info; connect (action, SIGNAL (triggered ()), this, SLOT (handleUnclose ())); if (UncloseMenu_->defaultAction ()) UncloseMenu_->defaultAction ()->setShortcut (QKeySequence ()); UncloseMenu_->insertAction (UncloseMenu_->actions ().value (0), action); UncloseMenu_->setDefaultAction (action); action->setShortcut (QString ("Ctrl+Shift+T")); }
void Core::Unregister (BrowserWidget *widget) { widgets_t::iterator pos = std::find (Widgets_.begin (), Widgets_.end (), widget); if (pos == Widgets_.end ()) { qWarning () << Q_FUNC_INFO << widget << "not found in the collection"; return; } QString title = widget->GetView ()->title (); if (title.isEmpty ()) title = widget->GetView ()->url ().toString (); if (!title.isEmpty ()) { if (title.size () > 53) title = title.left (50) + "..."; QAction *action = new QAction (widget->GetView ()->icon (), title, this); QByteArray ba; QDataStream out (&ba, QIODevice::WriteOnly); out << *widget->GetView ()->page ()->history (); UncloseData ud = { widget->GetView ()->url (), widget->GetView ()->page ()->mainFrame ()->scrollPosition (), ba }; action->setData (QVariant::fromValue (ud)); connect (action, SIGNAL (triggered ()), this, SLOT (handleUnclose ())); emit newUnclose (action); Unclosers_.push_front (action); } Widgets_.erase (pos); saveSession (); }