custom shortcuts

This commit is contained in:
Zira project 2020-11-29 17:04:52 +05:00
parent 6d31d82111
commit 8542f3ff8c
12 changed files with 316 additions and 45 deletions

View File

@ -68,6 +68,7 @@ SOURCES += \
src/parsecss.cpp \
src/parse.cpp \
src/navigator.cpp \
src/shortcutsdialog.cpp \
src/snippets.cpp \
src/spellchecker.cpp \
src/style.cpp \
@ -134,6 +135,7 @@ HEADERS += \
include/parsecss.h \
include/parse.h \
include/navigator.h \
include/shortcutsdialog.h \
include/snippets.h \
include/spellchecker.h \
include/style.h \
@ -177,6 +179,7 @@ FORMS += \
ui/editproject.ui \
ui/settings.ui \
ui/helpdialog.ui \
ui/shortcutsdialog.ui \
ui/welcome.ui
RESOURCES += \

View File

@ -17,7 +17,6 @@ class HelpDialog : public QDialog
public:
explicit HelpDialog(QWidget *parent = nullptr);
~HelpDialog() override;
void shortcutsContent();
void faqContent();
void aboutContent();
protected:

View File

@ -53,6 +53,7 @@ namespace Ui {
class ContextDialog;
class InputDialog;
class MenuDialog;
class ShortcutsDialog;
}
Q_DECLARE_METATYPE(ParsePHP::ParseResult)

22
include/shortcutsdialog.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SHORTCUTSDIALOG_H
#define SHORTCUTSDIALOG_H
#include "ui_shortcutsdialog.h"
#include <QDialog>
#include <unordered_map>
class ShortcutsDialog : public QDialog
{
Q_OBJECT
public:
explicit ShortcutsDialog(QWidget *parent = nullptr);
~ShortcutsDialog();
std::unordered_map<std::string, std::string> getData();
protected:
std::vector<std::pair<std::string, std::string>> getShortcutNames();
private:
Ui::ShortcutsDialog *ui;
};
#endif // SHORTCUTSDIALOG_H

View File

@ -3,7 +3,6 @@
<file alias="php_function_descs">resources/help/php/function_descs</file>
<file alias="php_class_method_descs">resources/help/php/class_method_descs</file>
<file alias="php_manual_files">resources/help/php/files</file>
<file alias="editor_shortcuts">resources/help/shortcuts</file>
<file alias="about">resources/help/about</file>
<file alias="faq">resources/help/faq</file>
</qresource>

View File

@ -2,6 +2,7 @@
<qresource prefix="/image">
<file alias="abstract">resources/images/abstract.png</file>
<file alias="zira.png">resources/images/zira.png</file>
<file alias="emblem.png">resources/images/uzssr.png</file>
</qresource>
<qresource prefix="/icons">
<file alias="application-exit.png">resources/images/icons/application-exit.png</file>

View File

@ -1,22 +0,0 @@
<div><center>
<table cellspacing="0" cellpadding="5">
<tr><td>Undo:</td><td><b>Ctrl+Z</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Open file:</td><td><b>Ctrl+O</b></td></tr>
<tr><td>Redo:</td><td><b>Ctrl+Shift+Z</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Open project:</td><td><b>Ctrl+Shift+O</b></td></tr>
<tr><td>Indent:</td><td><b>Tab</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>New file:</td><td><b>Ctrl+N</b></td></tr>
<tr><td>Unindent:</td><td><b>Shift+Tab</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>New folder:</td><td><b>Ctrl+Shift+N</b></td></tr>
<tr><td>Overwrite mode:</td><td><b>Insert</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Context menu:</td><td><b>F2</b></td></tr>
<tr><td>Save:</td><td><b>Ctrl+S</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Previous tab:</td><td><b>Alt+&larr;</b></td></tr>
<tr><td>Save All:</td><td><b>Ctrl+Shift+S</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Next tab:</td><td><b>Alt+&rarr; / Ctrl+Tab</b></td></tr>
<tr><td>Commenting:</td><td><b>Ctrl+/</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Tabs list:</td><td><b>Alt+&uarr;</b></td></tr>
<tr><td>Show tooltip:</td><td><b>Ctrl+Space</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Search file:</td><td><b>Ctrl+F</b></td></tr>
<tr><td>Context help:</td><td><b>F1</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Search in files:</td><td><b>Ctrl+Shift+F</b></td></tr>
<tr><td>Select word:</td><td><b>Ctrl+W</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Multi-Selection:</td><td><b>Ctrl+R</b></td></tr>
<tr><td>Duplicate line:</td><td><b>Ctrl+D</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Focus on files tree:</td><td><b>Alt+&darr;</b></td></tr>
<tr><td>Delete line:</td><td><b>Ctrl+Shift+D</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Quick Access: </td><td><b>F3 / Ctrl+P</b></td></tr>
<tr><td>Show Terminal:</td><td><b>Ctrl+T</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Execute file:</td><td><b>F5</b></td></tr>
<tr><td>Split tab:</td><td><b>Ctrl+\</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Execute selection:</td><td><b>Shift+F5</b></td></tr>
<tr><td>Show Toolbar:</td><td><b>Ctrl+Shift+T</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Close tab:</td><td><b>Ctrl+Q</b></td></tr>
<tr><td>Show Sidebar:</td><td><b>Ctrl+Enter</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Close project:</td><td><b>Ctrl+Shift+Q</b></td></tr>
<tr><td>Show Output:</td><td><b>Ctrl+Shift+Enter</b></td> <td>&nbsp;</td><td>&nbsp;</td> <td>Exit:</td><td><b>Ctrl+Alt+Q</b></td></tr>
</table>
</center></div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

