Skip to content

Commit ff3a420

Browse files
Add implementation for Open option in menu
1 parent 88ef612 commit ff3a420

File tree

7 files changed

+71
-20
lines changed

7 files changed

+71
-20
lines changed

src/GUI/EditorWindow.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QDialogButtonBox>
77
#include <QVBoxLayout>
88
#include <QComboBox>
9+
#include <QFileDialog>
910

1011
#include "../Parsers/CSFParser.hpp"
1112
#include "../Info.hpp"
@@ -426,12 +427,13 @@ void EditorWindow::SetActionHotkey(const QString& fctShortName, const QString& g
426427

427428
void EditorWindow::ActAbout_Triggered()
428429
{
429-
// if dialog already exists
430+
// If dialog already exists, we reuse created window
430431
if (pAboutDialog != nullptr)
431432
{
432433
pAboutDialog->activateWindow();
433434
return;
434435
}
436+
435437
QGridLayout* lblContent = new QGridLayout();
436438
lblContent->setSizeConstraint(QLayout::SetFixedSize);
437439

@@ -521,4 +523,17 @@ void EditorWindow::ActSaveAs_Triggered()
521523

522524
void EditorWindow::ActOpen_Triggered()
523525
{
526+
QFileDialog* fdSelectFileWindow = new QFileDialog();
527+
connect(fdSelectFileWindow, &QFileDialog::fileSelected, this, &EditorWindow::ActOpen_NewHotkeyFileSelected);
528+
fdSelectFileWindow->setFileMode(QFileDialog::FileMode::ExistingFile);
529+
fdSelectFileWindow->setAcceptMode(QFileDialog::AcceptMode::AcceptOpen);
530+
fdSelectFileWindow->setNameFilters({tr("Binary files") + " (*.csf *.big)",
531+
tr("Any files") + " (*)"});
532+
fdSelectFileWindow->exec();
533+
}
534+
535+
void EditorWindow::ActOpen_NewHotkeyFileSelected(const QString& filepath)
536+
{
537+
LOGMSG("Selected file: " + filepath);
538+
emit newHotkeyFileSelected(filepath);
524539
}

src/GUI/EditorWindow.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ private slots:
5656
void ActSave_Triggered();
5757
void ActSaveAs_Triggered();
5858
void ActOpen_Triggered();
59+
void ActOpen_NewHotkeyFileSelected(const QString& filepath);
5960

6061
signals:
6162
void languageChanged();
63+
void newHotkeyFileSelected(const QString& filepath);
6264
};

src/GUI/EditorWindowWrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ void EditorWindowWrapper::AttachConnections()
1919
{
2020
connect(pEditorWindow, &EditorWindow::languageChanged,
2121
this, &EditorWindowWrapper::EditorWindow_LanguageChanged);
22+
23+
connect(pEditorWindow, &EditorWindow::newHotkeyFileSelected,
24+
this, &EditorWindowWrapper::EditorWindow_NewHotkeyFileSelected);
2225
}
2326

2427
void EditorWindowWrapper::DetachConnections()
2528
{
2629
disconnect(pEditorWindow, &EditorWindow::languageChanged,
2730
this, &EditorWindowWrapper::EditorWindow_LanguageChanged);
31+
32+
disconnect(pEditorWindow, &EditorWindow::newHotkeyFileSelected,
33+
this, &EditorWindowWrapper::EditorWindow_NewHotkeyFileSelected);
2834
}
2935

3036
void EditorWindowWrapper::EditorWindow_LanguageChanged()
@@ -38,3 +44,9 @@ void EditorWindowWrapper::EditorWindow_LanguageChanged()
3844
AttachConnections();
3945
setCurrentWidget(pEditorWindow);
4046
}
47+
48+
void EditorWindowWrapper::EditorWindow_NewHotkeyFileSelected(const QString& filepath)
49+
{
50+
WINDOW_MANAGER->SetCSFFilePath(filepath);
51+
WINDOW_MANAGER->EditorWindow_NewHotkeyFileSelected();
52+
}

src/GUI/EditorWindowWrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ class EditorWindowWrapper final : public QStackedWidget
2121
EditorWindowWrapper(QWidget* parent = nullptr);
2222
public slots:
2323
void EditorWindow_LanguageChanged();
24+
void EditorWindow_NewHotkeyFileSelected(const QString& filepath);
2425
};

