Skip to content

Commit

Permalink
feat(formatter): clang-format update (#96)
Browse files Browse the repository at this point in the history
* feat(formatter): clang-format update

1. Set clang-format binary instead of set format command.

2. Use `--cursor` argument to keep the cursor after formatting.

3. Format selection only if there is a selection.

4. Set format style in preference window.

5. Add format on save option.

6. Open temporary file for formatting when necessary instead of holding it.

7. Other text changes and minor changes.

8. Modify README.md for these changes.

* style: format codes
  • Loading branch information
ouuan authored and coder3101 committed Jan 15, 2020
1 parent 1900722 commit e5c7848
Show file tree
Hide file tree
Showing 17 changed files with 464 additions and 363 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- Parse problem example test cases from over 30+ online platforms, and test on them with verdict feedback.
- You can use code snippets conveniently.
- Fast and memory efficient. Runs flawlessly on low-end devices.
- Code formating using tools like clang-format.
- Code formating using clang-format.
- Customizable hotkeys for actions in the editor.
- Over 5 themes to choose from (Drakula, Monkai, Solarised, Solarised Dark and Light).
- Supports Multi tabs.
Expand Down Expand Up @@ -48,12 +48,12 @@ You **must not** make your Java class public, and the name of the class should b

| Shortcut | Description |
| ------------ | ------------------------------------------------------------ |
| CTRL+N | Launches a new Session and resets the editor. Once you solved a problem you need to Launch a new Session for the next Problem. |
| CTRL+Q | Quit and Exit Application |
| CTRL+O | Opens a new Source File into Editor |
| CTRL+N | Launches a new session and resets the editor. Once you solved a problem you need to launch a new session for the next problem. |
| CTRL+Q | Quit and exit application |
| CTRL+O | Opens a new source file into the editor |
| CTRL+S | Saves the current content of editor to a File |
| CTRL+Shift+S | Saves as |
| CTRL+Alt+L | Formats the editor using `format_command` |
| CTRL+Alt+L | Formats the editor using clang-format, format selection only if there is a selection |
| CTRL+Shift+R | Compile and Run |
| CTRL+Shift+C | Compile only |
| CTRL+R | Run |
Expand Down
52 changes: 26 additions & 26 deletions include/Formatter.hpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
/*
* 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 FORMATTER_HPP
#define FORMATTER_HPP
#include <BaseFiles.hpp>
#include <MessageLogger.hpp>
#include <QCodeEditor>
#include <QFile>
#include <QPair>
#include <QString>

namespace Core
{
class Formatter : private Base::Files
class Formatter
{
public:
Formatter(QString runCommand, int index, MessageLogger *log);
~Formatter();
void format(QCodeEditor *editor);
static bool check(QString command);
void updateCommand(QString newCommand);
Formatter(QString clangFormatBinary, const QString &clangFormatStyle, MessageLogger *log);
void format(QCodeEditor *editor, const QString &filePath, const QString &lang, bool selectionOnly);
static bool check(QString checkBinary, const QString &checkStyle);
void updateBinary(QString newBinary);
void updateStyle(const QString &newStyle);

private:
QFile *file;
QString command;
QString binary;
QString style;
MessageLogger *log;

QPair<int, QString> getFormatResult(const QStringList &args);
};

} // namespace Core
Expand Down
44 changes: 25 additions & 19 deletions include/SettingsManager.hpp
Original file line number Diff line number Diff line change
@@ -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 SETTINGSMANAGER_HPP
#define SETTINGSMANAGER_HPP
Expand Down Expand Up @@ -53,7 +52,8 @@ struct SettingsData
QString runtimeArgumentsJava;
QString runtimeArgumentsPython;

QString formatCommand;
QString clangFormatBinary;
QString clangFormatStyle;

QString compileCommandJava;
QString compileCommandCpp;
Expand All @@ -75,6 +75,7 @@ struct SettingsData
bool isWindowMaximized;
bool isCheckUpdateOnStartup;
bool isUpdateCheckOnStartup;
bool isFormatOnSave;

QKeySequence hotkeyRun;
QKeySequence hotkeyCompile;
Expand Down Expand Up @@ -122,8 +123,10 @@ class SettingManager
void setRuntimeArgumentsJava(QString command);
void setRuntimeArgumentsPython(QString command);

QString getFormatCommand();
void setFormatCommand(QString command);
QString getClangFormatBinary();
void setClangFormatBinary(QString binary);
QString getClangFormatStyle();
void setClangFormatStyle(const QString &style);

QString getCompileCommandCpp();
QString getCompileCommandJava();
Expand Down Expand Up @@ -171,6 +174,9 @@ class SettingManager
bool isCheckUpdateOnStartup();
void checkUpdateOnStartup(bool value);

bool isFormatOnSave();
void formatOnSave(bool value);

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

Expand Down
31 changes: 15 additions & 16 deletions include/UpdateNotifier.hpp
Original file line number Diff line number Diff line change
@@ -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 UPDATENOTIFIER_HPP
#define UPDATENOTIFIER_HPP
Expand Down
31 changes: 15 additions & 16 deletions include/appwindow.hpp
Original file line number Diff line number Diff line change
@@ -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 APPWINDOW_HPP
#define APPWINDOW_HPP
Expand Down
39 changes: 19 additions & 20 deletions include/preferencewindow.hpp
Original file line number Diff line number Diff line change
@@ -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 PREFERENCEWINDOW_HPP
#define PREFERENCEWINDOW_HPP
Expand Down Expand Up @@ -61,9 +60,9 @@ class PreferenceWindow : public QMainWindow

void on_load_snippets_from_file_clicked();

void on_snippets_lang_changed(const QString &lang);
void onSnippetsLangChanged(const QString &lang);

void on_current_snippet_changed(const QString &text);
void onCurrentSnippetChanged(const QString &text);

void applySettingsToEditor();

Expand All @@ -75,7 +74,7 @@ class PreferenceWindow : public QMainWindow

void on_snippet_rename_clicked();

private:
private:
Ui::PreferenceWindow *ui;
QFont currentFont;
QString cppTemplatePath, pythonTemplatePath, javaTemplatePath;
Expand All @@ -88,7 +87,7 @@ class PreferenceWindow : public QMainWindow
void updateSnippets();
void switchToSnippet(const QString &text);

QString getNewSnippetName(const QString& lang, const QString &old = QString());
QString getNewSnippetName(const QString &lang, const QString &old = QString());
};

#endif // PREFERENCEWINDOW_HPP
31 changes: 15 additions & 16 deletions src/DiffViewer.cpp
Original file line number Diff line number Diff line change
@@ -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.
*
*/

#include "DiffViewer.hpp"

Expand Down

0 comments on commit e5c7848

Please sign in to comment.