Commit c9cc98f9 authored by Fabien Parent's avatar Fabien Parent
Browse files

Add syntax highlighting with gtksourceviewmm

parent 50ed43ca
......@@ -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])
......
......@@ -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_ (),
......
......@@ -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();
......
......@@ -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;
......
......@@ -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();
......
......@@ -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_);
......
......@@ -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_;
......
......@@ -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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment