diff --git a/Guitar.pri b/Guitar.pri index 61125478..a45aa691 100644 --- a/Guitar.pri +++ b/Guitar.pri @@ -246,7 +246,8 @@ SOURCES += \ src/coloredit/ColorPreviewWidget.cpp \ src/coloredit/ColorSlider.cpp \ src/coloredit/ColorSquareWidget.cpp \ - src/coloredit/RingSlider.cpp + src/ManageWorkingFolderDialog.cpp \ + src/coloredit/RingSlider.cpp HEADERS += \ $$PWD/src/CommitDetailGetter.h \ @@ -399,6 +400,7 @@ HEADERS += \ src/texteditor/UnicodeWidth.h \ src/texteditor/unicode.h \ src/urlencode.h \ + src/ManageWorkingFolderDialog.h \ src/webclient.h HEADERS += version.h @@ -468,7 +470,8 @@ FORMS += \ src/TextEditDialog.ui \ src/WelcomeWizardDialog.ui \ src/coloredit/ColorDialog.ui \ - src/coloredit/ColorEditWidget.ui + src/coloredit/ColorEditWidget.ui \ + src/ManageWorkingFolderDialog.ui RESOURCES += \ src/resources/resources.qrc diff --git a/Guitar.pro b/Guitar.pro index 51ae52ad..3e1c9488 100644 --- a/Guitar.pro +++ b/Guitar.pro @@ -2,3 +2,4 @@ include(Guitar.pri) CONFIG(debug,debug|release):TARGET = Guitard CONFIG(release,debug|release):TARGET = Guitar DESTDIR=$$PWD/_bin + diff --git a/src/AbstractSettingForm.cpp b/src/AbstractSettingForm.cpp index 03a597fa..d55168f8 100644 --- a/src/AbstractSettingForm.cpp +++ b/src/AbstractSettingForm.cpp @@ -7,14 +7,22 @@ AbstractSettingForm::AbstractSettingForm(QWidget *parent) MainWindow *AbstractSettingForm::mainwindow() { +#if 0 auto *w = qobject_cast(window()); Q_ASSERT(w); return w->mainwindow(); +#else + return mainwindow_; +#endif } ApplicationSettings *AbstractSettingForm::settings() { +#if 0 auto *w = qobject_cast(window()); Q_ASSERT(w); return &w->set; +#else + return settings_; +#endif } diff --git a/src/AbstractSettingForm.h b/src/AbstractSettingForm.h index 8f25d1d8..4f4f15c8 100644 --- a/src/AbstractSettingForm.h +++ b/src/AbstractSettingForm.h @@ -9,11 +9,19 @@ class MainWindow; class AbstractSettingForm : public QWidget { Q_OBJECT +private: + MainWindow *mainwindow_ = nullptr; + ApplicationSettings *settings_ = nullptr; protected: MainWindow *mainwindow(); ApplicationSettings *settings(); public: AbstractSettingForm(QWidget *parent = nullptr); + void reset(MainWindow *mw, ApplicationSettings *s) + { + mainwindow_ = mw; + settings_ = s; + } virtual void exchange(bool save) = 0; }; diff --git a/src/AddRepositoryDialog.cpp b/src/AddRepositoryDialog.cpp index cc1505b8..93226cd6 100644 --- a/src/AddRepositoryDialog.cpp +++ b/src/AddRepositoryDialog.cpp @@ -3,11 +3,16 @@ #include "Git.h" #include "MainWindow.h" #include "SearchFromGitHubDialog.h" +#include "ManageWorkingFolderDialog.h" #include "common/misc.h" #include #include #include +enum { + Manage = -100, +}; + AddRepositoryDialog::AddRepositoryDialog(MainWindow *parent, QString const &dir) : QDialog(parent) , ui(new Ui::AddRepositoryDialog) @@ -19,8 +24,7 @@ AddRepositoryDialog::AddRepositoryDialog(MainWindow *parent, QString const &dir) working_dir_ = mainwindow()->defaultWorkingDir(); - ui->comboBox_folder->addItem(working_dir_); - ui->comboBox_folder->addItem(tr("Browse...")); + updateComboBoxFolders(); already_exists_ = tr("A valid git repository exists."); @@ -44,6 +48,19 @@ AddRepositoryDialog::~AddRepositoryDialog() delete ui; } +void AddRepositoryDialog::updateComboBoxFolders() +{ + ui->comboBox_folder->clear(); + ui->comboBox_folder->addItem(working_dir_); + { + for (QString const &s : global->appsettings.favorite_working_dirs) { + ui->comboBox_folder->addItem(s); + } + } + ui->comboBox_folder->addItem(tr("Manage..."), QVariant((int)Manage)); +} + + QString AddRepositoryDialog::repositoryName() const { return reponame_; @@ -348,16 +365,21 @@ void AddRepositoryDialog::on_groupBox_remote_clicked() void AddRepositoryDialog::on_comboBox_folder_currentTextChanged(const QString &arg1) { QString dir; - if (ui->comboBox_folder->currentIndex() == 1) { - dir = QFileDialog::getExistingDirectory(this, tr("Working Folder"), workingDir()); - if (!dir.isEmpty()) { - ui->comboBox_folder->setCurrentIndex(0); - ui->comboBox_folder->setCurrentText(dir); - } - } else { - dir = arg1; + if (ui->comboBox_folder->currentData() == Manage) { + ManageWorkingFolderDialog dlg(this); + dlg.exec(); + ui->comboBox_folder->setCurrentIndex(0); + updateComboBoxFolders(); + return; } + dir = arg1; setWorkingDir(dir); updateLocalPath(); } + +void AddRepositoryDialog::on_pushButton_manage_favorite_dirs_clicked() +{ + +} + diff --git a/src/AddRepositoryDialog.h b/src/AddRepositoryDialog.h index 6a154994..b3a315a1 100644 --- a/src/AddRepositoryDialog.h +++ b/src/AddRepositoryDialog.h @@ -43,6 +43,7 @@ class AddRepositoryDialog : public QDialog { void updateUI(); void setWorkingDir(const QString &dir); void updateLocalPath(); + void updateComboBoxFolders(); public: explicit AddRepositoryDialog(MainWindow *parent, QString const &dir = QString()); ~AddRepositoryDialog() override; @@ -70,6 +71,8 @@ private slots: void on_comboBox_folder_currentTextChanged(const QString &arg1); + void on_pushButton_manage_favorite_dirs_clicked(); + public slots: void accept() override; }; diff --git a/src/AddRepositoryDialog.ui b/src/AddRepositoryDialog.ui index 88e77de5..24460b27 100644 --- a/src/AddRepositoryDialog.ui +++ b/src/AddRepositoryDialog.ui @@ -79,13 +79,6 @@ - - - - Manage... - - - @@ -304,7 +297,6 @@ radioButton_add_existing radioButton_initialize comboBox_folder - pushButton_manage_favorite_dirs lineEdit_local_path pushButton_browse_local_path lineEdit_remote_name diff --git a/src/CloneDialog.ui b/src/CloneDialog.ui index a91f86f2..203c7aec 100644 --- a/src/CloneDialog.ui +++ b/src/CloneDialog.ui @@ -29,7 +29,15 @@ - + + + + 0 + 0 + 470 + 56 + + diff --git a/src/ManageWorkingFolderDialog.cpp b/src/ManageWorkingFolderDialog.cpp new file mode 100644 index 00000000..79888805 --- /dev/null +++ b/src/ManageWorkingFolderDialog.cpp @@ -0,0 +1,26 @@ +#include "ManageWorkingFolderDialog.h" +#include "ui_ManageWorkingFolderDialog.h" + +ManageWorkingFolderDialog::ManageWorkingFolderDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ManageWorkingFolderDialog) +{ + ui->setupUi(this); + settings_ = global->appsettings; + SettingWorkingFolderForm::loadFavoliteDirs(&settings_.favorite_working_dirs); + ui->widget->reset(nullptr, &settings_); + ui->widget->exchange(false); +} + +ManageWorkingFolderDialog::~ManageWorkingFolderDialog() +{ + delete ui; +} + +void ManageWorkingFolderDialog::accept() +{ + ui->widget->exchange(true); + SettingWorkingFolderForm::saveFavoliteDirs(settings_.favorite_working_dirs); + global->appsettings.favorite_working_dirs = settings_.favorite_working_dirs; + QDialog::accept(); +} diff --git a/src/ManageWorkingFolderDialog.h b/src/ManageWorkingFolderDialog.h new file mode 100644 index 00000000..b5b89189 --- /dev/null +++ b/src/ManageWorkingFolderDialog.h @@ -0,0 +1,28 @@ +#ifndef MANAGEWORKINGFOLDERDIALOG_H +#define MANAGEWORKINGFOLDERDIALOG_H + +#include "main.h" + +#include + +namespace Ui { +class ManageWorkingFolderDialog; +} + +class ManageWorkingFolderDialog : public QDialog { + Q_OBJECT +private: + ApplicationSettings settings_; +public: + explicit ManageWorkingFolderDialog(QWidget *parent = nullptr); + ~ManageWorkingFolderDialog(); + +private: + Ui::ManageWorkingFolderDialog *ui; + + // QDialog interface +public slots: + void accept(); +}; + +#endif // MANAGEWORKINGFOLDERDIALOG_H diff --git a/src/ManageWorkingFolderDialog.ui b/src/ManageWorkingFolderDialog.ui new file mode 100644 index 00000000..5eae8d2c --- /dev/null +++ b/src/ManageWorkingFolderDialog.ui @@ -0,0 +1,103 @@ + + + ManageWorkingFolderDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + + SettingWorkingFolderForm + QWidget +
SettingWorkingFolderForm.h
+ 1 +
+
+ + + + pushButton + clicked() + ManageWorkingFolderDialog + accept() + + + 233 + 281 + + + 210 + 278 + + + + + pushButton_2 + clicked() + ManageWorkingFolderDialog + reject() + + + 375 + 274 + + + 394 + 279 + + + + +
diff --git a/src/SettingWorkingFolderForm.cpp b/src/SettingWorkingFolderForm.cpp index be350c5d..1f16d36c 100644 --- a/src/SettingWorkingFolderForm.cpp +++ b/src/SettingWorkingFolderForm.cpp @@ -22,9 +22,45 @@ SettingWorkingFolderForm::~SettingWorkingFolderForm() delete ui; } +static QString favoliteDirsIni() +{ + return global->app_config_dir / "favoritedirs.ini"; +} + +bool SettingWorkingFolderForm::saveFavoliteDirs(QStringList const &favdirs) +{ + QFile file(favoliteDirsIni()); + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QTextStream out(&file); + for (QString const &dir : favdirs) { + out << dir << "\n"; + } + return true; + } + return false; +} + +bool SettingWorkingFolderForm::loadFavoliteDirs(QStringList *favdirs) +{ + QStringList list; + QFile file(favoliteDirsIni()); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine().trimmed(); + if (!line.isEmpty()) { + list.append(line); + } + } + *favdirs = list; + return true; + } + return false; +} + void SettingWorkingFolderForm::exchange(bool save) { - QString favoritedirs_ini = global->app_config_dir / "favoritedirs.ini"; + QString favoritedirs_ini = favoliteDirsIni(); if (save) { settings()->default_working_dir = ui->lineEdit_recentry_used->text(); { @@ -32,27 +68,13 @@ void SettingWorkingFolderForm::exchange(bool save) for (int i = 0; i < ui->listWidget_favorites->count(); i++) { settings()->favorite_working_dirs.append(ui->listWidget_favorites->item(i)->text()); } - QFile file(favoritedirs_ini); - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream out(&file); - for (QString const &dir : settings()->favorite_working_dirs) { - out << dir << "\n"; - } - } + saveFavoliteDirs(settings()->favorite_working_dirs); } } else { ui->lineEdit_recentry_used->setText(settings()->default_working_dir); { QStringList list; - QFile file(favoritedirs_ini); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine().trimmed(); - if (!line.isEmpty()) { - list.append(line); - } - } + if (loadFavoliteDirs(&list)) { global->appsettings.favorite_working_dirs = list; ui->listWidget_favorites->clear(); for (const QString &s : list) { @@ -99,3 +121,25 @@ void SettingWorkingFolderForm::on_pushButton_remove_clicked() } } + +void SettingWorkingFolderForm::on_pushButton_up_clicked() +{ + int row = ui->listWidget_favorites->currentRow(); + if (row > 0) { + QString item = ui->listWidget_favorites->takeItem(row)->text(); + ui->listWidget_favorites->insertItem(row - 1, item); + ui->listWidget_favorites->setCurrentRow(row - 1); + } +} + + +void SettingWorkingFolderForm::on_pushButton_down_clicked() +{ + int row = ui->listWidget_favorites->currentRow(); + if (row >= 0 && row + 1 < ui->listWidget_favorites->count()) { + QString item = ui->listWidget_favorites->takeItem(row)->text(); + ui->listWidget_favorites->insertItem(row + 1, item); + ui->listWidget_favorites->setCurrentRow(row + 1); + } +} + diff --git a/src/SettingWorkingFolderForm.h b/src/SettingWorkingFolderForm.h index 74f1ae6d..a94b90ca 100644 --- a/src/SettingWorkingFolderForm.h +++ b/src/SettingWorkingFolderForm.h @@ -15,10 +15,14 @@ class SettingWorkingFolderForm : public AbstractSettingForm { explicit SettingWorkingFolderForm(QWidget *parent = nullptr); ~SettingWorkingFolderForm() override; void exchange(bool save) override; + static bool saveFavoliteDirs(QStringList const &favdirs); + static bool loadFavoliteDirs(QStringList *favdirs); private slots: void on_pushButton_clicked(); void on_pushButton_add_clicked(); void on_pushButton_remove_clicked(); + void on_pushButton_up_clicked(); + void on_pushButton_down_clicked(); }; #endif // SETTINGWORKINGFOLDERFORM_H diff --git a/src/SettingWorkingFolderForm.ui b/src/SettingWorkingFolderForm.ui index 45266484..004aa4e8 100644 --- a/src/SettingWorkingFolderForm.ui +++ b/src/SettingWorkingFolderForm.ui @@ -64,6 +64,20 @@
+ + + + Up + + + + + + + Down + + +
@@ -71,6 +85,15 @@ + + pushButton + lineEdit_recentry_used + pushButton_add + pushButton_remove + pushButton_up + pushButton_down + listWidget_favorites + diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 7cb35e4e..17a9951f 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -17,18 +17,15 @@ SettingsDialog::SettingsDialog(MainWindow *parent) : mainwindow_ = parent; - loadSettings(); - - QTreeWidgetItem *item; - - auto AddPage = [&](QWidget *page){ + auto AddPage = [&](AbstractSettingForm *page){ // page->layout()->setMargin(0); auto *l = page->layout(); if (l) { l->setContentsMargins(0, 0, 0, 0); } + page->reset(mainwindow_, &settings_); QString name = page->windowTitle(); - item = new QTreeWidgetItem(); + QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, name); item->setData(0, Qt::UserRole, QVariant::fromValue((uintptr_t)(QWidget *)page)); ui->treeWidget->addTopLevelItem(item); @@ -43,6 +40,8 @@ SettingsDialog::SettingsDialog(MainWindow *parent) : AddPage(ui->page_options); // AddPage(ui->page_example); + loadSettings(); + ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(page_number)); } @@ -196,7 +195,7 @@ void SettingsDialog::saveSettings(ApplicationSettings const *as) void SettingsDialog::saveSettings() { - saveSettings(&set); + saveSettings(&settings_); } void SettingsDialog::exchange(bool save) @@ -209,7 +208,7 @@ void SettingsDialog::exchange(bool save) void SettingsDialog::loadSettings() { - loadSettings(&set); + loadSettings(&settings_); exchange(false); } diff --git a/src/SettingsDialog.h b/src/SettingsDialog.h index 9e16478c..760d8da1 100644 --- a/src/SettingsDialog.h +++ b/src/SettingsDialog.h @@ -15,7 +15,7 @@ class SettingsDialog : public QDialog { Q_OBJECT public: - ApplicationSettings set; + ApplicationSettings settings_; private: Ui::SettingsDialog *ui; MainWindow *mainwindow_; @@ -41,7 +41,7 @@ class SettingsDialog : public QDialog ApplicationSettings const &settings() const { - return set; + return settings_; } static void loadSettings(ApplicationSettings *as);