]> git.lyx.org Git - features.git/commitdiff
Transfer readOnly() and updateWindowTitle() from Delegates to WorkArea/WorkAreaManage...
authorAbdelrazak Younes <younes@lyx.org>
Sun, 11 Nov 2007 22:30:21 +0000 (22:30 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 11 Nov 2007 22:30:21 +0000 (22:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21551 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/Buffer.cpp
src/frontends/Delegates.h
src/frontends/LyXView.cpp
src/frontends/LyXView.h
src/frontends/WorkArea.cpp
src/frontends/WorkArea.h
src/frontends/WorkAreaManager.cpp
src/frontends/WorkAreaManager.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index edb0684b739a678a8623e1d82cbe9d42e892f26e..8ee9e09764bbce423a9c1098f98ce450544ec84e 100644 (file)
@@ -1996,15 +1996,15 @@ void Buffer::setBusy(bool on) const
 
 void Buffer::setReadOnly(bool on) const
 {
-       if (gui_)
-               gui_->setReadOnly(on);
+       if (pimpl_->wa_)
+               pimpl_->wa_->setReadOnly(on);
 }
 
 
 void Buffer::updateTitles() const
 {
-       if (gui_)
-               gui_->updateTitles();
+       if (pimpl_->wa_)
+               pimpl_->wa_->updateTitles();
 }
 
 
index 3c75c66c4ba9944f810f1b8e8660e0aa97697749..270e4fabf189576bcdd863dfd35eeb9b4a26107a 100644 (file)
@@ -59,10 +59,6 @@ public:
        virtual void message(docstring const &) = 0;
        /// This function is called when the buffer busy status change.
        virtual void setBusy(bool) = 0;
-       /// This function is called when the buffer readonly status change.
-       virtual void setReadOnly(bool) = 0;
-       /// Update window titles of all users.
-       virtual void updateTitles() = 0;
        /// Reset autosave timers for all users.
        virtual void resetAutosaveTimers() = 0;
 };
index 9d9029dd575b98c7d901e5c20fe8bbd988303ead..eeceb2f2fbadf4eefaafa1e977ec11646dfd8791 100644 (file)
@@ -217,13 +217,6 @@ void LyXView::updateDialog(string const & name, string const & data)
 }
 
 
-void LyXView::setReadOnly(bool)
-{
-       updateWindowTitle();
-       getDialogs().updateBufferDependent(false);
-}
-
-
 BufferView * LyXView::view()
 {
        WorkArea * wa = currentWorkArea();
@@ -259,30 +252,6 @@ void LyXView::resetAutosaveTimer()
 }
 
 
