Skip to content

Commit

Permalink
Merge Development branch for next release 6.0 (#123)
Browse files Browse the repository at this point in the history
* fix(cf-tool): add --version to check, fixes #112

* fix(transparency): min/max: from 60/99 to 40/100

* feat: support hot exit, closes #92

* fix: set minimum transparency to 60

* fix: use monospace fonts for Windows

* fix(Compiler): use canonicalFilePath for compiling

* fix: use quotes for paths

* fix(Runner): fix detached runner on Windows

* perf(appwindow): remove useless operations, make startup faster

* perf(appwindow): delete widgets after closing tabs

* feat(appwindow): add context menu for tabs

* perf: use timer for editorChanged

Use a timer for editorChanged, this will save lots of duplicated works.

As a benchmark, it took 29s to open a hundred tabs, and takes 18s now.

* feat(appwindow): add action Close Current

* chore(mainwindow): use QSaveFile instead of QFile for safety

* feat: different heads for different save methods

* feat(snippets): add extract snippets to files

* feat(Hot Exit): add choice of enable hot exit or not

* feat: add Linux reveal in file manager for popular file managers

* feat(tabs): add Close to the Left in context menu

* feat: Change template when change language

Change template when change language, if the tab is untitled,
and the code is unchanged template of the old language.

* feat: add Ctrl+P as shortcut for Preferences

* feat: add open contest action / open folder function / others

1. Add open contest action, which open serveral files named A.cpp, B.cpp,
   ..., Z.cpp (the suffix depends on the language) in a given directory.

2. Add open folder function, which open all files with a certain max
   depth and suffix.

3. Change "Cpp" to "C++".

4. Delete `Core.hpp` and `Core.cpp`.

* feat(appwindow): Abort on a single cancel when close all

* fix(cf-tool): accept 0 as problem code, fix #117

* feat(main.cc): add --help and --version

* feat: add --depth --contest --lang --no-hot-exit

* refactor(main.cc): use QTextStream instead of std::iostream

* feat(ui): add separators in menus

* docs(README.md): Add hot exit and transparency

* fix(cf-tool): parse problemset URL

* Update README.md (#119)

* feat(appwindow): Add open multiple files

* feat(ui): Use "..." for actions which need dialogs

* feat(main.cc): Arbitary order of <number of problems>/<contest directory>

Now you can use either `CPEditor -c <number of problems> <contest
directory>` or `CP Editor -c <contest directory> <number of problems>`.

This also fixes the segmentation fault happened when there are no
positional arguments.

* fix(main.cc): Optimize command line interaction

* feat(appwindow): No hot exit for single template tab

* Make application more flexible and re-sizeable

The input and output boxes had a minimum size contraints
that has been lifted and now they can be resized to smallest possible
size, this makes default window small and also gives you more space for
code on display with larger sizes. This commit also fixes #93 and fixes #88

* fix: make on_cfpath_button_clicked() a slot

The conflict was resolved incorrectly in 99a18da.

* fix: Use LineEdit instead of PushButton for CF Tool path

Co-authored-by: ouuan <1609483441@qq.com>
Co-authored-by: queen bee shuttle <wtnmmo@gmail.com>
  • Loading branch information
3 people authored and ouuan committed Jan 26, 2020
1 parent 1a49958 commit a012964
Show file tree
Hide file tree
Showing 19 changed files with 914 additions and 645 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -12,9 +12,10 @@
- One click for either running on the test cases / running in the terminal.
- Submit code on Codeforces inside the editor.
- Set/Use code snippets conveniently.
- Fast and memory efficient. Runs flawlessly on low-end devices.
- Supports Hot Exit. You can close the editor and keep all tabs in the next session.
- Code formating using clang-format. You can edit the `.clang-format` config in the editor.
- Customizable hotkeys for actions in the editor.
- You can set transparency of the editor.
- Fast and memory efficient. Runs flawlessly on low-end devices.
- Over 5 editor themes to choose from (Drakula, Monkai, Solarised, Solarised Dark and Light).

<img src=https://i.imgur.com/jKOtf6W.jpg width="85%">
Expand Down
33 changes: 16 additions & 17 deletions include/CompanionServer.hpp
@@ -1,20 +1,19 @@
/*
* Copyright (C) 2019-2020 Ashar Khan <ashar786khan@gmail.com>
*
* This file is part of CPEditor.
*
* CPEditor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* I will not be responsible if CPEditor behaves in unexpected way and
* causes your ratings to go down and or loose any important contest.
*
* Believe Software is "Software" and it isn't immune to bugs.
*
*/

* Copyright (C) 2019-2020 Ashar Khan <ashar786khan@gmail.com>
*
* This file is part of CPEditor.
*
* CPEditor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* I will not be responsible if CPEditor behaves in unexpected way and
* causes your ratings to go down and or loose any important contest.
*
* Believe Software is "Software" and it isn't immune to bugs.
*
*/

#ifndef COMPANIONSERVER_HPP
#define COMPANIONSERVER_HPP
Expand Down Expand Up @@ -84,7 +83,7 @@ class CompanionServer : public QObject
QTcpServer *server = nullptr;
QTcpSocket *socket = nullptr;
int portNumber;
MessageLogger *log;
MessageLogger *log = nullptr;
};
} // namespace Network
#endif // COMPANIONSERVER_HPP
69 changes: 0 additions & 69 deletions include/Core.hpp

