changeset 15361:b4c32f245da7 draft default tip

GUI: Settings take immediate effect on the m-editor * main-window.cc (main_window::construct): connect settings change to file-editor * file-editor.h (file-editor::notice_settings): new notice settings method * file-editor.cc (file-editor::notice_settings): new notice settings method and pass-through to all file-editor-tabs * file-editor-tab.h (file-editor::notice_settings): new notice settings method * file-editor-tab.c (file_editor_tab::file_editor_tab): removed all settings to file-editor::notice_settings (file-editor::update_lexer): fix in case settings is 0 (should never happen) (file-editor::notice_settings): all settings moved here
author Thorsten Liebig <thorsten.liebig@gmx.de>
date Tue, 11 Sep 2012 22:19:51 +0200
parents 75f28de3a387
children
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc
diffstat 5 files changed, 78 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc
+++ b/libgui/src/m-editor/file-editor-tab.cc
@@ -49,10 +49,6 @@
 file_editor_tab::file_editor_tab(file_editor *fileEditor)
   : QWidget ((QWidget*)fileEditor), octave_event_observer ()
 {
-  QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
-
   _file_editor = fileEditor;
   _file_name = "";
   _edit_area = new QsciScintilla (this);
@@ -74,39 +70,27 @@
   // line numbers
   _edit_area->setMarginsForegroundColor(QColor(96,96,96));
   _edit_area->setMarginsBackgroundColor(QColor(232,232,220));
-  if (settings->value ("editor/showLineNumbers",true).toBool ())
-    {
-      QFont marginFont( settings->value ("editor/fontName","Courier").toString () ,
-                        settings->value ("editor/fontSize",10).toInt () );
-      _edit_area->setMarginsFont( marginFont );
-      QFontMetrics metrics(marginFont);
-      _edit_area->setMarginType (2, QsciScintilla::TextMargin);
-      _edit_area->setMarginWidth(2, metrics.width("9999"));
-      _edit_area->setMarginLineNumbers (2, true);
-    }
-
+  _edit_area->setMarginType (2, QsciScintilla::TextMargin);
+  
   // code folding
   _edit_area->setMarginType (3, QsciScintilla::SymbolMargin);
   _edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3);
 
+  //highlight current line color
+  _edit_area->setCaretLineBackgroundColor(QColor(245,245,245));
+
   // other features
-  if (settings->value ("editor/highlightCurrentLine",true).toBool ())
-    {
-      _edit_area->setCaretLineVisible(true);
-      _edit_area->setCaretLineBackgroundColor(QColor(245,245,245));
-    }
   _edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch);
   _edit_area->setAutoIndent (true);
   _edit_area->setIndentationWidth (2);
   _edit_area->setIndentationsUseTabs (false);
-  if (settings->value ("editor/codeCompletion",true).toBool ())
-    {
-      _edit_area->autoCompleteFromAll ();
-      _edit_area->setAutoCompletionSource(QsciScintilla::AcsAll);
-      _edit_area->setAutoCompletionThreshold (1);
-    }
+
   _edit_area->setUtf8 (true);
 
+  // auto completion
+  _edit_area->autoCompleteFromAll ();
+  _edit_area->setAutoCompletionSource(QsciScintilla::AcsAll);
+  
   QVBoxLayout *layout = new QVBoxLayout ();
   layout->addWidget (_edit_area);
   layout->setMargin (0);
@@ -121,8 +105,8 @@
            this, SLOT (file_has_changed (QString)));
 
   _file_name = "";
-  _long_title = settings->value ("editor/longWindowTitle",false).toBool ();
-  update_window_title (false);
+ 
+  notice_settings ();
 }
 
 bool
@@ -299,18 +283,17 @@
     {
       lexer = new QsciLexerBash ();
     }
-
+  
   QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
-
+  
   // Editor font (default or from settings)
