Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Submit): Improve and add action menu #681

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0eda5d4
feat(Submit/CF Tool): Improve and add action menu
coder3101 Nov 20, 2020
7c80784
add changelog and update Translation
coder3101 Nov 20, 2020
0cc02fb
Apply suggestions from code review
coder3101 Nov 21, 2020
8e38276
Merge branch 'master' into submit-in-action-menu
coder3101 Nov 21, 2020
cbade8b
update translations
coder3101 Nov 21, 2020
3787b5e
Rephrase the CHANGELOG
coder3101 Nov 21, 2020
79c7afb
Update CHANGELOG.md
coder3101 Nov 21, 2020
d1f9cfe
Fix problem code 0 for cf tool 1.0 or above
coder3101 Nov 21, 2020
31267c7
Revert changed problem code warning message.
coder3101 Nov 21, 2020
ebdc4c4
Update translations
coder3101 Nov 21, 2020
21f3181
Submit button is set visible or hidden depening on URL
coder3101 Nov 21, 2020
51ca45d
Improve some code
coder3101 Nov 21, 2020
12c66d4
style: Format codes (#684)
github-actions[bot] Nov 21, 2020
9568bfb
Format code in settings.json
coder3101 Nov 21, 2020
23266e3
Apply code review suggestion
coder3101 Nov 21, 2020
b9bf10b
Merge branch 'master' into submit-in-action-menu
coder3101 Nov 22, 2020
e52f228
Use lambda for connecting signals
coder3101 Nov 22, 2020
7e9c2c3
Update ru_RU.ts
IZOBRETATEL777 Nov 22, 2020
f28103e
Merge branch 'master' into submit-in-action-menu
ouuan Nov 29, 2020
5cfb3ab
Update translations and text
ouuan Nov 29, 2020
98aeaa5
Merge branch 'master' into submit-in-action-menu
coder3101 Dec 6, 2020
8467f2c
Merge branch 'master' into submit-in-action-menu
coder3101 Dec 9, 2020
2171e34
add Russian translations
IZOBRETATEL777 Dec 11, 2020
6bf4f87
Merge branch 'master' into submit-in-action-menu
coder3101 Jan 30, 2021
2460f39
update translations
coder3101 Jan 30, 2021
2a88b5d
CFtool: Improve logic and refactor
coder3101 Feb 6, 2021
cae1d5f
style: format codes (#758)
github-actions[bot] Feb 6, 2021
b0958f6
Update translations
coder3101 Feb 6, 2021
2295e82
Merge branch 'master' into submit-in-action-menu
coder3101 Feb 6, 2021
3aa259e
Update CHANGELOG
coder3101 Feb 6, 2021
c58f627
Update CHANGELOG.md
coder3101 Feb 6, 2021
eb7db91
Merge branch 'master' into submit-in-action-menu
coder3101 Feb 10, 2021
ab4ddf3
Move cfParseUrl to utils. Fix missing toast problem code/id
coder3101 Feb 10, 2021
4f0291b
update translations
coder3101 Feb 10, 2021
0e1dcac
Format code
coder3101 Feb 10, 2021
e4e01b5
Apply suggestions from code review
coder3101 Feb 10, 2021
1ebc700
Merge branch 'master' into submit-in-action-menu
coder3101 Feb 13, 2021
869a438
Merge branch 'master' into submit-in-action-menu
coder3101 Mar 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
- Format python codes by YAPF. (#652)
- Now you can open the corresponding preferences page via a link when asked to check the setting in the message logger. (#659)
- Now you can toggle fullscreen mode by pressing F11 or clicking View->Full Screen. (#642, #660 and #670)
- Now you can set shortcut for submitting solution. (#201 and #681)

### Fixed

- Fixed an issue that in some rare cases CP Editor could not get full data from Competitive Companion. (#345 and #624)
- Fixed an issue that in some rare cases CP Editor could not get full data from Competitive Companion. (#345 and #624)

### Changed

Expand All @@ -19,6 +20,7 @@
### Improved

- Now unfinished checks will be cancelled at the new execution. (#635)
- If you use CF tool 1.0 or above, it will never fail to parse URL for submission. (#681)
coder3101 marked this conversation as resolved.
Show resolved Hide resolved

## v6.7

Expand Down
82 changes: 47 additions & 35 deletions src/Extensions/CFTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,52 +57,64 @@ void CFTool::submit(const QString &filePath, const QString &url)

LOG_INFO(INFO_OF(filePath) << INFO_OF(url));

if (parseCfUrl(url, problemContestId, problemCode))
auto version = getCFToolVersion();
if (version.isEmpty())
{
if (problemCode == "0")
{
problemCode = "A";
log->warn(tr("CF Tool"),
tr("The problem code is 0, now use A automatically. If the actual problem code is not A, "
"please set the problem code manually in the right-click menu of the current tab."));
}
lastStatus = "Unknown"; // No tr here. We don't know what we'll get from network. Maybe a array for mapping.
CFToolProcess = new QProcess();
CFToolProcess->setProgram(CFToolPath);
auto version = getCFToolVersion();
if (version.isEmpty())
{
log->error(
tr("CF Tool"),
tr("Failed to get the version of CF Tool. Have you set the correct path to CF Tool in Preferences?"));
return;
}
if (version.split('.')[0] == "0")
CFToolProcess->setArguments({"submit", problemContestId, problemCode, filePath});
else
CFToolProcess->setArguments({"submit", "-f", filePath, url});

LOG_INFO(INFO_OF(CFToolProcess->arguments().join(' ')));
log->error(
tr("CF Tool"),
tr("Failed to get the version of CF Tool. Have you set the correct path to CF Tool in Preferences?"));
return;
}

lastStatus = "Unknown"; // No tr here. We don't know what we'll get from network. Maybe a array for mapping.
CFToolProcess = new QProcess();
CFToolProcess->setProgram(CFToolPath);

connect(CFToolProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadReady()));
connect(CFToolProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int)));
CFToolProcess->start();
bool started = CFToolProcess->waitForStarted(2000);
if (started)
if (version.split('.')[0] == "0")
{
log->warn(tr("CF Tool"),
tr("You are using CF Tool %1. Please update to CF tools 1.0 or above.").append(version));
if (parseCfUrl(url, problemContestId, problemCode))
{
log->info(tr("CF Tool"), tr("CF Tool has started"));

if (problemCode == "0")
{
problemCode = "A";
log->warn(tr("CF Tool"),
tr("The problem code is 0, now use A automatically. If the actual problem code is not A, "
"please set the problem code manually in the right-click menu of the current tab."));
}

CFToolProcess->setArguments({"submit", problemContestId, problemCode, filePath});
}
else
{
CFToolProcess->kill();
log->error(
tr("CF Tool"),
tr("Failed to start CF Tool in 2 seconds. Have you set the correct path to CF Tool in Preferences?"));
log->error(tr("CF Tool"), tr("Failed to parse the URL [%1]").arg(url));
return;
}
}
else
{
log->error(tr("CF Tool"), tr("Failed to parse the URL [%1]").arg(url));
CFToolProcess->setArguments({"submit", "-f", filePath, url});
}

LOG_INFO(INFO_OF(CFToolProcess->arguments().join(' ')));

connect(CFToolProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadReady()));
connect(CFToolProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int)));
CFToolProcess->start();
bool started = CFToolProcess->waitForStarted(2000);
if (started)
{
log->info(tr("CF Tool"), tr("CF Tool has started"));
}
else
{
CFToolProcess->kill();
log->error(
tr("CF Tool"),
tr("Failed to start CF Tool in 2 seconds. Have you set the correct path to CF Tool in Preferences?"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Settings/PreferencesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QMainWindow(parent)
.page(TRKEY("Default Paths"), DefaultPathManager::actionSettingsList() << "Default Path/Names And Paths")
.end()
.page(TRKEY("Key Bindings"), {"Hotkey/Compile", "Hotkey/Run", "Hotkey/Compile Run", "Hotkey/Format", "Hotkey/Kill",
"Hotkey/Change View Mode", "Hotkey/Snippets"})
"Hotkey/Change View Mode", "Hotkey/Snippets", "Hotkey/Submit"})
.dir(TRKEY("Advanced"))
.page(TRKEY("Update"), {"Check Update", "Beta"})
.page(TRKEY("Limits"), {"Default Time Limit", "Output Length Limit", "Output Display Length Limit", "Message Length Limit",
Expand Down
8 changes: 7 additions & 1 deletion src/Settings/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,12 @@
"old": [
"hotkey_snippets"
]
},
{
"name": "Hotkey/Submit",
"desc": "Submit Solution",
"type": "QString",
"ui": "ShortcutItem"
},
{
"name": "Hot Exit/Enable",
Expand Down Expand Up @@ -1224,4 +1230,4 @@
"immediatelyApply": true,
"tip": "Show only monospaced fonts when choosing a font"
}
]
]
13 changes: 13 additions & 0 deletions src/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ void AppWindow::maybeSetHotkeys()
hotkeyObjects.push_back(
new QShortcut(SettingsHelper::getHotkeySnippets(), this, SLOT(on_actionUseSnippets_triggered())));
}
if (!SettingsHelper::getHotkeySubmit().isEmpty())
{
hotkeyObjects.push_back(
new QShortcut(SettingsHelper::getHotkeySubmit(), this, SLOT(on_actionSubmit_triggered())));
}

hotkeyObjects.push_back(new QShortcut(Qt::Key_Escape, this, [this] { ui->actionFullScreen->setChecked(false); }));
}
Expand Down Expand Up @@ -894,6 +899,8 @@ void AppWindow::onTabChanged(int index)
connect(tmp->getSplitter(), SIGNAL(splitterMoved(int, int)), this, SLOT(onSplitterMoved(int, int)));
activeRightSplitterMoveConnection =
connect(tmp->getRightSplitter(), SIGNAL(splitterMoved(int, int)), this, SLOT(onRightSplitterMoved(int, int)));

ui->actionSubmit->setEnabled(tmp->canSubmitSolution());
}

void AppWindow::onEditorFileChanged()
Expand Down Expand Up @@ -1550,3 +1557,9 @@ void AppWindow::onCompileOrRunTriggered()
if (ui->actionEditorMode->isChecked())
on_actionSplitMode_triggered();
}

