1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

FileManager: Make properties windows non-modal

Fixes #46488
This commit is contained in:
Andreas Kling 2021-01-02 00:31:30 +01:00
parent c381e7f5a0
commit 7e6c27a688
4 changed files with 28 additions and 22 deletions

View file

@ -6,7 +6,7 @@ set(SOURCES
FileManagerWindowGML.h FileManagerWindowGML.h
FileUtils.cpp FileUtils.cpp
main.cpp main.cpp
PropertiesDialog.cpp PropertiesWindow.cpp
) )
serenity_app(FileManager ICON filetype-folder) serenity_app(FileManager ICON filetype-folder)

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "PropertiesDialog.h" #include "PropertiesWindow.h"
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibDesktop/Launcher.h> #include <LibDesktop/Launcher.h>
@ -43,8 +43,8 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Window* parent_window) PropertiesWindow::PropertiesWindow(const String& path, bool disable_rename, Window* parent_window)
: Dialog(parent_window) : Window(parent_window)
{ {
auto lexical_path = LexicalPath(path); auto lexical_path = LexicalPath(path);
ASSERT(lexical_path.is_valid()); ASSERT(lexical_path.is_valid());
@ -166,15 +166,17 @@ PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Wind
update(); update();
} }
PropertiesDialog::~PropertiesDialog() { } PropertiesWindow::~PropertiesWindow()
{
}
void PropertiesDialog::update() void PropertiesWindow::update()
{ {
m_icon->set_bitmap(GUI::FileIconProvider::icon_for_path(make_full_path(m_name), m_mode).bitmap_for_size(32)); m_icon->set_bitmap(GUI::FileIconProvider::icon_for_path(make_full_path(m_name), m_mode).bitmap_for_size(32));
set_title(String::formatted("{} - Properties", m_name)); set_title(String::formatted("{} - Properties", m_name));
} }
void PropertiesDialog::permission_changed(mode_t mask, bool set) void PropertiesWindow::permission_changed(mode_t mask, bool set)
{ {
if (set) { if (set) {
m_mode |= mask; m_mode |= mask;
@ -186,12 +188,12 @@ void PropertiesDialog::permission_changed(mode_t mask, bool set)
m_apply_button->set_enabled(m_name_dirty || m_permissions_dirty); m_apply_button->set_enabled(m_name_dirty || m_permissions_dirty);
} }
String PropertiesDialog::make_full_path(const String& name) String PropertiesWindow::make_full_path(const String& name)
{ {
return String::formatted("{}/{}", m_parent_path, name); return String::formatted("{}/{}", m_parent_path, name);
} }
bool PropertiesDialog::apply_changes() bool PropertiesWindow::apply_changes()
{ {
if (m_name_dirty) { if (m_name_dirty) {
String new_name = m_name_box->text(); String new_name = m_name_box->text();
@ -227,7 +229,7 @@ bool PropertiesDialog::apply_changes()
return true; return true;
} }
void PropertiesDialog::make_permission_checkboxes(GUI::Widget& parent, PermissionMasks masks, String label_string, mode_t mode) void PropertiesWindow::make_permission_checkboxes(GUI::Widget& parent, PermissionMasks masks, String label_string, mode_t mode)
{ {
auto& widget = parent.add<GUI::Widget>(); auto& widget = parent.add<GUI::Widget>();
widget.set_layout<GUI::HorizontalBoxLayout>(); widget.set_layout<GUI::HorizontalBoxLayout>();
@ -261,7 +263,7 @@ void PropertiesDialog::make_permission_checkboxes(GUI::Widget& parent, Permissio
box_execute.set_enabled(can_edit_checkboxes); box_execute.set_enabled(can_edit_checkboxes);
} }
void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent) void PropertiesWindow::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent)
{ {
int max_width = 0; int max_width = 0;
Vector<NonnullRefPtr<GUI::Label>> property_labels; Vector<NonnullRefPtr<GUI::Label>> property_labels;
@ -294,7 +296,7 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
label->set_fixed_width(max_width); label->set_fixed_width(max_width);
} }
GUI::Button& PropertiesDialog::make_button(String text, GUI::Widget& parent) GUI::Button& PropertiesWindow::make_button(String text, GUI::Widget& parent)
{ {
auto& button = parent.add<GUI::Button>(text); auto& button = parent.add<GUI::Button>(text);
button.set_fixed_size(70, 22); button.set_fixed_size(70, 22);

View file

@ -34,13 +34,14 @@
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/TextBox.h> #include <LibGUI/TextBox.h>
class PropertiesDialog final : public GUI::Dialog { class PropertiesWindow final : public GUI::Window {
C_OBJECT(PropertiesDialog) C_OBJECT(PropertiesWindow);
public: public:
virtual ~PropertiesDialog() override; virtual ~PropertiesWindow() override;
private: private:
PropertiesDialog(const String& path, bool disable_rename, Window* parent = nullptr); PropertiesWindow(const String& path, bool disable_rename, Window* parent = nullptr);
struct PropertyValuePair { struct PropertyValuePair {
String property; String property;

View file

@ -27,7 +27,7 @@
#include "DesktopWidget.h" #include "DesktopWidget.h"
#include "DirectoryView.h" #include "DirectoryView.h"
#include "FileUtils.h" #include "FileUtils.h"
#include "PropertiesDialog.h" #include "PropertiesWindow.h"
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/URL.h> #include <AK/URL.h>
@ -195,14 +195,17 @@ void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* wind
void show_properties(const String& container_dir_path, const String& path, const Vector<String>& selected, GUI::Window* window) void show_properties(const String& container_dir_path, const String& path, const Vector<String>& selected, GUI::Window* window)
{ {
RefPtr<PropertiesDialog> properties; RefPtr<PropertiesWindow> properties;
if (selected.is_empty()) { if (selected.is_empty()) {
properties = window->add<PropertiesDialog>(path, true); properties = window->add<PropertiesWindow>(path, true);
} else { } else {
properties = window->add<PropertiesDialog>(selected.first(), access(container_dir_path.characters(), W_OK) != 0); properties = window->add<PropertiesWindow>(selected.first(), access(container_dir_path.characters(), W_OK) != 0);
} }
properties->on_close = [properties = properties.ptr()] {
properties->exec(); properties->remove_from_parent();
};
properties->center_on_screen();
properties->show();
} }
int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config) int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)