/[svn]/gigedit/trunk/src/gigedit/scripteditor.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/scripteditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2939 by schoenebeck, Mon Jul 11 17:58:33 2016 UTC revision 2956 by schoenebeck, Sat Jul 16 15:31:47 2016 UTC
# Line 148  ScriptEditor::ScriptEditor() : Line 148  ScriptEditor::ScriptEditor() :
148      m_actionGroup->add(Gtk::Action::create("Close", _("_Close")),      m_actionGroup->add(Gtk::Action::create("Close", _("_Close")),
149                         Gtk::AccelKey("<control>q"),                         Gtk::AccelKey("<control>q"),
150                         sigc::mem_fun(*this, &ScriptEditor::onButtonCancel));                         sigc::mem_fun(*this, &ScriptEditor::onButtonCancel));
151        m_actionGroup->add(Gtk::Action::create("MenuEditor", _("_Editor")));
152        m_actionGroup->add(Gtk::Action::create("ChangeFont", _("_Font Size ...")),
153                           sigc::mem_fun(*this, &ScriptEditor::onMenuChangeFontSize));
154      m_uiManager = Gtk::UIManager::create();      m_uiManager = Gtk::UIManager::create();
155      m_uiManager->insert_action_group(m_actionGroup);      m_uiManager->insert_action_group(m_actionGroup);
156      add_accel_group(m_uiManager->get_accel_group());      add_accel_group(m_uiManager->get_accel_group());
# Line 159  ScriptEditor::ScriptEditor() : Line 162  ScriptEditor::ScriptEditor() :
162          "      <separator/>"          "      <separator/>"
163          "      <menuitem action='Close'/>"          "      <menuitem action='Close'/>"
164          "    </menu>"          "    </menu>"
165            "    <menu action='MenuEditor'>"
166            "      <menuitem action='ChangeFont'/>"
167            "    </menu>"
168          "  </menubar>"          "  </menubar>"
169          "</ui>"          "</ui>"
170      );      );
171    
172      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);
173      m_textView.set_buffer(m_textBuffer);      m_textView.set_buffer(m_textBuffer);
174      {      setFontSize(currentFontSize(), false);
         Pango::FontDescription fdesc;  
         fdesc.set_family("monospace");  
 #if defined(__APPLE__)  
         fdesc.set_size(14 * PANGO_SCALE);  
 #else  
         fdesc.set_size(10 * PANGO_SCALE);  
 #endif  
 #if GTKMM_MAJOR_VERSION < 3  
         m_textView.modify_font(fdesc);  
 #else  
         m_textView.override_font(fdesc);  
 #endif  
     }  
175      m_scrolledWindow.add(m_textView);      m_scrolledWindow.add(m_textView);
176      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
177    
# Line 247  ScriptEditor::~ScriptEditor() { Line 240  ScriptEditor::~ScriptEditor() {
240  #endif  #endif
241  }  }
242    
243    int ScriptEditor::currentFontSize() const {
244    #if defined(__APPLE__)
245        const int defaultFontSize = 14;
246    #else
247        const int defaultFontSize = 10;
248    #endif
249        const int settingFontSize = Settings::singleton()->scriptEditorFontSize;
250        const int fontSize = (settingFontSize > 0) ? settingFontSize : defaultFontSize;
251        return fontSize;
252    }
253    
254    void ScriptEditor::setFontSize(int size, bool save) {
255        //printf("setFontSize(%d,%d)\n", size, save);
256        Pango::FontDescription fdesc;
257        fdesc.set_family("monospace");
258        fdesc.set_size(size * PANGO_SCALE);
259    #if GTKMM_MAJOR_VERSION < 3
260        m_textView.modify_font(fdesc);
261    #else
262        m_textView.override_font(fdesc);
263    #endif
264        if (save) Settings::singleton()->scriptEditorFontSize = size;
265    }
266    
267  void ScriptEditor::setScript(gig::Script* script) {  void ScriptEditor::setScript(gig::Script* script) {
268      m_script = script;      m_script = script;
269      if (!script) {      if (!script) {
# Line 501  bool ScriptEditor::on_motion_notify_even Line 518  bool ScriptEditor::on_motion_notify_even
518      return ManagedWindow::on_motion_notify_event(e);      return ManagedWindow::on_motion_notify_event(e);
519  }  }
520    
521    void ScriptEditor::onMenuChangeFontSize() {
522        //TODO: for GTKMM >= 3.2 class Gtk::FontChooser could be used instead
523        Gtk::Dialog dialog(_("Font Size"), true /*modal*/);
524        Gtk::HBox hbox;
525        hbox.set_spacing(6);
526    
527        Gtk::Label label(_("Editor's Font Size:"), Gtk::ALIGN_START);
528        hbox.pack_start(label, Gtk::PACK_SHRINK);
529    
530        Gtk::SpinButton spinButton;
531        spinButton.set_range(4, 80);
532        spinButton.set_increments(1, 10);
533        spinButton.set_value(currentFontSize());
534        hbox.pack_start(spinButton);
535    
536        dialog.get_vbox()->pack_start(hbox);
537        dialog.add_button(_("_OK"), 0);
538        dialog.add_button(_("_Cancel"), 1);
539    
540        dialog.show_all_children();
541    
542        if (!dialog.run()) { // OK selected ...
543            const int newFontSize = spinButton.get_value_as_int();
544            if (newFontSize >= 4)
545                setFontSize(newFontSize, true);
546        }
547    }
548    
549  bool ScriptEditor::onWindowDelete(GdkEventAny* e) {  bool ScriptEditor::onWindowDelete(GdkEventAny* e) {
550      //printf("onWindowDelete\n");      //printf("onWindowDelete\n");
551    

Legend:
Removed from v.2939  
changed lines
  Added in v.2956

  ViewVC Help
Powered by ViewVC