Skip to content

Commit

Permalink
many improvements around the project file watcher functionality.
Browse files Browse the repository at this point in the history
- the Toggle File Watcher toolbar button and corresponding menu items are now checkable.
- moved the corresponding menu item to the File menu.
  • Loading branch information
dictoon committed Apr 13, 2014
1 parent ff66e56 commit 880b859
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 53 deletions.
75 changes: 39 additions & 36 deletions src/appleseed.studio/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void MainWindow::build_menus()
m_ui->action_file_save_project_as->setShortcut(QKeySequence::SaveAs);
connect(m_ui->action_file_save_project_as, SIGNAL(triggered()), SLOT(slot_save_project_as()));

connect(m_ui->action_watch_project_changes, SIGNAL(toggled(bool)), SLOT(slot_toggle_project_file_watcher(const bool)));

m_ui->action_file_exit->setShortcut(QKeySequence::Quit);
connect(m_ui->action_file_exit, SIGNAL(triggered()), SLOT(close()));

Expand Down Expand Up @@ -295,7 +297,6 @@ void MainWindow::build_menus()

connect(m_ui->action_tools_save_settings, SIGNAL(triggered()), SLOT(slot_save_settings()));
connect(m_ui->action_tools_reload_settings, SIGNAL(triggered()), SLOT(slot_load_settings()));
connect(m_ui->action_tools_toggle_file_watcher, SIGNAL(triggered()), SLOT(slot_toggle_file_watcher()));

//
// Help menu.
Expand Down Expand Up @@ -465,9 +466,10 @@ void MainWindow::build_toolbar()
connect(m_action_save_project, SIGNAL(triggered()), SLOT(slot_save_project()));
m_ui->main_toolbar->addAction(m_action_save_project);

m_action_toggle_file_watcher = new QAction(QIcon(":/icons/file_toggle_off.png"), "Toggle File Watcher", this);
connect(m_action_toggle_file_watcher, SIGNAL(triggered()), SLOT(slot_toggle_file_watcher()));
m_ui->main_toolbar->addAction(m_action_toggle_file_watcher);
m_action_toggle_project_watcher = new QAction(QIcon(":/icons/file_toggle.png"), "Toggle Project Watcher", this);
m_action_toggle_project_watcher->setCheckable(true);
connect(m_action_toggle_project_watcher, SIGNAL(toggled(bool)), SLOT(slot_toggle_project_file_watcher(const bool)));
m_ui->main_toolbar->addAction(m_action_toggle_project_watcher);

m_ui->main_toolbar->addSeparator();

Expand Down Expand Up @@ -540,6 +542,14 @@ void MainWindow::build_minimize_buttons()

void MainWindow::build_connections()
{
connect(
m_action_toggle_project_watcher, SIGNAL(toggled(bool)),
m_ui->action_watch_project_changes, SLOT(setChecked(bool)));

connect(
m_ui->action_watch_project_changes, SIGNAL(toggled(bool)),
m_action_toggle_project_watcher, SLOT(setChecked(bool)));

connect(
&m_project_manager, SIGNAL(signal_load_project_async_complete(const QString&, const bool)),
SLOT(slot_open_project_complete(const QString&, const bool)));
Expand Down Expand Up @@ -642,11 +652,6 @@ void MainWindow::set_file_widgets_enabled(const bool is_enabled)
m_ui->action_file_save_project->setEnabled(is_enabled && is_project_open);
m_action_save_project->setEnabled(is_enabled && is_project_open);
m_ui->action_file_save_project_as->setEnabled(is_enabled && is_project_open);

// Project File Watcher toolbar button.
m_ui->action_tools_toggle_file_watcher->setEnabled(
is_project_open &&
m_project_manager.get_project()->has_path());
}

void MainWindow::set_project_explorer_enabled(const bool is_enabled)
Expand Down Expand Up @@ -874,32 +879,30 @@ void MainWindow::on_project_change()

void MainWindow::enable_project_file_watcher()
{
assert(m_project_file_watcher == 0);

m_project_file_watcher = new QFileSystemWatcher(this);

connect(
m_project_file_watcher,
SIGNAL(fileChanged(const QString&)),
SLOT(slot_file_changed(const QString&)));
if (m_project_file_watcher == 0)
{
m_project_file_watcher = new QFileSystemWatcher(this);

m_action_toggle_file_watcher->setIcon(QIcon(":/icons/file_toggle_on.png"));
connect(
m_project_file_watcher,
SIGNAL(fileChanged(const QString&)),
SLOT(slot_project_file_changed(const QString&)));

RENDERER_LOG_INFO("the project file watcher is now enabled.");
RENDERER_LOG_INFO("the project file watcher is now enabled.");

start_watching_project_file();
start_watching_project_file();
}
}