src/GUI/Translations/ru.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,92 +38,102 @@
3838
<context>
3939
<name>EditorWindow</name>
4040
<message>
41-
<location filename="../EditorWindow.cpp" line="167"/>
41+
<location filename="../EditorWindow.cpp" line="168"/>
4242
<source>File</source>
4343
<translation>Файл</translation>
4444
</message>
4545
<message>
46-
<location filename="../EditorWindow.cpp" line="168"/>
46+
<location filename="../EditorWindow.cpp" line="169"/>
4747
<source>Open</source>
4848
<translation>Открыть</translation>
4949
</message>
5050
<message>
51-
<location filename="../EditorWindow.cpp" line="169"/>
51+
<location filename="../EditorWindow.cpp" line="170"/>
5252
<source>Save</source>
5353
<translation>Сохранить</translation>
5454
</message>
5555
<message>
56-
<location filename="../EditorWindow.cpp" line="170"/>
56+
<location filename="../EditorWindow.cpp" line="171"/>
5757
<source>Save As...</source>
5858
<translation>Сохранить как...</translation>
5959
</message>
6060
<message>
61-
<location filename="../EditorWindow.cpp" line="171"/>
61+
<location filename="../EditorWindow.cpp" line="172"/>
6262
<source>Special</source>
6363
<translation>Дополнительно</translation>
6464
</message>
6565
<message>
66-
<location filename="../EditorWindow.cpp" line="182"/>
66+
<location filename="../EditorWindow.cpp" line="183"/>
6767
<source>View</source>
6868
<translation>Вид</translation>
6969
</message>
7070
<message>
71-
<location filename="../EditorWindow.cpp" line="183"/>
71+
<location filename="../EditorWindow.cpp" line="184"/>
7272
<source>Status Bar</source>
7373
<translation>Строка состояния</translation>
7474
</message>
7575
<message>
76-
<location filename="../EditorWindow.cpp" line="184"/>
76+
<location filename="../EditorWindow.cpp" line="185"/>
7777
<source>Enable</source>
7878
<translation>Включить</translation>
7979
</message>
8080
<message>
81-
<location filename="../EditorWindow.cpp" line="185"/>
81+
<location filename="../EditorWindow.cpp" line="186"/>
8282
<source>Disable</source>
8383
<translation>Отключить</translation>
8484
</message>
8585
<message>
86-
<location filename="../EditorWindow.cpp" line="189"/>
87-
<location filename="../EditorWindow.cpp" line="496"/>
86+
<location filename="../EditorWindow.cpp" line="190"/>
87+
<location filename="../EditorWindow.cpp" line="498"/>
8888
<source>Settings</source>
8989
<translation>Настройки</translation>
9090
</message>
9191
<message>
92-
<location filename="../EditorWindow.cpp" line="193"/>
93-
<location filename="../EditorWindow.cpp" line="461"/>
92+
<location filename="../EditorWindow.cpp" line="194"/>
93+
<location filename="../EditorWindow.cpp" line="463"/>
9494
<source>About</source>
9595
<translation>О программе</translation>
9696
</message>
9797
<message>
98-
<location filename="../EditorWindow.cpp" line="327"/>
98+
<location filename="../EditorWindow.cpp" line="328"/>
9999
<source>Layout %1</source>
100100
<translation>Раскладка %1</translation>
101101
</message>
102102
<message>
103-
<location filename="../EditorWindow.cpp" line="441"/>
103+
<location filename="../EditorWindow.cpp" line="443"/>
104104
<source>Authors: </source>
105105
<translation>Авторы: </translation>
106106
</message>
107107
<message>
108-
<location filename="../EditorWindow.cpp" line="442"/>
108+
<location filename="../EditorWindow.cpp" line="444"/>
109109
<source>Version: </source>
110110
<translation>Версия: </translation>
111111
</message>
112112
<message>
113-
<location filename="../EditorWindow.cpp" line="443"/>
113+
<location filename="../EditorWindow.cpp" line="445"/>
114114
<source>Program licensed with </source>
115115
<translation>Программа лицензирована под </translation>
116116
</message>
117117
<message>
118-
<location filename="../EditorWindow.cpp" line="444"/>
118+
<location filename="../EditorWindow.cpp" line="446"/>
119119
<source>GitHub repository:</source>
120120
<translation>Репозиторий на GitHub:</translation>
121121
</message>
122122
<message>
123-
<location filename="../EditorWindow.cpp" line="446"/>
123+
<location filename="../EditorWindow.cpp" line="448"/>
124124
<source>Support development:</source>
125125
<translation>Поддержать разработку:</translation>
126126
</message>
127+
<message>
128+
<location filename="../EditorWindow.cpp" line="530"/>
129+
<source>Binary files</source>
130+
<translation type="unfinished">Двоичные файлы</translation>
131+
</message>
132+
<message>
133+
<location filename="../EditorWindow.cpp" line="531"/>
134+
<source>Any files</source>
135+
<translation type="unfinished">Все файлы</translation>
136+
</message>
127137
</context>
128138
<context>
129139
<name>GreetingWindow</name>

src/GUI/WindowManager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ void WindowManager::SetTranslator()
124124
void WindowManager::Show() { pStartUpWindow->show(); }
125125
void WindowManager::SetCSFFilePath(const QString& input) { strCSFFilePath = input; }
126126

127+
void WindowManager::EditorWindow_NewHotkeyFileSelected()
128+
{
129+
CSF_PARSER = nullptr;
130+
pHotkeysEditor->close();
131+
pHotkeysEditor = nullptr;
132+
InitializeCSFParser();
133+
StartUpWindow_AcceptConfiguration();
134+
}
135+
127136
WindowManager::~WindowManager()
128137
{
129138
if (pHotkeysEditor != nullptr) pHotkeysEditor->deleteLater();

src/GUI/WindowManager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class WindowManager final
3131
void SetTranslator();
3232
/// @brief Set CSF file path. Uses if in `LoadFromTheFileWindow` file has been set.
3333
void SetCSFFilePath(const QString& filepath);
34+
/// @brief Reinitialize CSF parser and editor window when new CSF/BIG file has been selected.
35+
void EditorWindow_NewHotkeyFileSelected();
3436
/// @brief Return CSF file path. Uses if in `LoadFromTheFileWindow` file has been set.
3537
void StartUpWindow_AcceptConfiguration();
3638
};

0 commit comments

Comments
 (0)