Skip to content

Commit

Permalink
number items in dropdown menus
Browse files Browse the repository at this point in the history
  • Loading branch information
benapetr committed May 28, 2018
1 parent 13ca55c commit 07d1a95
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/huggle_core/huggleparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QString HuggleParser::GetSummaryOfWarningTypeFromWarningKey(QString key, Project
HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION);
foreach (QString line, project_conf->RevertSummaries)
if (line.startsWith(key + ";"))
return HuggleParser::GetValueFromKey(line);
return HuggleParser::GetValueFromSSItem(line);
if (!user_conf)
return project_conf->DefaultSummary;

Expand All @@ -72,7 +72,7 @@ QString HuggleParser::GetNameOfWarningTypeFromWarningKey(QString key, ProjectCon
// get a key
foreach (QString line, project_conf->WarningTypes)
if (line.startsWith(key + ";"))
return HuggleParser::GetValueFromKey(line);
return HuggleParser::GetValueFromSSItem(line);
return key;
}

Expand All @@ -83,7 +83,7 @@ QString HuggleParser::GetKeyOfWarningTypeFromWarningName(QString id, ProjectConf
{
if (line.endsWith(id) || line.endsWith(id + ","))
{
return HuggleParser::GetKeyFromValue(line);
return HuggleParser::GetKeyFromSSItem(line);
}
}
return id;
Expand Down Expand Up @@ -157,7 +157,7 @@ void HuggleParser::ParseWords(QString text, WikiSite *site)
site->ProjectConfig->ScoreWords = ParseScoreWords(text, "score-words");
}

QString HuggleParser::GetValueFromKey(QString item)
QString HuggleParser::GetValueFromSSItem(QString item)
{
HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION);
if (item.contains(";"))
Expand All @@ -172,7 +172,7 @@ QString HuggleParser::GetValueFromKey(QString item)
return item;
}

