FreeBasic
Главная
Вход
Регистрация
Пятница, 19.04.2024, 07:33Приветствую Вас Гость | RSS
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум » Freebasic » Исходники » GtkSourceView (виджет для gtk)
GtkSourceView
haavДата: Среда, 03.04.2019, 11:34 | Сообщение # 1
Генералиссимус
Группа: Администраторы
Сообщений: 1361
Репутация: 49
Статус: Offline
Когда-то еще до создания IUP_FB_EDITOR, я искал редактор с подсветкой, ну и натолкнулся на данный виджет. В принципе данный виджет представляет из себя расширенную версию GtkTextView с дополнительными плюшками. Как там управляться с данным виджетом , меня не спрашивайте, ибо я дальше этого исходника не ушел. Все что могу посоветовать, это оф. документацию . 

Это маленький пример работы с данным виджетом:

Код
#include "gtk/gtk.bi"

#inclib "gtksourceview-2.0"

extern "C"
    
    declare function gtk_source_language_manager_new() as any ptr
    
    declare function gtk_source_language_manager_get_language (as any ptr, as zstring ptr) as any ptr
    
    declare function gtk_source_buffer_new_with_language(as any ptr) as any ptr
    
    declare function gtk_source_view_new_with_buffer(as any ptr) as any ptr
    
    declare sub gtk_source_view_set_show_line_numbers(as any ptr , as Integer)
    
    declare sub gtk_source_view_set_auto_indent(as any ptr , as Integer)
    
    declare function gtk_source_language_manager_get_language_ids(as any ptr) as zstring ptr ptr
    
End Extern

gtk_init(0, 0)

dim as any ptr pWin = gtk_window_new (GTK_WINDOW_TOPLEVEL)

g_signal_connect(G_OBJECT(pWin), "destroy", G_CALLBACK (@gtk_main_quit), 0)

gtk_window_set_default_size (pWin, 500, 300)

gtk_window_set_position (pWin, GTK_WIN_POS_CENTER)

dim as any ptr pScroll = gtk_scrolled_window_new (NULL, NULL)

gtk_scrolled_window_set_policy (pScroll, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)

dim as any ptr pLM = gtk_source_language_manager_new()

dim as any ptr pLang = gtk_source_language_manager_get_language (pLM , "freebasic")

dim as any ptr sBuf = gtk_source_buffer_new_with_language(pLang)

g_object_ref (pLM)

g_object_set_data_full(sBuf, "languages-manager", pLM, NULL)

dim as any ptr pView = gtk_source_view_new_with_buffer(sBuf)

gtk_source_view_set_show_line_numbers(pView, TRUE)

gtk_source_view_set_auto_indent(pView, TRUE)

gtk_container_add(pScroll, pView)

gtk_container_add(pWin, pScroll)

gtk_widget_show_all(pScroll)

gtk_widget_show(pWin)

gtk_main()


Ниже freebasic.lang (брал отсюда) , если конечно хотите подсветку для FB:

Код
<?xml version="1.0" encoding="UTF-8"?>

<!--
 This file is part of GtkSourceView
 Author: John Luke <jluke@cfl.rr.com>, Daniel C. Klauer, Nicolas Kiely
 Copyright (C) 2004 John Luke <jluke@cfl.rr.com>
 Copyright (C) 2014 Daniel C. Klauer
 Copyright (C) 2014 Nicolas Kiely <mitchell3141@gmail.com>
 GtkSourceView is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 GtkSourceView is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-->
 
<!-- Place this file in ~/.local/share/gtksourceview-2.0/language-specs/ -->
 
