[regexxer] Add syntax highlighting with gtksourceviewmm
- From: Fabien Parent <fparent src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [regexxer] Add syntax highlighting with gtksourceviewmm
- Date: Mon, 21 Sep 2009 20:31:23 +0000 (UTC)
commit c9cc98f959514880d5f879346b50d6c0592dfbc2
Author: Fabien Parent <parent f gmail com>
Date: Tue Aug 4 22:05:13 2009 +0200
Add syntax highlighting with gtksourceviewmm
configure.ac | 2 +-
src/filebuffer.cc | 2 +-
src/filebuffer.h | 4 ++--
src/fileio.cc | 10 ++++++++++
src/main.cc | 4 ++++
src/mainwindow.cc | 9 +++++++--
src/mainwindow.h | 9 +++++++--
ui/mainwindow.ui | 7 +------
8 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2f7a71d..6479395 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ AM_GLIB_GNU_GETTEXT
# so that libglade can get at the custom widget creation functions.
PKG_CHECK_MODULES([REGEXXER_MODULES],
[gtk+-2.0 >= 2.16.0 gtkmm-2.4 >= 2.12.0 gconfmm-2.6 >= 2.6.1
- libpcre >= 5.0 gtksourceviewmm-2.0 >= 2.4])
+ libpcre >= 5.0 gtksourceviewmm-2.0 >= 2.3.1])
DK_PKG_PATH_PROG([GDK_PIXBUF_CSOURCE], [gdk-pixbuf-2.0], [gdk-pixbuf-csource])
DK_PKG_PATH_PROG([GTK_UPDATE_ICON_CACHE], [gtk+-2.0], [gtk-update-icon-cache])
diff --git a/src/filebuffer.cc b/src/filebuffer.cc
index 2f4642e..f1ce216 100644
--- a/src/filebuffer.cc
+++ b/src/filebuffer.cc
@@ -160,7 +160,7 @@ public:
FileBuffer::FileBuffer()
:
- Gtk::TextBuffer (RegexxerTags::instance()),
+ gtksourceview::SourceBuffer(Glib::RefPtr<Gtk::TextTagTable>(RegexxerTags::instance())),
match_set_ (),
current_match_ (match_set_.end()),
user_action_stack_ (),
diff --git a/src/filebuffer.h b/src/filebuffer.h
index 64bb45b..f4b542d 100644
--- a/src/filebuffer.h
+++ b/src/filebuffer.h
@@ -25,7 +25,7 @@
#include "signalutils.h"
#include "undostack.h"
-#include <gtkmm/textbuffer.h>
+#include <gtksourceviewmm/sourcebuffer.h>
#include <set>
#include <stack>
@@ -36,7 +36,7 @@ namespace Regexxer
class FileBufferActionRemoveMatch;
-class FileBuffer : public Gtk::TextBuffer
+class FileBuffer : public gtksourceview::SourceBuffer
{
public:
static Glib::RefPtr<FileBuffer> create();
diff --git a/src/fileio.cc b/src/fileio.cc
index 48376da..ada4d4f 100644
--- a/src/fileio.cc
+++ b/src/fileio.cc
@@ -25,8 +25,11 @@
#include <glib.h>
#include <glibmm.h>
+#include <giomm.h>
+#include <gtksourceviewmm.h>
#include <cstring>
+namespace Gsv=gtksourceview;
namespace
{
@@ -154,6 +157,13 @@ void load_file(const FileInfoPtr& fileinfo, const std::string& fallback_encoding
if (!buffer)
throw ErrorBinaryFile();
+ Glib::RefPtr<Gsv::SourceLanguageManager> language_manager = Gsv::SourceLanguageManager::create();
+
+ bool uncertain = false;
+ std::string content_type = Gio::content_type_guess(fileinfo->fullname, buffer->get_text(), uncertain);
+
+ buffer->set_highlight_syntax(true);
+ buffer->set_language(language_manager->guess_language(fileinfo->fullname, content_type));
buffer->set_modified(false);
fileinfo->encoding = encoding;
diff --git a/src/main.cc b/src/main.cc
index f59f9a4..6648379 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -34,6 +34,8 @@
#include <gtkmm/stock.h>
#include <gtkmm/stockitem.h>
#include <gtkmm/window.h>
+#include <gtksourceviewmm/init.h>
+#include <giomm/init.h>
#include <exception>
#include <list>
@@ -242,6 +244,8 @@ int main(int argc, char** argv)
std::auto_ptr<RegexxerOptions> options = RegexxerOptions::create();
Gtk::Main main_instance (argc, argv, options->context());
+ gtksourceview::init();
+ Gio::init();
Glib::set_application_name(PACKAGE_NAME);
register_stock_items();
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index edbbbfd..b404452 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -29,6 +29,7 @@
#include <glib.h>
#include <gtkmm.h>
+#include <gtksourceviewmm.h>
#include <gconfmm/client.h>
#include <algorithm>
#include <functional>
@@ -190,7 +191,8 @@ MainWindow::MainWindow()
button_caseless_ (0),
filetree_ (Gtk::manage(new FileTree())),
scrollwin_filetree_ (0),
- textview_ (0),
+ scrollwin_textview_ (0),
+ textview_ (Gtk::manage(new gtksourceview::SourceView())),
entry_preview_ (0),
statusline_ (Gtk::manage(new StatusLine())),
busy_action_running_ (false),
@@ -207,9 +209,12 @@ MainWindow::MainWindow()
scrollwin_filetree_->add(*filetree_);
table_file_->attach(*combo_entry_pattern_, 1, 2, 1, 2);
+ scrollwin_textview_->add(*textview_);
+
statusline_->show_all();
filetree_->show_all();
combo_entry_pattern_->show_all();
+ scrollwin_textview_->show_all();
connect_signals();
}
@@ -281,7 +286,7 @@ void MainWindow::load_xml()
xml->get_widget("entry_substitution", entry_substitution_);
xml->get_widget("button_multiple", button_multiple_);
xml->get_widget("button_caseless", button_caseless_);
- xml->get_widget("textview", textview_);
+ xml->get_widget("scrollwin_textview", scrollwin_textview_);
xml->get_widget("entry_preview", entry_preview_);
xml->get_widget("vbox_main", vbox_main_);
xml->get_widget("scrollwin_filetree", scrollwin_filetree_);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 315f772..a915e86 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -39,7 +39,6 @@ class CheckButton;
class Dialog;
class Entry;
class FileChooser;
-class TextView;
class Toolbar;
class Window;
class ComboBoxEntryText;
@@ -48,6 +47,11 @@ class ScrolledWindow;
class Table;
}
+namespace gtksourceview
+{
+class SourceView;
+}
+
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
@@ -107,7 +111,8 @@ private:
FileTree* filetree_;
Gtk::ScrolledWindow* scrollwin_filetree_;
- Gtk::TextView* textview_;
+ Gtk::ScrolledWindow* scrollwin_textview_;
+ gtksourceview::SourceView* textview_;
Gtk::Entry* entry_preview_;
StatusLine* statusline_;
diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui
index d00fcf9..5c4a855 100644
--- a/ui/mainwindow.ui
+++ b/ui/mainwindow.ui
@@ -674,12 +674,7 @@
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkTextView" id="textview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">False</property>
- <property name="cursor_visible">False</property>
- </object>
+ <placeholder/>
</child>
</object>
<packing>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]