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-assist.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 "undock.png"
56 #define ANJUTA_PIXMAP_INDENT "indent.xpm"
57 #define ANJUTA_PIXMAP_SYNTAX "syntax.xpm"
58 #define ANJUTA_PIXMAP_BOOKMARK_TOGGLE "bookmark_toggle.xpm"
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_ERROR_PREV "error-prev.png"
64 #define ANJUTA_PIXMAP_ERROR_NEXT "error-next.png"
66 #define ANJUTA_PIXMAP_FOLD_TOGGLE "fold_toggle.xpm"
67 #define ANJUTA_PIXMAP_FOLD_CLOSE "fold_close.xpm"
68 #define ANJUTA_PIXMAP_FOLD_OPEN "fold_open.xpm"
70 #define ANJUTA_PIXMAP_BLOCK_SELECT "block_select.xpm"
71 #define ANJUTA_PIXMAP_BLOCK_START "block-start.png"
72 #define ANJUTA_PIXMAP_BLOCK_END "block-end.png"
74 #define ANJUTA_PIXMAP_INDENT_INC "indent_inc.xpm"
75 #define ANJUTA_PIXMAP_INDENT_DCR "indent_dcr.xpm"
76 #define ANJUTA_PIXMAP_INDENT_AUTO "indent_auto.xpm"
77 #define ANJUTA_PIXMAP_AUTOFORMAT_SETTING "indent_set.xpm"
79 #define ANJUTA_PIXMAP_CALLTIP "calltip.xpm"
80 #define ANJUTA_PIXMAP_AUTOCOMPLETE "autocomplete.png"
83 #define ANJUTA_STOCK_SWAP "anjuta-swap"
84 #define ANJUTA_STOCK_FOLD_TOGGLE "anjuta-fold-toggle"
85 #define ANJUTA_STOCK_FOLD_OPEN "anjuta-fold-open"
86 #define ANJUTA_STOCK_FOLD_CLOSE "anjuta-fold-close"
87 #define ANJUTA_STOCK_BLOCK_SELECT "anjuta-block-select"
88 #define ANJUTA_STOCK_INDENT_INC "anjuta-indent-inc"
89 #define ANJUTA_STOCK_INDENT_DCR "anjuta-indect-dcr"
90 #define ANJUTA_STOCK_INDENT_AUTO "anjuta-indent-auto"
91 #define ANJUTA_STOCK_AUTOFORMAT_SETTINGS "anjuta-autoformat-settings"
92 #define ANJUTA_STOCK_AUTOCOMPLETE "anjuta-autocomplete"
93 #define ANJUTA_STOCK_PREV_BRACE "anjuta-prev-brace"
94 #define ANJUTA_STOCK_NEXT_BRACE "anjuta-next-brace"
95 #define ANJUTA_STOCK_BLOCK_START "anjuta-block-start"
96 #define ANJUTA_STOCK_BLOCK_END "anjuta-block-end"
97 #define ANJUTA_STOCK_BOOKMARK_TOGGLE "anjuta-bookmark-toggle"
98 #define ANJUTA_STOCK_BOOKMARK_FIRST "anjuta-bookmark-first"
99 #define ANJUTA_STOCK_BOOKMARK_PREV "anjuta-bookmark-previous"
100 #define ANJUTA_STOCK_BOOKMARK_NEXT "anjuta-bookmark-next"
101 #define ANJUTA_STOCK_BOOKMARK_LAST "anjuta-bookmark-last"
104 static gpointer parent_class
;
106 /* Shortcuts implementation */
109 mS__
= GDK_SHIFT_MASK
,
110 m_C_
= GDK_CONTROL_MASK
,
111 m__M
= GDK_MOD1_MASK
,
112 mSC_
= GDK_SHIFT_MASK
| GDK_CONTROL_MASK
,
116 ID_NEXTBUFFER
= 1, /* Note: the value mustn't be 0 ! */
123 unsigned int gdk_key
;
127 static ShortcutMapping global_keymap
[] = {
128 /* FIXME: HIG requires that Ctrl+Tab be used to transfer focus in multiline
129 text entries. So we can't use the following ctrl+tabbing. Is there other
130 sensible keys that can be used for them?
133 { m_C_, GDK_Tab, ID_NEXTBUFFER },
134 { mSC_, GDK_ISO_Left_Tab, ID_PREVBUFFER },
136 { m__M
, GDK_1
, ID_FIRSTBUFFER
},
137 { m__M
, GDK_2
, ID_FIRSTBUFFER
+ 1},
138 { m__M
, GDK_3
, ID_FIRSTBUFFER
+ 2},
139 { m__M
, GDK_4
, ID_FIRSTBUFFER
+ 3},
140 { m__M
, GDK_5
, ID_FIRSTBUFFER
+ 4},
141 { m__M
, GDK_6
, ID_FIRSTBUFFER
+ 5},
142 { m__M
, GDK_7
, ID_FIRSTBUFFER
+ 6},
143 { m__M
, GDK_8
, ID_FIRSTBUFFER
+ 7},
144 { m__M
, GDK_9
, ID_FIRSTBUFFER
+ 8},
145 { m__M
, GDK_0
, ID_FIRSTBUFFER
+ 9},
149 static GtkActionEntry actions_file
[] = {
150 { "ActionFileSave", N_("_Save"), GTK_STOCK_SAVE
, "<control>s",
151 N_("Save current file"), G_CALLBACK (on_save_activate
)},
152 { "ActionFileSaveAs", N_("Save _As..."), GTK_STOCK_SAVE_AS
, NULL
,
153 N_("Save the current file with a different name"),
154 G_CALLBACK (on_save_as_activate
)},
155 { "ActionFileSaveAll", N_("Save A_ll"), NULL
, NULL
,
156 N_("Save all currently open files, except new files"),
157 G_CALLBACK (on_save_all_activate
)},
158 { "ActionFileClose", N_("_Close File"), GTK_STOCK_CLOSE
, "<control>w",
159 N_("Close current file"),
160 G_CALLBACK (on_close_file_activate
)},
161 { "ActionFileCloseAll", N_("Close All Files"), GTK_STOCK_CLOSE
, "<shift><control>w",
162 N_("Close all files"),
163 G_CALLBACK (on_close_all_file_activate
)},
164 { "ActionFileReload", N_("Reload F_ile"), GTK_STOCK_REVERT_TO_SAVED
, NULL
,
165 N_("Reload current file"),
166 G_CALLBACK (on_reload_file_activate
)},
167 { "ActionFileSwap", N_("Swap .h/.c"), ANJUTA_STOCK_SWAP
, NULL
,
168 N_("Swap c header and source file"),
169 G_CALLBACK (on_swap_activate
)},
170 { "ActionMenuFileRecentFiles", N_("Recent _Files"), NULL
, NULL
, NULL
, NULL
},
173 static GtkActionEntry actions_print
[] = {
174 { "ActionPrintFile", N_("_Print..."), GTK_STOCK_PRINT
, "<control>p",
175 N_("Print the current file"), G_CALLBACK (anjuta_print_cb
)},
176 { "ActionPrintPreview", N_("_Print Preview"), NULL
, NULL
,
177 N_("Print preview of the current file"),
178 G_CALLBACK (anjuta_print_preview_cb
)},
181 static GtkActionEntry actions_transform
[] = {
182 { "ActionMenuEditTransform", N_("_Transform"), NULL
, NULL
, NULL
, NULL
},
183 { "ActionEditMakeSelectionUppercase", N_("_Make Selection Uppercase"), NULL
, NULL
,
184 N_("Make the selected text uppercase"),
185 G_CALLBACK (on_editor_command_upper_case_activate
)},
186 { "ActionEditMakeSelectionLowercase", N_("Make Selection Lowercase"), NULL
, NULL
,
187 N_("Make the selected text lowercase"),
188 G_CALLBACK (on_editor_command_lower_case_activate
)},
189 { "ActionEditConvertCRLF", N_("Convert EOL to CRLF"), NULL
, NULL
,
190 N_("Convert End Of Line characters to DOS EOL (CRLF)"),
191 G_CALLBACK (on_editor_command_eol_crlf_activate
)},
192 { "ActionEditConvertLF", N_("Convert EOL to LF"), NULL
, NULL
,
193 N_("Convert End Of Line characters to Unix EOL (LF)"),
194 G_CALLBACK (on_editor_command_eol_lf_activate
)},
195 { "ActionEditConvertCR", N_("Convert EOL to CR"), NULL
, NULL
,
196 N_("Convert End Of Line characters to Mac OS EOL (CR)"),
197 G_CALLBACK (on_editor_command_eol_cr_activate
)},
198 { "ActionEditConvertEOL", N_("Convert EOL to Majority EOL"), NULL
, NULL
,
199 N_("Convert End Of Line characters to majority of the EOL found in the file"),
200 G_CALLBACK (on_transform_eolchars1_activate
)},
203 static GtkActionEntry actions_select
[] = {
204 { "ActionMenuEditSelect", N_("_Select"), NULL
, NULL
, NULL
, NULL
},
205 { "ActionEditSelectAll", N_("Select _All"), NULL
, "<control>a",
206 N_("Select all text in the editor"),
207 G_CALLBACK (on_editor_command_select_all_activate
)},
208 { "ActionEditSelectToBrace", N_("Select to _Brace"), NULL
, NULL
,
209 N_("Select the text in the matching braces"),
210 G_CALLBACK (on_editor_command_select_to_brace_activate
)},
211 { "ActionEditSelectBlock", N_("Select _Code Block"),
212 ANJUTA_STOCK_BLOCK_SELECT
, "<shift><control>b",
213 N_("Select the current code block"),
214 G_CALLBACK (on_editor_command_select_block_activate
)},
217 static GtkActionEntry actions_comment
[] = {
218 { "ActionMenuEditComment", N_("Co_mment"), NULL
, NULL
, NULL
, NULL
},
219 { "ActionEditCommentBlock", N_("_Block Comment/Uncomment"), NULL
, NULL
,
220 N_("Block comment the selected text"),
221 G_CALLBACK (on_comment_block
)},
222 { "ActionEditCommentBox", N_("Bo_x Comment/Uncomment"), NULL
, NULL
,
223 N_("Box comment the selected text"),
224 G_CALLBACK (on_comment_box
)},
225 { "ActionEditCommentStream", N_("_Stream Comment/Uncomment"), NULL
, NULL
,
226 N_("Stream comment the selected text"),
227 G_CALLBACK (on_comment_block
)},
230 static GtkActionEntry actions_navigation
[] = {
231 { "ActionMenuGoto", N_("_Goto"), NULL
, NULL
, NULL
, NULL
},
232 { "ActionEditGotoLineActivate", N_("_Goto Line number"),
233 GTK_STOCK_JUMP_TO
, NULL
,
234 N_("Go to a particular line in the editor"),
235 G_CALLBACK (on_goto_activate
)},
236 { "ActionEditGotoLine", N_("_Line Number..."),
237 GTK_STOCK_JUMP_TO
, "<control><alt>g",
238 N_("Go to a particular line in the editor"),
239 G_CALLBACK (on_goto_line_no1_activate
)},
240 { "ActionEditGotoMatchingBrace", N_("Matching _Brace"),
241 GTK_STOCK_JUMP_TO
, "<control><alt>m",
242 N_("Go to the matching brace in the editor"),
243 G_CALLBACK (on_editor_command_match_brace_activate
)},
244 { "ActionEditGotoBlockStart", N_("_Start of Block"),
245 ANJUTA_STOCK_BLOCK_START
, "<control><alt>s",
246 N_("Go to the start of the current block"),
247 G_CALLBACK (on_goto_block_start1_activate
)},
248 { "ActionEditGotoBlockEnd", N_("_End of Block"),
249 ANJUTA_STOCK_BLOCK_END
, "<control><alt>e",
250 N_("Go to the end of the current block"),
251 G_CALLBACK (on_goto_block_end1_activate
)},
252 { "ActionEditGotoHistoryPrev", N_("Previous _History"),
253 GTK_STOCK_JUMP_TO
, NULL
,
254 N_("Goto previous history"),
255 G_CALLBACK (on_prev_history
)},
256 { "ActionEditGotoHistoryNext", N_("Next Histor_y"),
257 GTK_STOCK_JUMP_TO
, NULL
,
258 N_("Goto next history"),
259 G_CALLBACK (on_next_history
)}
262 static GtkActionEntry actions_edit
[] = {
263 { "ActionMenuEdit", N_("_Edit"), NULL
, NULL
, NULL
, NULL
},
264 { "ActionMenuViewEditor", N_("_Editor"), NULL
, NULL
, NULL
, NULL
},
265 { "ActionViewEditorAddView", N_("_Add Editor View"), NULL
, NULL
,
266 N_("Add one more view of current document"),
267 G_CALLBACK (on_editor_add_view_activate
)},
268 { "ActionViewEditorRemoveView", N_("_Remove Editor View"), NULL
, NULL
,
269 N_("Remove current view of the document"),
270 G_CALLBACK (on_editor_remove_view_activate
)},
271 { "ActionEditUndo", N_("U_ndo"), GTK_STOCK_UNDO
, "<control>z",
272 N_("Undo the last action"),
273 G_CALLBACK (on_editor_command_undo_activate
)},
274 { "ActionEditRedo", N_("_Redo"), GTK_STOCK_REDO
, "<control>r",
275 N_("Redo the last undone action"),
276 G_CALLBACK (on_editor_command_redo_activate
)},
277 { "ActionEditCut", N_("C_ut"), GTK_STOCK_CUT
, "<control>x",
278 N_("Cut the selected text from the editor to the clipboard"),
279 G_CALLBACK (on_editor_command_cut_activate
)},
280 { "ActionEditCopy", N_("_Copy"), GTK_STOCK_COPY
, "<control>c",
281 N_("Copy the selected text to the clipboard"),
282 G_CALLBACK (on_editor_command_copy_activate
)},
283 { "ActionEditPaste", N_("_Paste"), GTK_STOCK_PASTE
, "<control>v",
284 N_("Paste the content of clipboard at the current position"),
285 G_CALLBACK (on_editor_command_paste_activate
)},
286 { "ActionEditClear", N_("_Clear"), NULL
, "Delete",
287 N_("Delete the selected text from the editor"),
288 G_CALLBACK (on_editor_command_clear_activate
)},
289 { "ActionEditAutocomplete", N_("_AutoComplete"),
290 ANJUTA_STOCK_AUTOCOMPLETE
, "<control>Return",
291 N_("AutoComplete the current word"),
292 G_CALLBACK (on_editor_command_complete_word_activate
)}
295 static GtkToggleActionEntry actions_view
[] = {
296 { "ActionViewEditorLinenumbers", N_("_Line Number Margin"), NULL
, NULL
,
297 N_("Show/Hide line numbers"),
298 G_CALLBACK (on_editor_linenos1_activate
), FALSE
},
299 { "ActionViewEditorMarkers", N_("_Marker Margin"), NULL
, NULL
,
300 N_("Show/Hide marker margin"),
301 G_CALLBACK (on_editor_markers1_activate
), FALSE
},
302 { "ActionViewEditorFolds", N_("_Code Fold Margin"), NULL
, NULL
,
303 N_("Show/Hide code fold margin"),
304 G_CALLBACK (on_editor_codefold1_activate
), FALSE
},
305 { "ActionViewEditorGuides", N_("_Indentation Guides"), NULL
, NULL
,
306 N_("Show/Hide indentation guides"),
307 G_CALLBACK (on_editor_indentguides1_activate
), FALSE
},
308 { "ActionViewEditorSpaces", N_("_White Space"), NULL
, NULL
,
309 N_("Show/Hide white spaces"),
310 G_CALLBACK (on_editor_whitespaces1_activate
), FALSE
},
311 { "ActionViewEditorEOL", N_("_Line End Characters"), NULL
, NULL
,
312 N_("Show/Hide line end characters"),
313 G_CALLBACK (on_editor_eolchars1_activate
), FALSE
},
314 { "ActionViewEditorWrapping", N_("Line _Wrapping"), NULL
, NULL
,
315 N_("Enable/disable line wrapping"),
316 G_CALLBACK (on_editor_linewrap1_activate
), FALSE
}
319 static GtkActionEntry actions_zoom
[] = {
320 { "ActionViewEditorZoomIn", N_("Zoom In"), GTK_STOCK_ZOOM_IN
, "<control>plus",
321 N_("Zoom in: Increase font size"),
322 G_CALLBACK (on_zoom_in_text_activate
)},
323 { "ActionViewEditorZoomOut", N_("Zoom Out"), GTK_STOCK_ZOOM_OUT
, "<control>minus",
324 N_("Zoom out: Decrease font size"),
325 G_CALLBACK (on_zoom_out_text_activate
)}
328 static GtkActionEntry actions_style
[] = {
329 { "ActionMenuFormatStyle", N_("_Highlight Mode"), NULL
, NULL
, NULL
, NULL
}
332 static GtkActionEntry actions_format
[] = {
333 { "ActionMenuFormat", N_("For_mat"), NULL
, NULL
, NULL
, NULL
},
334 { "ActionFormatAutoformat", N_("Auto _Format"),
335 ANJUTA_STOCK_INDENT_AUTO
, NULL
,
336 N_("Autoformat the current source file"),
337 G_CALLBACK (on_indent1_activate
)},
339 { "ActionFormatSettings", N_("Autoformat _settings"),
340 ANJUTA_STOCK_AUTOFORMAT_SETTINGS, NULL,
341 N_("Autoformat settings"),
342 G_CALLBACK (on_format_indent_style_clicked)},
343 { "ActionFormatIndentationIncrease", N_("_Increase Indent"),
344 ANJUTA_STOCK_INDENT_INC, NULL,
345 N_("Increase indentation of line/selection"),
346 G_CALLBACK (on_editor_command_indent_increase_activate)},
347 { "ActionFormatIndentationDecrease", N_("_Decrease Indent"),
348 ANJUTA_STOCK_INDENT_DCR, NULL,
349 N_("Decrease indentation of line/selection"),
350 G_CALLBACK (on_editor_command_indent_decrease_activate)},
352 { "ActionFormatFoldCloseAll", N_("_Close All Folds"),
353 ANJUTA_STOCK_FOLD_CLOSE
, NULL
,
354 N_("Close all code folds in the editor"),
355 G_CALLBACK (on_editor_command_close_folds_all_activate
)},
356 { "ActionFormatFoldOpenAll", N_("_Open All Folds"),
357 ANJUTA_STOCK_FOLD_OPEN
, NULL
,
358 N_("Open all code folds in the editor"),
359 G_CALLBACK (on_editor_command_open_folds_all_activate
)},
360 { "ActionFormatFoldToggle", N_("_Toggle Current Fold"),
361 ANJUTA_STOCK_FOLD_TOGGLE
, NULL
,
362 N_("Toggle current code fold in the editor"),
363 G_CALLBACK (on_editor_command_toggle_fold_activate
)},
366 static GtkActionEntry actions_bookmark
[] = {
367 { "ActionMenuBookmark", N_("Bookmar_k"), NULL
, NULL
, NULL
, NULL
},
368 { "ActionBookmarkToggle", N_("_Toggle Bookmark"),
369 ANJUTA_STOCK_BOOKMARK_TOGGLE
, "<control>k",
370 N_("Toggle a bookmark at the current line position"),
371 G_CALLBACK (on_editor_command_bookmark_toggle_activate
)},
372 { "ActionBookmarkFirst", N_("_First Bookmark"),
373 ANJUTA_STOCK_BOOKMARK_FIRST
, NULL
,
374 N_("Jump to the first bookmark in the file"),
375 G_CALLBACK (on_editor_command_bookmark_first_activate
)},
376 { "ActionBookmarkPrevious", N_("_Previous Bookmark"),
377 ANJUTA_STOCK_BOOKMARK_PREV
, "<control>comma",
378 N_("Jump to the previous bookmark in the file"),
379 G_CALLBACK (on_editor_command_bookmark_prev_activate
)},
380 { "ActionBookmarkNext", N_("_Next Bookmark"),
381 ANJUTA_STOCK_BOOKMARK_NEXT
, "<control>period",
382 N_("Jump to the next bookmark in the file"),
383 G_CALLBACK (on_editor_command_bookmark_next_activate
)},
384 { "ActionBookmarkLast", N_("_Last Bookmark"),
385 ANJUTA_STOCK_BOOKMARK_LAST
, NULL
,
386 N_("Jump to the last bookmark in the file"),
387 G_CALLBACK (on_editor_command_bookmark_last_activate
)},
388 { "ActionBookmarkClear", N_("_Clear All Bookmarks"),
390 N_("Clear bookmarks"),
391 G_CALLBACK (on_editor_command_bookmark_clear_activate
)},
394 struct ActionGroupInfo
{
395 GtkActionEntry
*group
;
401 struct ActionToggleGroupInfo
{
402 GtkToggleActionEntry
*group
;
408 static struct ActionGroupInfo action_groups
[] = {
409 { actions_file
, G_N_ELEMENTS (actions_file
), "ActionGroupEditorFile", N_("Editor file operations")},
410 { actions_print
, G_N_ELEMENTS (actions_print
), "ActionGroupEditorPrint", N_("Editor print operations")},
411 { actions_transform
, G_N_ELEMENTS (actions_transform
), "ActionGroupEditorTransform", N_("Editor text transformation") },
412 { actions_select
, G_N_ELEMENTS (actions_select
), "ActionGroupEditorSelect", N_("Editor text selection") },
413 // { actions_insert, G_N_ELEMENTS (actions_insert), "ActionGroupEditorInsert", N_("Editor text insertions") },
414 { actions_comment
, G_N_ELEMENTS (actions_comment
), "ActionGroupEditorComment", N_("Editor code commenting") },
415 { actions_navigation
, G_N_ELEMENTS (actions_navigation
), "ActionGroupEditorNavigate", N_("Editor navigations") },
416 { actions_edit
, G_N_ELEMENTS (actions_edit
), "ActionGroupEditorEdit", N_("Editor edit operations") },
417 { actions_zoom
, G_N_ELEMENTS (actions_zoom
), "ActionGroupEditorZoom", N_("Editor zoom operations") },
418 { actions_style
, G_N_ELEMENTS (actions_style
), "ActionGroupEditorStyle", N_("Editor syntax highlighting styles") },
419 { actions_format
, G_N_ELEMENTS (actions_format
), "ActionGroupEditorFormat", N_("Editor text formating") },
420 { actions_bookmark
, G_N_ELEMENTS (actions_bookmark
), "ActionGroupEditorBookmark", N_("Editor bookmarks") }
423 static struct ActionToggleGroupInfo action_toggle_groups
[] = {
424 { actions_view
, G_N_ELEMENTS (actions_view
), "ActionGroupEditorView", N_("Editor view settings") }
427 // void pref_set_style_combo(DocmanPlugin *plugin);
429 /* FIXME: There was a change in data representation in GtkActionEntry from
430 EggActionGroupEntry. The actual entries should be fixed and this hack removed */
432 swap_label_and_stock (GtkActionEntry
* actions
, gint size
)
435 for (i
= 0; i
< size
; i
++)
437 const gchar
*stock_id
= actions
[i
].label
;
438 actions
[i
].label
= actions
[i
].stock_id
;
439 actions
[i
].stock_id
= stock_id
;
440 if (actions
[i
].name
== NULL
)
441 DEBUG_PRINT ("Name is null: %s", actions
[i
].label
);
446 swap_toggle_label_and_stock (GtkToggleActionEntry
* actions
, gint size
)
449 for (i
= 0; i
< size
; i
++)
451 const gchar
*stock_id
= actions
[i
].label
;
452 actions
[i
].label
= actions
[i
].stock_id
;
453 actions
[i
].stock_id
= stock_id
;
454 if (actions
[i
].name
== NULL
)
455 DEBUG_PRINT ("Name is null: %s", actions
[i
].label
);
459 #define VIEW_LINENUMBERS_MARGIN "margin.linenumber.visible"
460 #define VIEW_MARKER_MARGIN "margin.marker.visible"
461 #define VIEW_FOLD_MARGIN "margin.fold.visible"
462 #define VIEW_INDENTATION_GUIDES "view.indentation.guides"
463 #define VIEW_WHITE_SPACES "view.whitespace"
464 #define VIEW_EOL "view.eol"
465 #define VIEW_LINE_WRAP "view.line.wrap"
468 ui_states_init (AnjutaPlugin
*plugin
)
471 DocmanPlugin
*eplugin
;
472 static const gchar
*prefs
[] = {
473 VIEW_LINENUMBERS_MARGIN
,
476 VIEW_INDENTATION_GUIDES
,
482 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
483 for (i
= 0; i
< sizeof (actions_view
)/sizeof(GtkToggleActionEntry
); i
++)
488 state
= anjuta_preferences_get_int (eplugin
->prefs
, prefs
[i
]);
489 action
= anjuta_ui_get_action (eplugin
->ui
, "ActionGroupEditorView",
490 actions_view
[i
].name
);
491 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action
), state
);
496 ui_give_shorter_names (AnjutaPlugin
*plugin
)
501 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
502 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
504 g_object_set (G_OBJECT (action
), "short-label", _("Save"),
505 "is-important", TRUE
, NULL
);
506 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
508 g_object_set (G_OBJECT (action
), "short-label", _("Reload"), NULL
);
509 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
511 g_object_set (G_OBJECT (action
), "is-important", TRUE
, NULL
);
512 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
513 "ActionEditGotoLineActivate");
514 g_object_set (G_OBJECT (action
), "short-label", _("Goto"), NULL
);
518 update_editor_ui_enable_all (AnjutaPlugin
*plugin
)
524 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
525 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
527 for (j
= 0; j
< action_groups
[i
].size
; j
++)
529 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
530 action_groups
[i
].group
[j
].name
);
531 if (action_groups
[i
].group
[j
].callback
)
533 g_object_set (G_OBJECT (action
), "sensitive", TRUE
, NULL
);
537 action
= anjuta_ui_get_action (ui
, "ActionGroupNavigation",
538 "ActionEditGotoLineEntry");
539 g_object_set (G_OBJECT (action
), "sensitive", TRUE
, NULL
);
543 update_editor_ui_disable_all (AnjutaPlugin
*plugin
)
549 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
550 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
552 for (j
= 0; j
< action_groups
[i
].size
; j
++)
554 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
555 action_groups
[i
].group
[j
].name
);
556 if (action_groups
[i
].group
[j
].callback
)
558 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
562 action
= anjuta_ui_get_action (ui
, "ActionGroupNavigation",
563 "ActionEditGotoLineEntry");
564 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
569 update_editor_ui_save_items (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
574 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
576 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
578 g_object_set (G_OBJECT (action
), "sensitive",
579 ianjuta_editor_can_undo (editor
, NULL
), NULL
);
581 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
583 g_object_set (G_OBJECT (action
), "sensitive",
584 ianjuta_editor_can_redo (editor
, NULL
), NULL
);
586 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
588 g_object_set (G_OBJECT (action
), "sensitive",
589 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
),
594 update_editor_ui_interface_items (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
600 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
602 /* IAnjutaEditorLanguage */
603 flag
= IANJUTA_IS_EDITOR_LANGUAGE (editor
);
605 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorStyle",
606 "ActionMenuFormatStyle");
607 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
609 /* IAnjutaEditorSelection */
610 flag
= IANJUTA_IS_EDITOR_SELECTION (editor
);
612 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
614 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
616 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
618 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
620 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
622 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
624 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
626 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
628 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
629 "ActionEditSelectAll");
630 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
632 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
633 "ActionEditSelectToBrace");
634 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
636 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
637 "ActionEditSelectBlock");
638 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
640 /* IAnjutaEditorConvert */
641 flag
= IANJUTA_IS_EDITOR_CONVERT (editor
);
642 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
643 "ActionEditMakeSelectionUppercase");
644 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
646 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
647 "ActionEditMakeSelectionLowercase");
648 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
650 /* IAnjutaEditorLineMode */
651 flag
= IANJUTA_IS_EDITOR_LINE_MODE (editor
);
653 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
654 "ActionEditConvertCRLF");
655 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
656 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
657 "ActionEditConvertLF");
658 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
659 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
660 "ActionEditConvertCR");
661 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
662 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
663 "ActionEditConvertEOL");
664 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
666 /* IAnjutaEditorView */
667 flag
= IANJUTA_IS_EDITOR_VIEW (editor
);
668 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
669 "ActionViewEditorAddView");
670 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
671 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
672 "ActionViewEditorRemoveView");
673 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
675 /* IAnjutaEditorAssist */
676 flag
= IANJUTA_IS_EDITOR_ASSIST (editor
);
677 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
678 "ActionEditAutocomplete");
679 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
681 /* IAnjutaEditorFolds */
682 flag
= IANJUTA_IS_EDITOR_FOLDS(editor
);
683 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorFormat",
684 "ActionFormatFoldCloseAll");
685 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
687 flag
= IANJUTA_IS_EDITOR_FOLDS(editor
);
688 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorFormat",
689 "ActionFormatFoldOpenAll");
690 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
692 flag
= IANJUTA_IS_EDITOR_FOLDS(editor
);
693 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorFormat",
694 "ActionFormatFoldToggle");
695 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
697 flag
= IANJUTA_IS_EDITOR_FOLDS(editor
);
698 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorView",
699 "ActionViewEditorFolds");
700 g_object_set (G_OBJECT (action
), "visible", flag
, NULL
);
702 /* IAnjutaEditorComment */
704 flag
= IANJUTA_IS_EDITOR_COMMENT(editor
);
705 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorComment", "ActionMenuEditComment");
706 g_object_set(G_OBJECT (action
), "visible", flag
, NULL
);
708 /* IAnjutaEditorZoom */
710 flag
= IANJUTA_IS_EDITOR_ZOOM(editor
);
711 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorZoom", "ActionViewEditorZoomIn");
712 g_object_set(G_OBJECT (action
), "visible", flag
, NULL
);
713 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorZoom", "ActionViewEditorZoomOut");
714 g_object_set(G_OBJECT (action
), "visible", flag
, NULL
);
716 /* IAnjutaEditorGoto */
717 flag
= IANJUTA_IS_EDITOR_GOTO(editor
);
718 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorNavigate", "ActionEditGotoBlockStart");
719 g_object_set(G_OBJECT (action
), "visible", flag
, NULL
);
720 action
= anjuta_ui_get_action(ui
, "ActionGroupEditorNavigate", "ActionEditGotoBlockEnd");
721 g_object_set(G_OBJECT (action
), "visible", flag
, NULL
);
725 update_editor_ui (AnjutaPlugin
*plugin
, IAnjutaEditor
*editor
)
729 update_editor_ui_disable_all (plugin
);
732 update_editor_ui_enable_all (plugin
);
733 update_editor_ui_save_items (plugin
, editor
);
734 update_editor_ui_interface_items (plugin
, editor
);
738 on_editor_update_save_ui (IAnjutaEditor
*editor
, gboolean entered
,
739 AnjutaPlugin
*plugin
)
741 update_editor_ui_save_items (plugin
, editor
);
744 #define REGISTER_ICON(icon, stock_id) \
745 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"icon, NULL); \
746 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
747 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
748 g_object_unref (pixbuf);
751 register_stock_icons (AnjutaPlugin
*plugin
)
754 GtkIconFactory
*icon_factory
;
755 GtkIconSet
*icon_set
;
757 static gboolean registered
= FALSE
;
763 /* Register stock icons */
764 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
765 icon_factory
= anjuta_ui_get_icon_factory (ui
);
766 REGISTER_ICON (ICON_FILE
, "editor-plugin-icon");
767 REGISTER_ICON (ANJUTA_PIXMAP_SWAP
, ANJUTA_STOCK_SWAP
);
768 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_TOGGLE
, ANJUTA_STOCK_FOLD_TOGGLE
);
769 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_OPEN
, ANJUTA_STOCK_FOLD_OPEN
);
770 REGISTER_ICON (ANJUTA_PIXMAP_FOLD_CLOSE
, ANJUTA_STOCK_FOLD_CLOSE
);
771 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_INC
, ANJUTA_STOCK_INDENT_INC
);
772 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_DCR
, ANJUTA_STOCK_INDENT_DCR
);
773 REGISTER_ICON (ANJUTA_PIXMAP_INDENT_AUTO
, ANJUTA_STOCK_INDENT_AUTO
);
774 REGISTER_ICON (ANJUTA_PIXMAP_AUTOFORMAT_SETTING
, ANJUTA_STOCK_AUTOFORMAT_SETTINGS
);
775 REGISTER_ICON (ANJUTA_PIXMAP_AUTOCOMPLETE
, ANJUTA_STOCK_AUTOCOMPLETE
);
776 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_SELECT
, ANJUTA_STOCK_BLOCK_SELECT
);
777 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_TOGGLE
, ANJUTA_STOCK_BOOKMARK_TOGGLE
);
778 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_FIRST
, ANJUTA_STOCK_BOOKMARK_FIRST
);
779 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_PREV
, ANJUTA_STOCK_BOOKMARK_PREV
);
780 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_NEXT
, ANJUTA_STOCK_BOOKMARK_NEXT
);
781 REGISTER_ICON (ANJUTA_PIXMAP_BOOKMARK_LAST
, ANJUTA_STOCK_BOOKMARK_LAST
);
782 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_START
, ANJUTA_STOCK_BLOCK_START
);
783 REGISTER_ICON (ANJUTA_PIXMAP_BLOCK_END
, ANJUTA_STOCK_BLOCK_END
);
786 #define TEXT_ZOOM_FACTOR "text.zoom.factor"
789 update_status (DocmanPlugin
*plugin
, IAnjutaEditor
*te
)
791 AnjutaStatus
*status
;
793 status
= anjuta_shell_get_status (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
800 gchar
*edit
/*, *mode*/;
801 guint line
, col
, zoom
;
803 /* TODO: Implement this in IAnjutaEditor some kind
805 editor_mode = scintilla_send_message (SCINTILLA (te->widgets.editor),
806 SCI_GETEOLMODE, 0, 0);
807 switch (editor_mode) {
809 mode = g_strdup(_("DOS (CRLF)"));
812 mode = g_strdup(_("Unix (LF)"));
815 mode = g_strdup(_("Mac (CR)"));
818 mode = g_strdup(_("Unknown"));
822 zoom
= anjuta_preferences_get_int (plugin
->prefs
, TEXT_ZOOM_FACTOR
);
823 line
= ianjuta_editor_get_lineno (te
, NULL
);
824 col
= ianjuta_editor_get_column (te
, NULL
);
826 if (ianjuta_editor_get_overwrite (te
, NULL
))
828 edit
= g_strdup (_("OVR"));
832 edit
= g_strdup (_("INS"));
834 anjuta_status_set_default (status
, _("Zoom"), "%d", zoom
);
835 anjuta_status_set_default (status
, _("Line"), "%04d", line
);
836 anjuta_status_set_default (status
, _("Col"), "%03d", col
);
837 anjuta_status_set_default (status
, _("Mode"), edit
);
838 // anjuta_status_set_default (status, _("EOL"), mode);
845 anjuta_status_set_default (status
, _("Zoom"), NULL
);
846 anjuta_status_set_default (status
, _("Line"), NULL
);
847 anjuta_status_set_default (status
, _("Col"), NULL
);
848 anjuta_status_set_default (status
, _("Mode"), NULL
);
849 /* anjuta_status_set_default (status, _("EOL"), NULL); */
854 on_editor_update_ui (IAnjutaEditor
*editor
, DocmanPlugin
*plugin
)
858 te
= anjuta_docman_get_current_editor (ANJUTA_DOCMAN (plugin
->docman
));
860 update_status (plugin
, te
);
863 /* Remove all instances of c from the string s. */
864 static void remove_char(gchar
*s
, gchar c
)
873 /* Compare two strings, ignoring _ characters which indicate mneumonics.
874 * Returns -1, 0, or 1, just like strcmp(). */
876 menu_name_compare(const gchar
*s
, const char *t
)
878 gchar
*s1
= g_utf8_strdown(s
, -1);
879 gchar
*t1
= g_utf8_strdown(t
, -1);
880 remove_char(s1
, '_');
881 remove_char(t1
, '_');
882 int result
= g_utf8_collate(s1
, t1
);
889 compare_language_name(const gchar
*lang1
, const gchar
*lang2
, IAnjutaEditorLanguage
*manager
)
891 const gchar
*fullname1
= ianjuta_editor_language_get_language_name (manager
, lang1
, NULL
);
892 const gchar
*fullname2
= ianjuta_editor_language_get_language_name (manager
, lang2
, NULL
);
893 return menu_name_compare(fullname1
, fullname2
);
897 create_highlight_submenu (DocmanPlugin
*plugin
, IAnjutaEditor
*editor
)
899 const GList
*languages
, *node
;
900 GList
*sorted_languages
;
904 submenu
= gtk_menu_new ();
906 if (!editor
|| !IANJUTA_IS_EDITOR_LANGUAGE (editor
))
909 languages
= ianjuta_editor_language_get_supported_languages (IANJUTA_EDITOR_LANGUAGE (editor
), NULL
);
913 /* Automatic highlight menu */
914 menuitem
= gtk_menu_item_new_with_mnemonic (_("Automatic"));
915 g_signal_connect (G_OBJECT (menuitem
), "activate",
916 G_CALLBACK (on_force_hilite_activate
),
918 g_object_set_data(G_OBJECT(menuitem
), "language_code", "auto-detect");
919 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
920 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), gtk_separator_menu_item_new());
922 /* Sort languages so they appear alphabetically in the menu. */
923 sorted_languages
= g_list_copy((GList
*) languages
);
924 sorted_languages
= g_list_sort_with_data(sorted_languages
, (GCompareDataFunc
) compare_language_name
,
925 IANJUTA_EDITOR_LANGUAGE (editor
));
927 node
= sorted_languages
;
930 const gchar
*lang
= node
->data
;
931 const gchar
*name
= ianjuta_editor_language_get_language_name (IANJUTA_EDITOR_LANGUAGE (editor
), lang
, NULL
);
933 menuitem
= gtk_menu_item_new_with_mnemonic (name
);
934 g_object_set_data_full (G_OBJECT (menuitem
), "language_code",
936 (GDestroyNotify
)g_free
);
937 g_signal_connect (G_OBJECT (menuitem
), "activate",
938 G_CALLBACK (on_force_hilite_activate
),
940 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
941 node
= g_list_next (node
);
943 g_list_free(sorted_languages
);
945 gtk_widget_show_all (submenu
);
950 on_editor_added (AnjutaDocman
*docman
, IAnjutaEditor
*te
,
951 AnjutaPlugin
*plugin
)
953 GtkWidget
*highlight_submenu
, *highlight_menu
;
954 DocmanPlugin
*editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
956 /* Create Highlight submenu */
958 create_highlight_submenu (editor_plugin
, te
);
959 if (highlight_submenu
)
962 gtk_ui_manager_get_widget (GTK_UI_MANAGER (editor_plugin
->ui
),
963 "/MenuMain/MenuView/MenuViewEditor/MenuFormatStyle");
964 gtk_menu_item_set_submenu (GTK_MENU_ITEM (highlight_menu
),
967 g_signal_connect (G_OBJECT (te
), "update-ui",
968 G_CALLBACK (on_editor_update_ui
),
969 ANJUTA_PLUGIN (plugin
));
970 g_signal_connect (G_OBJECT (te
), "save-point",
971 G_CALLBACK (on_editor_update_save_ui
),
972 ANJUTA_PLUGIN (plugin
));
973 anjuta_shell_present_widget (plugin
->shell
,
974 GTK_WIDGET (docman
), NULL
);
978 on_editor_changed (AnjutaDocman
*docman
, IAnjutaEditor
*te
,
979 AnjutaPlugin
*plugin
)
981 DocmanPlugin
*docman_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
983 update_status (docman_plugin
, te
);
984 update_editor_ui (plugin
, te
);
986 /* unload previous support plugins */
987 if (docman_plugin
->support_plugins
) {
988 g_list_foreach (docman_plugin
->support_plugins
,
989 (GFunc
) anjuta_plugin_deactivate
, NULL
);
990 g_list_free (docman_plugin
->support_plugins
);
991 docman_plugin
->support_plugins
= NULL
;
996 AnjutaPluginManager
*plugin_manager
;
997 const gchar
*language
;
998 GList
*support_plugin_descs
, *node
;
1000 GValue
*value
= g_new0 (GValue
, 1);
1001 g_value_init (value
, G_TYPE_OBJECT
);
1002 g_value_set_object (value
, te
);
1003 anjuta_shell_add_value (plugin
->shell
,
1004 "document_manager_current_editor",
1006 DEBUG_PRINT ("Editor Added");
1008 /* Load current language editor support plugins */
1009 plugin_manager
= anjuta_shell_get_plugin_manager (plugin
->shell
, NULL
);
1010 if (IANJUTA_IS_EDITOR_LANGUAGE (te
)) {
1011 language
= ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (te
), NULL
);
1012 support_plugin_descs
= anjuta_plugin_manager_query (plugin_manager
,
1015 "IAnjutaLanguageSupport",
1019 node
= support_plugin_descs
;
1022 GObject
*plugin_object
;
1024 AnjutaPluginDescription
*desc
= node
->data
;
1025 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin", "Location",
1027 plugin_object
= anjuta_plugin_manager_get_plugin_by_id (plugin_manager
,
1029 /* anjuta_plugin_activate (ANJUTA_PLUGIN (plugin_object)); */
1032 docman_plugin
->support_plugins
= g_list_prepend (docman_plugin
->support_plugins
,
1037 DEBUG_PRINT ("Failed to load support plugin %s", plugin_id
);
1042 g_list_free (support_plugin_descs
);
1047 anjuta_shell_remove_value (plugin
->shell
,
1048 "document_manager_current_editor", NULL
);
1049 DEBUG_PRINT ("Editor Removed");
1054 on_edit_editor_indent (GtkWidget
*button
, DocmanPlugin
*plugin
)
1056 IndentData
*idt
= plugin
->idt
;
1058 if (idt
->dialog
== NULL
)
1059 idt
->dialog
= create_dialog(idt
);
1060 gtk_widget_show(idt
->dialog
);
1064 on_style_combo_changed (GtkComboBox
*combo
, DocmanPlugin
*plugin
)
1066 IndentData
*idt
= plugin
->idt
;
1068 pref_style_combo_changed(combo
, idt
);
1072 on_window_key_press_event (GtkWidget
*widget
,
1074 DocmanPlugin
*plugin
)
1079 g_return_val_if_fail (event
!= NULL
, FALSE
);
1081 modifiers
= event
->state
& (GDK_SHIFT_MASK
| GDK_CONTROL_MASK
| GDK_MOD1_MASK
);
1083 for (i
= 0; global_keymap
[i
].id
; i
++)
1084 if (event
->keyval
== global_keymap
[i
].gdk_key
&&
1085 (event
->state
& global_keymap
[i
].modifiers
) == global_keymap
[i
].modifiers
)
1088 if (!global_keymap
[i
].id
)
1091 switch (global_keymap
[i
].id
) {
1093 case ID_PREVBUFFER
: {
1094 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1098 if (!notebook
->children
)
1101 if (!plugin
->g_tabbing
)
1103 plugin
->g_tabbing
= TRUE
;
1106 pages_nb
= g_list_length (notebook
->children
);
1107 cur_page
= gtk_notebook_get_current_page (notebook
);
1109 if (global_keymap
[i
].id
== ID_NEXTBUFFER
)
1110 cur_page
= (cur_page
< pages_nb
- 1) ? cur_page
+ 1 : 0;
1112 cur_page
= cur_page
? cur_page
- 1 : pages_nb
-1;
1114 gtk_notebook_set_page (notebook
, cur_page
);
1119 if (global_keymap
[i
].id
>= ID_FIRSTBUFFER
&&
1120 global_keymap
[i
].id
<= (ID_FIRSTBUFFER
+ 9))
1122 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1123 int page_req
= global_keymap
[i
].id
- ID_FIRSTBUFFER
;
1125 if (!notebook
->children
)
1127 gtk_notebook_set_page(notebook
, page_req
);
1133 /* Note: No reason for a shortcut to do more than one thing a time */
1134 gtk_signal_emit_stop_by_name (GTK_OBJECT (ANJUTA_PLUGIN(plugin
)->shell
),
1140 #define EDITOR_TABS_RECENT_FIRST "editor.tabs.recent.first"
1141 #define EDITOR_TABS_POS "editor.tabs.pos"
1142 #define EDITOR_TABS_HIDE "editor.tabs.hide"
1143 #define EDITOR_TABS_ORDERING "editor.tabs.ordering"
1144 #define AUTOSAVE_TIMER "autosave.timer"
1145 #define SAVE_AUTOMATIC "save.automatic"
1148 on_window_key_release_event (GtkWidget
*widget
,
1150 DocmanPlugin
*plugin
)
1152 g_return_val_if_fail (event
!= NULL
, FALSE
);
1154 if (plugin
->g_tabbing
&& ((event
->keyval
== GDK_Control_L
) ||
1155 (event
->keyval
== GDK_Control_R
)))
1157 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1160 plugin
->g_tabbing
= FALSE
;
1162 if (anjuta_preferences_get_int (plugin
->prefs
,
1163 EDITOR_TABS_RECENT_FIRST
))
1166 TTimo: move the current notebook page to first position
1167 that maintains Ctrl-TABing on a list of most recently edited files
1169 cur_page
= gtk_notebook_get_current_page (notebook
);
1170 widget
= gtk_notebook_get_nth_page (notebook
, cur_page
);
1171 gtk_notebook_reorder_child (notebook
, widget
, 0);
1178 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
1179 AnjutaSession
*session
, DocmanPlugin
*plugin
)
1181 GList
*editors
, *node
, *files
;
1183 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
1186 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
1187 files
= g_list_reverse (files
);
1189 editors
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1194 te
= IANJUTA_EDITOR (node
->data
);
1195 if (ianjuta_file_get_uri(IANJUTA_FILE(te
), NULL
))
1198 /* Save line locations also */
1199 uri
= g_strdup_printf ("%s#%d", ianjuta_file_get_uri(IANJUTA_FILE(te
), NULL
),
1200 ianjuta_editor_get_lineno(IANJUTA_EDITOR(te
), NULL
));
1201 files
= g_list_prepend (files
, uri
);
1202 /* uri not be freed here */
1204 node
= g_list_next (node
);
1206 files
= g_list_reverse (files
);
1207 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
1208 g_list_free (editors
);
1209 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
1210 g_list_free (files
);
1214 on_save_prompt_save_editor (AnjutaSavePrompt
*save_prompt
,
1215 gpointer item
, gpointer user_data
)
1217 DocmanPlugin
*plugin
;
1219 plugin
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1220 return anjuta_docman_save_editor (ANJUTA_DOCMAN (plugin
->docman
),
1221 IANJUTA_EDITOR (item
),
1222 GTK_WIDGET (save_prompt
));
1226 on_save_prompt (AnjutaShell
*shell
, AnjutaSavePrompt
*save_prompt
,
1227 DocmanPlugin
*plugin
)
1231 list
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1235 IAnjutaFileSavable
*editor
= IANJUTA_FILE_SAVABLE (node
->data
);
1236 if (ianjuta_file_savable_is_dirty (editor
, NULL
))
1241 name
= ianjuta_editor_get_filename (IANJUTA_EDITOR (editor
), NULL
);
1242 uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
1243 anjuta_save_prompt_add_item (save_prompt
, name
, uri
, editor
,
1244 on_save_prompt_save_editor
, plugin
);
1246 node
= g_list_next (node
);
1251 docman_plugin_set_tab_pos (DocmanPlugin
*ep
)
1253 if (anjuta_preferences_get_int_with_default (ep
->prefs
, EDITOR_TABS_HIDE
,
1256 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), FALSE
);
1261 GtkPositionType pos
;
1263 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), TRUE
);
1264 tab_pos
= anjuta_preferences_get (ep
->prefs
, EDITOR_TABS_POS
);
1269 if (strcasecmp (tab_pos
, "left") == 0)
1271 else if (strcasecmp (tab_pos
, "right") == 0)
1272 pos
= GTK_POS_RIGHT
;
1273 else if (strcasecmp (tab_pos
, "bottom") == 0)
1274 pos
= GTK_POS_BOTTOM
;
1277 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (ep
->docman
), pos
);
1282 on_gconf_notify_prefs (GConfClient
*gclient
, guint cnxn_id
,
1283 GConfEntry
*entry
, gpointer user_data
)
1285 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1286 docman_plugin_set_tab_pos (ep
);
1290 on_docman_auto_save (gpointer data
)
1292 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (data
);
1294 AnjutaPreferences
* prefs
;
1295 AnjutaDocman
*docman
;
1296 AnjutaStatus
* status
;
1297 IAnjutaEditor
* editor
;
1299 docman
= ANJUTA_DOCMAN (plugin
->docman
);
1301 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
1302 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1303 status
= anjuta_shell_get_status(shell
, NULL
);
1307 if (anjuta_preferences_get_int (prefs
, SAVE_AUTOMATIC
) == FALSE
)
1309 plugin
->autosave_on
= FALSE
;
1313 editors
= anjuta_docman_get_all_editors(docman
);
1316 editor
= IANJUTA_EDITOR(editors
->data
);
1317 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1319 if (ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
) != NULL
)
1321 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1324 editors
= g_list_next(editors
);
1326 // TODO: Check for errors
1329 mesg
= g_strdup("Autosaved complete");
1330 anjuta_status (status
, mesg
, 3);
1337 on_gconf_notify_timer (GConfClient
*gclient
, guint cnxn_id
,
1338 GConfEntry
*entry
, gpointer user_data
)
1340 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1342 AnjutaPreferences
* prefs
;
1343 gint auto_save_timer
;
1346 g_object_get(G_OBJECT(ep
), "shell", &shell
, NULL
);
1347 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1349 auto_save_timer
= anjuta_preferences_get_int(prefs
, AUTOSAVE_TIMER
);
1350 auto_save
= anjuta_preferences_get_int(prefs
, SAVE_AUTOMATIC
);
1354 if (ep
->autosave_on
== TRUE
)
1356 if (auto_save_timer
!= ep
->autosave_it
)
1358 gtk_timeout_remove (ep
->autosave_id
);
1360 gtk_timeout_add (auto_save_timer
*
1362 on_docman_auto_save
,
1369 gtk_timeout_add (auto_save_timer
* 60000,
1370 on_docman_auto_save
,
1373 ep
->autosave_it
= auto_save_timer
;
1374 ep
->autosave_on
= TRUE
;
1378 if (ep
->autosave_on
== TRUE
)
1379 gtk_timeout_remove (ep
->autosave_id
);
1380 ep
->autosave_on
= FALSE
;
1384 #define REGISTER_NOTIFY(key, func) \
1385 notify_id = anjuta_preferences_notify_add (ep->prefs, \
1386 key, func, ep, NULL); \
1387 ep->gconf_notify_ids = g_list_prepend (ep->gconf_notify_ids, \
1388 (gpointer)(notify_id));
1390 prefs_init (DocmanPlugin
*ep
)
1393 docman_plugin_set_tab_pos (ep
);
1394 REGISTER_NOTIFY (EDITOR_TABS_HIDE
, on_gconf_notify_prefs
);
1395 REGISTER_NOTIFY (EDITOR_TABS_POS
, on_gconf_notify_prefs
);
1396 REGISTER_NOTIFY (AUTOSAVE_TIMER
, on_gconf_notify_timer
);
1397 REGISTER_NOTIFY (SAVE_AUTOMATIC
, on_gconf_notify_timer
);
1399 on_gconf_notify_timer(NULL
,0,NULL
, ep
);
1403 prefs_finalize (DocmanPlugin
*ep
)
1406 node
= ep
->gconf_notify_ids
;
1409 anjuta_preferences_notify_remove (ep
->prefs
, (guint
)node
->data
);
1410 node
= g_list_next (node
);
1412 g_list_free (ep
->gconf_notify_ids
);
1413 ep
->gconf_notify_ids
= NULL
;
1417 activate_plugin (AnjutaPlugin
*plugin
)
1419 GtkWidget
*docman
, *popup_menu
;
1421 DocmanPlugin
*editor_plugin
;
1422 GtkActionGroup
*group
;
1425 AnjutaStatus
*status
;
1426 static gboolean initialized
= FALSE
;
1428 DEBUG_PRINT ("DocmanPlugin: Activating Editor plugin...");
1430 editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1431 editor_plugin
->ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1432 editor_plugin
->prefs
= anjuta_shell_get_preferences (plugin
->shell
, NULL
);
1433 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1435 ui
= editor_plugin
->ui
;
1436 docman
= anjuta_docman_new (editor_plugin
, editor_plugin
->prefs
);
1437 editor_plugin
->docman
= docman
;
1438 ANJUTA_DOCMAN(docman
)->shell
= plugin
->shell
;
1439 g_signal_connect (G_OBJECT (docman
), "editor-added",
1440 G_CALLBACK (on_editor_added
), plugin
);
1441 g_signal_connect (G_OBJECT (docman
), "editor-changed",
1442 G_CALLBACK (on_editor_changed
), plugin
);
1443 g_signal_connect_swapped (G_OBJECT (status
), "busy",
1444 G_CALLBACK (anjuta_docman_set_busy
), docman
);
1445 g_signal_connect (G_OBJECT (plugin
->shell
), "key-press-event",
1446 G_CALLBACK (on_window_key_press_event
), plugin
);
1447 g_signal_connect (G_OBJECT (plugin
->shell
), "key-release-event",
1448 G_CALLBACK (on_window_key_release_event
), plugin
);
1452 register_stock_icons (plugin
);
1454 editor_plugin
->action_groups
= NULL
;
1455 /* Add all our editor actions */
1456 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
1458 GList
*actions
, *act
;
1460 swap_label_and_stock (action_groups
[i
].group
,
1461 action_groups
[i
].size
);
1462 group
= anjuta_ui_add_action_group_entries (ui
,
1463 action_groups
[i
].name
,
1464 _(action_groups
[i
].label
),
1465 action_groups
[i
].group
,
1466 action_groups
[i
].size
,
1467 GETTEXT_PACKAGE
, TRUE
,
1469 editor_plugin
->action_groups
=
1470 g_list_prepend (editor_plugin
->action_groups
, group
);
1471 actions
= gtk_action_group_list_actions (group
);
1474 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1475 act
= g_list_next (act
);
1478 for (i
= 0; i
< G_N_ELEMENTS (action_toggle_groups
); i
++)
1480 GList
*actions
, *act
;
1482 swap_toggle_label_and_stock (action_toggle_groups
[i
].group
,
1483 action_toggle_groups
[i
].size
);
1484 group
= anjuta_ui_add_toggle_action_group_entries (ui
,
1485 action_toggle_groups
[i
].name
,
1486 _(action_toggle_groups
[i
].label
),
1487 action_toggle_groups
[i
].group
,
1488 action_toggle_groups
[i
].size
,
1489 GETTEXT_PACKAGE
, TRUE
, plugin
);
1490 editor_plugin
->action_groups
=
1491 g_list_prepend (editor_plugin
->action_groups
, group
);
1492 actions
= gtk_action_group_list_actions (group
);
1495 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1496 act
= g_list_next (act
);
1499 group
= gtk_action_group_new ("ActionGroupNavigation");
1500 editor_plugin
->action_groups
=
1501 g_list_prepend (editor_plugin
->action_groups
, group
);
1503 action
= g_object_new (EGG_TYPE_ENTRY_ACTION
,
1504 "name", "ActionEditGotoLineEntry",
1505 "label", _("Goto line"),
1506 "tooltip", _("Enter the line number to jump and press enter"),
1507 "stock_id", GTK_STOCK_JUMP_TO
,
1510 g_signal_connect (action
, "activate",
1511 G_CALLBACK (on_toolbar_goto_clicked
), plugin
);
1512 gtk_action_group_add_action (group
, action
);
1514 anjuta_ui_add_action_group (ui
, "ActionGroupNavigation",
1515 N_("Editor quick navigations"),
1519 editor_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
1520 anjuta_shell_add_widget (plugin
->shell
, docman
,
1521 "AnjutaDocumentManager", _("Documents"),
1522 "editor-plugin-icon",
1523 ANJUTA_SHELL_PLACEMENT_CENTER
, NULL
);
1524 ui_states_init(plugin
);
1525 ui_give_shorter_names (plugin
);
1526 update_editor_ui (plugin
, NULL
);
1528 /* Setup popup menu */
1529 popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
1530 "/PopupDocumentManager");
1531 g_assert (popup_menu
!= NULL
&& GTK_IS_MENU (popup_menu
));
1532 anjuta_docman_set_popup_menu (ANJUTA_DOCMAN (docman
), popup_menu
);
1535 //search_and_replace_init (ANJUTA_DOCMAN (docman));
1537 /* Connect to save session */
1538 g_signal_connect (G_OBJECT (plugin
->shell
), "save-session",
1539 G_CALLBACK (on_session_save
), plugin
);
1540 /* Connect to save prompt */
1541 g_signal_connect (G_OBJECT (plugin
->shell
), "save-prompt",
1542 G_CALLBACK (on_save_prompt
), plugin
);
1549 deactivate_plugin (AnjutaPlugin
*plugin
)
1551 // GtkIconFactory *icon_factory;
1552 DocmanPlugin
*eplugin
;
1554 AnjutaStatus
*status
;
1557 DEBUG_PRINT ("DocmanPlugin: Dectivating Editor plugin...");
1559 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1561 prefs_finalize (eplugin
);
1562 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1563 G_CALLBACK (on_session_save
), plugin
);
1564 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1565 G_CALLBACK (on_save_prompt
), plugin
);
1567 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1568 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1570 g_signal_handlers_disconnect_by_func (G_OBJECT (status
),
1571 G_CALLBACK (anjuta_docman_set_busy
),
1573 g_signal_handlers_disconnect_by_func (G_OBJECT (eplugin
->docman
),
1574 G_CALLBACK (on_editor_changed
),
1576 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1577 G_CALLBACK (on_window_key_press_event
),
1579 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1580 G_CALLBACK (on_window_key_release_event
),
1583 on_editor_changed (ANJUTA_DOCMAN (eplugin
->docman
), NULL
, plugin
);
1585 /* Widget is removed from the container when destroyed */
1586 gtk_widget_destroy (eplugin
->docman
);
1587 anjuta_ui_unmerge (ui
, eplugin
->uiid
);
1588 node
= eplugin
->action_groups
;
1591 GtkActionGroup
*group
= GTK_ACTION_GROUP (node
->data
);
1592 anjuta_ui_remove_action_group (ui
, group
);
1593 node
= g_list_next (node
);
1595 g_list_free (eplugin
->action_groups
);
1598 /* Unregister stock icons */
1599 /* Unregister preferences */
1601 eplugin
->docman
= NULL
;
1603 eplugin
->action_groups
= NULL
;
1609 dispose (GObject
*obj
)
1611 // DocmanPlugin *eplugin = ANJUTA_PLUGIN_DOCMAN (obj);
1612 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
1616 docman_plugin_instance_init (GObject
*obj
)
1618 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (obj
);
1620 plugin
->g_tabbing
= FALSE
;
1621 plugin
->gconf_notify_ids
= NULL
;
1622 plugin
->idt
= indent_init(plugin
->prefs
);
1626 docman_plugin_class_init (GObjectClass
*klass
)
1628 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
1630 parent_class
= g_type_class_peek_parent (klass
);
1632 plugin_class
->activate
= activate_plugin
;
1633 plugin_class
->deactivate
= deactivate_plugin
;
1634 klass
->dispose
= dispose
;
1637 /* Implement IAnjutaDocumentManager interfaces */
1638 static const gchar
*
1639 ianjuta_docman_get_full_filename (IAnjutaDocumentManager
*plugin
,
1640 const gchar
*file
, GError
**e
)
1642 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1643 return anjuta_docman_get_full_filename (ANJUTA_DOCMAN (docman
), file
);
1646 static IAnjutaEditor
*
1647 ianjuta_docman_find_editor_with_path (IAnjutaDocumentManager
*plugin
,
1648 const gchar
*file_path
, GError
**e
)
1650 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1651 return anjuta_docman_find_editor_with_path (ANJUTA_DOCMAN (docman
), file_path
);
1654 static IAnjutaEditor
*
1655 ianjuta_docman_get_current_editor (IAnjutaDocumentManager
*plugin
, GError
**e
)
1657 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1658 return anjuta_docman_get_current_editor (ANJUTA_DOCMAN (docman
));
1662 ianjuta_docman_set_current_editor (IAnjutaDocumentManager
*plugin
,
1663 IAnjutaEditor
*editor
, GError
**e
)
1665 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1666 anjuta_docman_set_current_editor (ANJUTA_DOCMAN (docman
),
1671 ianjuta_docman_get_editors (IAnjutaDocumentManager
*plugin
, GError
**e
)
1673 AnjutaDocman
*docman
;
1674 GList
* editors
= NULL
;
1675 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1676 editors
= anjuta_docman_get_all_editors (docman
);
1681 ianjuta_docman_goto_file_line (IAnjutaDocumentManager
*plugin
,
1682 const gchar
*uri
, gint linenum
, GError
**e
)
1684 AnjutaDocman
*docman
;
1685 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1686 anjuta_docman_goto_file_line (docman
, uri
, linenum
);
1690 ianjuta_docman_goto_file_line_mark (IAnjutaDocumentManager
*plugin
,
1691 const gchar
*uri
, gint linenum
, gboolean mark
, GError
**e
)
1693 AnjutaDocman
*docman
;
1694 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1695 anjuta_docman_goto_file_line_mark (docman
, uri
, linenum
, mark
);
1698 static IAnjutaEditor
*
1699 ianjuta_docman_add_buffer (IAnjutaDocumentManager
*plugin
,
1700 const gchar
*filename
, const gchar
*content
,
1703 AnjutaDocman
*docman
;
1705 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1706 te
= anjuta_docman_add_editor (docman
, NULL
, filename
);
1709 /*if (content && strlen (content) > 0)
1710 aneditor_command (te->editor_id, ANE_INSERTTEXT, -1,
1712 return IANJUTA_EDITOR (te
);
1718 ianjuta_docman_remove_buffer (IAnjutaDocumentManager
*plugin
,
1719 IAnjutaEditor
*editor
,
1720 gboolean save_before
, GError
**e
)
1722 gint ret_val
= TRUE
;
1723 AnjutaDocman
*docman
;
1724 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1728 ret_val
= anjuta_docman_save_editor (docman
, editor
,
1729 GTK_WIDGET (ANJUTA_PLUGIN (plugin
)->shell
));
1732 anjuta_docman_remove_editor (docman
, editor
);
1738 ianjuta_document_manager_iface_init (IAnjutaDocumentManagerIface
*iface
)
1740 iface
->get_full_filename
= ianjuta_docman_get_full_filename
;
1741 iface
->find_editor_with_path
= ianjuta_docman_find_editor_with_path
;
1742 iface
->get_current_editor
= ianjuta_docman_get_current_editor
;
1743 iface
->set_current_editor
= ianjuta_docman_set_current_editor
;
1744 iface
->get_editors
= ianjuta_docman_get_editors
;
1745 iface
->goto_file_line
= ianjuta_docman_goto_file_line
;
1746 iface
->goto_file_line_mark
= ianjuta_docman_goto_file_line_mark
;
1747 iface
->add_buffer
= ianjuta_docman_add_buffer
;
1748 iface
->remove_buffer
= ianjuta_docman_remove_buffer
;
1751 /* Implement IAnjutaFile interface */
1753 ifile_open (IAnjutaFile
* plugin
, const gchar
* uri
, GError
** e
)
1755 AnjutaDocman
*docman
;
1757 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1758 anjuta_docman_goto_file_line (docman
, uri
, -1);
1762 ifile_get_uri (IAnjutaFile
* plugin
, GError
** e
)
1764 AnjutaDocman
*docman
;
1765 IAnjutaEditor
* editor
;
1766 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1767 editor
= anjuta_docman_get_current_editor (docman
);
1769 return g_strdup (ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
));
1770 else if (ianjuta_editor_get_filename(editor
, NULL
))
1771 return gnome_vfs_get_uri_from_local_path (ianjuta_editor_get_filename(editor
, NULL
));
1777 ifile_iface_init (IAnjutaFileIface
*iface
)
1779 iface
->open
= ifile_open
;
1780 iface
->get_uri
= ifile_get_uri
;
1783 /* Implement IAnjutaFileSavable interface */
1785 isaveable_save (IAnjutaFileSavable
* plugin
, GError
** e
)
1787 /* Save all editors */
1788 AnjutaDocman
*docman
;
1789 IAnjutaEditor
* editor
;
1791 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1792 editors
= anjuta_docman_get_all_editors(docman
);
1795 editor
= IANJUTA_EDITOR(editors
->data
);
1796 if (ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
) != NULL
&&
1797 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1799 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1801 editors
= g_list_next(editors
);
1803 g_list_free(editors
);
1807 isavable_save_as (IAnjutaFileSavable
* plugin
, const gchar
* uri
, GError
** e
)
1809 DEBUG_PRINT("save_as: Not implemented in DocmanPlugin");
1813 isavable_is_dirty(IAnjutaFileSavable
* plugin
, GError
** e
)
1815 /* Is any editor unsaved */
1816 AnjutaDocman
*docman
;
1817 IAnjutaEditor
* editor
;
1819 gboolean retval
= FALSE
;
1820 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1821 editors
= anjuta_docman_get_all_editors(docman
);
1824 editor
= IANJUTA_EDITOR(editors
->data
);
1825 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1830 editors
= g_list_next(editors
);
1832 g_list_free(editors
);
1837 isavable_set_dirty(IAnjutaFileSavable
* plugin
, gboolean dirty
, GError
** e
)
1839 DEBUG_PRINT("set_dirty: Not implemented in DocmanPlugin");
1843 isavable_iface_init (IAnjutaFileSavableIface
*iface
)
1845 iface
->save
= isaveable_save
;
1846 iface
->save_as
= isavable_save_as
;
1847 iface
->set_dirty
= isavable_set_dirty
;
1848 iface
->is_dirty
= isavable_is_dirty
;
1852 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
1854 GtkWidget
*indent_button
;
1855 GtkWidget
*indent_combo
;
1856 GtkWidget
*indent_entry
;
1859 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN(ipref
);
1861 /* Add preferences */
1862 gxml
= glade_xml_new (PREFS_GLADE
, "preferences_dialog", NULL
);
1863 indent_button
= glade_xml_get_widget (gxml
, "set_indent_button");
1864 g_signal_connect (G_OBJECT (indent_button
), "clicked",
1865 G_CALLBACK (on_edit_editor_indent
), plugin
);
1867 anjuta_preferences_add_page (prefs
,
1868 gxml
, "Documents", _("Documents"), ICON_FILE
);
1869 anjuta_encodings_init (prefs
, gxml
);
1871 indent_combo
= glade_xml_get_widget (gxml
, "pref_indent_style_combobox");
1872 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->pref_indent_combo
= indent_combo
;
1873 g_signal_connect (G_OBJECT (indent_combo
), "changed",
1874 G_CALLBACK (on_style_combo_changed
), plugin
);
1877 indent_entry
= glade_xml_get_widget (gxml
, "preferences_style_entry");
1878 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->pref_indent_options
= indent_entry
;
1879 ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
->prefs
= ANJUTA_PLUGIN_DOCMAN (plugin
)->prefs
;
1880 indent_init_load_style(ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
);
1882 g_object_unref (G_OBJECT (gxml
));
1883 prefs_init(ANJUTA_PLUGIN_DOCMAN (plugin
));
1884 pref_set_style_combo(ANJUTA_PLUGIN_DOCMAN (plugin
)->idt
);
1888 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
1890 DocmanPlugin
* plugin
= ANJUTA_PLUGIN_DOCMAN (ipref
);
1891 prefs_finalize(plugin
);
1892 anjuta_preferences_dialog_remove_page(ANJUTA_PREFERENCES_DIALOG(prefs
),
1897 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
1899 iface
->merge
= ipreferences_merge
;
1900 iface
->unmerge
= ipreferences_unmerge
;
1903 ANJUTA_PLUGIN_BEGIN (DocmanPlugin
, docman_plugin
);
1904 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_document_manager
, IANJUTA_TYPE_DOCUMENT_MANAGER
);
1905 ANJUTA_PLUGIN_ADD_INTERFACE(ifile
, IANJUTA_TYPE_FILE
);
1906 ANJUTA_PLUGIN_ADD_INTERFACE(isavable
, IANJUTA_TYPE_FILE_SAVABLE
);
1907 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
1910 ANJUTA_SIMPLE_PLUGIN (DocmanPlugin
, docman_plugin
);