mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
improvements in UI
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QPushButton>
|
||||
#include <QTextBrowser>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include <Qsci/qscilexer.h>
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
@@ -44,8 +45,8 @@
|
||||
#include "parser.h"
|
||||
|
||||
// Atmiņas bāze.
|
||||
QString currentPath = "";
|
||||
std::string currentMdem = "";
|
||||
QString currentMbasePath = "";
|
||||
std::string currentMdemPath = "";
|
||||
QFileSystemModel *model;
|
||||
QTreeView *mdemList;
|
||||
std::map<std::string, MdemBuffer*> buffers;
|
||||
@@ -395,7 +396,7 @@ Mdem* makeMdem() {
|
||||
currentMdemBuffer->questions.erase(currentMdemBuffer->questions.begin() + i);
|
||||
delete mdem->question;
|
||||
mdem->question = nullptr;
|
||||
updateMdemInfo(getFilename(currentMdem), true);
|
||||
updateMdemInfo(getFilename(currentMdemPath), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -490,8 +491,8 @@ void update(bool isChanged) {
|
||||
if (pagination->currentPage > -1) {
|
||||
switchPage(pagination->currentPage);
|
||||
}
|
||||
if (currentMdem.length() > 0) {
|
||||
updateMdemInfo(getFilename(currentMdem), isChanged);
|
||||
if (currentMdemPath.length() > 0) {
|
||||
updateMdemInfo(getFilename(currentMdemPath), isChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +589,7 @@ void reloadMdem(std::string path) {
|
||||
auto toRemove = std::vector<std::string>();
|
||||
for (auto it = buffers.begin(); it != buffers.end(); ++it) {
|
||||
auto pair = *it;
|
||||
if (currentMdem.compare(path) != 0 &&
|
||||
if (currentMdemPath.compare(path) != 0 &&
|
||||
(!pair.second->isModified || pair.second->error)) {
|
||||
toRemove.push_back(pair.first);
|
||||
}
|
||||
@@ -599,8 +600,8 @@ void reloadMdem(std::string path) {
|
||||
|
||||
MdemBuffer *buffer;
|
||||
auto filename = getFilename(path);
|
||||
if (currentMdem.compare(path) == 0) {
|
||||
currentMdem = path;
|
||||
if (currentMdemPath.compare(path) == 0) {
|
||||
currentMdemPath = path;
|
||||
if (buffers.contains(path)) {
|
||||
buffers.erase(path);
|
||||
}
|
||||
@@ -608,14 +609,14 @@ void reloadMdem(std::string path) {
|
||||
buffer = new MdemBuffer;
|
||||
buffers[path] = buffer;
|
||||
currentMdemBuffer = buffer;
|
||||
currentMdem = path;
|
||||
currentMdemPath = path;
|
||||
} else {
|
||||
buffer = buffers[path];
|
||||
currentMdemBuffer = buffer;
|
||||
makePages();
|
||||
switchPage(0);
|
||||
updateMdemInfo(getFilename(filename), buffer->isModified);
|
||||
currentMdem = path;
|
||||
currentMdemPath = path;
|
||||
errorView->box.hide();
|
||||
return;
|
||||
}
|
||||
@@ -691,7 +692,7 @@ void reloadMdem(std::string path) {
|
||||
switchPage(0);
|
||||
updateMdemInfo(filename, false);
|
||||
} else {
|
||||
std::cout << std::format("Nevar atvert failu: {}", currentPath.toStdString()) << std::endl;
|
||||
std::cout << std::format("Nevar atvert failu: {}", currentMbasePath.toStdString()) << std::endl;
|
||||
}
|
||||
|
||||
for (auto mdem: mdems) {
|
||||
@@ -710,7 +711,7 @@ void pickDirectory(QString directory) {
|
||||
) {
|
||||
QMessageBox::information(
|
||||
nullptr,
|
||||
"Error",
|
||||
"Kļūda",
|
||||
"Direktorijs, kas ir norādīts kā noklusētais, neeksistē."
|
||||
);
|
||||
return;
|
||||
@@ -729,7 +730,7 @@ void pickDirectory(QString directory) {
|
||||
"Atveršanas kļūda",
|
||||
"Izvēlētajā direktorijā nav iespējams rakstīt."
|
||||
);
|
||||
currentPath = "";
|
||||
currentMbasePath = "";
|
||||
return;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
@@ -738,11 +739,11 @@ void pickDirectory(QString directory) {
|
||||
"Atveršanas kļūda",
|
||||
"Neizdevās pārbaudīt izvēlētā direktorija rakstāmību."
|
||||
);
|
||||
currentPath = "";
|
||||
currentMbasePath = "";
|
||||
return;
|
||||
}
|
||||
|
||||
currentPath = directory;
|
||||
currentMbasePath = directory;
|
||||
|
||||
// Atjauno failu sarakstu.
|
||||
if (directory.length() <= 0) {
|
||||
@@ -756,7 +757,7 @@ void pickDirectory(QString directory) {
|
||||
membaseLabel->setText(QString::fromStdString(
|
||||
std::format(
|
||||
"Atmiņas bāze: {}",
|
||||
getFilename(currentPath.toStdString())
|
||||
getFilename(currentMbasePath.toStdString())
|
||||
)
|
||||
));
|
||||
|
||||
@@ -800,7 +801,7 @@ void setupEditorSave() {
|
||||
setupMdem(editMdem, res.value.questions[0]);
|
||||
showBacklabels(editMdem);
|
||||
editorWindow->hide();
|
||||
updateMdemInfo(getFilename(currentMdem), true);
|
||||
updateMdemInfo(getFilename(currentMdemPath), true);
|
||||
} else {
|
||||
QMessageBox::information(
|
||||
nullptr,
|
||||
@@ -824,7 +825,7 @@ void setupEditorSave() {
|
||||
makePages();
|
||||
switchPage(0);
|
||||
editorWindow->hide();
|
||||
updateMdemInfo(getFilename(currentMdem), true);
|
||||
updateMdemInfo(getFilename(currentMdemPath), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -833,8 +834,20 @@ void setupEditorSave() {
|
||||
void saveMdem() {
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto filename = getFilename(currentMdem);
|
||||
std::ofstream out(currentMdem);
|
||||
std::filesystem::path dir(currentMdemPath);
|
||||
auto parentPath = dir.parent_path();
|
||||
if (!parentPath.empty() && !std::filesystem::exists(parentPath)) {
|
||||
if (!std::filesystem::create_directories(parentPath)) {
|
||||
QMessageBox::information(
|
||||
nullptr,
|
||||
"Kļūda",
|
||||
"Neizdevās izveidot direktorijus faila saglabāšanai."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
auto filename = getFilename(currentMdemPath);
|
||||
std::ofstream out(currentMdemPath);
|
||||
|
||||
int wrap_width = 80;
|
||||
if (settings->contains(SETTING_CHARACTER_WRAP)) {
|
||||
@@ -850,7 +863,7 @@ void saveMdem() {
|
||||
wrap_width,
|
||||
timezoneOffset
|
||||
);
|
||||
updateMdemInfo(getFilename(currentMdem), false);
|
||||
updateMdemInfo(getFilename(currentMdemPath), false);
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
||||
@@ -886,13 +899,14 @@ QMainWindow *initMdemListWindow() {
|
||||
}
|
||||
|
||||
QAction *actionOpen;
|
||||
QAction *revealMbase;
|
||||
QAction *openSettings;
|
||||
QAction *actionHelp;
|
||||
{ // Izvēlne.
|
||||
QMenuBar *menuBar = new QMenuBar;
|
||||
QFileDialog *fileDialog = new QFileDialog;
|
||||
|
||||
QMenu *menu = new QMenu("Fails");
|
||||
QMenu *menu = new QMenu("Darbības");
|
||||
menu->setStyleSheet("font-size: 15px;");
|
||||
actionOpen = menu->addAction("Atvērt atmiņas bāzi (Ctrl+O)");
|
||||
QObject::connect(
|
||||
@@ -901,6 +915,12 @@ QMainWindow *initMdemListWindow() {
|
||||
[fileDialog]() {
|
||||
fileDialog->setDirectory(QDir::homePath());
|
||||
fileDialog->setFileMode(QFileDialog::FileMode::Directory);
|
||||
if (
|
||||
!currentMbasePath.isEmpty() &&
|
||||
std::filesystem::exists(currentMbasePath.toStdString())
|
||||
) {
|
||||
fileDialog->setDirectory(currentMbasePath);
|
||||
}
|
||||
fileDialog->open();
|
||||
QObject::disconnect(fileDialog, 0, 0, 0);
|
||||
fileDialog->connect(
|
||||
@@ -911,6 +931,24 @@ QMainWindow *initMdemListWindow() {
|
||||
}
|
||||
);
|
||||
|
||||
revealMbase = menu->addAction("Atvērt atmiņas bāzi failu pārlūkā (Ctrl+M)");
|
||||
QObject::connect(
|
||||
revealMbase,
|
||||
&QAction::triggered,
|
||||
[]() {
|
||||
auto directoryUrl = QUrl::fromLocalFile(
|
||||
QDir(currentMbasePath).absolutePath()
|
||||
);
|
||||
if (!QDesktopServices::openUrl(directoryUrl)) {
|
||||
QMessageBox::information(
|
||||
nullptr,
|
||||
"Kļūda",
|
||||
"Neizdevās atvērt atmiņas bāzi failu pārlūkā."
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
openSettings = menu->addAction("Iestatījumi (Ctrl+,)");
|
||||
QObject::connect(
|
||||
openSettings,
|
||||
@@ -1032,7 +1070,7 @@ QMainWindow *initMdemListWindow() {
|
||||
if (!trainWindow->isHidden()) {
|
||||
trainWindow->hide();
|
||||
}
|
||||
reloadMdem(currentMdem);
|
||||
reloadMdem(currentMdemPath);
|
||||
});
|
||||
QObject::connect(&toolbar->btnSave, &QToolButton::clicked, []() {
|
||||
if (!currentMdemBuffer) {
|
||||
@@ -1109,9 +1147,9 @@ QMainWindow *initMdemListWindow() {
|
||||
);
|
||||
auto header = mdemList->header();
|
||||
header->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
currentPath = settings->value(SETTING_MEMORYBASE).toString();
|
||||
if (currentPath.size() > 0) {
|
||||
pickDirectory(currentPath);
|
||||
currentMbasePath = settings->value(SETTING_MEMORYBASE).toString();
|
||||
if (currentMbasePath.size() > 0) {
|
||||
pickDirectory(currentMbasePath);
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
@@ -1260,6 +1298,9 @@ QMainWindow *initMdemListWindow() {
|
||||
addShortcut("Ctrl+O", [actionOpen]() {
|
||||
actionOpen->trigger();
|
||||
});
|
||||
addShortcut("Ctrl+M", [revealMbase]() {
|
||||
revealMbase->trigger();
|
||||
});
|
||||
addShortcut("Ctrl+H", [actionHelp]() {
|
||||
actionHelp->trigger();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user