This file was deleted.

15 changes: 13 additions & 2 deletions include/SettingsManager.hpp
Expand Up @@ -172,6 +172,9 @@ class SettingManager
bool isSaveTests();
void setSaveTests(bool value);

bool isUseHotExit();
void setUseHotExit(bool value);

bool isCompetitiveCompanionActive();
void setCompetitiveCompanionActive(bool value);

Expand All @@ -187,6 +190,9 @@ class SettingManager
bool isFormatOnSave();
void formatOnSave(bool value);

int getTransparency();
void setTransparency(int val);

ViewMode getViewMode();
void setViewMode(ViewMode v);

Expand All @@ -213,8 +219,13 @@ class SettingManager
void removeSnippet(QString lang, QString name);
QStringList getSnippetsNames(QString lang);

int getTransparency();
void setTransparency(int val);
int getNumberOfTabs();
void setNumberOfTabs(int value);
int getCurrentIndex();
void setCurrentIndex(int index);
void clearEditorStatus();
QMap<QString, QVariant> getEditorStatus(int index);
void setEditorStatus(int index, const QMap<QString, QVariant> &status);

QString getCFPath();
void setCFPath(QString path);
Expand Down
35 changes: 29 additions & 6 deletions include/appwindow.hpp
Expand Up @@ -35,8 +35,11 @@ class AppWindow : public QMainWindow
Q_OBJECT

public:
explicit AppWindow(QWidget *parent = nullptr);
explicit AppWindow(QStringList args, QWidget *parent = nullptr);
explicit AppWindow(bool noHotExit, QWidget *parent = nullptr);
explicit AppWindow(int depth, bool cpp, bool java, bool python, bool noHotExit, const QStringList &paths,
QWidget *parent = nullptr);
explicit AppWindow(bool cpp, bool java, bool python, bool noHotExit, int number, const QString &path,
QWidget *parent = nullptr);
~AppWindow() override;

void closeEvent(QCloseEvent *event) override;
Expand All @@ -48,8 +51,6 @@ class AppWindow : public QMainWindow

void on_actionAbout_triggered();

void on_actionClose_All_triggered();

void on_actionAutosave_triggered(bool checked);

void on_actionQuit_triggered();
Expand All @@ -58,6 +59,8 @@ class AppWindow : public QMainWindow

void on_actionOpen_triggered();

void on_actionOpenContest_triggered();

void on_actionRestore_Settings_triggered();

void on_actionSettings_triggered();
Expand All @@ -68,15 +71,30 @@ class AppWindow : public QMainWindow

void on_actionSave_All_triggered();

void on_actionClose_Current_triggered();

void on_actionClose_All_triggered();

void on_actionClose_Saved_triggered();

void on_actionCheck_for_updates_triggered();

void onEditorChanged();

void applyEditorChanged();

void onTabCloseRequested(int);

void onTabChanged(int);
void onEditorChanged(MainWindow *);

void onSaveTimerElapsed();

void onSettingsApplied();

void onSplitterMoved(int, int);

void onIncomingCompanionRequest(Network::CompanionData);

void onViewModeToggle();

void on_actionCompile_triggered();
Expand All @@ -101,6 +119,8 @@ class AppWindow : public QMainWindow

void on_confirmTriggered(MainWindow *widget);

void onTabContextMenuRequested(const QPoint &pos);