-void LyXView::updateWindowTitle()
-{
-       docstring maximize_title = from_ascii("LyX");
-       docstring minimize_title = from_ascii("LyX");
-
-       Buffer * buf = buffer();
-       if (buf) {
-               string const cur_title = buf->absFileName();
-               if (!cur_title.empty()) {
-                       maximize_title += ": " + makeDisplayPath(cur_title, 30);
-                       minimize_title = lyx::from_utf8(onlyFilename(cur_title));
-                       if (!buf->isClean()) {
-                               maximize_title += _(" (changed)");
-                               minimize_title += char_type('*');
-                       }
-                       if (buf->isReadonly())
-                               maximize_title += _(" (read only)");
-               }
-       }
-
-       setWindowTitle(maximize_title, minimize_title);
-}
-
-
 void LyXView::dispatch(FuncRequest const & cmd)
 {
        string const argument = to_utf8(cmd.argument());
index 29508f2ef3ed14eb52614215fa0cf4446e2b4c49..433074a958c556330bade294159081bc094c6bba 100644 (file)
@@ -158,9 +158,6 @@ public:
        /// clear any temporary message and replace with current status
        virtual void clearMessage() = 0;
 
-       /// updates the title of the window
-       void updateWindowTitle();
-
        /// reset autosave timer
        void resetAutosaveTimer();
 
@@ -186,10 +183,6 @@ public:
        void structureChanged() { updateToc(); }
        /// This function is called when some parsing error shows up.
        void errors(std::string const & err) { showErrorList(err); }
-       /// This function is called when the buffer readonly status change.
-       void setReadOnly(bool on);
-       /// Update window titles of all users.
-       void updateTitles() { updateWindowTitle(); }
        /// Reset autosave timers for all users.
        void resetAutosaveTimers() { resetAutosaveTimer(); }
 
@@ -203,13 +196,6 @@ public:
        void disconnectBuffer();
 
 private:
-       /**
-        * setWindowTitle - set title of window
-        * @param t main window title
-        * @param it iconified (short) title
-        */
-       virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
-
        /// called on timeout
        void autoSave();
 
index c791877ac660344abfd853aae49a7e030077958b..849cadeaec6e7608693b959ae301ad76d92f26bf 100644 (file)
@@ -16,6 +16,7 @@
 #include "frontends/WorkArea.h"
 
 #include "frontends/Application.h"
+#include "frontends/Dialogs.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/LyXView.h"
 #include "frontends/WorkAreaManager.h"
 #include "MetricsInfo.h"
 
 #include "gettext.h"
-#include "support/ForkedcallsController.h"
 #include "support/FileName.h"
+#include "support/filetools.h"
+#include "support/ForkedcallsController.h"
 
 #include <boost/noncopyable.hpp>
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 
-using lyx::support::ForkedcallsController;
-
 using std::endl;
 using std::min;
 using std::max;
@@ -62,6 +62,11 @@ boost::signals::connection timecon;
 } // anon namespace
 
 namespace lyx {
+
+using support::ForkedcallsController;
+using support::makeDisplayPath;
+using support::onlyFilename;
+
 namespace frontend {
 
 WorkArea::WorkArea(Buffer & buffer, LyXView & lv)
@@ -311,5 +316,34 @@ void WorkArea::toggleCursor()
        cursor_timeout_.restart();
 }
 
+void WorkArea::updateWindowTitle()
+{
+       docstring maximize_title;
+       docstring minimize_title;
+
+       Buffer & buf = buffer_view_->buffer();
+       string const cur_title = buf.absFileName();
+       if (!cur_title.empty()) {
+               maximize_title = makeDisplayPath(cur_title, 30);
+               minimize_title = from_utf8(onlyFilename(cur_title));
+               if (!buf.isClean()) {
+                       maximize_title += _(" (changed)");
+                       minimize_title += char_type('*');
+               }
+               if (buf.isReadonly())
+                       maximize_title += _(" (read only)");
+       }
+
+       setWindowTitle(maximize_title, minimize_title);
+}
+
+
+void WorkArea::setReadOnly(bool)
+{
+       updateWindowTitle();
+       if (this == lyx_view_->currentWorkArea())
+               lyx_view_->getDialogs().updateBufferDependent(false);
+}
+
 } // namespace frontend
 } // namespace lyx
index 74a875f241f83141cd65b1589b14f4c662d8a192..306b655532b6bad3b91045067c4447bdf876ccad 100644 (file)
@@ -104,9 +104,23 @@ public:
        /// Slot for Buffer::closing signal.
        void close();
 
+       /// This function is called when the buffer readonly status change.
+       virtual void setReadOnly(bool);
+
+       /// Update window titles of all users.
+       virtual void updateWindowTitle();
+
 protected:
        /// cause the display of the given area of the work area
        virtual void expose(int x, int y, int w, int h) = 0;
+
+       /// set title of window.
+       /**
+        * @param t main window title
+        * @param it iconified (short) title
+        */
+       virtual void setWindowTitle(docstring const & t, docstring const & it) = 0;
+
        ///
        void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
 
index 4957f7bc3ba820a436fda29f20d5f0efde2d263c..e3c8d3e2a774a307994f4cb935dcac7ff1567ab3 100644 (file)
@@ -52,6 +52,26 @@ void WorkAreaManager::closeAll()
                (*work_areas_.begin())->close();
 }
 
+
+void WorkAreaManager::setReadOnly(bool on)
+{
+       for (list<WorkArea *>::iterator it = work_areas_.begin();
+               it != work_areas_.end(); ) {
+               (*it)->setReadOnly(on);
+               ++it;
+       }
+}
+
+
+void WorkAreaManager::updateTitles()
+{
+       for (list<WorkArea *>::iterator it = work_areas_.begin();
+               it != work_areas_.end(); ) {
+               (*it)->updateWindowTitle();
+               ++it;
+       }
+}
+
 } // namespace frontend
 } // namespace lyx
 
index f2c93be019375169bd9b5e44e159bf31b19530cd..00f7de53fe3eec9eb63678a395f617dcad161192 100644 (file)
@@ -42,6 +42,12 @@ public:
        ///
        void closeAll();
 
+       /// This function is called when the buffer readonly status change.
+       virtual void setReadOnly(bool);
+
+       /// Update window titles of all users.
+       virtual void updateTitles();
+
 private:
        std::list<WorkArea *> work_areas_;
 };
index 02dced7e54819efef4aac9de421c5a43fe33aaad..c79fc1a319a225644df4fa58c5b4ba47ea411453 100644 (file)
@@ -76,8 +76,6 @@ using std::vector;
 
 namespace lyx {
 
-using support::makeDisplayPath;
-
 extern bool quitting;
 
 namespace frontend {
@@ -541,10 +539,6 @@ void GuiView::setGeometry(unsigned int width,
        
        show();
 
-       // For an unknown reason, the Window title update is not effective for
-       // the second windows up until it is shown on screen (Qt bug?).
-       updateWindowTitle();
-
        // after show geometry() has changed (Qt bug?)
        // we compensate the drift when storing the position
        d.posx_offset = 0;
@@ -566,23 +560,6 @@ void GuiView::setGeometry(unsigned int width,
 }
 
 
-void GuiView::setWindowTitle(docstring const & t, docstring const & it)
-{
-       QString title = windowTitle();
-       QString new_title = toqstr(t);
-       if (title != new_title) {
-               QMainWindow::setWindowTitle(new_title);
-               QMainWindow::setWindowIconText(toqstr(it));
-       }
-       if (Buffer const * buf = buffer()) {
-               QString tabtext = toqstr(buf->fileName().displayName(30));
-               d.current_work_area_->setWindowTitle(tabtext);
-               TabWorkArea * twa = d.currentTabWorkArea();
-               twa->setTabText(twa->currentIndex(), tabtext);
-       }
-}
-
-
 void GuiView::message(docstring const & str)
 {
        statusBar()->showMessage(toqstr(str));
@@ -632,12 +609,25 @@ void GuiView::update_view_state_qt()
 }
 
 
+void GuiView::updateWindowTitle(GuiWorkArea * wa)
+{
+       if (wa != d.current_work_area_)
+               return;
+       setWindowTitle(qt_("LyX: ") + wa->windowTitle());
+       setWindowIconText(wa->windowIconText());
+}
+
+
 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
 {
        disconnectBuffer();
        disconnectBufferView();
        connectBufferView(wa->bufferView());
        connectBuffer(wa->bufferView().buffer());
+       d.current_work_area_ = wa;
+       QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
+               this, SLOT(updateWindowTitle(GuiWorkArea *)));
+       updateWindowTitle(wa);
 
        updateToc();
        // Buffer-dependent dialogs should be updated or
@@ -646,7 +636,6 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
        getDialogs().updateBufferDependent(true);
        updateToolbars();
        updateLayoutChoice(false);
-       updateWindowTitle();
        updateStatusBar();
 }
 
@@ -724,8 +713,10 @@ bool GuiView::event(QEvent * e)
                        connectBuffer(bv.buffer());
                        // The document structure, name and dialogs might have
                        // changed in another view.
-                       updateWindowTitle();
                        getDialogs().updateBufferDependent(true);
+               } else {
+                       setWindowTitle(qt_("LyX"));
+                       setWindowIconText(qt_("LyX"));
                }
                return QMainWindow::event(e);
        }
@@ -762,8 +753,8 @@ bool GuiView::focusNextPrevChild(bool /*next*/)
 
 void GuiView::showView()
 {
-       QMainWindow::setWindowTitle(qt_("LyX"));
-       QMainWindow::show();
+       setWindowTitle(qt_("LyX"));
+       show();
        updateFloatingGeometry();
 }
 
@@ -853,7 +844,10 @@ WorkArea * GuiView::addWorkArea(Buffer & buffer)
                addTabWorkArea();
 
        TabWorkArea * tab_widget = d.currentTabWorkArea();
-       tab_widget->addTab(wa, toqstr(buffer.fileName().displayName(30)));
+       tab_widget->addTab(wa, wa->windowTitle());
+       QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
+               tab_widget, SLOT(updateTabText(GuiWorkArea *)));
+
        wa->bufferView().updateMetrics();
 
        // Hide tabbar if there's only one tab.
index 14bf01a2e6d8919c1284978d2217547d7ed37fe1..78a7859a242bc400ba8c9742d384d3d2a5b4a587 100644 (file)
@@ -99,6 +99,9 @@ public Q_SLOTS:
        /// idle timeout
        void update_view_state_qt();
 
+       ///
+       void updateWindowTitle(GuiWorkArea * wa);
+
        ///
        void on_currentWorkAreaChanged(GuiWorkArea *);
 
@@ -134,13 +137,6 @@ private:
        ///
        void dropEvent(QDropEvent * ev);
 
-       /**
-        * setWindowTitle - set title of window
-        * @param t main window title
-        * @param it iconified (short) title
-        */
-       virtual void setWindowTitle(docstring const & t, docstring const & it);
-
        /// in order to catch Tab key press.
        bool event(QEvent * e);
        bool focusNextPrevChild(bool);
index a6206460bf2adb4c726d925f0366c6c1109640b9..e6deea60bd0a047427941988375ed5f36a27b701 100644 (file)
@@ -187,6 +187,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buf, LyXView & lv)
        setAcceptDrops(true);
        setMouseTracking(true);
        setMinimumSize(100, 70);
+       updateWindowTitle();
 
        viewport()->setAutoFillBackground(false);
        // We don't need double-buffering nor SystemBackground on
@@ -496,6 +497,19 @@ void GuiWorkArea::expose(int x, int y, int w, int h)
 }
 
 
+void GuiWorkArea::setWindowTitle(docstring const & t, docstring const & it)
+{
+       QString title = windowTitle();
+       QString new_title = toqstr(t);
+       if (title == new_title)
+               return;
+
+       QWidget::setWindowTitle(new_title);
+       QWidget::setWindowIconText(toqstr(it));
+       titleChanged(this);
+}
+
+
 void GuiWorkArea::updateScreen()
 {
        GuiPainter pain(&screen_);
@@ -827,6 +841,15 @@ void TabWorkArea::closeCurrentTab()
        lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
 }
 
+
+void TabWorkArea::updateTabText(GuiWorkArea * wa)
+{
+       int const i = indexOf(wa);
+       if (i < 0)
+               return;
+       setTabText(i, wa->windowTitle());
+}
+
 } // namespace frontend
 } // namespace lyx
 
index d6ad4baa3f0d3bee7d3f8a63fc31055212a455b5..ae1f752601a392cc03d1c9d4a0643e72c594d187 100644 (file)
@@ -117,6 +117,12 @@ public:
        /// hide the cursor
        virtual void removeCursor();
 
+       void setWindowTitle(docstring const & t, docstring const & it);
+
+Q_SIGNALS:
+       ///
+       void titleChanged(GuiWorkArea *);
+
 private:
        ///
        void focusInEvent(QFocusEvent *);
@@ -183,6 +189,7 @@ class TabWorkArea : public QTabWidget
        Q_OBJECT
 public:
        TabWorkArea(QWidget * parent = 0);
+
        void showBar(bool show);
        void closeAll();
        bool setCurrentWorkArea(GuiWorkArea *);
@@ -199,6 +206,8 @@ public Q_SLOTS:
        void on_currentTabChanged(int index);
        ///
        void closeCurrentTab();
+       ///
+       void updateTabText(GuiWorkArea *);
 }; // TabWorkArea
 
 } // namespace frontend