void AppWindow::on_actionSubmit_triggered()
{
if (currentWindow())
currentWindow()->submitSolution();
}
2 changes: 2 additions & 0 deletions src/appwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class AppWindow : public QMainWindow

void onViewModeToggle();

void on_actionSubmit_triggered();

private:
Ui::AppWindow *ui;
MessageLogger *activeLogger = nullptr;
Expand Down
12 changes: 12 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,18 @@ void MainWindow::compileAndRun()
compile();
}

void MainWindow::submitSolution()
{
LOG_INFO("Requesting submit solution");
if (submitToCodeforces)
coder3101 marked this conversation as resolved.
Show resolved Hide resolved
submitToCodeforces->click();
}

bool MainWindow::canSubmitSolution() const
{
return submitToCodeforces != nullptr;
}

void MainWindow::formatSource(bool selectionOnly, bool logOnNoChange)
{
LOG_INFO("Requested code format");
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MainWindow : public QMainWindow
void compileOnly();
void runOnly();
void compileAndRun();
void submitSolution();
bool canSubmitSolution() const;
void formatSource(bool selectionOnly, bool logOnNoChange);

void applyCompanion(const Extensions::CompanionData &data);
Expand Down
16 changes: 16 additions & 0 deletions translations/ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ Git commit hash: %3
<source>Full Screen</source>
<translation>Полный экран</translation>
</message>
<message>
<source>Submit</source>
<translation type="unfinished">Отправить</translation>
</message>
<message>
<source>Ctrl+Alt+S</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CodeSnippetsPage</name>
Expand Down Expand Up @@ -737,6 +745,10 @@ Press any key to exit</source>
<source>Contest %1 Problem %2</source>
<translation>Соревнование %1 Задача %2</translation>
</message>
<message>
<source>You are using CF Tool %1. Please update to CF tools 1.0 or above.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Extensions::CodeFormatter</name>
Expand Down Expand Up @@ -2581,6 +2593,10 @@ You can learn about it by running `yapf --style-help`.</source>
<source>Format the code when auto-saving it.</source>
<translation>Форматировать код, когда он автоматически сохраняется.</translation>
</message>
<message>
<source>Submit Solution</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ShortcutItem</name>
Expand Down
16 changes: 16 additions & 0 deletions translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ git 提交编号: %3
<source>Full Screen</source>
<translation>全屏</translation>
</message>
<message>
<source>Submit</source>
<translation type="unfinished">提交</translation>
</message>
<message>
<source>Ctrl+Alt+S</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CodeSnippetsPage</name>
Expand Down Expand Up @@ -737,6 +745,10 @@ Press any key to exit</source>
<source>Contest %1 Problem %2</source>
<translation>比赛 %1 题目 %2</translation>
</message>
<message>
<source>You are using CF Tool %1. Please update to CF tools 1.0 or above.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Extensions::CodeFormatter</name>
Expand Down Expand Up @@ -2573,6 +2585,10 @@ You can learn about it by running `yapf --style-help`.</source>
<source>Format the code when auto-saving it.</source>
<translation>自动保存时格式化代码。</translation>
</message>
<message>
<source>Submit Solution</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ShortcutItem</name>
Expand Down
11 changes: 10 additions & 1 deletion ui/appwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
<height>27</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -93,6 +93,7 @@
<addaction name="separator"/>
<addaction name="actionFormatCode"/>
<addaction name="actionUseSnippets"/>
<addaction name="actionSubmit"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
Expand Down Expand Up @@ -491,6 +492,14 @@
<string>Delete Log Files</string>
</property>
</action>
<action name="actionSubmit">
<property name="text">
<string>Submit</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+S</string>
coder3101 marked this conversation as resolved.
Show resolved Hide resolved
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down