Skip to content

Commit

Permalink
Add ManageWorkingFolderDialog to handle favorite directories
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Mar 10, 2024
1 parent 7b4f317 commit 0b4c349
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 48 deletions.
7 changes: 5 additions & 2 deletions Guitar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Guitar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include(Guitar.pri)
CONFIG(debug,debug|release):TARGET = Guitard
CONFIG(release,debug|release):TARGET = Guitar
DESTDIR=$$PWD/_bin

8 changes: 8 additions & 0 deletions src/AbstractSettingForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ AbstractSettingForm::AbstractSettingForm(QWidget *parent)

MainWindow *AbstractSettingForm::mainwindow()
{
#if 0
auto *w = qobject_cast<SettingsDialog *>(window());
Q_ASSERT(w);
return w->mainwindow();
#else
return mainwindow_;
#endif
}

ApplicationSettings *AbstractSettingForm::settings()
{
#if 0
auto *w = qobject_cast<SettingsDialog *>(window());
Q_ASSERT(w);
return &w->set;
#else
return settings_;
#endif
}
8 changes: 8 additions & 0 deletions src/AbstractSettingForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
42 changes: 32 additions & 10 deletions src/AddRepositoryDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
#include "Git.h"
#include "MainWindow.h"
#include "SearchFromGitHubDialog.h"
#include "ManageWorkingFolderDialog.h"
#include "common/misc.h"
#include <QFileDialog>
#include <QFocusEvent>
#include <QMessageBox>

enum {
Manage = -100,
};

AddRepositoryDialog::AddRepositoryDialog(MainWindow *parent, QString const &dir)
: QDialog(parent)
, ui(new Ui::AddRepositoryDialog)
Expand All @@ -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.");

Expand All @@ -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_;
Expand Down Expand Up @@ -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()
{

}

3 changes: 3 additions & 0 deletions src/AddRepositoryDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
8 changes: 0 additions & 8 deletions src/AddRepositoryDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_manage_favorite_dirs">
<property name="text">
<string>Manage...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
Expand Down Expand Up @@ -304,7 +297,6 @@
<tabstop>radioButton_add_existing</tabstop>
<tabstop>radioButton_initialize</tabstop>
<tabstop>comboBox_folder</tabstop>
<tabstop>pushButton_manage_favorite_dirs</tabstop>
<tabstop>lineEdit_local_path</tabstop>
<tabstop>pushButton_browse_local_path</tabstop>
<tabstop>lineEdit_remote_name</tabstop>
Expand Down
10 changes: 9 additions & 1 deletion src/CloneDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
</size>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>56</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
Expand Down
26 changes: 26 additions & 0 deletions src/ManageWorkingFolderDialog.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
28 changes: 28 additions & 0 deletions src/ManageWorkingFolderDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef MANAGEWORKINGFOLDERDIALOG_H
#define MANAGEWORKINGFOLDERDIALOG_H

#include "main.h"

#include <QDialog>

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
103 changes: 103 additions & 0 deletions src/ManageWorkingFolderDialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ManageWorkingFolderDialog</class>
<widget class="QDialog" name="ManageWorkingFolderDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="SettingWorkingFolderForm" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SettingWorkingFolderForm</class>
<extends>QWidget</extends>
<header>SettingWorkingFolderForm.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>ManageWorkingFolderDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>233</x>
<y>281</y>
</hint>
<hint type="destinationlabel">
<x>210</x>
<y>278</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>ManageWorkingFolderDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>375</x>
<y>274</y>
</hint>
<hint type="destinationlabel">
<x>394</x>
<y>279</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit 0b4c349

Please sign in to comment.