-  lexer->setDefaultFont (QFont (
-                                settings->value ("editor/fontName",
-                                                 "Courier").toString (),
-                                settings->value ("editor/fontSize",
-                                                 10).toInt ()));
-
+  if (settings)
+    lexer->setDefaultFont (QFont (
+                             settings->value ("editor/fontName",
+                                              "Courier").toString (),
+                             settings->value ("editor/fontSize",
+                                              10).toInt ()));
+  
   // TODO: Autoindent not working as it should
   lexer->setAutoIndentStyle (QsciScintilla::AiMaintain ||
                              QsciScintilla::AiOpening  ||
@@ -831,3 +814,40 @@
         }
     }
 }
+
+void
+file_editor_tab::notice_settings ()
+{
+  QSettings *settings = resource_manager::get_settings ();
+  
+  if (settings==NULL)
+    return; // this shouldn't happen!
+  
+  _edit_area->setCaretLineVisible(settings->value ("editor/highlightCurrentLine",true).toBool ());
+  
+  if (settings->value ("editor/codeCompletion",true).toBool ())
+    _edit_area->setAutoCompletionThreshold (1);
+  else
+    _edit_area->setAutoCompletionThreshold (-1);
+  
+  QFont font( settings->value ("editor/fontName","Courier").toString () ,
+              settings->value ("editor/fontSize",10).toInt () );
+  if (settings->value ("editor/showLineNumbers",true).toBool ())
+    {
+      _edit_area->setMarginLineNumbers (2, true);
+      _edit_area->setMarginsFont( font );
+      QFontMetrics metrics( font );      
+      _edit_area->setMarginWidth(2, metrics.width("9999"));
+    }      
+  else
+    {
+      _edit_area->setMarginLineNumbers (2, false);
+      _edit_area->setMarginWidth(2, 0);
+    }      
+  
+  update_lexer ();
+  
+  _long_title = settings->value ("editor/longWindowTitle",false).toBool ();
+
+  update_window_title (false);  
+}
--- a/libgui/src/m-editor/file-editor-tab.h
+++ b/libgui/src/m-editor/file-editor-tab.h
@@ -74,6 +74,9 @@
 
   void file_has_changed (const QString& fileName);
   QString get_file_name () const {return _file_name;} 
+  
+  /** Tells the editor tab to react on changed settings. */
+  void notice_settings ();
 
 signals:
   void file_name_changed (const QString& fileName);
--- a/libgui/src/m-editor/file-editor.cc
+++ b/libgui/src/m-editor/file-editor.cc
@@ -373,6 +373,18 @@
 }
 
 void
+file_editor::notice_settings ()
+{
+  for(int i = 0; i < _tab_widget->count (); i++)
+    {
+      file_editor_tab *fileEditorTab
+          = dynamic_cast <file_editor_tab*> (_tab_widget->widget (i));
+      if (fileEditorTab)
+        fileEditorTab->notice_settings ();
+    } 
+}
+
+void
 file_editor::construct ()
 {
   QWidget *widget = new QWidget (this);
--- a/libgui/src/m-editor/file-editor.h
+++ b/libgui/src/m-editor/file-editor.h
@@ -93,6 +93,9 @@
   void handle_tab_close_request ();
   void active_tab_changed (int index);
   void handle_editor_state_changed ();
+  
+  /** Tells the editor to react on changed settings. */
+  void notice_settings ();
 
 private:
   void construct ();
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -833,6 +833,8 @@
   connect (reset_windows_action,        SIGNAL (triggered ()),
            this,                        SLOT   (reset_windows ()));
   connect (this,                        SIGNAL (settings_changed ()),
+           _file_editor,                SLOT   (notice_settings ()));
+  connect (this,                        SIGNAL (settings_changed ()),
            _files_dock_widget,          SLOT   (notice_settings ()));
   connect (this,                        SIGNAL (settings_changed ()),
            this,                        SLOT   (notice_settings ()));