void MainWindow::disable_project_file_watcher()
{
assert(m_project_file_watcher);

delete m_project_file_watcher;
m_project_file_watcher = 0;

m_action_toggle_file_watcher->setIcon(QIcon(":/icons/file_toggle_off.png"));
if (m_project_file_watcher)
{
delete m_project_file_watcher;
m_project_file_watcher = 0;

RENDERER_LOG_INFO("the project file watcher is now disabled.");
RENDERER_LOG_INFO("the project file watcher is now disabled.");
}
}

void MainWindow::start_watching_project_file()
Expand Down Expand Up @@ -1221,18 +1224,18 @@ void MainWindow::slot_project_modified()
update_window_title();
}

void MainWindow::slot_toggle_file_watcher()
void MainWindow::slot_toggle_project_file_watcher(const bool checked)
{
if (m_project_file_watcher)
disable_project_file_watcher();
else enable_project_file_watcher();
if (checked)
enable_project_file_watcher();
else disable_project_file_watcher();

m_settings.insert_path(
WATCH_FILE_CHANGES_SETTINGS_KEY,
m_project_file_watcher != 0);
}

void MainWindow::slot_file_changed(const QString& filepath)
void MainWindow::slot_project_file_changed(const QString& filepath)
{
RENDERER_LOG_INFO("project file changed on disk, reloading it.");

Expand Down Expand Up @@ -1265,13 +1268,13 @@ void MainWindow::slot_load_settings()

if (m_settings.get_optional<bool>(WATCH_FILE_CHANGES_SETTINGS_KEY))
{
if (m_project_file_watcher == 0)
enable_project_file_watcher();
m_action_toggle_project_watcher->setChecked(true);
enable_project_file_watcher();
}
else
{
if (m_project_file_watcher)
disable_project_file_watcher();
m_action_toggle_project_watcher->setChecked(false);
disable_project_file_watcher();
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/appleseed.studio/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MainWindow
QAction* m_action_start_interactive_rendering;
QAction* m_action_start_final_rendering;
QAction* m_action_stop_rendering;
QAction* m_action_toggle_file_watcher;
QAction* m_action_toggle_project_watcher;

std::vector<QAction*> m_recently_opened;
std::vector<MinimizeButton*> m_minimize_buttons;
Expand Down Expand Up @@ -206,8 +206,8 @@ class MainWindow
void slot_project_modified();

// Project file watcher.
void slot_toggle_file_watcher();
void slot_file_changed(const QString& filepath);
void slot_toggle_project_file_watcher(const bool checked);
void slot_project_file_changed(const QString& filepath);

// Settings I/O.
void slot_load_settings();
Expand Down
27 changes: 15 additions & 12 deletions src/appleseed.studio/mainwindow/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,13 @@
<addaction name="menu_file_open_builtin_project"/>
<addaction name="action_file_reload_project"/>
<addaction name="separator"/>
<addaction name="action_watch_project_changes"/>
<addaction name="separator"/>
<addaction name="action_file_save_project"/>
<addaction name="action_file_save_project_as"/>
<addaction name="separator"/>
<addaction name="action_file_exit"/>
</widget>
<widget class="QMenu" name="menu_navigation">
<property name="title">
<string>&amp;Navigation</string>
</property>
<addaction name="action_navigation_inspect"/>
<addaction name="action_navigation_fly"/>
<addaction name="action_navigation_freeze"/>
</widget>
<widget class="QMenu" name="menu_rendering">
<property name="title">
<string>&amp;Rendering</string>
Expand Down Expand Up @@ -127,7 +121,6 @@
</property>
<addaction name="action_tools_save_settings"/>
<addaction name="action_tools_reload_settings"/>
<addaction name="action_tools_toggle_file_watcher"/>
</widget>
<widget class="QMenu" name="menu_help">
<property name="title">
Expand All @@ -142,7 +135,6 @@
</widget>
<addaction name="menu_file"/>
<addaction name="menu_view"/>
<addaction name="menu_navigation"/>
<addaction name="menu_rendering"/>
<addaction name="menu_diagnostics"/>
<addaction name="menu_debug"/>
Expand Down Expand Up @@ -444,9 +436,20 @@
<string>Clear Menu</string>
</property>
</action>
<action name="action_tools_toggle_file_watcher">
<action name="action_tools_watch_file_changes">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Watch File Changes</string>
</property>
</action>
<action name="action_watch_project_changes">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Toggle File Watcher</string>
<string>Watch Project Changes</string>
</property>
</action>
</widget>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/appleseed.studio/resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<file>icons/cross_disable.png</file>
<file>icons/disk.png</file>
<file>icons/disk_disable.png</file>
<file>icons/file_toggle_off.png</file>
<file>icons/file_toggle_on.png</file>
<file>icons/file_toggle.png</file>
<file>icons/file_toggle_disable.png</file>
<file>icons/film_go.png</file>
<file>icons/film_go_disable.png</file>
<file>icons/folder.png</file>
Expand Down

0 comments on commit 880b859

Please sign in to comment.