private:
Ui::AppWindow *ui;
MessageLogger *activeLogger = nullptr;
Expand All @@ -111,6 +131,7 @@ class AppWindow : public QMainWindow
Telemetry::UpdateNotifier *updater = nullptr;
PreferenceWindow *preferenceWindow = nullptr;
Network::CompanionServer *server;
QTimer *editorChangeApply = nullptr;

void setConnections();
void allocate();
Expand All @@ -119,9 +140,11 @@ class AppWindow : public QMainWindow
bool diagonistics;
QVector<QShortcut *> hotkeyObjects;
void maybeSetHotkeys();
void closeAll();
bool closeTab(int index);
void openTab(QString path, bool isCompanionTab = false);
void openFolder(const QString &path, bool cpp, bool java, bool python, int depth);
void openContest(const QString &path, const QString &lang, int number);
bool quit();

MainWindow *currentWindow();
MainWindow *windowIndex(int index);
Expand Down
28 changes: 22 additions & 6 deletions include/mainwindow.hpp
Expand Up @@ -49,19 +49,37 @@ class MainWindow : public QMainWindow
Q_OBJECT

public:
const int untitledIndex;
struct EditorStatus
{
bool isLanguageSet;
QString filePath, savedText, problemURL, editorText, language;
int editorCursor, editorAnchor, horizontalScrollBarValue, verticalScrollbarValue, untitledIndex;
QStringList input, expected;

EditorStatus(){};

EditorStatus(const QMap<QString, QVariant> &status);

QMap<QString, QVariant> toMap() const;
};

MainWindow(QString fileOpen, const Settings::SettingsData &data, int index = 0, QWidget *parent = nullptr);
~MainWindow() override;

int getUntitledIndex() const;
QString getFileName() const;
QString getFilePath() const;
QString getProblemURL() const;
QString getTabTitle(bool complete, bool star);
bool isUntitled() const;
void save(bool force);

EditorStatus toStatus() const;
void loadStatus(const EditorStatus &status);

void save(bool force, const QString &head);
void saveAs();

bool isTextChanged();
bool closeConfirm();

void killProcesses();
Expand All @@ -85,8 +103,6 @@ class MainWindow : public QMainWindow
void focusOnEditor();

private slots:
void onTextChangedTriggered();

void on_compile_clicked();
void on_runOnly_clicked();
void on_run_clicked();
Expand Down Expand Up @@ -118,7 +134,7 @@ class MainWindow : public QMainWindow
void onFileWatcherChanged(const QString &);

signals:
void editorChanged(MainWindow *widget);
void editorChanged();
void confirmTriggered(MainWindow *widget);

private:
Expand Down Expand Up @@ -156,6 +172,7 @@ class MainWindow : public QMainWindow

MessageLogger log;

int untitledIndex;
QString problemURL;
QString filePath;
QString savedText;
Expand All @@ -178,7 +195,6 @@ class MainWindow : public QMainWindow
void saveTests();
void setCFToolsUI();
void updateVerdict(Verdict, int);
bool isTextChanged();
bool isVerdictPass(QString, QString);
void setText(const QString &text, bool saveCursor = false);
void updateWatcher();
Expand Down
8 changes: 4 additions & 4 deletions include/preferencewindow.hpp
Expand Up @@ -58,7 +58,9 @@ class PreferenceWindow : public QMainWindow

void on_java_template_clicked();

void on_load_snippets_from_file_clicked();
void on_load_snippets_from_files_clicked();

void on_extract_snippets_to_files_clicked();

void onSnippetsLangChanged(const QString &lang);

Expand All @@ -76,9 +78,7 @@ class PreferenceWindow : public QMainWindow

void on_transparency_slider_valueChanged(int value);

void on_cfpath_button_clicked();

private:
private:
Ui::PreferenceWindow *ui;
QFont currentFont;
QString cppTemplatePath, pythonTemplatePath, javaTemplatePath;
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler.cpp
Expand Up @@ -47,7 +47,7 @@ void Compiler::start(const QString &filePath, const QString &compileCommand, con

QString command;

if (lang == "Cpp")
if (lang == "C++")
{
command = compileCommand + " \"" + QFileInfo(filePath).canonicalFilePath() + "\" -o \"" +
QFileInfo(filePath).canonicalPath() + "/" + QFileInfo(filePath).completeBaseName() + "\"";
Expand Down

0 comments on commit a012964

Please sign in to comment.