1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <libgnomevfs/gnome-vfs-utils.h>
23 #include <libanjuta/anjuta-shell.h>
24 #include <libanjuta/anjuta-debug.h>
25 #include <libanjuta/anjuta-encodings.h>
27 #include <libegg/menu/egg-entry-action.h>
28 #include <libanjuta/interfaces/ianjuta-document-manager.h>
29 #include <libanjuta/interfaces/ianjuta-file.h>
30 #include <libanjuta/interfaces/ianjuta-editor.h>
31 #include <libanjuta/interfaces/ianjuta-editor-selection.h>
32 #include <libanjuta/interfaces/ianjuta-editor-convert.h>
33 #include <libanjuta/interfaces/ianjuta-editor-view.h>
34 #include <libanjuta/interfaces/ianjuta-editor-line-mode.h>
35 #include <libanjuta/interfaces/ianjuta-editor-autocomplete.h>
36 #include <libanjuta/interfaces/ianjuta-editor-factory.h>
37 #include <libanjuta/interfaces/ianjuta-editor-folds.h>
38 #include <libanjuta/interfaces/ianjuta-editor-comment.h>
39 #include <libanjuta/interfaces/ianjuta-editor-zoom.h>
40 #include <libanjuta/interfaces/ianjuta-editor-goto.h>
41 #include <libanjuta/interfaces/ianjuta-file-savable.h>
42 #include <libanjuta/interfaces/ianjuta-editor-language.h>
43 #include <libanjuta/interfaces/ianjuta-language-support.h>
44 #include <libanjuta/interfaces/ianjuta-preferences.h>
46 #include "anjuta-docman.h"
47 #include "action-callbacks.h"
50 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-document-manager.ui"
51 #define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-document-manager.glade"
52 #define ICON_FILE "anjuta-document-manager.png"
55 #define ANJUTA_PIXMAP_SWAP "swap.png"
56 #define ANJUTA_PIXMAP_INDENT "indent.xpm"
57 #define ANJUTA_PIXMAP_SYNTAX "syntax.xpm"
58 #define ANJUTA_PIXMAP_BOOKMARK_TOGGLE "bookmark-toggle.png"
59 #define ANJUTA_PIXMAP_BOOKMARK_FIRST "bookmark-first.png"
60 #define ANJUTA_PIXMAP_BOOKMARK_PREV "bookmark-prev.png"
61 #define ANJUTA_PIXMAP_BOOKMARK_NEXT "bookmark-next.png"
62 #define ANJUTA_PIXMAP_BOOKMARK_LAST "bookmark-last.png"
63 #define ANJUTA_PIXMAP_BOOKMARK_CLEAR "bookmark-clear.png"
64 #define ANJUTA_PIXMAP_ERROR_PREV "error-prev.png"
65 #define ANJUTA_PIXMAP_ERROR_NEXT "error-next.png"
67 #define ANJUTA_PIXMAP_FOLD_TOGGLE "fold_toggle.xpm"
68 #define ANJUTA_PIXMAP_FOLD_CLOSE "fold_close.xpm"
69 #define ANJUTA_PIXMAP_FOLD_OPEN "fold_open.xpm"
71 #define ANJUTA_PIXMAP_BLOCK_SELECT "block_select.xpm"
72 #define ANJUTA_PIXMAP_BLOCK_START "block-start.png"
73 #define ANJUTA_PIXMAP_BLOCK_END "block-end.png"
75 #define ANJUTA_PIXMAP_INDENT_INC "indent_inc.xpm"
76 #define ANJUTA_PIXMAP_INDENT_DCR "indent_dcr.xpm"
77 #define ANJUTA_PIXMAP_INDENT_AUTO "indent_auto.xpm"
78 #define ANJUTA_PIXMAP_AUTOFORMAT_SETTING "indent_set.xpm"
80 #define ANJUTA_PIXMAP_CALLTIP "calltip.xpm"
81 #define ANJUTA_PIXMAP_AUTOCOMPLETE "autocomplete.png"
84 #define ANJUTA_STOCK_SWAP "anjuta-swap"
85 #define ANJUTA_STOCK_FOLD_TOGGLE "anjuta-fold-toggle"
86 #define ANJUTA_STOCK_FOLD_OPEN "anjuta-fold-open"
87 #define ANJUTA_STOCK_FOLD_CLOSE "anjuta-fold-close"
88 #define ANJUTA_STOCK_BLOCK_SELECT "anjuta-block-select"
89 #define ANJUTA_STOCK_INDENT_INC "anjuta-indent-inc"
90 #define ANJUTA_STOCK_INDENT_DCR "anjuta-indect-dcr"
91 #define ANJUTA_STOCK_INDENT_AUTO "anjuta-indent-auto"
92 #define ANJUTA_STOCK_AUTOFORMAT_SETTINGS "anjuta-autoformat-settings"
93 #define ANJUTA_STOCK_AUTOCOMPLETE "anjuta-autocomplete"
94 #define ANJUTA_STOCK_PREV_BRACE "anjuta-prev-brace"
95 #define ANJUTA_STOCK_NEXT_BRACE "anjuta-next-brace"
96 #define ANJUTA_STOCK_BLOCK_START "anjuta-block-start"
97 #define ANJUTA_STOCK_BLOCK_END "anjuta-block-end"
98 #define ANJUTA_STOCK_BOOKMARK_TOGGLE "anjuta-bookmark-toggle"
99 #define ANJUTA_STOCK_BOOKMARK_FIRST "anjuta-bookmark-first"
100 #define ANJUTA_STOCK_BOOKMARK_PREV "anjuta-bookmark-previous"
101 #define ANJUTA_STOCK_BOOKMARK_NEXT "anjuta-bookmark-next"
102 #define ANJUTA_STOCK_BOOKMARK_LAST "anjuta-bookmark-last"
103 #define ANJUTA_STOCK_BOOKMARK_CLEAR "anjuta-bookmark-clear"
105 static gpointer parent_class
;
107 /* Shortcuts implementation */
110 mS__
= GDK_SHIFT_MASK
,
111 m_C_
= GDK_CONTROL_MASK
,
112 m__M
= GDK_MOD1_MASK
,
113 mSC_
= GDK_SHIFT_MASK
| GDK_CONTROL_MASK
,
117 ID_NEXTBUFFER
= 1, /* Note: the value mustn't be 0 ! */
124 unsigned int gdk_key
;
128 static ShortcutMapping global_keymap
[] = {
129 /* FIXME: HIG requires that Ctrl+Tab be used to transfer focus in multiline
130 text entries. So we can't use the following ctrl+tabbing. Is there other
131 sensible keys that can be used for them?
134 { m_C_, GDK_Tab, ID_NEXTBUFFER },
135 { mSC_, GDK_ISO_Left_Tab, ID_PREVBUFFER },
137 { m__M
, GDK_1
, ID_FIRSTBUFFER
},
138 { m__M
, GDK_2
, ID_FIRSTBUFFER
+ 1},
139 { m__M
, GDK_3
, ID_FIRSTBUFFER
+ 2},
140 { m__M
, GDK_4
, ID_FIRSTBUFFER
+ 3},
141 { m__M
, GDK_5
, ID_FIRSTBUFFER
+ 4},
142 { m__M
, GDK_6
, ID_FIRSTBUFFER
+ 5},
143 { m__M
, GDK_7
, ID_FIRSTBUFFER
+ 6},
144 { m__M
, GDK_8
, ID_FIRSTBUFFER
+ 7},
145 { m__M
, GDK_9
, ID_FIRSTBUFFER
+ 8},
146 { m__M
, GDK_0
, ID_FIRSTBUFFER
+ 9},
150 static GtkActionEntry actions_file
[] = {
151 { "ActionFileSave", N_("_Save"), GTK_STOCK_SAVE
, "<control>s",
152 N_("Save current file"), G_CALLBACK (on_save_activate
)},
153 { "ActionFileSaveAs", N_("Save _As..."), GTK_STOCK_SAVE_AS
, NULL
,
154 N_("Save the current file with a different name"),
155 G_CALLBACK (on_save_as_activate
)},
156 { "ActionFileSaveAll", N_("Save A_ll"), NULL
, NULL
,
157 N_("Save all currently open files, except new files"),
158 G_CALLBACK (on_save_all_activate
)},
159 { "ActionFileClose", N_("_Close File"), GTK_STOCK_CLOSE
, "<control>w",
160 N_("Close current file"),
161 G_CALLBACK (on_close_file_activate
)},
162 { "ActionFileCloseAll", N_("Close All Files"), GTK_STOCK_CLOSE
, "<shift><control>w",
163 N_("Close all files"),
164 G_CALLBACK (on_close_all_file_activate
)},
165 { "ActionFileReload", N_("Reload F_ile"), GTK_STOCK_REVERT_TO_SAVED
, NULL
,
166 N_("Reload current file"),
167 G_CALLBACK (on_reload_file_activate
)},
168 { "ActionFileSwap", N_("Swap .h/.c"), ANJUTA_STOCK_SWAP
, NULL
,
169 N_("Swap c header and source file"),
170 G_CALLBACK (on_swap_activate
)},
171 { "ActionMenuFileRecentFiles", N_("Recent _Files"), NULL
, NULL
, NULL
, NULL
},
174 static GtkActionEntry actions_print
[] = {
175 { "ActionPrintFile", N_("_Print..."), GTK_STOCK_PRINT
, "<control>p",
176 N_("Print the current file"), G_CALLBACK (anjuta_print_cb
)},
177 { "ActionPrintPreview", N_("_Print Preview"), NULL
, NULL
,
178 N_("Print preview of the current file"),
179 G_CALLBACK (anjuta_print_preview_cb
)},
182 static GtkActionEntry actions_transform
[] = {
183 { "ActionMenuEditTransform", N_("_Transform"), NULL
, NULL
, NULL
, NULL
},
184 { "ActionEditMakeSelectionUppercase", N_("_Make Selection Uppercase"), NULL
, NULL
,
185 N_("Make the selected text uppercase"),
186 G_CALLBACK (on_editor_command_upper_case_activate
)},
187 { "ActionEditMakeSelectionLowercase", N_("Make Selection Lowercase"), NULL
, NULL
,
188 N_("Make the selected text lowercase"),
189 G_CALLBACK (on_editor_command_lower_case_activate
)},
190 { "ActionEditConvertCRLF", N_("Convert EOL to CRLF"), NULL
, NULL
,
191 N_("Convert End Of Line characters to DOS EOL (CRLF)"),
192 G_CALLBACK (on_editor_command_eol_crlf_activate
)},
193 { "ActionEditConvertLF", N_("Convert EOL to LF"), NULL
, NULL
,
194 N_("Convert End Of Line characters to Unix EOL (LF)"),
195 G_CALLBACK (on_editor_command_eol_lf_activate
)},
196 { "ActionEditConvertCR", N_("Convert EOL to CR"), NULL
, NULL
,
197 N_("Convert End Of Line characters to Mac OS EOL (CR)"),
198 G_CALLBACK (on_editor_command_eol_cr_activate
)},
199 { "ActionEditConvertEOL", N_("Convert EOL to Majority EOL"), NULL
, NULL
,
200 N_("Convert End Of Line characters to majority of the EOL found in the file"),
201 G_CALLBACK (on_transform_eolchars1_activate
)},
204 static GtkActionEntry actions_select
[] = {
205 { "ActionMenuEditSelect", N_("_Select"), NULL
, NULL
, NULL
, NULL
},
206 { "ActionEditSelectAll", N_("Select _All"), NULL
, "<control>a",
207 N_("Select all text in the editor"),
208 G_CALLBACK (on_editor_command_select_all_activate
)},
209 { "ActionEditSelectToBrace", N_("Select to _Brace"), NULL
, NULL
,
210 N_("Select the text in the matching braces"),
211 G_CALLBACK (on_editor_command_select_to_brace_activate
)},
212 { "ActionEditSelectBlock", N_("Select _Code Block"),
213 ANJUTA_STOCK_BLOCK_SELECT
, "<shift><control>b",
214 N_("Select the current code block"),
215 G_CALLBACK (on_editor_command_select_block_activate
)},
218 static GtkActionEntry actions_comment
[] = {
219 { "ActionMenuEditComment", N_("Co_mment"), NULL
, NULL
, NULL
, NULL
},
220 { "ActionEditCommentBlock", N_("_Block Comment/Uncomment"), NULL
, NULL
,
221 N_("Block comment the selected text"),
222 G_CALLBACK (on_comment_block
)},
223 { "ActionEditCommentBox", N_("Bo_x Comment/Uncomment"), NULL
, NULL
,
224 N_("Box comment the selected text"),
225 G_CALLBACK (on_comment_box
)},
226 { "ActionEditCommentStream", N_("_Stream Comment/Uncomment"), NULL
, NULL
,
227 N_("Stream comment the selected text"),
228 G_CALLBACK (on_comment_block
)},
231 static GtkActionEntry actions_navigation
[] = {
232 { "ActionMenuGoto", N_("_Goto"), NULL
, NULL
, NULL
, NULL
},
233 { "ActionEditGotoLineActivate", N_("_Goto Line number"),
234 GTK_STOCK_JUMP_TO
, NULL
,
235 N_("Go to a particular line in the editor"),
236 G_CALLBACK (on_goto_activate
)},
237 { "ActionEditGotoLine", N_("_Line Number..."),
238 GTK_STOCK_JUMP_TO
, "<control><alt>g",
239 N_("Go to a particular line in the editor"),
240 G_CALLBACK (on_goto_line_no1_activate
)},
241 { "ActionEditGotoMatchingBrace", N_("Matching _Brace"),
242 GTK_STOCK_JUMP_TO
, "<control><alt>m",
243 N_("Go to the matching brace in the editor"),
244 G_CALLBACK (on_editor_command_match_brace_activate
)},
245 { "ActionEditGotoBlockStart", N_("_Start of Block"),
246 ANJUTA_STOCK_BLOCK_START
, "<control><alt>s",
247 N_("Go to the start of the current block"),
248 G_CALLBACK (on_goto_block_start1_activate
)},
249 { "ActionEditGotoBlockEnd", N_("_End of Block"),
250 ANJUTA_STOCK_BLOCK_END
, "<control><alt>e",
251 N_("Go to the end of the current block"),
252 G_CALLBACK (on_goto_block_end1_activate
)},
253 { "ActionEditGotoHistoryPrev", N_("Previous _History"),
254 GTK_STOCK_JUMP_TO
, NULL
,
255 N_("Goto previous history"),
256 G_CALLBACK (on_prev_history
)},
257 { "ActionEditGotoHistoryNext", N_("Next Histor_y"),
258 GTK_STOCK_JUMP_TO
, NULL
,
259 N_("Goto next history"),
260 G_CALLBACK (on_next_history
)}
263 static GtkActionEntry actions_edit
[] = {
264 { "ActionMenuEdit", N_("_Edit"), NULL
, NULL
, NULL
, NULL
},
265 { "ActionMenuViewEditor", N_("_Editor"), NULL
, NULL
, NULL
, NULL
},
266 { "ActionViewEditorAddView", N_("_Add Editor View"), NULL
, NULL
,
267 N_("Add one more view of current document"),
268 G_CALLBACK (on_editor_add_view_activate
)},
269 { "ActionViewEditorRemoveView", N_("_Remove Editor View"), NULL
, NULL
,
270 N_("Remove current view of the document"),
271 G_CALLBACK (on_editor_remove_view_activate
)},
272 { "ActionEditUndo", N_("U_ndo"), GTK_STOCK_UNDO
, "<control>z",
273 N_("Undo the last action"),
274 G_CALLBACK (on_editor_command_undo_activate
)},
275 { "ActionEditRedo", N_("_Redo"), GTK_STOCK_REDO
, "<control>r",
276 N_("Redo the last undone action"),
277 G_CALLBACK (on_editor_command_redo_activate
)},
278 { "ActionEditCut", N_("C_ut"), GTK_STOCK_CUT
, "<control>x",
279 N_("Cut the selected text from the editor to the clipboard"),
280 G_CALLBACK (on_editor_command_cut_activate
)},
281 { "ActionEditCopy", N_("_Copy"), GTK_STOCK_COPY
, "<control>c",
282 N_("Copy the selected text to the clipboard"),
283 G_CALLBACK (on_editor_command_copy_activate
)},
284 { "ActionEditPaste", N_("_Paste"), GTK_STOCK_PASTE
, "<control>v",
285 N_("Paste the content of clipboard at the current position"),
286 G_CALLBACK (on_editor_command_paste_activate
)},
287 { "ActionEditClear", N_("_Clear"), NULL
, "Delete",
288 N_("Delete the selected text from the editor"),
289 G_CALLBACK (on_editor_command_clear_activate
)},
290 { "ActionEditAutocomplete", N_("_AutoComplete"),
291 ANJUTA_STOCK_AUTOCOMPLETE
, "<control>Return",
292 N_("AutoComplete the current word"),
293 G_CALLBACK (on_editor_command_complete_word_activate
)}
296 static GtkToggleActionEntry actions_view
[] = {
297 { "ActionViewEditorLinenumbers", N_("_Line Number Margin"), NULL
, NULL
,
298 N_("Show/Hide line numbers"),
299 G_CALLBACK (on_editor_linenos1_activate
), FALSE
},
300 { "ActionViewEditorMarkers", N_("_Marker Margin"), NULL
, NULL
,
301 N_("Show/Hide marker margin"),
302 G_CALLBACK (on_editor_markers1_activate
), FALSE
},
303 { "ActionViewEditorFolds", N_("_Code Fold Margin"), NULL
, NULL
,
304 N_("Show/Hide code fold margin"),
305 G_CALLBACK (on_editor_codefold1_activate
), FALSE
},
306 { "ActionViewEditorGuides", N_("_Indentation Guides"), NULL
, NULL
,
307 N_("Show/Hide indentation guides"),
308 G_CALLBACK (on_editor_indentguides1_activate
), FALSE
},
309 { "ActionViewEditorSpaces", N_("_White Space"), NULL
, NULL
,
310 N_("Show/Hide white spaces"),
311 G_CALLBACK (on_editor_whitespaces1_activate
), FALSE
},
312 { "ActionViewEditorEOL", N_("_Line End Characters"), NULL
, NULL
,
313 N_("Show/Hide line end characters"),
314 G_CALLBACK (on_editor_eolchars1_activate
), FALSE
},
315 { "ActionViewEditorWrapping", N_("Line _Wrapping"), NULL
, NULL
,
316 N_("Enable/disable line wrapping"),
317 G_CALLBACK (on_editor_linewrap1_activate
), FALSE
}
320 static GtkActionEntry actions_zoom
[] = {
321 { "ActionViewEditorZoomIn", N_("Zoom In"), GTK_STOCK_ZOOM_IN
, "<control>plus",
322 N_("Zoom in: Increase font size"),
323 G_CALLBACK (on_zoom_in_text_activate
)},
324 { "ActionViewEditorZoomOut", N_("Zoom Out"), GTK_STOCK_ZOOM_OUT
, "<control>minus",
325 N_("Zoom out: Decrease font size"),
326 G_CALLBACK (on_zoom_out_text_activate
)}
329 static GtkActionEntry actions_style
[] = {
330 { "ActionMenuFormatStyle", N_("_Highlight Mode"), NULL
, NULL
, NULL
, NULL
}
333 static GtkActionEntry actions_format
[] = {
334 { "ActionMenuFormat", N_("For_mat"), NULL
, NULL
, NULL
, NULL
},
335 { "ActionFormatAutoformat", N_("Auto _Format"),
336 ANJUTA_STOCK_INDENT_AUTO
, NULL
,
337 N_("Autoformat the current source file"),
338 G_CALLBACK (on_indent1_activate
)},
340 { "ActionFormatSettings", N_("Autoformat _settings"),
341 ANJUTA_STOCK_AUTOFORMAT_SETTINGS, NULL,
342 N_("Autoformat settings"),
343 G_CALLBACK (on_format_indent_style_clicked)},
344 { "ActionFormatIndentationIncrease", N_("_Increase Indent"),
345 ANJUTA_STOCK_INDENT_INC, NULL,
346 N_("Increase indentation of line/selection"),
347 G_CALLBACK (on_editor_command_indent_increase_activate)},
348 { "ActionFormatIndentationDecrease", N_("_Decrease Indent"),
349 ANJUTA_STOCK_INDENT_DCR, NULL,
350 N_("Decrease indentation of line/selection"),
351 G_CALLBACK (on_editor_command_indent_decrease_activate)},
353 { "ActionFormatFoldCloseAll", N_("_Close All Folds"),
354 ANJUTA_STOCK_FOLD_CLOSE
, NULL
,
355 N_("Close all code folds in the editor"),
356 G_CALLBACK (on_editor_command_close_folds_all_activate
)},
357 { "ActionFormatFoldOpenAll", N_("_Open All Folds"),
358 ANJUTA_STOCK_FOLD_OPEN
, NULL
,
359 N_("Open all code folds in the editor"),
360 G_CALLBACK (on_editor_command_open_folds_all_activate
)},
361 { "ActionFormatFoldToggle", N_("_Toggle Current Fold"),
362 ANJUTA_STOCK_FOLD_TOGGLE
, NULL
,
363 N_("Toggle current code fold in the editor"),
364 G_CALLBACK (on_editor_command_toggle_fold_activate
)},
367 static GtkActionEntry actions_bookmark
[] = {
368 { "ActionMenuBookmark", N_("Bookmar_k"), NULL
, NULL
, NULL
, NULL
},
369 { "ActionBookmarkToggle", N_("_Toggle Bookmark"),
370 ANJUTA_STOCK_BOOKMARK_TOGGLE
, "<control>k",
371 N_("Toggle a bookmark at the current line position"),
372 G_CALLBACK (on_editor_command_bookmark_toggle_activate
)},
373 { "ActionBookmarkFirst", N_("_First Bookmark"),
374 ANJUTA_STOCK_BOOKMARK_FIRST
, NULL
,
375 N_("Jump to the first bookmark in the file"),
376 G_CALLBACK (on_editor_command_bookmark_first_activate
)},
377 { "ActionBookmarkPrevious", N_("_Previous Bookmark"),
378 ANJUTA_STOCK_BOOKMARK_PREV
, "<control>comma",
379 N_("Jump to the previous bookmark in the file"),
380 G_CALLBACK (on_editor_command_bookmark_prev_activate
)},
381 { "ActionBookmarkNext", N_("_Next Bookmark"),
382 ANJUTA_STOCK_BOOKMARK_NEXT
, "<control>period",
383 N_("Jump to the next bookmark in the file"),
384 G_CALLBACK (on_editor_command_bookmark_next_activate
)},
385 { "ActionBookmarkLast", N_("_Last Bookmark"),
386 ANJUTA_STOCK_BOOKMARK_LAST
, NULL
,
387 N_("Jump to the last bookmark in the file"),
388 G_CALLBACK (on_editor_command_bookmark_last_activate
)},
389 { "ActionBookmarkClear", N_("_Clear All Bookmarks"),
390 ANJUTA_STOCK_BOOKMARK_CLEAR
, NULL
,
391 N_("Clear bookmarks"),
392 G_CALLBACK (on_editor_command_bookmark_clear_activate
)},
395 struct ActionGroupInfo
{
396 GtkActionEntry
*group
;
402 struct ActionToggleGroupInfo
{
403 GtkToggleActionEntry
*group
;
409 static struct ActionGroupInfo action_groups
[] = {
410 { actions_file
, G_N_ELEMENTS (actions_file
), "ActionGroupEditorFile", N_("Editor file operations")},
411 { actions_print
, G_N_ELEMENTS (actions_print
), "ActionGroupEditorPrint", N_("Editor print operations")},
412 { actions_transform
, G_N_ELEMENTS (actions_transform
), "ActionGroupEditorTransform", N_("Editor text transformation") },
413 { actions_select
, G_N_ELEMENTS (actions_select
), "ActionGroupEditorSelect", N_("Editor text selection") },
414 // { actions_insert, G_N_ELEMENTS (actions_insert), "ActionGroupEditorInsert", N_("Editor text insertions") },
415 { actions_comment
, G_N_ELEMENTS (actions_comment
), "ActionGroupEditorComment", N_("Editor code commenting") },
416 { actions_navigation
, G_N_ELEMENTS (actions_navigation
), "ActionGroupEditorNavigate", N_("Editor navigations") },
417 { actions_edit
, G_N_ELEMENTS (actions_edit
), "ActionGroupEditorEdit", N_("Editor edit operations") },
418 { actions_zoom
, G_N_ELEMENTS (actions_zoom
), "ActionGroupEditorZoom", N_("Editor zoom operations") },
419 { actions_style
, G_N_ELEMENTS (actions_style
), "ActionGroupEditorStyle", N_("Editor syntax highlighting styles") },
420 { actions_format
, G_N_ELEMENTS (actions_format
), "ActionGroupEditorFormat", N_("Editor text formating") },
421 { actions_bookmark
, G_N_ELEMENTS (actions_bookmark
), "ActionGroupEditorBookmark", N_("Editor bookmarks") }
424 static struct ActionToggleGroupInfo action_toggle_groups
[] = {
425 { actions_view
, G_N_ELEMENTS (actions_view
), "ActionGroupEditorView", N_("Editor view settings") }
428 // void pref_set_style_combo(DocmanPlugin *plugin);
430 /* FIXME: There was a change in data representation in GtkActionEntry from
431 EggActionGroupEntry. The actual entries should be fixed and this hack removed */
433 swap_label_and_stock (GtkActionEntry
* actions
, gint size
)
436 for (i
= 0; i
< size
; i
++)
438 const gchar
*stock_id
= actions
[i
].label
;
439 actions
[i
].label
= actions
[i
].stock_id
;
440 actions
[i
].stock_id
= stock_id
;
441 if (actions
[i
].name
== NULL
)
442 DEBUG_PRINT ("Name is null: %s", actions
[i
].label
);
447 swap_toggle_label_and_stock (GtkToggleActionEntry
* actions
, gint size
)
450 for (i
= 0; i
< size
; i
++)
452 const gchar
*stock_id
= actions
[i
].label
;
453 actions
[i
].label
= actions
[i
].stock_id
;
454 actions
[i
].stock_id
= stock_id
;
455 if (actions
[i
].name
== NULL
)
456 DEBUG_PRINT ("Name is null: %s", actions
[i
].label
);
460 #define VIEW_LINENUMBERS_MARGIN "margin.linenumber.visible"
461 #define VIEW_MARKER_MARGIN "margin.marker.visible"
462 #define VIEW_FOLD_MARGIN "margin.fold.visible"
463 #define VIEW_INDENTATION_GUIDES "view.indentation.guides"
464 #define VIEW_WHITE_SPACES "view.whitespace"
465 #define VIEW_EOL "view.eol"
466 #define VIEW_LINE_WRAP "view.line.wrap"
469 ui_states_init (AnjutaPlugin
*plugin
)
472 DocmanPlugin
*eplugin
;
473 static const gchar
*prefs
[] = {
474 VIEW_LINENUMBERS_MARGIN
,
477 VIEW_INDENTATION_GUIDES
,
483 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
484 for (i
= 0; i
< sizeof (actions_view
)/sizeof(GtkToggleActionEntry
); i
++)
489 state
= anjuta_preferences_get_int (eplugin
->prefs
, prefs
[i
]);
490 action
= anjuta_ui_get_action (eplugin
->ui
, "ActionGroupEditorView",
491 actions_view
[i
].name
);
492 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action
), state
);
497 ui_give_shorter_names (AnjutaPlugin
*plugin
)
502 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
503 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
505 g_object_set (G_OBJECT (action
), "short-label", _("Save"),
506 "is-important", TRUE
, NULL
);
507 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
509 g_object_set (G_OBJECT (action
), "short-label", _("Reload"), NULL
);
510 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
512 g_object_set (G_OBJECT (action
), "is-important", TRUE
, NULL
);
513 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
514 "ActionEditGotoLineActivate");
515 g_object_set (G_OBJECT (action
), "short-label", _("Goto"), NULL
);
519 update_editor_ui_enable_all (AnjutaPlugin
*plugin
)
525 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
526 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
528 for (j
= 0; j
< action_groups
[i
].size
; j
++)
530 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
531 action_groups
[i
].group
[j
].name
);
532 if (action_groups
[i
].group
[j
].callback
)
534 g_object_set (G_OBJECT (action
), "sensitive", TRUE
, NULL
);
538 action
= anjuta_ui_get_action (ui
, "ActionGroupNavigation",
539 "ActionEditGotoLineEntry");
540 g_object_set (G_OBJECT (action
), "sensitive", TRUE
, NULL
);
544 update_editor_ui_disable_all (AnjutaPlugin
*plugin
)
550 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
551 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
553 for (j
= 0; j
< action_groups
[i
].size
; j
++)
555 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
556 action_groups
[i
].group
[j
].name
);
557 if (action_groups
[i
].group
[j
].callback
)
559 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
563 action
= anjuta_ui_get_action (ui
, "ActionGroupNavigation",
564 "ActionEditGotoLineEntry");
565 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
570 update_editor_ui_save_items (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
575 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
577 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
579 g_object_set (G_OBJECT (action
), "sensitive",
580 ianjuta_editor_can_undo (editor
, NULL
), NULL
);
582 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
584 g_object_set (G_OBJECT (action
), "sensitive",
585 ianjuta_editor_can_redo (editor
, NULL
), NULL
);
587 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
589 g_object_set (G_OBJECT (action
), "sensitive",
590 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
),
595 update_editor_ui_interface_items (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
601 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
603 /* IAnjutaEditorLanguage */
604 flag
= IANJUTA_IS_EDITOR_LANGUAGE (editor
);
606 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorStyle",
607 "ActionMenuFormatStyle");
608 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
610 /* IAnjutaEditorSelection */
611 flag
= IANJUTA_IS_EDITOR_SELECTION (editor
);
613 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
615 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
617 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
619 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
621 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
623 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
625 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
627 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
629 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
630 "ActionEditSelectAll");
631 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
633 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
634 "ActionEditSelectToBrace");
635 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
637 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
638 "ActionEditSelectBlock");
639 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
641 /* IAnjutaEditorConvert */
642 flag
= IANJUTA_IS_EDITOR_CONVERT (editor
);
643 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
644 "ActionEditMakeSelectionUppercase");
645 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
647 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
648 "ActionEditMakeSelectionLowercase");
649 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
651 /* IAnjutaEditorLineMode */
652 flag
= IANJUTA_IS_EDITOR_LINE_MODE (editor
);
654 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
655 "ActionEditConvertCRLF");
656 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
657 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
658 "ActionEditConvertLF");
659 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
660 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
661 "ActionEditConvertCR");
662 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
663 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
664 "ActionEditConvertEOL");
665 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
667 /* IAnjutaEditorView */
668 flag
= IANJUTA_IS_EDITOR_VIEW (editor
);
669 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
670 "ActionViewEditorAddView");
671 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
672 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
673 "ActionViewEditorRemoveView");
674 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
676 /* IAnjutaEditorAutocomplete */
677 flag
= IANJUTA_IS_EDITOR_AUTOCOMPLETE (editor
);
678 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
679 "ActionEditAutocomplete");
680 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
682 /* IAnjutaEditorFolds */
683 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
684 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
685 "ActionFormatFoldCloseAll");
686 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
688 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
689 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
690 "ActionFormatFoldOpenAll");
691 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
693 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
694 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
695 "ActionFormatFoldToggle");
696 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
698 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
699 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorView",
700 "ActionViewEditorFolds");
701 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
703 /* IAnjutaEditorComment */
704 flag
= IANJUTA_IS_EDITOR_COMMENT (editor
);
705 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorComment",
706 "ActionMenuEditComment");
707 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
709 /* IAnjutaEditorZoom */
710 flag
= IANJUTA_IS_EDITOR_ZOOM (editor
);
711 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorZoom",
712 "ActionViewEditorZoomIn");
713 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
714 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorZoom",
715 "ActionViewEditorZoomOut");
716 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
718 /* IAnjutaEditorGoto */
719 flag
= IANJUTA_IS_EDITOR_GOTO (editor
);
720 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
721 "ActionEditGotoBlockStart");
722 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
723 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
724 "ActionEditGotoBlockEnd");
725 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
726 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
727 "ActionEditGotoMatchingBrace");
728 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
732 update_editor_ui (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
736 update_editor_ui_disable_all (plugin
);
739 update_editor_ui_enable_all (plugin
);
740 update_editor_ui_save_items (plugin
, editor
);
741 update_editor_ui_interface_items (plugin
, editor
);
745 on_editor_update_save_ui (IAnjutaEditor
*editor
, gboolean entered
,
746 AnjutaPlugin
*plugin
)
748 update_editor_ui_save_items (plugin
, editor
);
751 #define REGISTER_ICON(icon, stock_id) \
752 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"icon, NULL); \
753 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
754 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
755 g_object_unref (pixbuf);
758 register_stock_icons (AnjutaPlugin
*plugin
)
761 GtkIconFactory
*icon_factory
;
762 GtkIconSet
*icon_set
;
764 static gboolean registered
= FALSE
;
770 /* Register stock icons */
771 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
772 icon_factory
= anjuta_ui_get_icon_factory (ui
);
773 REGISTER_ICON (ICON_FILE
, "editor-plugin-icon");
774 REGISTER_ICON (ANJUTA_PIXMAP_SWAP
, ANJUTA_STOCK_SWAP
);
775 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_TOGGLE
, ANJUTA_STOCK_FOLD_TOGGLE
);
776 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_OPEN
, ANJUTA_STOCK_FOLD_OPEN
);
777 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_CLOSE
, ANJUTA_STOCK_FOLD_CLOSE
);
778 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_INC
, ANJUTA_STOCK_INDENT_INC
);
779 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_DCR
, ANJUTA_STOCK_INDENT_DCR
);
780 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_AUTO
, ANJUTA_STOCK_INDENT_AUTO
);
781 REGISTER_ICON (ANJUTA_PIXMAP_AUTOFORMAT_SETTING
, ANJUTA_STOCK_AUTOFORMAT_SETTINGS
);
782 REGISTER_ICON (ANJUTA_PIXMAP_AUTOCOMPLETE
, ANJUTA_STOCK_AUTOCOMPLETE
);
783 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_SELECT
, ANJUTA_STOCK_BLOCK_SELECT
);
784 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_TOGGLE
, ANJUTA_STOCK_BOOKMARK_TOGGLE
);
785 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_FIRST
, ANJUTA_STOCK_BOOKMARK_FIRST
);
786 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_PREV
, ANJUTA_STOCK_BOOKMARK_PREV
);
787 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_NEXT
, ANJUTA_STOCK_BOOKMARK_NEXT
);
788 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_LAST
, ANJUTA_STOCK_BOOKMARK_LAST
);
789 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_CLEAR
, ANJUTA_STOCK_BOOKMARK_CLEAR
);
790 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_START
, ANJUTA_STOCK_BLOCK_START
);
791 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_END
, ANJUTA_STOCK_BLOCK_END
);
794 #define TEXT_ZOOM_FACTOR "text.zoom.factor"
797 update_status (DocmanPlugin
*plugin
, IAnjutaEditor
*te
)
799 AnjutaStatus
*status
;
801 status
= anjuta_shell_get_status (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
808 gchar
*edit
/*, *mode*/;
809 guint line
, col
, zoom
;
811 /* TODO: Implement this in IAnjutaEditor some kind
813 editor_mode = scintilla_send_message (SCINTILLA (te->widgets.editor),
814 SCI_GETEOLMODE, 0, 0);
815 switch (editor_mode) {
817 mode = g_strdup(_("DOS (CRLF)"));
820 mode = g_strdup(_("Unix (LF)"));
823 mode = g_strdup(_("Mac (CR)"));
826 mode = g_strdup(_("Unknown"));
830 zoom
= anjuta_preferences_get_int (plugin
->prefs
, TEXT_ZOOM_FACTOR
);
831 line
= ianjuta_editor_get_lineno (te
, NULL
);
832 col
= ianjuta_editor_get_column (te
, NULL
);
834 if (ianjuta_editor_get_overwrite (te
, NULL
))
836 edit
= g_strdup (_("OVR"));
840 edit
= g_strdup (_("INS"));
842 anjuta_status_set_default (status
, _("Zoom"), "%d", zoom
);
843 anjuta_status_set_default (status
, _("Line"), "%04d", line
);
844 anjuta_status_set_default (status
, _("Col"), "%03d", col
);
845 anjuta_status_set_default (status
, _("Mode"), edit
);
846 // anjuta_status_set_default (status, _("EOL"), mode);
853 anjuta_status_set_default (status
, _("Zoom"), NULL
);
854 anjuta_status_set_default (status
, _("Line"), NULL
);
855 anjuta_status_set_default (status
, _("Col"), NULL
);
856 anjuta_status_set_default (status
, _("Mode"), NULL
);
857 /* anjuta_status_set_default (status, _("EOL"), NULL); */
862 on_editor_update_ui (IAnjutaEditor
*editor
, DocmanPlugin
*plugin
)
866 te
= anjuta_docman_get_current_editor (ANJUTA_DOCMAN (plugin
->docman
));
868 update_status (plugin
, te
);
871 /* Remove all instances of c from the string s. */
872 static void remove_char(gchar
*s
, gchar c
)
881 /* Compare two strings, ignoring _ characters which indicate mneumonics.
882 * Returns -1, 0, or 1, just like strcmp(). */
884 menu_name_compare(const gchar
*s
, const char *t
)
886 gchar
*s1
= g_utf8_strdown(s
, -1);
887 gchar
*t1
= g_utf8_strdown(t
, -1);
888 remove_char(s1
, '_');
889 remove_char(t1
, '_');
890 int result
= g_utf8_collate(s1
, t1
);
897 compare_language_name(const gchar
*lang1
, const gchar
*lang2
, IAnjutaEditorLanguage
*manager
)
899 const gchar
*fullname1
= ianjuta_editor_language_get_language_name (manager
, lang1
, NULL
);
900 const gchar
*fullname2
= ianjuta_editor_language_get_language_name (manager
, lang2
, NULL
);
901 return menu_name_compare(fullname1
, fullname2
);
905 create_highlight_submenu (DocmanPlugin
*plugin
, IAnjutaEditor
*editor
)
907 const GList
*languages
, *node
;
908 GList
*sorted_languages
;
912 submenu
= gtk_menu_new ();
914 if (!editor
|| !IANJUTA_IS_EDITOR_LANGUAGE (editor
))
917 languages
= ianjuta_editor_language_get_supported_languages (IANJUTA_EDITOR_LANGUAGE (editor
), NULL
);
921 /* Automatic highlight menu */
922 menuitem
= gtk_menu_item_new_with_mnemonic (_("Automatic"));
923 g_signal_connect (G_OBJECT (menuitem
), "activate",
924 G_CALLBACK (on_force_hilite_activate
),
926 g_object_set_data(G_OBJECT(menuitem
), "language_code", "auto-detect");
927 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
928 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), gtk_separator_menu_item_new());
930 /* Sort languages so they appear alphabetically in the menu. */
931 sorted_languages
= g_list_copy((GList
*) languages
);
932 sorted_languages
= g_list_sort_with_data(sorted_languages
, (GCompareDataFunc
) compare_language_name
,
933 IANJUTA_EDITOR_LANGUAGE (editor
));
935 node
= sorted_languages
;
938 const gchar
*lang
= node
->data
;
939 const gchar
*name
= ianjuta_editor_language_get_language_name (IANJUTA_EDITOR_LANGUAGE (editor
), lang
, NULL
);
941 menuitem
= gtk_menu_item_new_with_mnemonic (name
);
942 g_object_set_data_full (G_OBJECT (menuitem
), "language_code",
944 (GDestroyNotify
)g_free
);
945 g_signal_connect (G_OBJECT (menuitem
), "activate",
946 G_CALLBACK (on_force_hilite_activate
),
948 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
949 node
= g_list_next (node
);
951 g_list_free(sorted_languages
);
953 gtk_widget_show_all (submenu
);
958 on_editor_added (AnjutaDocman
*docman
, IAnjutaEditor
*te
,
959 AnjutaPlugin
*plugin
)
961 GtkWidget
*highlight_submenu
, *highlight_menu
;
962 DocmanPlugin
*editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
964 /* Create Highlight submenu */
966 create_highlight_submenu (editor_plugin
, te
);
967 if (highlight_submenu
)
970 gtk_ui_manager_get_widget (GTK_UI_MANAGER (editor_plugin
->ui
),
971 "/MenuMain/MenuView/MenuViewEditor/MenuFormatStyle");
972 gtk_menu_item_set_submenu (GTK_MENU_ITEM (highlight_menu
),
975 g_signal_connect (G_OBJECT (te
), "update-ui",
976 G_CALLBACK (on_editor_update_ui
),
977 ANJUTA_PLUGIN (plugin
));
978 g_signal_connect (G_OBJECT (te
), "save-point",
979 G_CALLBACK (on_editor_update_save_ui
),
980 ANJUTA_PLUGIN (plugin
));
981 anjuta_shell_present_widget (plugin
->shell
,
982 GTK_WIDGET (docman
), NULL
);
986 on_editor_changed (AnjutaDocman
*docman
, IAnjutaEditor
*te
,
987 AnjutaPlugin
*plugin
)
989 DocmanPlugin
*docman_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
991 update_status (docman_plugin
, te
);
992 update_editor_ui (plugin
, te
);
994 /* unload previous support plugins */
995 if (docman_plugin
->support_plugins
) {
996 g_list_foreach (docman_plugin
->support_plugins
,
997 (GFunc
) anjuta_plugin_deactivate
, NULL
);
998 g_list_free (docman_plugin
->support_plugins
);
999 docman_plugin
->support_plugins
= NULL
;
1004 AnjutaPluginManager
*plugin_manager
;
1005 const gchar
*language
;
1006 GList
*support_plugin_descs
, *node
;
1008 GValue value
= {0, };
1009 g_value_init (&value
, G_TYPE_OBJECT
);
1010 g_value_set_object (&value
, te
);
1011 anjuta_shell_add_value (plugin
->shell
,
1012 "document_manager_current_editor",
1014 g_value_unset(&value
);
1015 DEBUG_PRINT ("Editor Added");
1017 /* Load current language editor support plugins */
1018 plugin_manager
= anjuta_shell_get_plugin_manager (plugin
->shell
, NULL
);
1019 if (IANJUTA_IS_EDITOR_LANGUAGE (te
)) {
1020 language
= ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (te
), NULL
);
1021 support_plugin_descs
= anjuta_plugin_manager_query (plugin_manager
,
1024 "IAnjutaLanguageSupport",
1028 node
= support_plugin_descs
;
1031 GObject
*plugin_object
;
1033 AnjutaPluginDescription
*desc
= node
->data
;
1034 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin", "Location",
1036 plugin_object
= anjuta_plugin_manager_get_plugin_by_id (plugin_manager
,
1038 /* anjuta_plugin_activate (ANJUTA_PLUGIN (plugin_object)); */
1041 DEBUG_PRINT("Loaded language support plugin: %s", plugin_id
);
1042 docman_plugin
->support_plugins
= g_list_prepend (docman_plugin
->support_plugins
,
1047 DEBUG_PRINT ("Failed to load support plugin %s", plugin_id
);
1052 g_list_free (support_plugin_descs
);
1057 anjuta_shell_remove_value (plugin
->shell
,
1058 "document_manager_current_editor", NULL
);
1059 DEBUG_PRINT ("Editor Removed");
1064 on_edit_editor_indent (GtkWidget
*button
, DocmanPlugin
*plugin
)
1066 IndentData
*idt
= plugin
->idt
;
1068 if (idt
->dialog
== NULL
)
1069 idt
->dialog
= create_dialog(idt
);
1070 gtk_widget_show(idt
->dialog
);
1074 on_style_combo_changed (GtkComboBox
*combo
, DocmanPlugin
*plugin
)
1076 IndentData
*idt
= plugin
->idt
;
1078 pref_style_combo_changed(combo
, idt
);
1082 on_window_key_press_event (GtkWidget
*widget
,
1084 DocmanPlugin
*plugin
)
1089 g_return_val_if_fail (event
!= NULL
, FALSE
);
1091 modifiers
= event
->state
& (GDK_SHIFT_MASK
| GDK_CONTROL_MASK
| GDK_MOD1_MASK
);
1093 for (i
= 0; global_keymap
[i
].id
; i
++)
1094 if (event
->keyval
== global_keymap
[i
].gdk_key
&&
1095 (event
->state
& global_keymap
[i
].modifiers
) == global_keymap
[i
].modifiers
)
1098 if (!global_keymap
[i
].id
)
1101 switch (global_keymap
[i
].id
) {
1103 case ID_PREVBUFFER
: {
1104 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1108 if (!notebook
->children
)
1111 if (!plugin
->g_tabbing
)
1113 plugin
->g_tabbing
= TRUE
;
1116 pages_nb
= g_list_length (notebook
->children
);
1117 cur_page
= gtk_notebook_get_current_page (notebook
);
1119 if (global_keymap
[i
].id
== ID_NEXTBUFFER
)
1120 cur_page
= (cur_page
< pages_nb
- 1) ? cur_page
+ 1 : 0;
1122 cur_page
= cur_page
? cur_page
- 1 : pages_nb
-1;
1124 gtk_notebook_set_page (notebook
, cur_page
);
1129 if (global_keymap
[i
].id
>= ID_FIRSTBUFFER
&&
1130 global_keymap
[i
].id
<= (ID_FIRSTBUFFER
+ 9))
1132 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1133 int page_req
= global_keymap
[i
].id
- ID_FIRSTBUFFER
;
1135 if (!notebook
->children
)
1137 gtk_notebook_set_page(notebook
, page_req
);
1143 /* Note: No reason for a shortcut to do more than one thing a time */
1144 gtk_signal_emit_stop_by_name (GTK_OBJECT (ANJUTA_PLUGIN(plugin
)->shell
),
1150 #define EDITOR_TABS_RECENT_FIRST "editor.tabs.recent.first"
1151 #define EDITOR_TABS_POS "editor.tabs.pos"
1152 #define EDITOR_TABS_HIDE "editor.tabs.hide"
1153 #define EDITOR_TABS_ORDERING "editor.tabs.ordering"
1154 #define AUTOSAVE_TIMER "autosave.timer"
1155 #define SAVE_AUTOMATIC "save.automatic"
1158 on_window_key_release_event (GtkWidget
*widget
,
1160 DocmanPlugin
*plugin
)
1162 g_return_val_if_fail (event
!= NULL
, FALSE
);
1164 if (plugin
->g_tabbing
&& ((event
->keyval
== GDK_Control_L
) ||
1165 (event
->keyval
== GDK_Control_R
)))
1167 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1170 plugin
->g_tabbing
= FALSE
;
1172 if (anjuta_preferences_get_int (plugin
->prefs
,
1173 EDITOR_TABS_RECENT_FIRST
))
1176 TTimo: move the current notebook page to first position
1177 that maintains Ctrl-TABing on a list of most recently edited files
1179 cur_page
= gtk_notebook_get_current_page (notebook
);
1180 widget
= gtk_notebook_get_nth_page (notebook
, cur_page
);
1181 gtk_notebook_reorder_child (notebook
, widget
, 0);
1188 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
1189 AnjutaSession
*session
, DocmanPlugin
*plugin
)
1191 GList
*editors
, *node
, *files
;
1193 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
1196 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
1197 files
= g_list_reverse (files
);
1199 editors
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1206 te
= IANJUTA_EDITOR (node
->data
);
1207 te_uri
= ianjuta_file_get_uri(IANJUTA_FILE(te
), NULL
);
1211 /* Save line locations also */
1212 uri
= g_strdup_printf ("%s#%d", te_uri
,
1213 ianjuta_editor_get_lineno(IANJUTA_EDITOR(te
), NULL
));
1214 files
= g_list_prepend (files
, uri
);
1215 /* uri not be freed here */
1218 node
= g_list_next (node
);
1220 files
= g_list_reverse (files
);
1221 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
1222 g_list_free (editors
);
1223 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
1224 g_list_free (files
);
1228 on_save_prompt_save_editor (AnjutaSavePrompt
*save_prompt
,
1229 gpointer item
, gpointer user_data
)
1231 DocmanPlugin
*plugin
;
1233 plugin
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1234 return anjuta_docman_save_editor (ANJUTA_DOCMAN (plugin
->docman
),
1235 IANJUTA_EDITOR (item
),
1236 GTK_WIDGET (save_prompt
));
1240 on_save_prompt (AnjutaShell
*shell
, AnjutaSavePrompt
*save_prompt
,
1241 DocmanPlugin
*plugin
)
1245 list
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1249 IAnjutaFileSavable
*editor
= IANJUTA_FILE_SAVABLE (node
->data
);
1250 if (ianjuta_file_savable_is_dirty (editor
, NULL
))
1255 name
= ianjuta_editor_get_filename (IANJUTA_EDITOR (editor
), NULL
);
1256 uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
1257 anjuta_save_prompt_add_item (save_prompt
, name
, uri
, editor
,
1258 on_save_prompt_save_editor
, plugin
);
1261 node
= g_list_next (node
);
1266 docman_plugin_set_tab_pos (DocmanPlugin
*ep
)
1268 if (anjuta_preferences_get_int_with_default (ep
->prefs
, EDITOR_TABS_HIDE
,
1271 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), FALSE
);
1276 GtkPositionType pos
;
1278 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), TRUE
);
1279 tab_pos
= anjuta_preferences_get (ep
->prefs
, EDITOR_TABS_POS
);
1284 if (strcasecmp (tab_pos
, "left") == 0)
1286 else if (strcasecmp (tab_pos
, "right") == 0)
1287 pos
= GTK_POS_RIGHT
;
1288 else if (strcasecmp (tab_pos
, "bottom") == 0)
1289 pos
= GTK_POS_BOTTOM
;
1292 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (ep
->docman
), pos
);
1297 on_gconf_notify_prefs (GConfClient
*gclient
, guint cnxn_id
,
1298 GConfEntry
*entry
, gpointer user_data
)
1300 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1301 docman_plugin_set_tab_pos (ep
);
1305 on_docman_auto_save (gpointer data
)
1307 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (data
);
1309 AnjutaPreferences
* prefs
;
1310 AnjutaDocman
*docman
;
1311 AnjutaStatus
* status
;
1312 IAnjutaEditor
* editor
;
1314 docman
= ANJUTA_DOCMAN (plugin
->docman
);
1316 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
1317 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1318 status
= anjuta_shell_get_status(shell
, NULL
);
1322 if (anjuta_preferences_get_int (prefs
, SAVE_AUTOMATIC
) == FALSE
)
1324 plugin
->autosave_on
= FALSE
;
1328 editors
= anjuta_docman_get_all_editors(docman
);
1331 editor
= IANJUTA_EDITOR(editors
->data
);
1332 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1334 gchar
*uri
= ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1337 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1341 editors
= g_list_next(editors
);
1343 // TODO: Check for errors
1346 mesg
= g_strdup("Autosaved complete");
1347 anjuta_status (status
, mesg
, 3);
1354 on_gconf_notify_timer (GConfClient
*gclient
, guint cnxn_id
,
1355 GConfEntry
*entry
, gpointer user_data
)
1357 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1359 AnjutaPreferences
* prefs
;
1360 gint auto_save_timer
;
1363 g_object_get(G_OBJECT(ep
), "shell", &shell
, NULL
);
1364 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1366 auto_save_timer
= anjuta_preferences_get_int(prefs
, AUTOSAVE_TIMER
);
1367 auto_save
= anjuta_preferences_get_int(prefs
, SAVE_AUTOMATIC
);
1371 if (ep
->autosave_on
== TRUE
)
1373 if (auto_save_timer
!= ep
->autosave_it
)
1375 gtk_timeout_remove (ep
->autosave_id
);
1377 gtk_timeout_add (auto_save_timer
*
1379 on_docman_auto_save
,
1386 gtk_timeout_add (auto_save_timer
* 60000,
1387 on_docman_auto_save
,
1390 ep
->autosave_it
= auto_save_timer
;
1391 ep
->autosave_on
= TRUE
;
1395 if (ep
->autosave_on
== TRUE
)
1396 gtk_timeout_remove (ep
->autosave_id
);
1397 ep
->autosave_on
= FALSE
;
1401 #define REGISTER_NOTIFY(key, func) \
1402 notify_id = anjuta_preferences_notify_add (ep->prefs, \
1403 key, func, ep, NULL); \
1404 ep->gconf_notify_ids = g_list_prepend (ep->gconf_notify_ids, \
1405 GUINT_TO_POINTER (notify_id));
1407 prefs_init (DocmanPlugin
*ep
)
1410 docman_plugin_set_tab_pos (ep
);
1411 REGISTER_NOTIFY (EDITOR_TABS_HIDE
, on_gconf_notify_prefs
);
1412 REGISTER_NOTIFY (EDITOR_TABS_POS
, on_gconf_notify_prefs
);
1413 REGISTER_NOTIFY (AUTOSAVE_TIMER
, on_gconf_notify_timer
);
1414 REGISTER_NOTIFY (SAVE_AUTOMATIC
, on_gconf_notify_timer
);
1416 on_gconf_notify_timer(NULL
,0,NULL
, ep
);
1420 prefs_finalize (DocmanPlugin
*ep
)
1423 node
= ep
->gconf_notify_ids
;
1426 anjuta_preferences_notify_remove (ep
->prefs
,
1427 GPOINTER_TO_UINT (node
->data
));
1428 node
= g_list_next (node
);
1430 g_list_free (ep
->gconf_notify_ids
);
1431 ep
->gconf_notify_ids
= NULL
;
1435 activate_plugin (AnjutaPlugin
*plugin
)
1437 GtkWidget
*docman
, *popup_menu
;
1439 DocmanPlugin
*editor_plugin
;
1440 GtkActionGroup
*group
;
1443 AnjutaStatus
*status
;
1444 static gboolean initialized
= FALSE
;
1446 DEBUG_PRINT ("DocmanPlugin: Activating Editor plugin...");
1448 editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1449 editor_plugin
->ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1450 editor_plugin
->prefs
= anjuta_shell_get_preferences (plugin
->shell
, NULL
);
1451 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1453 ui
= editor_plugin
->ui
;
1454 docman
= anjuta_docman_new (editor_plugin
, editor_plugin
->prefs
);
1455 editor_plugin
->docman
= docman
;
1456 ANJUTA_DOCMAN(docman
)->shell
= plugin
->shell
;
1457 g_signal_connect (G_OBJECT (docman
), "editor-added",
1458 G_CALLBACK (on_editor_added
), plugin
);
1459 g_signal_connect (G_OBJECT (docman
), "editor-changed",
1460 G_CALLBACK (on_editor_changed
), plugin
);
1461 g_signal_connect_swapped (G_OBJECT (status
), "busy",
1462 G_CALLBACK (anjuta_docman_set_busy
), docman
);
1463 g_signal_connect (G_OBJECT (plugin
->shell
), "key-press-event",
1464 G_CALLBACK (on_window_key_press_event
), plugin
);
1465 g_signal_connect (G_OBJECT (plugin
->shell
), "key-release-event",
1466 G_CALLBACK (on_window_key_release_event
), plugin
);
1470 register_stock_icons (plugin
);
1472 editor_plugin
->action_groups
= NULL
;
1473 /* Add all our editor actions */
1474 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
1476 GList
*actions
, *act
;
1478 swap_label_and_stock (action_groups
[i
].group
,
1479 action_groups
[i
].size
);
1480 group
= anjuta_ui_add_action_group_entries (ui
,
1481 action_groups
[i
].name
,
1482 _(action_groups
[i
].label
),
1483 action_groups
[i
].group
,
1484 action_groups
[i
].size
,
1485 GETTEXT_PACKAGE
, TRUE
,
1487 editor_plugin
->action_groups
=
1488 g_list_prepend (editor_plugin
->action_groups
, group
);
1489 actions
= gtk_action_group_list_actions (group
);
1492 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1493 act
= g_list_next (act
);
1496 for (i
= 0; i
< G_N_ELEMENTS (action_toggle_groups
); i
++)
1498 GList
*actions
, *act
;
1500 swap_toggle_label_and_stock (action_toggle_groups
[i
].group
,
1501 action_toggle_groups
[i
].size
);
1502 group
= anjuta_ui_add_toggle_action_group_entries (ui
,
1503 action_toggle_groups
[i
].name
,
1504 _(action_toggle_groups
[i
].label
),
1505 action_toggle_groups
[i
].group
,
1506 action_toggle_groups
[i
].size
,
1507 GETTEXT_PACKAGE
, TRUE
, plugin
);
1508 editor_plugin
->action_groups
=
1509 g_list_prepend (editor_plugin
->action_groups
, group
);
1510 actions
= gtk_action_group_list_actions (group
);
1513 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1514 act
= g_list_next (act
);
1517 group
= gtk_action_group_new ("ActionGroupNavigation");
1518 editor_plugin
->action_groups
=
1519 g_list_prepend (editor_plugin
->action_groups
, group
);
1521 action
= g_object_new (EGG_TYPE_ENTRY_ACTION
,
1522 "name", "ActionEditGotoLineEntry",
1523 "label", _("Goto line"),
1524 "tooltip", _("Enter the line number to jump and press enter"),
1525 "stock_id", GTK_STOCK_JUMP_TO
,
1528 g_signal_connect (action
, "activate",
1529 G_CALLBACK (on_toolbar_goto_clicked
), plugin
);
1530 gtk_action_group_add_action (group
, action
);
1532 anjuta_ui_add_action_group (ui
, "ActionGroupNavigation",
1533 N_("Editor quick navigations"),
1537 editor_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
1538 anjuta_shell_add_widget (plugin
->shell
, docman
,
1539 "AnjutaDocumentManager", _("Documents"),
1540 "editor-plugin-icon",
1541 ANJUTA_SHELL_PLACEMENT_CENTER
, NULL
);
1542 ui_states_init(plugin
);
1543 ui_give_shorter_names (plugin
);
1544 update_editor_ui (plugin
, NULL
);
1546 /* Setup popup menu */
1547 popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
1548 "/PopupDocumentManager");
1549 g_assert (popup_menu
!= NULL
&& GTK_IS_MENU (popup_menu
));
1550 anjuta_docman_set_popup_menu (ANJUTA_DOCMAN (docman
), popup_menu
);
1553 //search_and_replace_init (ANJUTA_DOCMAN (docman));
1555 /* Connect to save session */
1556 g_signal_connect (G_OBJECT (plugin
->shell
), "save-session",
1557 G_CALLBACK (on_session_save
), plugin
);
1558 /* Connect to save prompt */
1559 g_signal_connect (G_OBJECT (plugin
->shell
), "save-prompt",
1560 G_CALLBACK (on_save_prompt
), plugin
);
1567 deactivate_plugin (AnjutaPlugin
*plugin
)
1569 // GtkIconFactory *icon_factory;
1570 DocmanPlugin
*eplugin
;
1572 AnjutaStatus
*status
;
1575 DEBUG_PRINT ("DocmanPlugin: Dectivating Editor plugin...");
1577 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1579 prefs_finalize (eplugin
);
1580 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1581 G_CALLBACK (on_session_save
), plugin
);
1582 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1583 G_CALLBACK (on_save_prompt
), plugin
);
1585 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1586 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1588 g_signal_handlers_disconnect_by_func (G_OBJECT (status
),
1589 G_CALLBACK (anjuta_docman_set_busy
),
1591 g_signal_handlers_disconnect_by_func (G_OBJECT (eplugin
->docman
),
1592 G_CALLBACK (on_editor_changed
),
1594 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1595 G_CALLBACK (on_window_key_press_event
),
1597 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1598 G_CALLBACK (on_window_key_release_event
),
1601 on_editor_changed (ANJUTA_DOCMAN (eplugin
->docman
), NULL
, plugin
);
1603 /* Widget is removed from the container when destroyed */
1604 gtk_widget_destroy (eplugin
->docman
);
1605 anjuta_ui_unmerge (ui
, eplugin
->uiid
);
1606 node
= eplugin
->action_groups
;
1609 GtkActionGroup
*group
= GTK_ACTION_GROUP (node
->data
);
1610 anjuta_ui_remove_action_group (ui
, group
);
1611 node
= g_list_next (node
);
1613 g_list_free (eplugin
->action_groups
);
1616 /* Unregister stock icons */
1617 /* Unregister preferences */
1619 eplugin
->docman
= NULL
;
1621 eplugin
->action_groups
= NULL
;
1627 dispose (GObject
*obj
)
1629 // DocmanPlugin *eplugin = ANJUTA_PLUGIN_DOCMAN (obj);
1630 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
1634 docman_plugin_instance_init (GObject
*obj
)
1636 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (obj
);
1638 plugin
->g_tabbing
= FALSE
;
1639 plugin
->gconf_notify_ids
= NULL
;
1640 plugin
->idt
= indent_init(plugin
->prefs
);
1644 docman_plugin_class_init (GObjectClass
*klass
)
1646 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
1648 parent_class
= g_type_class_peek_parent (klass
);
1650 plugin_class
->activate
= activate_plugin
;
1651 plugin_class
->deactivate
= deactivate_plugin
;
1652 klass
->dispose
= dispose
;
1655 /* Implement IAnjutaDocumentManager interfaces */
1656 static const gchar
*
1657 ianjuta_docman_get_full_filename (IAnjutaDocumentManager
*plugin
,
1658 const gchar
*file
, GError
**e
)
1660 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1661 return anjuta_docman_get_full_filename (ANJUTA_DOCMAN (docman
), file
);
1664 static IAnjutaEditor
*
1665 ianjuta_docman_find_editor_with_path (IAnjutaDocumentManager
*plugin
,
1666 const gchar
*file_path
, GError
**e
)
1668 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1669 return anjuta_docman_find_editor_with_path (ANJUTA_DOCMAN (docman
), file_path
);
1672 static IAnjutaEditor
*
1673 ianjuta_docman_get_current_editor (IAnjutaDocumentManager
*plugin
, GError
**e
)
1675 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1676 return anjuta_docman_get_current_editor (ANJUTA_DOCMAN (docman
));
1680 ianjuta_docman_set_current_editor (IAnjutaDocumentManager
*plugin
,
1681 IAnjutaEditor
*editor
, GError
**e
)
1683 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1684 anjuta_docman_set_current_editor (ANJUTA_DOCMAN (docman
),
1689 ianjuta_docman_get_editors (IAnjutaDocumentManager
*plugin
, GError
**e
)
1691 AnjutaDocman
*docman
;
1692 GList
* editors
= NULL
;
1693 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1694 editors
= anjuta_docman_get_all_editors (docman
);
1698 static IAnjutaEditor
*
1699 ianjuta_docman_goto_file_line (IAnjutaDocumentManager
*plugin
,
1700 const gchar
*uri
, gint linenum
, GError
**e
)
1702 AnjutaDocman
*docman
;
1703 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1704 return anjuta_docman_goto_file_line (docman
, uri
, linenum
);
1707 static IAnjutaEditor
*
1708 ianjuta_docman_goto_file_line_mark (IAnjutaDocumentManager
*plugin
,
1709 const gchar
*uri
, gint linenum
, gboolean mark
, GError
**e
)
1711 AnjutaDocman
*docman
;
1712 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1713 return anjuta_docman_goto_file_line_mark (docman
, uri
, linenum
, mark
);
1716 static IAnjutaEditor
*
1717 ianjuta_docman_add_buffer (IAnjutaDocumentManager
*plugin
,
1718 const gchar
*filename
, const gchar
*content
,
1721 AnjutaDocman
*docman
;
1723 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1724 te
= anjuta_docman_add_editor (docman
, NULL
, filename
);
1727 /*if (content && strlen (content) > 0)
1728 aneditor_command (te->editor_id, ANE_INSERTTEXT, -1,
1730 return IANJUTA_EDITOR (te
);
1736 ianjuta_docman_remove_buffer (IAnjutaDocumentManager
*plugin
,
1737 IAnjutaEditor
*editor
,
1738 gboolean save_before
, GError
**e
)
1740 gint ret_val
= TRUE
;
1741 AnjutaDocman
*docman
;
1742 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1746 ret_val
= anjuta_docman_save_editor (docman
, editor
,
1747 GTK_WIDGET (ANJUTA_PLUGIN (plugin
)->shell
));
1750 anjuta_docman_remove_editor (docman
, editor
);
1756 ianjuta_document_manager_iface_init (IAnjutaDocumentManagerIface
*iface
)
1758 iface
->get_full_filename
= ianjuta_docman_get_full_filename
;
1759 iface
->find_editor_with_path
= ianjuta_docman_find_editor_with_path
;
1760 iface
->get_current_editor
= ianjuta_docman_get_current_editor
;
1761 iface
->set_current_editor
= ianjuta_docman_set_current_editor
;
1762 iface
->get_editors
= ianjuta_docman_get_editors
;
1763 iface
->goto_file_line
= ianjuta_docman_goto_file_line
;
1764 iface
->goto_file_line_mark
= ianjuta_docman_goto_file_line_mark
;
1765 iface
->add_buffer
= ianjuta_docman_add_buffer
;
1766 iface
->remove_buffer
= ianjuta_docman_remove_buffer
;
1769 /* Implement IAnjutaFile interface */
1771 ifile_open (IAnjutaFile
* plugin
, const gchar
* uri
, GError
** e
)
1773 AnjutaDocman
*docman
;
1775 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1776 anjuta_docman_goto_file_line_mark (docman
, uri
, -1, TRUE
);
1780 ifile_get_uri (IAnjutaFile
* plugin
, GError
** e
)
1782 AnjutaDocman
*docman
;
1783 IAnjutaEditor
* editor
;
1784 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1785 editor
= anjuta_docman_get_current_editor (docman
);
1787 return ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1788 else if (ianjuta_editor_get_filename(editor
, NULL
))
1789 return gnome_vfs_get_uri_from_local_path (ianjuta_editor_get_filename(editor
, NULL
));
1795 ifile_iface_init (IAnjutaFileIface
*iface
)
1797 iface
->open
= ifile_open
;
1798 iface
->get_uri
= ifile_get_uri
;
1801 /* Implement IAnjutaFileSavable interface */
1803 isaveable_save (IAnjutaFileSavable
* plugin
, GError
** e
)
1805 /* Save all editors */
1806 AnjutaDocman
*docman
;
1807 IAnjutaEditor
* editor
;
1809 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1810 editors
= anjuta_docman_get_all_editors(docman
);
1814 editor
= IANJUTA_EDITOR(editors
->data
);
1815 uri
= ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1817 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1819 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1822 editors
= g_list_next(editors
);
1824 g_list_free(editors
);
1828 isavable_save_as (IAnjutaFileSavable
* plugin
, const gchar
* uri
, GError
** e
)
1830 DEBUG_PRINT("save_as: Not implemented in DocmanPlugin");
1834 isavable_is_dirty(IAnjutaFileSavable
* plugin
, GError
** e
)
1836 /* Is any editor unsaved */
1837 AnjutaDocman
*docman
;
1838 IAnjutaEditor
* editor
;
1840 gboolean retval
= FALSE
;
1841 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1842 editors
= anjuta_docman_get_all_editors(docman
);
1845 editor
= IANJUTA_EDITOR(editors
->data
);
1846 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1851 editors
= g_list_next(editors
);
1853 g_list_free(editors
);
1858 isavable_set_dirty(IAnjutaFileSavable
* plugin
, gboolean dirty
, GError
** e
)
1860 DEBUG_PRINT("set_dirty: Not implemented in DocmanPlugin");
1864 isavable_iface_init (IAnjutaFileSavableIface
*iface
)
1866 iface
->save
= isaveable_save
;
1867 iface
->save_as
= isavable_save_as
;
1868 iface
->set_dirty
= isavable_set_dirty
;
1869 iface
->is_dirty
= isavable_is_dirty
;
1873 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
1875 GtkWidget
*indent_button
;
1876 GtkWidget
*indent_combo
;
1877 GtkWidget
*indent_entry
;
1880 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN(ipref
);
1882 /* Add preferences */
1883 gxml
= glade_xml_new (PREFS_GLADE
, "preferences_dialog", NULL
);
1884 indent_button
= glade_xml_get_widget (gxml
, "set_indent_button");
1885 g_signal_connect (G_OBJECT (indent_button
), "clicked",
1886 G_CALLBACK (on_edit_editor_indent
), plugin
);
1888 anjuta_preferences_add_page (prefs
,
1889 gxml
, "Documents", _("Documents"), ICON_FILE
);
1890 anjuta_encodings_init (prefs
, gxml
);
1892 indent_combo
= glade_xml_get_widget (gxml
, "pref_indent_style_combobox");
1893 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->pref_indent_combo
= indent_combo
;
1894 g_signal_connect (G_OBJECT (indent_combo
), "changed",
1895 G_CALLBACK (on_style_combo_changed
), plugin
);
1898 indent_entry
= glade_xml_get_widget (gxml
, "preferences_style_entry");
1899 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->pref_indent_options
= indent_entry
;
1900 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->prefs
= ANJUTA_PLUGIN_DOCMAN (plugin
)->prefs
;
1901 indent_init_load_style(ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
);
1903 g_object_unref (G_OBJECT (gxml
));
1904 prefs_init(ANJUTA_PLUGIN_DOCMAN (plugin
));
1905 pref_set_style_combo(ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
);
1909 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
1911 DocmanPlugin
* plugin
= ANJUTA_PLUGIN_DOCMAN (ipref
);
1912 prefs_finalize(plugin
);
1913 anjuta_preferences_dialog_remove_page(ANJUTA_PREFERENCES_DIALOG(prefs
),
1918 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
1920 iface
->merge
= ipreferences_merge
;
1921 iface
->unmerge
= ipreferences_unmerge
;
1924 ANJUTA_PLUGIN_BEGIN (DocmanPlugin
, docman_plugin
);
1925 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_document_manager
, IANJUTA_TYPE_DOCUMENT_MANAGER
);
1926 ANJUTA_PLUGIN_ADD_INTERFACE(ifile
, IANJUTA_TYPE_FILE
);
1927 ANJUTA_PLUGIN_ADD_INTERFACE(isavable
, IANJUTA_TYPE_FILE_SAVABLE
);
1928 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
1931 ANJUTA_SIMPLE_PLUGIN (DocmanPlugin
, docman_plugin
);