View File

@ -29,7 +29,6 @@ HelpDialog::HelpDialog(QWidget *parent) :
ui->helpDialogIconLayout->setMargin(0);
ui->helpDialogIconLayout->setSpacing(0);
// maximize dialog in Android
#if defined(Q_OS_ANDROID)
setWindowState( windowState() | Qt::WindowMaximized);
@ -46,21 +45,6 @@ HelpDialog::~HelpDialog()
delete ui;
}
void HelpDialog::shortcutsContent()
{
QFile f(":/help/editor_shortcuts");
f.open(QIODevice::ReadOnly);
QTextStream in(&f);
QString text = in.readAll();
f.close();
setWindowTitle(tr("Shortcuts"));
ui->helpDialogIconLabel->hide();
ui->helpLabel->setText(text);
pressed = 10;
}
void HelpDialog::faqContent()
{
QFile f(":/help/faq");
@ -105,15 +89,17 @@ void HelpDialog::mousePressEvent(QMouseEvent *event)
// easter egg
pressed++;
if (pressed == 10) {
QString text = ui->helpLabel->text();
QString text;
QString ah = "3c6469763e3c63656e7465723e417574686f723a2042616b68616469722052616b68696d626165762e3c2f63656e7465723e3c2f6469763e";
QString lh = "3c6469763e3c63656e7465723e546173686b656e742c20557a62656b697374616e2e3c2f63656e7465723e3c2f6469763e";
QString gh = "3c6469763e3c63656e7465723e4772656574696e677320746f20616c6c2074686f736520626f726e20696e207468652055535352213c2f63656e7465723e3c2f6469763e";
text += TPL_BLANK;
QString eh = "3a2f696d6167652f656d626c656d2e706e67";
text += QByteArray::fromHex(gh.toLocal8Bit());
text += QByteArray::fromHex(ah.toLocal8Bit());
text += QByteArray::fromHex(lh.toLocal8Bit());
ui->helpLabel->setText(text);
ui->helpDialogIconLabel->setPixmap(QPixmap(QString(QByteArray::fromHex(eh.toLocal8Bit()))));
ui->helpDialogIconLabel->setMaximumSize(300, 300);
}
QDialog::mousePressEvent(event);
}

View File

@ -36,6 +36,7 @@
#include "colordialog.h"
#include "spellchecker.h"
#include "terminal.h"
#include "shortcutsdialog.h"
const int OUTPUT_TAB_MESSAGES_INDEX = 0;
const int OUTPUT_TAB_HELP_INDEX = 1;
@ -1812,9 +1813,10 @@ void MainWindow::on_actionSettings_triggered()
void MainWindow::on_actionHelpShortcuts_triggered()
{
HelpDialog dialog(this);
dialog.shortcutsContent();
dialog.exec();
ShortcutsDialog dialog(this);
if (dialog.exec() != QDialog::Accepted) return;
Settings::change(dialog.getData());
restartApp();
}
void MainWindow::on_actionHelpAbout_triggered()