QString HuggleParser::GetKeyFromValue(QString item)
QString HuggleParser::GetKeyFromSSItem(QString item)
{
HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION);
if (item.contains(";"))
Expand Down Expand Up @@ -322,7 +322,7 @@ byte_ht HuggleParser::GetLevel(QString page, QDate bt, WikiSite *site)
{
foreach (QString df, site->ProjectConfig->WarningDefs)
{
if (HuggleParser::GetKeyFromValue(df).toInt() == level && page.contains(HuggleParser::GetValueFromKey(df)))
if (HuggleParser::GetKeyFromSSItem(df).toInt() == level && page.contains(HuggleParser::GetValueFromSSItem(df)))
{
return level;
}
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_core/huggleparser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ namespace Huggle
HUGGLE_EX_CORE void ParseNoTalkWords_yaml(YAML::Node &node, WikiSite *site);
HUGGLE_EX_CORE void ParseNoTalkPatterns_yaml(YAML::Node &node, WikiSite *site);
//! \todo This function needs a unit test
HUGGLE_EX_CORE QString GetValueFromKey(QString item);
HUGGLE_EX_CORE QString GetValueFromSSItem(QString item);
//! \todo This function needs a unit test
HUGGLE_EX_CORE QString GetKeyFromValue(QString item);
HUGGLE_EX_CORE QString GetKeyFromSSItem(QString item);
/*!
* \brief Process content of talk page in order to figure which user level they have
* \param page The content of talk page
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_core/projectconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ bool ProjectConfiguration::Parse(QString config, QString *reason, WikiSite *site
int CurrentTemplate=0;
while (CurrentTemplate<this->WarningTypes.count())
{
QString type = HuggleParser::GetKeyFromValue(this->WarningTypes.at(CurrentTemplate));
QString type = HuggleParser::GetKeyFromSSItem(this->WarningTypes.at(CurrentTemplate));
int CurrentWarning = 1;
while (CurrentWarning <= 4)
{
Expand Down Expand Up @@ -848,7 +848,7 @@ bool ProjectConfiguration::ParseYAML(QString yaml_src, QString *reason, WikiSite
int CurrentTemplate=0;
while (CurrentTemplate<this->WarningTypes.count())
{
QString type = HuggleParser::GetKeyFromValue(this->WarningTypes.at(CurrentTemplate));
QString type = HuggleParser::GetKeyFromSSItem(this->WarningTypes.at(CurrentTemplate));
int CurrentWarning = 1;
while (CurrentWarning <= 4)
{
Expand Down
2 changes: 2 additions & 0 deletions src/huggle_core/userconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ QString UserConfiguration::MakeLocalUserConfig(ProjectConfiguration *Project)
AppendConf(&configuration, "automatically-watchlist-warned-users", this->AutomaticallyWatchlistWarnedUsers);
AppendConf(&configuration, "shortcut-hash", this->ShortcutHash);
AppendConf(&configuration, "show-warning-if-not-on-last-revision", this->ShowWarningIfNotOnLastRevision);
AppendConf(&configuration, "number-dropdown-menu-items", this->NumberDropdownMenuItems);
// shortcuts
QStringList shortcuts = Configuration::HuggleConfiguration->Shortcuts.keys();
// we need to do this otherwise huggle may sort the items differently every time and spam wiki
Expand Down Expand Up @@ -598,6 +599,7 @@ bool UserConfiguration::ParseYAML(QString config, ProjectConfiguration *ProjectC
this->MinScore = YAML2LongLong("min-score", yaml, this->MinScore);
this->MaxScore = YAML2LongLong("max-score", yaml, this->MaxScore);
this->EnableMinScore = YAML2Bool("enable-min-score", yaml, this->EnableMinScore);
this->NumberDropdownMenuItems = YAML2Bool("number-dropdown-menu-items", yaml, this->NumberDropdownMenuItems);
this->AutomaticRefresh = YAML2Bool("automatic-refresh", yaml, this->AutomaticRefresh);
this->ShortcutHash = YAML2String("shortcut-hash", yaml, "null");
this->ShowWarningIfNotOnLastRevision = YAML2Bool("show-warning-if-not-on-last-revision", yaml, this->ShowWarningIfNotOnLastRevision);
Expand Down
1 change: 1 addition & 0 deletions src/huggle_core/userconfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace Huggle
//! it get automatically loaded instead of cached version
bool LastEdit = false;
bool SectionKeep = true;
bool NumberDropdownMenuItems = true;
unsigned int HistoryMax = 50;
bool TruncateEdits = false;
//! By default Huggle highlights "Missing summary", if this is set to true, it's highlighted instead when it's there
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_core/warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ QString Warnings::RetrieveTemplateToWarn(QString type, WikiSite *site, bool forc
QString result = "";
while (x < site->GetProjectConfig()->WarningTemplates.count())
{
if (HuggleParser::GetKeyFromValue(site->GetProjectConfig()->WarningTemplates.at(x)) == type)
if (HuggleParser::GetKeyFromSSItem(site->GetProjectConfig()->WarningTemplates.at(x)) == type)
{
result = HuggleParser::GetValueFromKey(site->GetProjectConfig()->WarningTemplates.at(x));
result = HuggleParser::GetValueFromSSItem(site->GetProjectConfig()->WarningTemplates.at(x));
if (force)
result += "im";
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_ui/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void History::Tick()
this->Fail();
return;
}
QString message = HuggleParser::GetValueFromKey(edit->GetSite()->ProjectConfig->WelcomeTypes.at(0));
QString message = HuggleParser::GetValueFromSSItem(edit->GetSite()->ProjectConfig->WelcomeTypes.at(0));
if (!message.size())
{
// This error should never happen so we don't need to localize this
Expand Down
44 changes: 29 additions & 15 deletions src/huggle_ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
this->PauseQueue();
}
HUGGLE_PROFILER_PRINT_TIME("MainWindow::MainWindow(QWidget *parent)@providers");
this->reloadInterface();
this->ReloadInterface();
this->tabifyDockWidget(this->SystemLog, this->Queries);
this->generalTimer = new QTimer(this);
//this->ui->actionTag_2->setVisible(false);
Expand Down Expand Up @@ -570,7 +570,7 @@ void MainWindow::Render(bool KeepHistory, bool KeepUser)
this->changeCurrentBrowserTabTitle(this->CurrentEdit->Page->PageName);
if (this->previousSite != this->GetCurrentWikiSite())
{
this->reloadInterface();
this->ReloadInterface();
this->previousSite = this->GetCurrentWikiSite();
}
this->tb->SetTitle(this->CurrentEdit->Page->PageName);
Expand Down Expand Up @@ -1339,7 +1339,7 @@ void MainWindow::triggerWelcome()
if (!conf->Welcome.isEmpty())
message = conf->Welcome;
else
message = HuggleParser::GetValueFromKey(conf->WelcomeTypes.at(0));
message = HuggleParser::GetValueFromSSItem(conf->WelcomeTypes.at(0));
message += " ~~~~";
}
this->welcomeCurrentUser(message);
Expand Down Expand Up @@ -1776,7 +1776,7 @@ void MainWindow::CustomWelcome()
if (!this->EditingChecks())
return;
QAction *welcome = (QAction*) QObject::sender();
this->welcomeCurrentUser(HuggleParser::GetValueFromKey(welcome->data().toString()));
this->welcomeCurrentUser(HuggleParser::GetValueFromSSItem(welcome->data().toString()));
}

void MainWindow::CustomRevert()
Expand All @@ -1788,7 +1788,9 @@ void MainWindow::CustomRevert()
QAction *revert = (QAction*) QObject::sender();
ProjectConfiguration *conf = this->GetCurrentWikiSite()->GetProjectConfig();
UserConfiguration *ucf = this->GetCurrentWikiSite()->GetUserConfig();
QString key = HuggleParser::GetKeyOfWarningTypeFromWarningName(revert->text(), conf);
if (!this->actionKeys.contains(revert))
throw new Huggle::Exception("QAction was not found in this->actionKeys", BOOST_CURRENT_FUNCTION);
QString key = this->actionKeys[revert];
QString summary = HuggleParser::GetSummaryOfWarningTypeFromWarningKey(key, conf, ucf);
summary = Huggle::Configuration::GenerateSuffix(summary, conf);
this->Revert(summary);
Expand All @@ -1803,7 +1805,9 @@ void MainWindow::CustomRevertWarn()
QAction *revert = (QAction*) QObject::sender();
ProjectConfiguration *conf = this->GetCurrentWikiSite()->GetProjectConfig();
UserConfiguration *uconf = this->GetCurrentWikiSite()->GetUserConfig();
QString key = HuggleParser::GetKeyOfWarningTypeFromWarningName(revert->text(), conf);
if (!this->actionKeys.contains(revert))
throw new Huggle::Exception("QAction was not found in this->actionKeys", BOOST_CURRENT_FUNCTION);
QString key = this->actionKeys[revert];
QString summary = HuggleParser::GetSummaryOfWarningTypeFromWarningKey(key, conf, uconf);
summary = Huggle::Configuration::GenerateSuffix(summary, conf);
Collectable_SmartPtr<RevertQuery> result = this->Revert(summary, false);
Expand All @@ -1823,10 +1827,11 @@ void MainWindow::CustomWarn()
return;
if (!this->EditingChecks())
return;
ProjectConfiguration *conf = this->GetCurrentWikiSite()->GetProjectConfig();
QAction *revert = (QAction*) QObject::sender();
QString k = HuggleParser::GetKeyOfWarningTypeFromWarningName(revert->text(), conf);
this->Warn(k, nullptr, this->CurrentEdit);
if (!this->actionKeys.contains(revert))
throw new Huggle::Exception("QAction was not found in this->actionKeys", BOOST_CURRENT_FUNCTION);
QString key = this->actionKeys[revert];
this->Warn(key, nullptr, this->CurrentEdit);
}

void MainWindow::EnableDev()
Expand Down Expand Up @@ -2462,13 +2467,14 @@ void MainWindow::ChangeProvider(WikiSite *site, int id)
}
}

void MainWindow::reloadInterface()
void MainWindow::ReloadInterface()
{
HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION);
ProjectConfiguration *conf = this->GetCurrentWikiSite()->GetProjectConfig();
this->warnItems.clear();
this->revertAndWarnItems.clear();
this->revertItems.clear();
this->actionKeys.clear();
delete this->RevertSummaries;
delete this->WarnMenu;
delete this->RevertWarn;
Expand All @@ -2481,9 +2487,17 @@ void MainWindow::reloadInterface()
int r=0;
while (r< conf->WarningTypes.count())
{
QAction *action = new QAction(HuggleParser::GetValueFromKey(conf->WarningTypes.at(r)), this->RevertSummaries);
QAction *actiona = new QAction(HuggleParser::GetValueFromKey(conf->WarningTypes.at(r)), this->RevertWarn);
QAction *actionb = new QAction(HuggleParser::GetValueFromKey(conf->WarningTypes.at(r)), this->WarnMenu);
QString prefix = QString::number(r) + ": ";
if (!hcfg->UserConfig->NumberDropdownMenuItems)
prefix = "";
QString name = HuggleParser::GetValueFromSSItem(conf->WarningTypes.at(r));
QString key = HuggleParser::GetKeyFromSSItem(conf->WarningTypes.at(r));
QAction *action = new QAction(prefix + name, this->RevertSummaries);
QAction *actiona = new QAction(prefix + name, this->RevertWarn);
QAction *actionb = new QAction(prefix + name, this->WarnMenu);
this->actionKeys.insert(action, key);
this->actionKeys.insert(actiona, key);
this->actionKeys.insert(actionb, key);
this->revertAndWarnItems.append(actiona);
this->warnItems.append(actionb);
this->revertItems.append(action);
Expand All @@ -2505,7 +2519,7 @@ void MainWindow::reloadInterface()
int r = 0;
while (r < conf->WelcomeTypes.count())
{
QAction *action = new QAction(HuggleParser::GetKeyFromValue(conf->WelcomeTypes.at(r)), this->WelcomeMenu);
QAction *action = new QAction(HuggleParser::GetKeyFromSSItem(conf->WelcomeTypes.at(r)), this->WelcomeMenu);
QVariant qv(conf->WelcomeTypes.at(r));
action->setData(qv);
this->WelcomeMenu->addAction(action);
Expand Down Expand Up @@ -3178,7 +3192,7 @@ void MainWindow::on_actionTag_2_triggered()

void MainWindow::on_actionReload_menus_triggered()
{
this->reloadInterface();
this->ReloadInterface();
}

void MainWindow::SetProviderIRC()
Expand Down
3 changes: 2 additions & 1 deletion src/huggle_ui/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ namespace Huggle
void UpdateStatusBarData();
//! Perform all common tests that are needed before a page can be edited and return false if they fail
bool EditingChecks();
void ReloadInterface();
void DecreaseBS();
void IncreaseBS();
void GoForward();
Expand Down Expand Up @@ -410,7 +411,6 @@ namespace Huggle
bool preflightCheck(WikiEdit *_e);
//! Welcome user
void welcomeCurrentUser(QString message);
void reloadInterface();
void RevertAgf(bool only);
//! This function is called by main thread and is used to remove edits that were already reverted
void TruncateReverts();
Expand Down Expand Up @@ -447,6 +447,7 @@ namespace Huggle
WaitingForm *fWaiting = nullptr;
RequestProtect *fRFProtection = nullptr;
QHash<QAction*, WikiSite*> ActionSites;
QHash<QAction*, QString> actionKeys;
QHash<WikiSite*, QAction*> lXml;
QHash<WikiSite*, QAction*> lIRC;
QHash<WikiSite*, QAction*> lWikis;
Expand Down
3 changes: 3 additions & 0 deletions src/huggle_ui/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void Huggle::Preferences::on_pushButton_2_clicked()
hcfg->UserConfig->EnableMinScore = this->ui->cbMinScore->isChecked();
hcfg->UserConfig->MinScore = this->ui->leMinScore->text().toLongLong();
hcfg->UserConfig->MaxScore = this->ui->leMaxScore->text().toLongLong();
hcfg->UserConfig->NumberDropdownMenuItems = this->ui->cbNumberMenus->isChecked();
hcfg->UserConfig->EnableMaxScore = this->ui->cbMaxScore->isChecked();
hcfg->SystemConfig_QueueSize = this->ui->le_QueueSize->text().toInt();
hcfg->UserConfig->AutomaticallyWatchlistWarnedUsers = this->ui->cb_WatchWarn->isChecked();
Expand Down Expand Up @@ -377,6 +378,7 @@ void Huggle::Preferences::on_pushButton_2_clicked()
hcfg->ReloadOfMainformNeeded = true;
}
Configuration::SaveSystemConfig();
MainWindow::HuggleMain->ReloadInterface();
this->hide();
}

Expand Down Expand Up @@ -797,6 +799,7 @@ void Preferences::ResetItems()
this->ui->cb_WatchWarn->setChecked(hcfg->UserConfig->AutomaticallyWatchlistWarnedUsers);
this->ui->le_KeystrokeRate->setText(QString::number(hcfg->SystemConfig_KeystrokeMultiPressRate));
this->ui->checkBox_7->setChecked(hcfg->UserConfig->HighlightSummaryIfExists);
this->ui->cbNumberMenus->setChecked(hcfg->UserConfig->NumberDropdownMenuItems);
this->ui->checkBox_unsafe->setChecked(hcfg->SystemConfig_UnsafeExts);
this->ui->cbKeystrokeFix->setChecked(hcfg->SystemConfig_KeystrokeMultiPressFix);

Expand Down
7 changes: 7 additions & 0 deletions src/huggle_ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbNumberMenus">
<property name="text">
<string>Number items in dropdown menus</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbShowWarningIfNotOnLastRevision">
<property name="text">
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_ui/warninglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ WarningList::WarningList(WikiEdit *edit, QWidget *parent) : QDialog(parent), ui(
int r=0;
while (r<Configuration::HuggleConfiguration->ProjectConfig->WarningTypes.count())
{
this->ui->comboBox->addItem(HuggleParser::GetValueFromKey(Configuration::HuggleConfiguration->ProjectConfig->WarningTypes.at(r)));
this->ui->comboBox->addItem(HuggleParser::GetValueFromSSItem(Configuration::HuggleConfiguration->ProjectConfig->WarningTypes.at(r)));
r++;
}
this->ui->comboBox->setCurrentIndex(0);
Expand Down

0 comments on commit 07d1a95

Please sign in to comment.