[pitivi] undo: Allow undo/redo the project's meta
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] undo: Allow undo/redo the project's meta
- Date: Sat, 16 Apr 2016 14:25:07 +0000 (UTC)
commit 68f040abb4689ba4341a9cdaa42c0c3418e4e1b3
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Apr 7 02:52:25 2016 +0200
undo: Allow undo/redo the project's meta
Differential Revision: https://phabricator.freedesktop.org/D895
pitivi/mainwindow.py | 7 ++++---
pitivi/project.py | 12 +++++++++++-
pitivi/render.py | 2 +-
pitivi/undo/project.py | 34 +++++++++++++++++-----------------
tests/test_undo_project.py | 42 +++++++++++++++++++++++++++++++++++++-----
5 files changed, 70 insertions(+), 27 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index c9124b3..419d625 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -44,6 +44,7 @@ from pitivi.dialogs.prefs import PreferencesDialog
from pitivi.effects import EffectListWidget
from pitivi.mediafilespreviewer import PreviewWidget
from pitivi.medialibrary import MediaLibraryWidget
+from pitivi.project import ProjectSettingsDialog
from pitivi.settings import GlobalSettings
from pitivi.tabsmanager import BaseTabs
from pitivi.timeline.timeline import TimelineContainer
@@ -588,9 +589,9 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
self.showProjectSettingsDialog()
def showProjectSettingsDialog(self):
- from pitivi.project import ProjectSettingsDialog
- ProjectSettingsDialog(
- self, self.app.project_manager.current_project).window.run()
+ project = self.app.project_manager.current_project
+ dialog = ProjectSettingsDialog(self, project, self.app)
+ dialog.window.run()
self.updateTitle()
def _menuCb(self, unused_action, unused_param):
diff --git a/pitivi/project.py b/pitivi/project.py
index 05c6ad0..fdaaedc 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1507,7 +1507,15 @@ class Project(Loggable, GES.Project):
class ProjectSettingsDialog(object):
- def __init__(self, parent_window, project):
+ """
+ UI for viewing and changing the project settings.
+
+ Attributes:
+ project (Project): The project who's settings are displayed.
+ """
+
+ def __init__(self, parent_window, project, app):
+ self.app = app
self.project = project
self.audio_presets = AudioPresetManager()
self.video_presets = VideoPresetManager()
@@ -1819,6 +1827,7 @@ class ProjectSettingsDialog(object):
self.year_spinbutton.get_adjustment().set_value(year)
def updateProject(self):
+ self.app.action_log.begin("change project settings")
self.project.name = self.title_entry.get_text()
self.project.author = self.author_entry.get_text()
self.project.year = str(self.year_spinbutton.get_value_as_int())
@@ -1831,6 +1840,7 @@ class ProjectSettingsDialog(object):
self.project.audiochannels = get_combo_value(self.channels_combo)
self.project.audiorate = get_combo_value(self.sample_rate_combo)
+ self.app.action_log.commit()
def _responseCb(self, unused_widget, response):
"""Handle the dialog being closed."""
diff --git a/pitivi/render.py b/pitivi/render.py
index 5b2bdd2..1d891ad 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -977,7 +977,7 @@ class RenderDialog(Loggable):
def _projectSettingsButtonClickedCb(self, unused_button):
from pitivi.project import ProjectSettingsDialog
- dialog = ProjectSettingsDialog(self.window, self.project)
+ dialog = ProjectSettingsDialog(self.window, self.project, self.app)
dialog.window.run()
def _audioOutputCheckbuttonToggledCb(self, unused_audio):
diff --git a/pitivi/undo/project.py b/pitivi/undo/project.py
index 8ef08ec..21859c5 100644
--- a/pitivi/undo/project.py
+++ b/pitivi/undo/project.py
@@ -66,21 +66,20 @@ class AssetRemovedAction(UndoableAction):
return st
-class ProjectSettingsChanged(UndoableAction):
+class MetaChangedAction(UndoableAction):
- def __init__(self, project, old, new):
+ def __init__(self, meta_container, item, current_value, new_value):
UndoableAction.__init__(self)
- self.project = project
- self.oldsettings = old
- self.newsettings = new
+ self.meta_container = meta_container
+ self.item = item
+ self.old_value = current_value
+ self.new_value = new_value
def do(self):
- self.project.setSettings(self.newsettings)
- self._done()
+ self.meta_container.set_meta(self.item, self.new_value)
def undo(self):
- self.project.setSettings(self.oldsettings)
- self._undone()
+ self.meta_container.set_meta(self.item, self.old_value)
class ProjectObserver():
@@ -99,19 +98,20 @@ class ProjectObserver():
Args:
project (Project): The project to be monitored.
"""
+ self.metas = {}
+ def set_meta(project, item, value):
+ self.metas[item] = value
+ project.foreach(set_meta)
+
project.connect("notify-meta", self._settingsChangedCb)
project.connect("asset-added", self._assetAddedCb)
project.connect("asset-removed", self._assetRemovedCb)
def _settingsChangedCb(self, project, item, value):
- """
- FIXME Renable undo/redo
- action = ProjectSettingsChanged(project, old, new)
- self.log.begin("change project settings")
- self.log.push(action)
- self.log.commit()
- """
- pass
+ current_value = self.metas.get(item)
+ action = MetaChangedAction(project, item, current_value, value)
+ self.metas[item] = value
+ self.action_log.push(action)
def _assetAddedCb(self, project, asset):
action = AssetAddedAction(project, asset)
diff --git a/tests/test_undo_project.py b/tests/test_undo_project.py
index dd88316..bc5faa5 100644
--- a/tests/test_undo_project.py
+++ b/tests/test_undo_project.py
@@ -21,20 +21,22 @@
from unittest import TestCase
from gi.repository import GES
+from gi.repository import Gtk
from pitivi.application import Pitivi
+from pitivi.project import ProjectSettingsDialog
from tests import common
class TestProjectUndo(TestCase):
def setUp(self):
- app = Pitivi()
- app._startupCb(app)
- self.assertTrue(app.project_manager.newBlankProject())
+ self.app = Pitivi()
+ self.app._startupCb(self.app)
+ self.assertTrue(self.app.project_manager.newBlankProject())
- self.project = app.project_manager.current_project
- self.action_log = app.action_log
+ self.project = self.app.project_manager.current_project
+ self.action_log = self.app.action_log
def test_new_project_has_nothing_to_undo(self):
mainloop = common.create_main_loop()
@@ -71,3 +73,33 @@ class TestProjectUndo(TestCase):
self.assertEqual(len(self.project.list_assets(GES.Extractable)), 0)
self.action_log.redo()
self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
+
+ def test_project_settings(self):
+ window = Gtk.Window()
+ dialog = ProjectSettingsDialog(parent_window=window,
+ project=self.project,
+ app=self.app)
+
+ def assert_meta(title, author, year):
+ self.assertEqual(self.project.name, title)
+ self.assertEqual(self.project.author, author)
+ self.assertEqual(self.project.year, year)
+
+
+ dialog.title_entry.set_text("t1")
+ dialog.author_entry.set_text("a1")
+ dialog.year_spinbutton.set_value(2001)
+ dialog.updateProject()
+ assert_meta("t1", "a1", "2001")
+
+ dialog.title_entry.set_text("t2")
+ dialog.author_entry.set_text("a2")
+ dialog.year_spinbutton.set_value(2002)
+ dialog.updateProject()
+ assert_meta("t2", "a2", "2002")
+
+ self.action_log.undo()
+ assert_meta("t1", "a1", "2001")
+
+ self.action_log.redo()
+ assert_meta("t2", "a2", "2002")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]