1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4 
5 #ifndef PLAT_GTK
6 #   define PLAT_GTK 1
7 #endif
8 
9 #include <gtk/gtk.h>
10 
11 #include "cssedwindow.h"
12 #include "document.h"
13 #include "file-type-manager.h"
14 #include "support.h"
15 #include "debug.h"
16 #include "utils.h"
17 
18 #include <Scintilla.h>
19 #include <SciLexer.h>
20 #include <ScintillaWidget.h>
21 
22 void
filetype_python_char_added(CssedDoc * doc,gchar lastchar)23 filetype_python_char_added(CssedDoc* doc, gchar  lastchar)
24 {
25 	if( lastchar == '\n')
26 		document_indent_as_last_line(doc);
27 }
28 
29 void
filetype_python_set_style(CssedDoc * doc)30 filetype_python_set_style(CssedDoc* doc)
31 {
32 	ScintillaObject * sci;
33 	CssedWindow* window;
34 	CssedConfig* cfg;
35 	GtkWidget *scintilla;
36 
37 	const gchar pyKeyWords[] = "and assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while yield";
38 
39 	window = document_get_window(doc);
40 	cfg = cssed_window_get_config(window);
41 	scintilla = document_get_scintilla_widget(doc);
42 	sci = SCINTILLA(scintilla);
43 
44 	SSM (sci, SCI_SETPROPERTY, (sptr_t) "fold.commnent.python", (sptr_t) "1");
45 	SSM (sci, SCI_SETPROPERTY, (sptr_t) "fold.quotes.python", (sptr_t) "1");
46 
47 	SSM (sci, SCI_STYLECLEARALL, 0, 0);
48 	SSM (sci, SCI_SETLEXER, SCLEX_PYTHON, 0);
49 
50 	SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) pyKeyWords);
51 
52 	// on python indentation matters
53 	SSM(sci, SCI_SETINDENTATIONGUIDES, TRUE, 0);
54 
55 	SSM(sci, SCI_STYLESETFORE, SCE_P_DEFAULT, 0x000000);
56 	SSM(sci, SCI_STYLESETBACK, SCE_P_DEFAULT, 0xffffff);
57 
58 	SSM(sci, SCI_STYLESETFORE, SCE_P_COMMENTLINE, 0x808080);
59 	SSM(sci, SCI_STYLESETBACK, SCE_P_COMMENTLINE, 0xffffff);
60 
61 	SSM(sci, SCI_STYLESETFORE, SCE_P_NUMBER, 0x800040);
62 	SSM(sci, SCI_STYLESETBACK, SCE_P_NUMBER, 0xffffff);
63 
64 	SSM(sci, SCI_STYLESETFORE, SCE_P_STRING, 0x008000);
65 	SSM(sci, SCI_STYLESETBACK, SCE_P_STRING, 0xffffff);
66 
67 	SSM(sci, SCI_STYLESETFORE, SCE_P_CHARACTER, 0x008000);
68 	SSM(sci, SCI_STYLESETBACK, SCE_P_CHARACTER, 0xffffff);
69 
70 	SSM(sci, SCI_STYLESETFORE, SCE_P_WORD, 0x800060);
71 	SSM(sci, SCI_STYLESETBACK, SCE_P_WORD, 0xffffff);
72 
73 	SSM(sci, SCI_STYLESETFORE, SCE_P_TRIPLE, 0x208000);
74 	SSM(sci, SCI_STYLESETBACK, SCE_P_TRIPLE, 0xffffff);
75 
76 	SSM(sci, SCI_STYLESETFORE, SCE_P_TRIPLEDOUBLE, 0x004040);
77 	SSM(sci, SCI_STYLESETBACK, SCE_P_TRIPLEDOUBLE, 0xffffff);
78 
79 	SSM(sci, SCI_STYLESETFORE, SCE_P_CLASSNAME, 0x303000);
80 	SSM(sci, SCI_STYLESETBACK, SCE_P_CLASSNAME, 0xffffff);
81 
82 	SSM(sci, SCI_STYLESETFORE, SCE_P_DEFNAME, 0x800000);
83 	SSM(sci, SCI_STYLESETBACK, SCE_P_DEFNAME, 0xffffff);
84 
85 	SSM(sci, SCI_STYLESETFORE, SCE_P_OPERATOR, 0x800030);
86 	SSM(sci, SCI_STYLESETBACK, SCE_P_OPERATOR, 0xffffff);
87 
88 	SSM(sci, SCI_STYLESETFORE, SCE_P_IDENTIFIER, 0x000000);
89 	SSM(sci, SCI_STYLESETBACK, SCE_P_IDENTIFIER, 0xffffff);
90 
91 	SSM(sci, SCI_STYLESETFORE, SCE_P_COMMENTBLOCK, 0x808080);
92 	SSM(sci, SCI_STYLESETBACK, SCE_P_COMMENTBLOCK, 0xffffff);
93 
94 	SSM(sci, SCI_STYLESETFORE, SCE_P_STRINGEOL, 0x000000);
95 	SSM(sci, SCI_STYLESETBACK, SCE_P_STRINGEOL, 0xffffff);
96 
97 }
98 /* ********************************** */
99 
100 void
create_and_register_python_file_type(CssedWindow * window)101 create_and_register_python_file_type (CssedWindow* window)
102 {
103 	CssedFileType* python;
104 	GtkWidget* python_menu;
105 
106 	python_menu = gtk_menu_item_new_with_label("Python");
107 
108 	python = cssed_file_type_new();
109 	python->char_added  = filetype_python_char_added;
110 
111 	python->modify_attemp_read_only = NULL;
112 	python->double_click = NULL;
113 	python->user_list_selection = NULL;
114 	python->dwell_start = NULL;
115 	python->dwell_end = NULL;
116 	python->hot_spot_click = NULL;
117 	python->hot_spot_doubleclick = NULL;
118 	python->call_tip_click = NULL;
119 
120 	python->save_point_reached = NULL;
121 	python->save_point_left = NULL;
122 	python->uri_dropped = NULL;
123 	python->margin_click = NULL;
124 	python->modified = NULL;
125 	python->key_pressed = NULL;
126 
127 	// configuraton and styling
128 	python->apply_style = filetype_python_set_style;
129 
130 	// THOSE ARE NOT USED TEMPORALY
131 	python->get_config_page_widget = NULL;
132 	python->save_configuration_from_widget = NULL;
133 	python->pop_menu = NULL;
134 	python->clean_popmenu = NULL;
135 	python->menu_item = python_menu;
136 	python->clean_menu = NULL;
137 	python->load_ui = NULL;
138 
139 	// file related issues, those are mostly to avoid to open or save files
140 	python->open_file = NULL;
141 	python->save_doc = NULL;
142 
143 	python->id = CSSED_FILETYPE_PYTHON;
144 	python->style_min = SCE_P_DEFAULT;//(document_set_font_size)  (document_set_font_by_name) (Read/Write const only)
145 	python->style_max = SCE_P_STRINGEOL; //(document_set_font_size) (document_set_font_by_name)(Read/Write const only)
146 	python->can_fold = TRUE;
147 	python->label_language = g_strdup("Python"); // a name for the menu as CSS or XML
148 	python->lable_file = g_strdup("Python");
149 
150 	cssed_file_type_add_pattern_spec (python, "*.py");
151 	cssed_file_type_menu_set_default_callback (window, python_menu, python);
152 	cssed_window_add_filetype (window, python, FALSE);
153 }
154