[pitivi] mainwindow: Allow editing the project name by clicking it



commit 6e656777dec9569ecf6ca98d14a7ee1fd6b8d2d7
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Wed Nov 25 12:04:50 2015 +0100

    mainwindow: Allow editing the project name by clicking it
    
    Fixes https://phabricator.freedesktop.org/T3375
    
    Maniphest Tasks: T3191, T3375
    
    Reviewers: thiblahute
    
    Differential Revision: https://phabricator.freedesktop.org/D403

 pitivi/mainwindow.py |   43 ++++++++++++++++++++++++++++++++++++++++++-
 pitivi/project.py    |    7 ++++++-
 2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index fb4b27f..b49b1dd 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -1289,9 +1289,50 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
             title = "%s%s — %s" % (unsaved_mark, name, APPNAME)
         else:
             title = APPNAME
-        self._headerbar.set_title(title)
+        event_box = Gtk.EventBox()
+        label = Gtk.Label()
+        label.set_text(title)
+        event_box.add(label)
+        event_box.show_all()
+        event_box.connect("button-press-event", self.__titleClickCb, project)
+        self._headerbar.set_custom_title(event_box)
         self.set_title(title)
 
+    def __titleClickCb(self, unused_widget, unused_event, project):
+        entry = Gtk.Entry()
+        entry.set_width_chars(100)
+        entry.set_margin_left(SPACING)
+        entry.set_margin_right(SPACING)
+        entry.show()
+        entry.set_text(project.name)
+        self._headerbar.set_custom_title(entry)
+        if project.hasDefaultName():
+            entry.grab_focus()
+        else:
+            entry.grab_focus_without_selecting()
+        entry.connect("focus-out-event", self.__titleChangedCb, project)
+        entry.connect("key_release_event", self.__titleTypeCb, project)
+
+    def __titleChangedCb(self, widget, event, project):
+        if not event.window:
+            # Workaround https://bugzilla.gnome.org/show_bug.cgi?id=757036
+            return
+        name = widget.get_text()
+        if project.name == name:
+            self.updateTitle()
+        else:
+            project.name = name
+
+    def __titleTypeCb(self, widget, event, project):
+        if event.keyval == Gdk.KEY_Return:
+            self.timeline_ui.grab_focus()
+            return True
+        elif event.keyval == Gdk.KEY_Escape:
+            widget.set_text(project.name)
+            self.timeline_ui.grab_focus()
+            return True
+        return False
+
 
 class PreviewAssetWindow(Gtk.Window):
 
diff --git a/pitivi/project.py b/pitivi/project.py
index 20e6641..37648ea 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -54,6 +54,7 @@ from pitivi.preset import AudioPresetManager, VideoPresetManager
 from pitivi.render import CachedEncoderList
 
 
+DEFAULT_NAME = _("New Project")
 DEFAULT_MUXER = "oggmux"
 DEFAULT_VIDEO_ENCODER = "theoraenc"
 DEFAULT_AUDIO_ENCODER = "vorbisenc"
@@ -588,7 +589,7 @@ class ProjectManager(GObject.Object, Loggable):
         self.__missing_uris = False
         if emission:
             self.emit("new-project-loading", None)
-        project = Project(self.app, name=_("New Project"))
+        project = Project(self.app, name=DEFAULT_NAME)
 
         # setting default values for project metadata
         project.author = getpwuid(os.getuid()).pw_gecos.split(",")[0]
@@ -1101,6 +1102,10 @@ class Project(Loggable, GES.Project):
     # ------------------------------------------ #
     # Our API                                    #
     # ------------------------------------------ #
+
+    def hasDefaultName(self):
+        return DEFAULT_NAME == self.name
+
     def _commit(self):
         """
         Our override of the GES.Timeline.commit method, letting us


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]