101
src/shortcutsdialog.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "shortcutsdialog.h"
#include "ui_shortcutsdialog.h"
#include <QLabel>
#include <QKeySequenceEdit>
#include "settings.h"
#include "scroller.h"
const char * SEQUENCE_NAME_PROPERTY = "settings_name";
ShortcutsDialog::ShortcutsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ShortcutsDialog)
{
ui->setupUi(this);
std::vector<std::pair<std::string, std::string>> names = getShortcutNames();
for (auto namesIterator : names) {
std::string name = namesIterator.first;
std::string label = namesIterator.second;
QLabel * nameLabel = new QLabel(tr(label.c_str()), this);
nameLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
ui->shortcutsGridLayout->addWidget(nameLabel);
QKeySequenceEdit * nameEdit = new QKeySequenceEdit(this);
nameEdit->setKeySequence(QKeySequence(QString::fromStdString(Settings::get(name))));
nameEdit->setProperty(SEQUENCE_NAME_PROPERTY, QVariant(name.c_str()));
ui->shortcutsGridLayout->addWidget(nameEdit);
}
// maximize dialog in Android
#if defined(Q_OS_ANDROID)
setWindowState( windowState() | Qt::WindowMaximized);
// scrolling by gesture
if (Settings::get("enable_android_gestures") == "yes") {
Scroller::enableGestures(ui->shortcutsScrollArea);
}
#endif
}
ShortcutsDialog::~ShortcutsDialog()
{
delete ui;
}
std::vector<std::pair<std::string, std::string>> ShortcutsDialog::getShortcutNames()
{
return std::vector<std::pair<std::string, std::string>> {
{"shortcut_open_file", "Open file"},
{"shortcut_open_project", "Open project"},
{"shortcut_new_file", "Create file"},
{"shortcut_new_folder", "Create folder"},
{"shortcut_save", "Save"},
{"shortcut_save_all", "Save All"},
{"shortcut_comment", "Comment"},
{"shortcut_overwrite_mode", "Overwrite mode"},
{"shortcut_previous_tab", "Previous tab"},
{"shortcut_next_tab", "Next tab"},
{"shortcut_tabs_list", "Tabs list"},
{"shortcut_split_tab", "Split tab"},
{"shortcut_tooltip", "Show tooltip"},
{"shortcut_search", "Search"},
{"shortcut_search_in_files", "Search in files"},
{"shortcut_select_word", "Select word"},
{"shortcut_multiselect", "Multi-Selection"},
{"shortcut_help", "Context help"},
{"shortcut_quick_access", "Quick Access"},
{"shortcut_duplicate_line", "Duplicate line"},
{"shortcut_delete_line", "Delete line"},
{"shortcut_context_menu", "Context menu"},
{"shortcut_focus_tree", "File Browser"},
{"shortcut_sidebar", "Show sidebar"},
{"shortcut_toolbar", "Show toolbar"},
{"shortcut_output", "Show output"},
{"shortcut_execute", "Execute file"},
{"shortcut_execute_selection", "Execute selection"},
{"shortcut_terminal", "Show terminal"},
{"shortcut_close_tab", "Close tab"},
{"shortcut_close_project", "Close project"},
{"shortcut_close_app", "Quit"}
};
}
std::unordered_map<std::string, std::string> ShortcutsDialog::getData()
{
std::unordered_map<std::string, std::string> data;
std::vector<std::pair<std::string, std::string>> names = getShortcutNames();
QList<QKeySequenceEdit *> edits = findChildren<QKeySequenceEdit *>();
for (QKeySequenceEdit * edit : edits) {
QVariant nameV = edit->property(SEQUENCE_NAME_PROPERTY);
if (!nameV.isValid()) continue;
std::string name = nameV.toString().toStdString();
auto it = std::find_if( names.begin(), names.end(), [&](const std::pair<std::string, std::string>& pair){ return pair.first == name;} );
if (it == names.end()) continue;
std::string value = edit->keySequence().toString().toStdString();
data[name] = value;
}
return data;
}

179
ui/shortcutsdialog.ui Normal file
View File

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShortcutsDialog</class>
<widget class="QDialog" name="ShortcutsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Shortcuts</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="shortcutsScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="shortcutsScrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>346</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="shortcutsGridLayout">
<item row="0" column="3">
<widget class="QLineEdit" name="shortcutRedoLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ctrl+Shift+Z</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="shortcutUndoLabel">
<property name="text">
<string>Undo</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="shortcutUndoLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ctrl+Z</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="shortcutRedoLabel">
<property name="text">
<string>Redo</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="shortcutIndentLabel">
<property name="text">
<string>Indent</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="shortcutIndentLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Tab</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="shortcutUnindentLabel">
<property name="text">
<string>Unindent</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="shortcutUnindentLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Shift+Tab</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ShortcutsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ShortcutsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>