<language id="freebasic" _name="FreeBASIC" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/x-freebasic</property>
    <property name="globs">*.bas;*.bi</property>
    <property name="line-comment-start">'</property>
    <property name="block-comment-start">/'</property>
    <property name="block-comment-end">'/</property>
  </metadata>
 
  <styles>
    <style id="comment" _name="Comment" map-to="def:comment"/>
    <style id="string" _name="String" map-to="def:string"/>
    <style id="preprocessor" _name="Preprocessor" map-to="def:preprocessor"/>
    <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    <style id="type" _name="Data Type" map-to="def:type"/>
    <style id="operator" _name="Operator" map-to="def:operator"/>
    <style id="storage-class" _name="Storage class" map-to="def:type"/>
    <style id="special-constant" _name="Special constant" map-to="def:special-constant"/>
    <style id="boolean" _name="Boolean value" map-to="def:boolean"/>
  </styles>
 
  <default-regex-options case-sensitive="false"/>
 
  <definitions>
 
    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
      <start>'</start>
      <include>
        <context ref="def:in-line-comment"/>
      </include>
    </context>
    
    <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
      <start>/'</start>
      <end>'/</end>
      <include>
        <context ref="def:in-comment"/>
      </include>
    </context>
 
    <context id="old-style-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
      <start>^rem</start>
      <include>
        <context ref="def:in-line-comment"/>
      </include>
    </context>
 
    <context id="string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
      <start>"</start>
      <end>"</end>
    </context>
 
    <context id="preprocessor" style-ref="preprocessor" end-at-line-end="true">
      <start>^#</start>
      <end>$</end>
      <include>
        <context ref="line-comment"/>
      </include>
    </context>
    
    <context id="built-in" style-ref="keyword">
      <keyword>close</keyword>
      <keyword>delete</keyword>
      <keyword>draw</keyword>
      <keyword>erase</keyword>
      <keyword>get</keyword>
      <keyword>input</keyword>
      <keyword>line</keyword>
      <keyword>new</keyword>
      <keyword>output</keyword>
      <keyword>print</keyword>
      <keyword>put</keyword>
      <keyword>sleep</keyword>
    </context>
    
    <context id="primitives" style-ref="type">
      <keyword>any</keyword>
      <keyword>byte</keyword>
      <keyword>double</keyword>
      <keyword>integer</keyword>
      <keyword>longint</keyword>
      <keyword>object</keyword>
      <keyword>pointer</keyword>
      <keyword>ptr</keyword>
      <keyword>short</keyword>
      <keyword>single</keyword>
      <keyword>string</keyword>
      <keyword>ubyte</keyword>
      <keyword>uinteger</keyword>
      <keyword>ulongint</keyword>
      <keyword>ushort</keyword>
      <keyword>wstring</keyword>
      <keyword>zstring</keyword>
    </context>
    
    <context id="storage-class" style-ref="storage-class">
      <keyword>class</keyword>
      <keyword>const</keyword>
      <keyword>enum</keyword>
      <keyword>extern</keyword>
      <keyword>friend</keyword>
      <keyword>private</keyword>
      <keyword>property</keyword>
      <keyword>protected</keyword>
      <keyword>public</keyword>
      <keyword>shared</keyword>
      <keyword>static</keyword>
      <keyword>type</keyword>
    </context>
    
    <context id="flow-control" style-ref="keyword">
      <keyword>case</keyword>
      <keyword>continue</keyword>
      <keyword>do</keyword>
      <keyword>else</keyword>
      <keyword>elseif</keyword>
      <keyword>end</keyword>
      <keyword>endif</keyword>
      <keyword>exit</keyword>
      <keyword>for</keyword>
      <keyword>goto</keyword>
      <keyword>if</keyword>
      <keyword>is</keyword>
      <keyword>loop</keyword>
      <keyword>next</keyword>
      <keyword>select</keyword>
      <keyword>step</keyword>
      <keyword>then</keyword>
      <keyword>to</keyword>
      <keyword>until</keyword>
      <keyword>wend</keyword>
      <keyword>while</keyword>
    </context>
    
    <context id="subroutine" style-ref="keyword">
      <keyword>byref</keyword>
      <keyword>byval</keyword>
      <keyword>call</keyword>
      <keyword>constructor</keyword>
      <keyword>declare</keyword>
      <keyword>destructor</keyword>
      <keyword>function</keyword>
      <keyword>return</keyword>
      <keyword>sub</keyword>
    </context>
    
    <context id="operator" style-ref="operator">
      <keyword>and</keyword>
      <keyword>andalso</keyword>
      <keyword>mod</keyword>
      <keyword>not</keyword>
      <keyword>or</keyword>
      <keyword>orelse</keyword>
      <keyword>xor</keyword>
    </context>
 
    <context id="keywords" style-ref="keyword">
      <keyword>alias</keyword>
      <keyword>ansi</keyword>
      <keyword>as</keyword>
      <keyword>binary</keyword>
      <keyword>cbyte</keyword>
      <keyword>cdbl</keyword>
      <keyword>cint</keyword>
      <keyword>clng</keyword>
      <keyword>cshort</keyword>
      <keyword>csng</keyword>
      <keyword>dim</keyword>
      <keyword>error</keyword>
      <keyword>event</keyword>
      <keyword>explicit</keyword>
      <keyword>let</keyword>
      <keyword>lib</keyword>
      <keyword>namespace</keyword>
      <keyword>on</keyword>
      <keyword>option</keyword>
      <keyword>optional</keyword>
      <keyword>preserve</keyword>
      <keyword>redim</keyword>
      <keyword>rem</keyword>
      <keyword>resume</keyword>
      <keyword>sizeof</keyword>
      <keyword>stop</keyword>
      <keyword>with</keyword>
    </context>
 
    <context id="freebasic" class="no-spell-check">
      <include>
        <context ref="line-comment"/>
        <context ref="block-comment"/>
        <context ref="old-style-comment"/>
        <context ref="string"/>
        <context ref="preprocessor"/>
        <context ref="built-in"/>
        <context ref="primitives"/>
        <context ref="storage-class"/>
        <context ref="flow-control"/>
        <context ref="subroutine"/>
        <context ref="operator"/>
        <context ref="keywords"/>
      </include>
    </context>
 
  </definitions>
 
</language>



Прикрепления: 6072475.png (57.1 Kb)


Вы сохраняете власть над людьми покуда оставляете им что-то…Отберите у человека все, и этот человек уже будет неподвластен вам…
 
Форум » Freebasic » Исходники » GtkSourceView (виджет для gtk)
  • Страница 1 из 1
  • 1
Поиск: