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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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-factory.h>
36 #include <libanjuta/interfaces/ianjuta-editor-folds.h>
37 #include <libanjuta/interfaces/ianjuta-editor-comment.h>
38 #include <libanjuta/interfaces/ianjuta-editor-zoom.h>
39 #include <libanjuta/interfaces/ianjuta-editor-goto.h>
40 #include <libanjuta/interfaces/ianjuta-editor-search.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-language.h>
45 #include <libanjuta/interfaces/ianjuta-preferences.h>
46 #include <libanjuta/interfaces/ianjuta-document.h>
48 #include "anjuta-docman.h"
49 #include "action-callbacks.h"
51 #include "search-box.h"
53 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-document-manager.ui"
54 #define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-document-manager.glade"
55 #define ICON_FILE "anjuta-document-manager.png"
58 #define ANJUTA_PIXMAP_SWAP "anjuta-swap"
59 #define ANJUTA_PIXMAP_BOOKMARK_TOGGLE "anjuta-bookmark-toggle"
60 #define ANJUTA_PIXMAP_BOOKMARK_FIRST "anjuta-bookmark-first"
61 #define ANJUTA_PIXMAP_BOOKMARK_PREV "anjuta-bookmark-prev"
62 #define ANJUTA_PIXMAP_BOOKMARK_NEXT "anjuta-bookmark-next"
63 #define ANJUTA_PIXMAP_BOOKMARK_LAST "anjuta-bookmark-last"
64 #define ANJUTA_PIXMAP_BOOKMARK_CLEAR "anjuta-bookmark-clear"
66 #define ANJUTA_PIXMAP_FOLD_TOGGLE "anjuta-fold-toggle"
67 #define ANJUTA_PIXMAP_FOLD_CLOSE "anjuta-fold-close"
68 #define ANJUTA_PIXMAP_FOLD_OPEN "anjuta-fold-open"
70 #define ANJUTA_PIXMAP_BLOCK_SELECT "anjuta-block-select"
71 #define ANJUTA_PIXMAP_BLOCK_START "anjuta-block-start"
72 #define ANJUTA_PIXMAP_BLOCK_END "anjuta-block-end"
74 #define ANJUTA_PIXMAP_INDENT_INC "anjuta-indent-more"
75 #define ANJUTA_PIXMAP_INDENT_DCR "anjuta-indent-less"
77 #define ANJUTA_PIXMAP_GOTO_LINE "anjuta-go-line"
79 #define ANJUTA_PIXMAP_HISTORY_NEXT "anjuta-go-history-next"
80 #define ANJUTA_PIXMAP_HISTORY_PREV "anjuta-go-history-prev"
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_PREV_BRACE "anjuta-prev-brace"
92 #define ANJUTA_STOCK_NEXT_BRACE "anjuta-next-brace"
93 #define ANJUTA_STOCK_BLOCK_START "anjuta-block-start"
94 #define ANJUTA_STOCK_BLOCK_END "anjuta-block-end"
95 #define ANJUTA_STOCK_BOOKMARK_TOGGLE "anjuta-bookmark-toggle"
96 #define ANJUTA_STOCK_BOOKMARK_FIRST "anjuta-bookmark-first"
97 #define ANJUTA_STOCK_BOOKMARK_PREV "anjuta-bookmark-previous"
98 #define ANJUTA_STOCK_BOOKMARK_NEXT "anjuta-bookmark-next"
99 #define ANJUTA_STOCK_BOOKMARK_LAST "anjuta-bookmark-last"
100 #define ANJUTA_STOCK_BOOKMARK_CLEAR "anjuta-bookmark-clear"
101 #define ANJUTA_STOCK_GOTO_LINE "anjuta-goto-line"
102 #define ANJUTA_STOCK_HISTORY_NEXT "anjuta-history-next"
103 #define ANJUTA_STOCK_HISTORY_PREV "anjuta-history-prev"
104 #define ANJUTA_STOCK_MATCH_NEXT "anjuta-match-next"
105 #define ANJUTA_STOCK_MATCH_PREV "anjuta-match-prev"
108 static gpointer parent_class
;
110 /* Shortcuts implementation */
113 mS__
= GDK_SHIFT_MASK
,
114 m_C_
= GDK_CONTROL_MASK
,
115 m__M
= GDK_MOD1_MASK
,
116 mSC_
= GDK_SHIFT_MASK
| GDK_CONTROL_MASK
,
120 ID_NEXTBUFFER
= 1, /* Note: the value mustn't be 0 ! */
127 unsigned int gdk_key
;
131 static ShortcutMapping global_keymap
[] = {
132 /* FIXME: HIG requires that Ctrl+Tab be used to transfer focus in multiline
133 text entries. So we can't use the following ctrl+tabbing. Is there other
134 sensible keys that can be used for them?
137 { m_C_, GDK_Tab, ID_NEXTBUFFER },
138 { mSC_, GDK_ISO_Left_Tab, ID_PREVBUFFER },
140 { m__M
, GDK_1
, ID_FIRSTBUFFER
},
141 { m__M
, GDK_2
, ID_FIRSTBUFFER
+ 1},
142 { m__M
, GDK_3
, ID_FIRSTBUFFER
+ 2},
143 { m__M
, GDK_4
, ID_FIRSTBUFFER
+ 3},
144 { m__M
, GDK_5
, ID_FIRSTBUFFER
+ 4},
145 { m__M
, GDK_6
, ID_FIRSTBUFFER
+ 5},
146 { m__M
, GDK_7
, ID_FIRSTBUFFER
+ 6},
147 { m__M
, GDK_8
, ID_FIRSTBUFFER
+ 7},
148 { m__M
, GDK_9
, ID_FIRSTBUFFER
+ 8},
149 { m__M
, GDK_0
, ID_FIRSTBUFFER
+ 9},
153 static GtkActionEntry actions_file
[] = {
154 { "ActionFileNew", GTK_STOCK_NEW
, N_("_New"), "<control>n",
155 N_("New empty file"),
156 G_CALLBACK (on_new_file_activate
)},
157 { "ActionFileSave", GTK_STOCK_SAVE
, N_("_Save"), "<control>s",
158 N_("Save current file"), G_CALLBACK (on_save_activate
)},
159 { "ActionFileSaveAs", GTK_STOCK_SAVE_AS
, N_("Save _As..."), NULL
,
160 N_("Save the current file with a different name"),
161 G_CALLBACK (on_save_as_activate
)},
162 { "ActionFileSaveAll", NULL
, N_("Save A_ll"), NULL
,
163 N_("Save all currently open files, except new files"),
164 G_CALLBACK (on_save_all_activate
)},
165 { "ActionFileClose", GTK_STOCK_CLOSE
, N_("_Close File"), "<control>w",
166 N_("Close current file"),
167 G_CALLBACK (on_close_file_activate
)},
168 { "ActionFileCloseAll", GTK_STOCK_CLOSE
, N_("Close All"), "<shift><control>w",
169 N_("Close all files"),
170 G_CALLBACK (on_close_all_file_activate
)},
171 { "ActionFileReload", GTK_STOCK_REVERT_TO_SAVED
, N_("Reload F_ile"), NULL
,
172 N_("Reload current file"),
173 G_CALLBACK (on_reload_file_activate
)},
174 { "ActionFileSwap", ANJUTA_STOCK_SWAP
, N_("Swap .h/.c"), NULL
,
175 N_("Swap c header and source files"),
176 G_CALLBACK (on_swap_activate
)},
177 { "ActionMenuFileRecentFiles", NULL
, N_("Recent _Files"), NULL
, NULL
, NULL
}, /* menu title */
180 static GtkActionEntry actions_print
[] = {
181 { "ActionPrintFile", GTK_STOCK_PRINT
, N_("_Print..."), "<control>p",
182 N_("Print the current file"), G_CALLBACK (anjuta_print_cb
)},
183 { "ActionPrintPreview",
184 #ifdef GTK_STOCK_PRINT_PREVIEW
185 GTK_STOCK_PRINT_PREVIEW
189 , N_("_Print Preview"), NULL
,
190 N_("Preview the current file in print-format"),
191 G_CALLBACK (anjuta_print_preview_cb
)},
194 static GtkActionEntry actions_transform
[] = {
195 { "ActionMenuEditTransform", NULL
, N_("_Transform"), NULL
, NULL
, NULL
}, /* menu title */
196 { "ActionEditMakeSelectionUppercase", NULL
, N_("_Make Selection Uppercase"), NULL
,
197 N_("Make the selected text uppercase"),
198 G_CALLBACK (on_editor_command_upper_case_activate
)},
199 { "ActionEditMakeSelectionLowercase", NULL
, N_("Make Selection Lowercase"), NULL
,
200 N_("Make the selected text lowercase"),
201 G_CALLBACK (on_editor_command_lower_case_activate
)},
202 { "ActionEditConvertCRLF", NULL
, N_("Convert EOL to CRLF"), NULL
,
203 N_("Convert End Of Line characters to DOS EOL (CRLF)"),
204 G_CALLBACK (on_editor_command_eol_crlf_activate
)},
205 { "ActionEditConvertLF", NULL
, N_("Convert EOL to LF"), NULL
,
206 N_("Convert End Of Line characters to Unix EOL (LF)"),
207 G_CALLBACK (on_editor_command_eol_lf_activate
)},
208 { "ActionEditConvertCR", NULL
, N_("Convert EOL to CR"), NULL
,
209 N_("Convert End Of Line characters to Mac OS EOL (CR)"),
210 G_CALLBACK (on_editor_command_eol_cr_activate
)},
211 { "ActionEditConvertEOL", NULL
, N_("Convert EOL to Majority EOL"), NULL
,
212 N_("Convert End Of Line characters to majority of the EOL found in the file"),
213 G_CALLBACK (on_transform_eolchars1_activate
)},
216 static GtkActionEntry actions_select
[] = {
217 { "ActionMenuEditSelect", NULL
, N_("_Select"), NULL
, NULL
, NULL
}, /* menu title */
218 { "ActionEditSelectAll",
219 #ifdef GTK_STOCK_SELECT_ALL
224 , N_("Select _All"), "<control>a",
225 N_("Select all text in the editor"),
226 G_CALLBACK (on_editor_command_select_all_activate
)},
227 { "ActionEditSelectToBrace", NULL
, N_("Select to _Brace"), NULL
,
228 N_("Select the text in the matching braces"),
229 G_CALLBACK (on_editor_command_select_to_brace_activate
)},
230 { "ActionEditSelectBlock", ANJUTA_STOCK_BLOCK_SELECT
, N_("Select _Code Block"),
231 "<shift><control>b", N_("Select the current code block"),
232 G_CALLBACK (on_editor_command_select_block_activate
)},
235 static GtkActionEntry actions_comment
[] = {
236 { "ActionMenuEditComment", NULL
, N_("Co_mment"), NULL
, NULL
, NULL
}, /* menu title */
237 { "ActionEditCommentBlock", NULL
, N_("_Block Comment/Uncomment"), NULL
,
238 N_("Block comment the selected text"),
239 G_CALLBACK (on_comment_block
)},
240 { "ActionEditCommentBox", NULL
, N_("Bo_x Comment/Uncomment"), NULL
,
241 N_("Box comment the selected text"),
242 G_CALLBACK (on_comment_box
)},
243 { "ActionEditCommentStream", NULL
, N_("_Stream Comment/Uncomment"), NULL
,
244 N_("Stream comment the selected text"),
245 G_CALLBACK (on_comment_block
)},
248 static GtkActionEntry actions_navigation
[] = {
249 { "ActionMenuGoto", NULL
, N_("_Goto"), NULL
, NULL
, NULL
},/* menu title */
250 { "ActionEditGotoLine", ANJUTA_STOCK_GOTO_LINE
, N_("_Line Number..."),
251 "<control><alt>g", N_("Go to a particular line in the editor"),
252 G_CALLBACK (on_goto_line_no1_activate
)},
253 { "ActionEditGotoMatchingBrace", GTK_STOCK_JUMP_TO
, N_("Matching _Brace"),
254 "<control><alt>m", N_("Go to the matching brace in the editor"),
255 G_CALLBACK (on_editor_command_match_brace_activate
)},
256 { "ActionEditGotoBlockStart", ANJUTA_STOCK_BLOCK_START
, N_("_Start of Block"),
257 "<control><alt>s", N_("Go to the start of the current block"),
258 G_CALLBACK (on_goto_block_start1_activate
)},
259 { "ActionEditGotoBlockEnd", ANJUTA_STOCK_BLOCK_END
, N_("_End of Block"),
260 "<control><alt>e", N_("Go to the end of the current block"),
261 G_CALLBACK (on_goto_block_end1_activate
)},
262 { "ActionEditGotoHistoryPrev", ANJUTA_STOCK_HISTORY_PREV
, N_("Previous _History"),
263 NULL
, N_("Goto previous history"),
264 G_CALLBACK (on_prev_history
)},
265 { "ActionEditGotoHistoryNext", ANJUTA_STOCK_HISTORY_NEXT
, N_("Next Histor_y"),
266 NULL
, N_("Goto next history"),
267 G_CALLBACK (on_next_history
)}
270 static GtkActionEntry actions_search
[] = {
271 { "ActionMenuEditSearch", NULL
, N_("_Search"), NULL
, NULL
, NULL
},
272 { "ActionEditSearchQuickSearch", GTK_STOCK_FIND
, N_("_Quick Search"),
273 "<control>f", N_("Quick editor embedded search"),
274 G_CALLBACK (on_show_search
)}
277 static GtkActionEntry actions_edit
[] = {
278 { "ActionMenuEdit", NULL
, N_("_Edit"), NULL
, NULL
, NULL
},/* menu title */
279 { "ActionMenuViewEditor", NULL
, N_("_Editor"), NULL
, NULL
, NULL
},
280 { "ActionViewEditorAddView",
281 #ifdef GTK_STOCK_EDIT
286 , N_("_Add Editor View"), NULL
,
287 N_("Add one more view of current document"),
288 G_CALLBACK (on_editor_add_view_activate
)},
289 { "ActionViewEditorRemoveView", NULL
, N_("_Remove Editor View"), NULL
,
290 N_("Remove current view of the document"),
291 G_CALLBACK (on_editor_remove_view_activate
)},
292 { "ActionEditUndo", GTK_STOCK_UNDO
, N_("U_ndo"), "<control>z",
293 N_("Undo the last action"),
294 G_CALLBACK (on_editor_command_undo_activate
)},
295 { "ActionEditRedo", GTK_STOCK_REDO
, N_("_Redo"), "<control>r",
296 N_("Redo the last undone action"),
297 G_CALLBACK (on_editor_command_redo_activate
)},
298 { "ActionEditCut", GTK_STOCK_CUT
, N_("C_ut"), "<control>x",
299 N_("Cut the selected text from the editor to the clipboard"),
300 G_CALLBACK (on_editor_command_cut_activate
)},
301 { "ActionEditCopy", GTK_STOCK_COPY
, N_("_Copy"), "<control>c",
302 N_("Copy the selected text to the clipboard"),
303 G_CALLBACK (on_editor_command_copy_activate
)},
304 { "ActionEditPaste", GTK_STOCK_PASTE
, N_("_Paste"), "<control>v",
305 N_("Paste the content of clipboard at the current position"),
306 G_CALLBACK (on_editor_command_paste_activate
)},
308 #ifdef GTK_STOCK_DISCARD
313 , N_("_Clear"), "Delete",
314 N_("Delete the selected text from the editor"),
315 G_CALLBACK (on_editor_command_clear_activate
)},
318 static GtkToggleActionEntry actions_view
[] = {
319 { "ActionViewEditorLinenumbers", NULL
, N_("_Line Number Margin"), NULL
,
320 N_("Show/Hide line numbers"),
321 G_CALLBACK (on_editor_linenos1_activate
), FALSE
},
322 { "ActionViewEditorMarkers", NULL
, N_("_Marker Margin"), NULL
,
323 N_("Show/Hide marker margin"),
324 G_CALLBACK (on_editor_markers1_activate
), FALSE
},
325 { "ActionViewEditorFolds", NULL
, N_("_Code Fold Margin"), NULL
,
326 N_("Show/Hide code fold margin"),
327 G_CALLBACK (on_editor_codefold1_activate
), FALSE
},
328 { "ActionViewEditorGuides", NULL
, N_("_Indentation Guides"), NULL
,
329 N_("Show/Hide indentation guides"),
330 G_CALLBACK (on_editor_indentguides1_activate
), FALSE
},
331 { "ActionViewEditorSpaces", NULL
, N_("_White Space"), NULL
,
332 N_("Show/Hide white spaces"),
333 G_CALLBACK (on_editor_whitespaces1_activate
), FALSE
},
334 { "ActionViewEditorEOL", NULL
, N_("_Line End Characters"), NULL
,
335 N_("Show/Hide line end characters"),
336 G_CALLBACK (on_editor_eolchars1_activate
), FALSE
},
337 { "ActionViewEditorWrapping", NULL
, N_("Line _Wrapping"), NULL
,
338 N_("Enable/disable line wrapping"),
339 G_CALLBACK (on_editor_linewrap1_activate
), FALSE
}
342 static GtkActionEntry actions_zoom
[] = {
343 { "ActionViewEditorZoomIn", GTK_STOCK_ZOOM_IN
, N_("Zoom In"), "<control>plus",
344 N_("Zoom in: Increase font size"),
345 G_CALLBACK (on_zoom_in_text_activate
)},
346 { "ActionViewEditorZoomOut", GTK_STOCK_ZOOM_OUT
, N_("Zoom Out"), "<control>minus",
347 N_("Zoom out: Decrease font size"),
348 G_CALLBACK (on_zoom_out_text_activate
)}
351 static GtkActionEntry actions_style
[] = {
352 { "ActionMenuFormatStyle", NULL
, N_("_Highlight Mode"), NULL
, NULL
, NULL
}/* menu title */
355 static GtkActionEntry actions_format
[] = {
356 { "ActionFormatFoldCloseAll", ANJUTA_STOCK_FOLD_CLOSE
, N_("_Close All Folds"),
357 NULL
, N_("Close all code folds in the editor"),
358 G_CALLBACK (on_editor_command_close_folds_all_activate
)},
359 { "ActionFormatFoldOpenAll", ANJUTA_STOCK_FOLD_OPEN
, N_("_Open All Folds"),
360 NULL
, N_("Open all code folds in the editor"),
361 G_CALLBACK (on_editor_command_open_folds_all_activate
)},
362 { "ActionFormatFoldToggle", ANJUTA_STOCK_FOLD_TOGGLE
, N_("_Toggle Current Fold"),
363 NULL
, N_("Toggle current code fold in the editor"),
364 G_CALLBACK (on_editor_command_toggle_fold_activate
)},
367 static GtkActionEntry actions_bookmark
[] = {
368 { "ActionMenuBookmark", NULL
, N_("Bookmar_k"), NULL
, NULL
, NULL
},
369 { "ActionBookmarkToggle", ANJUTA_STOCK_BOOKMARK_TOGGLE
, N_("_Toggle Bookmark"),
370 "<control>k", N_("Toggle a bookmark at the current line position"),
371 G_CALLBACK (on_editor_command_bookmark_toggle_activate
)},
372 { "ActionBookmarkFirst", ANJUTA_STOCK_BOOKMARK_FIRST
, N_("_First Bookmark"),
373 NULL
, N_("Jump to the first bookmark in the file"),
374 G_CALLBACK (on_editor_command_bookmark_first_activate
)},
375 { "ActionBookmarkPrevious", ANJUTA_STOCK_BOOKMARK_PREV
, N_("_Previous Bookmark"),
376 "<control>comma", N_("Jump to the previous bookmark in the file"),
377 G_CALLBACK (on_editor_command_bookmark_prev_activate
)},
378 { "ActionBookmarkNext", ANJUTA_STOCK_BOOKMARK_NEXT
, N_("_Next Bookmark"),
379 "<control>period", N_("Jump to the next bookmark in the file"),
380 G_CALLBACK (on_editor_command_bookmark_next_activate
)},
381 { "ActionBookmarkLast", ANJUTA_STOCK_BOOKMARK_LAST
, N_("_Last Bookmark"),
382 NULL
, N_("Jump to the last bookmark in the file"),
383 G_CALLBACK (on_editor_command_bookmark_last_activate
)},
384 { "ActionBookmarkClear", ANJUTA_STOCK_BOOKMARK_CLEAR
, N_("_Clear All Bookmarks"),
385 NULL
, N_("Clear bookmarks"),
386 G_CALLBACK (on_editor_command_bookmark_clear_activate
)},
389 struct ActionGroupInfo
{
390 GtkActionEntry
*group
;
396 struct ActionToggleGroupInfo
{
397 GtkToggleActionEntry
*group
;
403 static struct ActionGroupInfo action_groups
[] = {
404 { actions_file
, G_N_ELEMENTS (actions_file
), "ActionGroupEditorFile", N_("Editor file operations")},
405 { actions_print
, G_N_ELEMENTS (actions_print
), "ActionGroupEditorPrint", N_("Editor print operations")},
406 { actions_transform
, G_N_ELEMENTS (actions_transform
), "ActionGroupEditorTransform", N_("Editor text transformation") },
407 { actions_select
, G_N_ELEMENTS (actions_select
), "ActionGroupEditorSelect", N_("Editor text selection") },
408 // { actions_insert, G_N_ELEMENTS (actions_insert), "ActionGroupEditorInsert", N_("Editor text insertions") },
409 { actions_comment
, G_N_ELEMENTS (actions_comment
), "ActionGroupEditorComment", N_("Editor code commenting") },
410 { actions_navigation
, G_N_ELEMENTS (actions_navigation
), "ActionGroupEditorNavigate", N_("Editor navigations") },
411 { actions_edit
, G_N_ELEMENTS (actions_edit
), "ActionGroupEditorEdit", N_("Editor edit operations") },
412 { actions_zoom
, G_N_ELEMENTS (actions_zoom
), "ActionGroupEditorZoom", N_("Editor zoom operations") },
413 { actions_style
, G_N_ELEMENTS (actions_style
), "ActionGroupEditorStyle", N_("Editor syntax highlighting styles") },
414 { actions_format
, G_N_ELEMENTS (actions_format
), "ActionGroupEditorFormat", N_("Editor text formating") },
415 { actions_bookmark
, G_N_ELEMENTS (actions_bookmark
), "ActionGroupEditorBookmark", N_("Editor bookmarks") },
416 { actions_search
, G_N_ELEMENTS (actions_search
), "ActionGroupEditorSearch", N_("Simple searching") }
419 static struct ActionToggleGroupInfo action_toggle_groups
[] = {
420 { actions_view
, G_N_ELEMENTS (actions_view
), "ActionGroupEditorView", N_("Editor view settings") }
423 // void pref_set_style_combo(DocmanPlugin *plugin);
426 #define VIEW_LINENUMBERS_MARGIN "margin.linenumber.visible"
427 #define VIEW_MARKER_MARGIN "margin.marker.visible"
428 #define VIEW_FOLD_MARGIN "margin.fold.visible"
429 #define VIEW_INDENTATION_GUIDES "view.indentation.guides"
430 #define VIEW_WHITE_SPACES "view.whitespace"
431 #define VIEW_EOL "view.eol"
432 #define VIEW_LINE_WRAP "view.line.wrap"
435 update_title (DocmanPlugin
* doc_plugin
)
437 IAnjutaDocument
* doc
=
438 anjuta_docman_get_current_document (ANJUTA_DOCMAN(doc_plugin
->docman
));
439 AnjutaStatus
* status
= anjuta_shell_get_status (ANJUTA_PLUGIN(doc_plugin
)->shell
, NULL
);
440 gchar
* filename
= NULL
;
444 gchar
* uri
= ianjuta_file_get_uri (IANJUTA_FILE(doc
), NULL
);
447 filename
= gnome_vfs_get_local_path_from_uri (uri
);
451 if (filename
&& doc_plugin
->project_name
)
453 title
= g_strconcat (doc_plugin
->project_name
, " - ", filename
, NULL
);
457 title
= g_strdup(filename
);
459 else if (doc_plugin
->project_name
)
461 title
= g_strdup(doc_plugin
->project_name
);
467 anjuta_status_set_title (status
, title
);
472 value_added_project_root_uri (AnjutaPlugin
*plugin
, const gchar
*name
,
473 const GValue
*value
, gpointer user_data
)
475 DocmanPlugin
*doc_plugin
;
476 const gchar
*root_uri
;
478 doc_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
480 DEBUG_PRINT ("Project added");
483 g_free (doc_plugin
->project_name
);
484 doc_plugin
->project_name
= NULL
;
486 root_uri
= g_value_get_string (value
);
490 gnome_vfs_get_local_path_from_uri (root_uri
);
492 doc_plugin
->project_name
= g_path_get_basename(path
);
494 if (doc_plugin
->project_name
)
496 update_title (doc_plugin
);
503 value_removed_project_root_uri (AnjutaPlugin
*plugin
, const gchar
*name
,
506 DocmanPlugin
*doc_plugin
;
508 doc_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
510 DEBUG_PRINT ("Project added");
512 g_free (doc_plugin
->project_name
);
513 doc_plugin
->project_name
= NULL
;
515 update_title(doc_plugin
);
519 ui_states_init (AnjutaPlugin
*plugin
)
522 DocmanPlugin
*eplugin
;
523 static const gchar
*prefs
[] = {
524 VIEW_LINENUMBERS_MARGIN
,
527 VIEW_INDENTATION_GUIDES
,
533 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
534 for (i
= 0; i
< sizeof (actions_view
)/sizeof(GtkToggleActionEntry
); i
++)
539 state
= anjuta_preferences_get_int (eplugin
->prefs
, prefs
[i
]);
540 action
= anjuta_ui_get_action (eplugin
->ui
, "ActionGroupEditorView",
541 actions_view
[i
].name
);
542 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action
), state
);
547 ui_give_shorter_names (AnjutaPlugin
*plugin
)
552 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
553 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
555 g_object_set (G_OBJECT (action
), "short-label", _("New"),
556 "is-important", TRUE
, NULL
);
557 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
559 g_object_set (G_OBJECT (action
), "short-label", _("Save"),
560 "is-important", TRUE
, NULL
);
561 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
563 g_object_set (G_OBJECT (action
), "short-label", _("Reload"), NULL
);
564 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
566 g_object_set (G_OBJECT (action
), "is-important", TRUE
, NULL
);
567 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
568 "ActionEditGotoLine");
569 g_object_set (G_OBJECT (action
), "short-label", _("Goto"), NULL
);
573 update_editor_ui_enable_all (AnjutaPlugin
*plugin
)
579 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
580 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
582 for (j
= 0; j
< action_groups
[i
].size
; j
++)
584 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
585 action_groups
[i
].group
[j
].name
);
586 if (action_groups
[i
].group
[j
].callback
)
588 g_object_set (G_OBJECT (action
), "sensitive", TRUE
, NULL
);
595 update_editor_ui_disable_all (AnjutaPlugin
*plugin
)
601 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
602 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
604 for (j
= 0; j
< action_groups
[i
].size
; j
++)
606 action
= anjuta_ui_get_action (ui
, action_groups
[i
].name
,
607 action_groups
[i
].group
[j
].name
);
608 if (action_groups
[i
].group
[j
].callback
)
610 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
617 update_editor_ui_save_items (AnjutaPlugin
*plugin
, IAnjutaDocument
*editor
)
622 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
624 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
626 g_object_set (G_OBJECT (action
), "sensitive",
627 ianjuta_document_can_undo (editor
, NULL
), NULL
);
629 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
631 g_object_set (G_OBJECT (action
), "sensitive",
632 ianjuta_document_can_redo (editor
, NULL
), NULL
);
634 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
636 g_object_set (G_OBJECT (action
), "sensitive",
637 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
),
642 update_editor_ui_interface_items (AnjutaPlugin
*plugin
, IAnjutaDocument
*editor
)
647 IAnjutaLanguage
* language
=
648 anjuta_shell_get_interface (plugin
->shell
, IAnjutaLanguage
, NULL
);
650 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
652 /* IAnjutaEditorLanguage */
653 flag
= IANJUTA_IS_EDITOR_LANGUAGE (editor
);
655 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorStyle",
656 "ActionMenuFormatStyle");
657 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
659 /* Check if it is a C or C++ file */
660 if (language
&& flag
)
664 const gchar
* lang_name
=
665 ianjuta_language_get_name_from_editor (language
, IANJUTA_EDITOR_LANGUAGE (editor
), NULL
);
667 if (lang_name
&& (g_str_equal (lang_name
, "C") || g_str_equal (lang_name
, "C++")))
680 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFile",
682 g_object_set (G_OBJECT (action
), "sensitive", flag
, NULL
);
684 /* IAnjutaDocument */
685 flag
= IANJUTA_IS_DOCUMENT (editor
);
687 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
689 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
691 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
693 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
695 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
697 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
699 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
701 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
703 /* IAnjutaEditorSelection */
704 flag
= IANJUTA_IS_EDITOR_SELECTION (editor
);
706 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
707 "ActionEditSelectAll");
708 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
710 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
711 "ActionEditSelectToBrace");
712 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
714 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSelect",
715 "ActionEditSelectBlock");
716 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
718 /* IAnjutaEditorConvert */
719 flag
= IANJUTA_IS_EDITOR_CONVERT (editor
);
720 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
721 "ActionEditMakeSelectionUppercase");
722 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
724 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
725 "ActionEditMakeSelectionLowercase");
726 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
728 /* IAnjutaEditorLineMode */
729 flag
= IANJUTA_IS_EDITOR_LINE_MODE (editor
);
731 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
732 "ActionEditConvertCRLF");
733 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
734 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
735 "ActionEditConvertLF");
736 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
737 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
738 "ActionEditConvertCR");
739 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
740 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorTransform",
741 "ActionEditConvertEOL");
742 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
744 /* IAnjutaEditorView */
745 flag
= IANJUTA_IS_EDITOR_VIEW (editor
);
746 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
747 "ActionViewEditorAddView");
748 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
749 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorEdit",
750 "ActionViewEditorRemoveView");
751 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
753 /* IAnjutaEditorFolds */
754 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
755 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
756 "ActionFormatFoldCloseAll");
757 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
759 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
760 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
761 "ActionFormatFoldOpenAll");
762 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
764 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
765 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorFormat",
766 "ActionFormatFoldToggle");
767 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
769 flag
= IANJUTA_IS_EDITOR_FOLDS (editor
);
770 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorView",
771 "ActionViewEditorFolds");
772 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
774 /* IAnjutaEditorComment */
775 flag
= IANJUTA_IS_EDITOR_COMMENT (editor
);
776 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorComment",
777 "ActionMenuEditComment");
778 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
780 /* IAnjutaEditorZoom */
781 flag
= IANJUTA_IS_EDITOR_ZOOM (editor
);
782 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorZoom",
783 "ActionViewEditorZoomIn");
784 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
785 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorZoom",
786 "ActionViewEditorZoomOut");
787 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
789 /* IAnjutaEditorGoto */
790 flag
= IANJUTA_IS_EDITOR_GOTO (editor
);
791 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
792 "ActionEditGotoBlockStart");
793 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
794 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
795 "ActionEditGotoBlockEnd");
796 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
797 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
798 "ActionEditGotoMatchingBrace");
799 g_object_set (G_OBJECT (action
), "visible", flag
, "sensitive", flag
, NULL
);
801 /* IAnjutaEditorSearch */
802 flag
= IANJUTA_IS_EDITOR_SEARCH (editor
);
803 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorSearch",
804 "ActionEditSearchQuickSearch");
805 g_object_set (G_OBJECT (action
), "sensitive", flag
, NULL
);
806 action
= anjuta_ui_get_action (ui
, "ActionGroupEditorNavigate",
807 "ActionEditGotoLine");
808 g_object_set (G_OBJECT (action
), "sensitive", flag
, NULL
);
813 update_editor_ui (AnjutaPlugin
*plugin
, IAnjutaDocument
*editor
)
817 update_editor_ui_disable_all (plugin
);
820 update_editor_ui_enable_all (plugin
);
821 update_editor_ui_save_items (plugin
, editor
);
822 update_editor_ui_interface_items (plugin
, editor
);
826 on_editor_update_save_ui (IAnjutaDocument
*editor
, gboolean entered
,
827 AnjutaPlugin
*plugin
)
829 update_editor_ui_save_items (plugin
, editor
);
833 register_stock_icons (AnjutaPlugin
*plugin
)
835 static gboolean registered
= FALSE
;
840 /* Register stock icons */
841 BEGIN_REGISTER_ICON (plugin
);
842 REGISTER_ICON (ICON_FILE
, "editor-plugin-icon");
843 REGISTER_ICON_FULL (ANJUTA_PIXMAP_SWAP
, ANJUTA_STOCK_SWAP
);
844 REGISTER_ICON_FULL (ANJUTA_PIXMAP_FOLD_TOGGLE
, ANJUTA_STOCK_FOLD_TOGGLE
);
845 REGISTER_ICON_FULL (ANJUTA_PIXMAP_FOLD_OPEN
, ANJUTA_STOCK_FOLD_OPEN
);
846 REGISTER_ICON_FULL (ANJUTA_PIXMAP_FOLD_CLOSE
, ANJUTA_STOCK_FOLD_CLOSE
);
847 REGISTER_ICON_FULL (ANJUTA_PIXMAP_INDENT_DCR
, ANJUTA_STOCK_INDENT_DCR
);
848 REGISTER_ICON_FULL (ANJUTA_PIXMAP_INDENT_INC
, ANJUTA_STOCK_INDENT_INC
);
849 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BLOCK_SELECT
, ANJUTA_STOCK_BLOCK_SELECT
);
850 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_TOGGLE
, ANJUTA_STOCK_BOOKMARK_TOGGLE
);
851 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_FIRST
, ANJUTA_STOCK_BOOKMARK_FIRST
);
852 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_PREV
, ANJUTA_STOCK_BOOKMARK_PREV
);
853 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_NEXT
, ANJUTA_STOCK_BOOKMARK_NEXT
);
854 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_LAST
, ANJUTA_STOCK_BOOKMARK_LAST
);
855 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BOOKMARK_CLEAR
, ANJUTA_STOCK_BOOKMARK_CLEAR
);
856 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BLOCK_START
, ANJUTA_STOCK_BLOCK_START
);
857 REGISTER_ICON_FULL (ANJUTA_PIXMAP_BLOCK_END
, ANJUTA_STOCK_BLOCK_END
);
858 REGISTER_ICON_FULL (ANJUTA_PIXMAP_GOTO_LINE
, ANJUTA_STOCK_GOTO_LINE
);
859 REGISTER_ICON_FULL (ANJUTA_PIXMAP_HISTORY_NEXT
, ANJUTA_STOCK_HISTORY_NEXT
);
860 REGISTER_ICON_FULL (ANJUTA_PIXMAP_HISTORY_PREV
, ANJUTA_STOCK_HISTORY_PREV
);
864 #define TEXT_ZOOM_FACTOR "text.zoom.factor"
867 update_status (DocmanPlugin
*plugin
, IAnjutaEditor
*te
)
869 AnjutaStatus
*status
;
871 status
= anjuta_shell_get_status (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
878 gchar
*edit
/*, *mode*/;
879 guint line
, col
, zoom
;
881 /* TODO: Implement this in IAnjutaEditor some kind
883 editor_mode = scintilla_send_message (SCINTILLA (te->widgets.editor),
884 SCI_GETEOLMODE, 0, 0);
885 switch (editor_mode) {
887 mode = g_strdup(_("DOS (CRLF)"));
890 mode = g_strdup(_("Unix (LF)"));
893 mode = g_strdup(_("Mac (CR)"));
896 mode = g_strdup(_("Unknown"));
900 zoom
= anjuta_preferences_get_int (plugin
->prefs
, TEXT_ZOOM_FACTOR
);
901 line
= ianjuta_editor_get_lineno (te
, NULL
);
902 col
= ianjuta_editor_get_column (te
, NULL
);
904 if (ianjuta_editor_get_overwrite (te
, NULL
))
906 edit
= g_strdup (_("OVR"));
910 edit
= g_strdup (_("INS"));
912 anjuta_status_set_default (status
, _("Zoom"), "%d", zoom
);
913 anjuta_status_set_default (status
, _("Line"), "%04d", line
);
914 anjuta_status_set_default (status
, _("Col"), "%03d", col
);
915 anjuta_status_set_default (status
, _("Mode"), edit
);
916 // anjuta_status_set_default (status, _("EOL"), mode);
923 anjuta_status_set_default (status
, _("Zoom"), NULL
);
924 anjuta_status_set_default (status
, _("Line"), NULL
);
925 anjuta_status_set_default (status
, _("Col"), NULL
);
926 anjuta_status_set_default (status
, _("Mode"), NULL
);
927 /* anjuta_status_set_default (status, _("EOL"), NULL); */
932 on_editor_update_ui (IAnjutaDocument
*editor
, DocmanPlugin
*plugin
)
936 te
= anjuta_docman_get_current_document(ANJUTA_DOCMAN (plugin
->docman
));
937 if (IANJUTA_IS_EDITOR(te
) && te
== editor
)
938 update_status (plugin
, IANJUTA_EDITOR(te
));
941 /* Remove all instances of c from the string s. */
942 static void remove_char(gchar
*s
, gchar c
)
951 /* Compare two strings, ignoring _ characters which indicate mnemonics.
952 * Returns -1, 0, or 1, just like strcmp(). */
954 menu_name_compare(const gchar
*s
, const char *t
)
956 gchar
*s1
= g_utf8_strdown(s
, -1);
957 gchar
*t1
= g_utf8_strdown(t
, -1);
958 remove_char(s1
, '_');
959 remove_char(t1
, '_');
960 int result
= g_utf8_collate(s1
, t1
);
967 compare_language_name(const gchar
*lang1
, const gchar
*lang2
, IAnjutaEditorLanguage
*manager
)
969 const gchar
*fullname1
= ianjuta_editor_language_get_language_name (manager
, lang1
, NULL
);
970 const gchar
*fullname2
= ianjuta_editor_language_get_language_name (manager
, lang2
, NULL
);
971 return menu_name_compare(fullname1
, fullname2
);
975 create_highlight_submenu (DocmanPlugin
*plugin
, IAnjutaEditor
*editor
)
977 const GList
*languages
, *node
;
978 GList
*sorted_languages
;
982 submenu
= gtk_menu_new ();
984 if (!editor
|| !IANJUTA_IS_EDITOR_LANGUAGE (editor
))
987 languages
= ianjuta_editor_language_get_supported_languages (IANJUTA_EDITOR_LANGUAGE (editor
), NULL
);
991 /* Automatic highlight menu */
992 menuitem
= gtk_menu_item_new_with_mnemonic (_("Automatic"));
993 g_signal_connect (G_OBJECT (menuitem
), "activate",
994 G_CALLBACK (on_force_hilite_activate
),
996 g_object_set_data(G_OBJECT(menuitem
), "language_code", "auto-detect");
997 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
998 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), gtk_separator_menu_item_new());
1000 /* Sort languages so they appear alphabetically in the menu. */
1001 sorted_languages
= g_list_copy((GList
*) languages
);
1002 sorted_languages
= g_list_sort_with_data(sorted_languages
, (GCompareDataFunc
) compare_language_name
,
1003 IANJUTA_EDITOR_LANGUAGE (editor
));
1005 node
= sorted_languages
;
1008 const gchar
*lang
= node
->data
;
1009 const gchar
*name
= ianjuta_editor_language_get_language_name (IANJUTA_EDITOR_LANGUAGE (editor
), lang
, NULL
);
1011 menuitem
= gtk_menu_item_new_with_mnemonic (name
);
1012 g_object_set_data_full (G_OBJECT (menuitem
), "language_code",
1014 (GDestroyNotify
)g_free
);
1015 g_signal_connect (G_OBJECT (menuitem
), "activate",
1016 G_CALLBACK (on_force_hilite_activate
),
1018 gtk_menu_shell_append (GTK_MENU_SHELL (submenu
), menuitem
);
1019 node
= g_list_next (node
);
1021 g_list_free(sorted_languages
);
1023 gtk_widget_show_all (submenu
);
1028 on_editor_added (AnjutaDocman
*docman
, IAnjutaDocument
*doc
,
1029 AnjutaPlugin
*plugin
)
1031 GtkWidget
*highlight_submenu
, *highlight_menu
;
1032 DocmanPlugin
*editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1035 g_signal_connect (G_OBJECT (doc
), "update-ui",
1036 G_CALLBACK (on_editor_update_ui
),
1037 ANJUTA_PLUGIN (plugin
));
1038 g_signal_connect (G_OBJECT (doc
), "save-point",
1039 G_CALLBACK (on_editor_update_save_ui
),
1040 ANJUTA_PLUGIN (plugin
));
1041 anjuta_shell_present_widget (plugin
->shell
,
1042 GTK_WIDGET (editor_plugin
->vbox
), NULL
);
1044 if (!IANJUTA_IS_EDITOR(doc
))
1049 te
= IANJUTA_EDITOR(doc
);
1051 /* Create Highlight submenu */
1053 create_highlight_submenu (editor_plugin
, te
);
1054 if (highlight_submenu
)
1057 gtk_ui_manager_get_widget (GTK_UI_MANAGER (editor_plugin
->ui
),
1058 "/MenuMain/MenuView/MenuViewEditor/MenuFormatStyle");
1059 gtk_menu_item_set_submenu (GTK_MENU_ITEM (highlight_menu
),
1065 on_support_plugin_deactivated (AnjutaPlugin
* plugin
, DocmanPlugin
* docman_plugin
)
1067 docman_plugin
->support_plugins
= g_list_remove (docman_plugin
->support_plugins
, plugin
);
1071 load_new_support_plugins (DocmanPlugin
* docman_plugin
, GList
* new_plugin_ids
,
1072 AnjutaPluginManager
* plugin_manager
)
1075 GList
* needed_plugins
= NULL
;
1076 for (node
= new_plugin_ids
; node
!= NULL
; node
= g_list_next (node
))
1078 gchar
* plugin_id
= node
->data
;
1079 GObject
* new_plugin
= anjuta_plugin_manager_get_plugin_by_id (plugin_manager
,
1081 GList
* item
= g_list_find (docman_plugin
->support_plugins
, new_plugin
);
1084 DEBUG_PRINT ("Loading plugin: %s", plugin_id
);
1085 g_signal_connect (new_plugin
, "deactivated",
1086 G_CALLBACK (on_support_plugin_deactivated
), docman_plugin
);
1088 needed_plugins
= g_list_append (needed_plugins
, new_plugin
);
1090 return needed_plugins
;
1094 unload_unused_support_plugins (DocmanPlugin
* docman_plugin
,
1095 GList
* needed_plugins
)
1097 GList
* plugins
= g_list_copy (docman_plugin
->support_plugins
);
1099 for (node
= plugins
; node
!= NULL
; node
= g_list_next (node
))
1101 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN (node
->data
);
1102 if (!g_list_find (needed_plugins
, plugin
))
1104 DEBUG_PRINT ("Unloading plugin");
1105 anjuta_plugin_deactivate (plugin
);
1108 g_list_free (plugins
);
1112 on_editor_changed (AnjutaDocman
*docman
, IAnjutaDocument
*te
,
1113 AnjutaPlugin
*plugin
)
1115 DocmanPlugin
*docman_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1117 update_editor_ui (plugin
, te
);
1119 GValue value
= {0, };
1120 g_value_init (&value
, G_TYPE_OBJECT
);
1121 g_value_set_object (&value
, te
);
1122 anjuta_shell_add_value (plugin
->shell
,
1123 "document_manager_current_editor",
1125 g_value_unset(&value
);
1126 DEBUG_PRINT ("Editor Added");
1128 if (te
&& IANJUTA_IS_EDITOR(te
))
1130 DEBUG_PRINT("Beginning language support");
1132 AnjutaPluginManager
*plugin_manager
;
1133 GList
*support_plugin_descs
, *node
;
1135 update_status (docman_plugin
, IANJUTA_EDITOR(te
));
1137 /* Load current language editor support plugins */
1138 plugin_manager
= anjuta_shell_get_plugin_manager (plugin
->shell
, NULL
);
1139 if (IANJUTA_IS_EDITOR_LANGUAGE (te
))
1141 GList
* new_support_plugins
= NULL
;
1142 GList
* needed_plugins
= NULL
;
1143 const gchar
*language
= NULL
;
1144 IAnjutaLanguage
* lang_manager
= anjuta_shell_get_interface (plugin
->shell
,
1149 g_warning ("Could not load language manager!");
1152 language
= ianjuta_language_get_name_from_editor (lang_manager
,
1153 IANJUTA_EDITOR_LANGUAGE (te
),
1157 /* Unload all language support plugins */
1158 GList
* plugins
= g_list_copy (docman_plugin
->support_plugins
);
1159 DEBUG_PRINT ("Unloading all plugins");
1160 g_list_foreach (plugins
, (GFunc
) anjuta_plugin_deactivate
,
1162 g_list_free (plugins
);
1166 support_plugin_descs
= anjuta_plugin_manager_query (plugin_manager
,
1169 "IAnjutaLanguageSupport",
1173 for (node
= support_plugin_descs
; node
!= NULL
; node
= g_list_next (node
))
1178 AnjutaPluginDescription
*desc
= node
->data
;
1180 anjuta_plugin_description_get_string (desc
, "Language Support",
1181 "Languages", &languages
);
1183 anjuta_plugin_description_get_string (desc
, "Anjuta Plugin", "Location",
1186 new_support_plugins
= g_list_append (new_support_plugins
, plugin_id
);
1188 g_list_free (support_plugin_descs
);
1190 /* Load new plugins */
1192 load_new_support_plugins (docman_plugin
, new_support_plugins
,
1195 /* Unload unused plugins */
1196 unload_unused_support_plugins (docman_plugin
, needed_plugins
);
1199 g_list_free (docman_plugin
->support_plugins
);
1200 docman_plugin
->support_plugins
= needed_plugins
;
1202 g_list_foreach (new_support_plugins
, (GFunc
) g_free
, NULL
);
1203 g_list_free (new_support_plugins
);
1207 update_title (ANJUTA_PLUGIN_DOCMAN(plugin
));
1211 on_window_key_press_event (GtkWidget
*widget
,
1213 DocmanPlugin
*plugin
)
1218 g_return_val_if_fail (event
!= NULL
, FALSE
);
1220 modifiers
= event
->state
& (GDK_SHIFT_MASK
| GDK_CONTROL_MASK
| GDK_MOD1_MASK
);
1222 for (i
= 0; global_keymap
[i
].id
; i
++)
1223 if (event
->keyval
== global_keymap
[i
].gdk_key
&&
1224 (event
->state
& global_keymap
[i
].modifiers
) == global_keymap
[i
].modifiers
)
1227 if (!global_keymap
[i
].id
)
1230 switch (global_keymap
[i
].id
) {
1232 case ID_PREVBUFFER
: {
1233 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1237 if (!notebook
->children
)
1240 if (!plugin
->g_tabbing
)
1242 plugin
->g_tabbing
= TRUE
;
1245 pages_nb
= g_list_length (notebook
->children
);
1246 cur_page
= gtk_notebook_get_current_page (notebook
);
1248 if (global_keymap
[i
].id
== ID_NEXTBUFFER
)
1249 cur_page
= (cur_page
< pages_nb
- 1) ? cur_page
+ 1 : 0;
1251 cur_page
= cur_page
? cur_page
- 1 : pages_nb
-1;
1253 gtk_notebook_set_page (notebook
, cur_page
);
1258 if (global_keymap
[i
].id
>= ID_FIRSTBUFFER
&&
1259 global_keymap
[i
].id
<= (ID_FIRSTBUFFER
+ 9))
1261 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1262 int page_req
= global_keymap
[i
].id
- ID_FIRSTBUFFER
;
1264 if (!notebook
->children
)
1266 gtk_notebook_set_page(notebook
, page_req
);
1272 /* Note: No reason for a shortcut to do more than one thing a time */
1273 g_signal_stop_emission_by_name (G_OBJECT (ANJUTA_PLUGIN(plugin
)->shell
),
1279 #define EDITOR_TABS_RECENT_FIRST "editor.tabs.recent.first"
1280 #define EDITOR_TABS_POS "editor.tabs.pos"
1281 #define EDITOR_TABS_HIDE "editor.tabs.hide"
1282 #define EDITOR_TABS_ORDERING "editor.tabs.ordering"
1283 #define AUTOSAVE_TIMER "autosave.timer"
1284 #define SAVE_AUTOMATIC "save.automatic"
1287 on_window_key_release_event (GtkWidget
*widget
,
1289 DocmanPlugin
*plugin
)
1291 g_return_val_if_fail (event
!= NULL
, FALSE
);
1293 if (plugin
->g_tabbing
&& ((event
->keyval
== GDK_Control_L
) ||
1294 (event
->keyval
== GDK_Control_R
)))
1296 GtkNotebook
*notebook
= GTK_NOTEBOOK (plugin
->docman
);
1299 plugin
->g_tabbing
= FALSE
;
1301 if (anjuta_preferences_get_int (plugin
->prefs
,
1302 EDITOR_TABS_RECENT_FIRST
))
1305 TTimo: move the current notebook page to first position
1306 that maintains Ctrl-TABing on a list of most recently edited files
1308 cur_page
= gtk_notebook_get_current_page (notebook
);
1309 widget
= gtk_notebook_get_nth_page (notebook
, cur_page
);
1310 gtk_notebook_reorder_child (notebook
, widget
, 0);
1317 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
1318 AnjutaSession
*session
, DocmanPlugin
*plugin
)
1320 GList
*editors
, *node
, *files
;
1322 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
1325 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
1326 files
= g_list_reverse (files
);
1328 editors
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1335 if (!IANJUTA_IS_EDITOR(node
->data
))
1337 node
= g_list_next(node
);
1341 te
= IANJUTA_EDITOR (node
->data
);
1342 te_uri
= ianjuta_file_get_uri(IANJUTA_FILE(te
), NULL
);
1346 /* Save line locations also */
1347 uri
= g_strdup_printf ("%s#%d", te_uri
,
1348 ianjuta_editor_get_lineno(IANJUTA_EDITOR(te
), NULL
));
1349 files
= g_list_prepend (files
, uri
);
1350 /* uri not be freed here */
1353 node
= g_list_next (node
);
1355 files
= g_list_reverse (files
);
1356 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
1357 g_list_free (editors
);
1358 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
1359 g_list_free (files
);
1363 on_save_prompt_save_editor (AnjutaSavePrompt
*save_prompt
,
1364 gpointer item
, gpointer user_data
)
1366 DocmanPlugin
*plugin
;
1368 plugin
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1369 return anjuta_docman_save_document (ANJUTA_DOCMAN (plugin
->docman
),
1370 IANJUTA_DOCUMENT (item
),
1371 GTK_WIDGET (save_prompt
));
1375 on_save_prompt (AnjutaShell
*shell
, AnjutaSavePrompt
*save_prompt
,
1376 DocmanPlugin
*plugin
)
1380 list
= anjuta_docman_get_all_editors (ANJUTA_DOCMAN (plugin
->docman
));
1384 IAnjutaFileSavable
*editor
= IANJUTA_FILE_SAVABLE (node
->data
);
1385 if (ianjuta_file_savable_is_dirty (editor
, NULL
))
1390 name
= ianjuta_document_get_filename (IANJUTA_DOCUMENT (editor
), NULL
);
1391 uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
1392 anjuta_save_prompt_add_item (save_prompt
, name
, uri
, editor
,
1393 on_save_prompt_save_editor
, plugin
);
1396 node
= g_list_next (node
);
1401 docman_plugin_set_tab_pos (DocmanPlugin
*ep
)
1403 if (anjuta_preferences_get_int_with_default (ep
->prefs
, EDITOR_TABS_HIDE
,
1406 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), FALSE
);
1411 GtkPositionType pos
;
1413 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ep
->docman
), TRUE
);
1414 tab_pos
= anjuta_preferences_get (ep
->prefs
, EDITOR_TABS_POS
);
1419 if (strcasecmp (tab_pos
, "left") == 0)
1421 else if (strcasecmp (tab_pos
, "right") == 0)
1422 pos
= GTK_POS_RIGHT
;
1423 else if (strcasecmp (tab_pos
, "bottom") == 0)
1424 pos
= GTK_POS_BOTTOM
;
1427 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (ep
->docman
), pos
);
1432 on_gconf_notify_prefs (GConfClient
*gclient
, guint cnxn_id
,
1433 GConfEntry
*entry
, gpointer user_data
)
1435 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1436 docman_plugin_set_tab_pos (ep
);
1440 on_docman_auto_save (gpointer data
)
1442 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (data
);
1444 AnjutaPreferences
* prefs
;
1445 AnjutaDocman
*docman
;
1446 AnjutaStatus
* status
;
1447 IAnjutaDocument
* editor
;
1449 docman
= ANJUTA_DOCMAN (plugin
->docman
);
1451 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
1452 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1453 status
= anjuta_shell_get_status(shell
, NULL
);
1457 if (anjuta_preferences_get_int (prefs
, SAVE_AUTOMATIC
) == FALSE
)
1459 plugin
->autosave_on
= FALSE
;
1463 editors
= anjuta_docman_get_all_editors(docman
);
1466 editor
= IANJUTA_DOCUMENT(editors
->data
);
1467 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1469 gchar
*uri
= ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1472 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1476 editors
= g_list_next(editors
);
1478 // TODO: Check for errors
1481 mesg
= g_strdup("Autosaved complete");
1482 anjuta_status (status
, mesg
, 3);
1489 on_gconf_notify_timer (GConfClient
*gclient
, guint cnxn_id
,
1490 GConfEntry
*entry
, gpointer user_data
)
1492 DocmanPlugin
*ep
= ANJUTA_PLUGIN_DOCMAN (user_data
);
1494 AnjutaPreferences
* prefs
;
1495 gint auto_save_timer
;
1498 g_object_get(G_OBJECT(ep
), "shell", &shell
, NULL
);
1499 prefs
= anjuta_shell_get_preferences(shell
, NULL
);
1501 auto_save_timer
= anjuta_preferences_get_int(prefs
, AUTOSAVE_TIMER
);
1502 auto_save
= anjuta_preferences_get_int(prefs
, SAVE_AUTOMATIC
);
1506 if (ep
->autosave_on
== TRUE
)
1508 if (auto_save_timer
!= ep
->autosave_it
)
1510 gtk_timeout_remove (ep
->autosave_id
);
1512 gtk_timeout_add (auto_save_timer
*
1514 on_docman_auto_save
,
1521 #if GLIB_CHECK_VERSION (2,14,0)
1522 g_timeout_add_seconds (auto_save_timer
* 60,
1524 g_timeout_add (auto_save_timer
* 60000,
1526 on_docman_auto_save
,
1529 ep
->autosave_it
= auto_save_timer
;
1530 ep
->autosave_on
= TRUE
;
1534 if (ep
->autosave_on
== TRUE
)
1535 gtk_timeout_remove (ep
->autosave_id
);
1536 ep
->autosave_on
= FALSE
;
1540 #define REGISTER_NOTIFY(key, func) \
1541 notify_id = anjuta_preferences_notify_add (ep->prefs, \
1542 key, func, ep, NULL); \
1543 ep->gconf_notify_ids = g_list_prepend (ep->gconf_notify_ids, \
1544 GUINT_TO_POINTER (notify_id));
1546 prefs_init (DocmanPlugin
*ep
)
1549 docman_plugin_set_tab_pos (ep
);
1550 REGISTER_NOTIFY (EDITOR_TABS_HIDE
, on_gconf_notify_prefs
);
1551 REGISTER_NOTIFY (EDITOR_TABS_POS
, on_gconf_notify_prefs
);
1552 REGISTER_NOTIFY (AUTOSAVE_TIMER
, on_gconf_notify_timer
);
1553 REGISTER_NOTIFY (SAVE_AUTOMATIC
, on_gconf_notify_timer
);
1555 on_gconf_notify_timer(NULL
,0,NULL
, ep
);
1559 prefs_finalize (DocmanPlugin
*ep
)
1562 node
= ep
->gconf_notify_ids
;
1565 anjuta_preferences_notify_remove (ep
->prefs
,
1566 GPOINTER_TO_UINT (node
->data
));
1567 node
= g_list_next (node
);
1569 g_list_free (ep
->gconf_notify_ids
);
1570 ep
->gconf_notify_ids
= NULL
;
1574 activate_plugin (AnjutaPlugin
*plugin
)
1576 GtkWidget
*docman
, *popup_menu
;
1578 DocmanPlugin
*editor_plugin
;
1579 GtkActionGroup
*group
;
1581 AnjutaStatus
*status
;
1582 static gboolean initialized
= FALSE
;
1584 DEBUG_PRINT ("DocmanPlugin: Activating Editor plugin...");
1586 editor_plugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1587 editor_plugin
->ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1588 editor_plugin
->prefs
= anjuta_shell_get_preferences (plugin
->shell
, NULL
);
1589 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1591 ui
= editor_plugin
->ui
;
1592 docman
= anjuta_docman_new (editor_plugin
, editor_plugin
->prefs
);
1593 editor_plugin
->docman
= docman
;
1595 editor_plugin
->search_box
= search_box_new (editor_plugin
);
1597 ANJUTA_DOCMAN(docman
)->shell
= plugin
->shell
;
1598 g_signal_connect (G_OBJECT (docman
), "editor-added",
1599 G_CALLBACK (on_editor_added
), plugin
);
1600 g_signal_connect (G_OBJECT (docman
), "editor-changed",
1601 G_CALLBACK (on_editor_changed
), plugin
);
1602 g_signal_connect_swapped (G_OBJECT (status
), "busy",
1603 G_CALLBACK (anjuta_docman_set_busy
), docman
);
1604 g_signal_connect (G_OBJECT (plugin
->shell
), "key-press-event",
1605 G_CALLBACK (on_window_key_press_event
), plugin
);
1606 g_signal_connect (G_OBJECT (plugin
->shell
), "key-release-event",
1607 G_CALLBACK (on_window_key_release_event
), plugin
);
1611 register_stock_icons (plugin
);
1613 editor_plugin
->action_groups
= NULL
;
1614 /* Add all our editor actions */
1615 for (i
= 0; i
< G_N_ELEMENTS (action_groups
); i
++)
1617 GList
*actions
, *act
;
1618 DEBUG_PRINT ("Adding action group: %s", action_groups
[i
].name
);
1619 group
= anjuta_ui_add_action_group_entries (ui
,
1620 action_groups
[i
].name
,
1621 _(action_groups
[i
].label
),
1622 action_groups
[i
].group
,
1623 action_groups
[i
].size
,
1624 GETTEXT_PACKAGE
, TRUE
,
1626 editor_plugin
->action_groups
=
1627 g_list_prepend (editor_plugin
->action_groups
, group
);
1628 actions
= gtk_action_group_list_actions (group
);
1631 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1632 act
= g_list_next (act
);
1635 for (i
= 0; i
< G_N_ELEMENTS (action_toggle_groups
); i
++)
1637 GList
*actions
, *act
;
1638 group
= anjuta_ui_add_toggle_action_group_entries (ui
,
1639 action_toggle_groups
[i
].name
,
1640 _(action_toggle_groups
[i
].label
),
1641 action_toggle_groups
[i
].group
,
1642 action_toggle_groups
[i
].size
,
1643 GETTEXT_PACKAGE
, TRUE
, plugin
);
1644 editor_plugin
->action_groups
=
1645 g_list_prepend (editor_plugin
->action_groups
, group
);
1646 actions
= gtk_action_group_list_actions (group
);
1649 g_object_set_data (G_OBJECT (act
->data
), "Plugin", editor_plugin
);
1650 act
= g_list_next (act
);
1655 editor_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
1656 editor_plugin
->vbox
= gtk_vbox_new (FALSE
, 0);
1657 gtk_widget_show (editor_plugin
->vbox
);
1658 gtk_box_pack_start_defaults (GTK_BOX(editor_plugin
->vbox
), docman
);
1659 anjuta_shell_add_widget_full (plugin
->shell
, editor_plugin
->vbox
,
1660 "AnjutaDocumentManager", _("Documents"),
1661 "editor-plugin-icon",
1662 ANJUTA_SHELL_PLACEMENT_CENTER
,
1665 ui_states_init(plugin
);
1666 ui_give_shorter_names (plugin
);
1667 update_editor_ui (plugin
, NULL
);
1669 /* Setup popup menu */
1670 popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
1671 "/PopupDocumentManager");
1672 g_assert (popup_menu
!= NULL
&& GTK_IS_MENU (popup_menu
));
1673 anjuta_docman_set_popup_menu (ANJUTA_DOCMAN (docman
), popup_menu
);
1676 //search_and_replace_init (ANJUTA_DOCMAN (docman));
1678 /* Connect to save session */
1679 g_signal_connect (G_OBJECT (plugin
->shell
), "save-session",
1680 G_CALLBACK (on_session_save
), plugin
);
1681 /* Connect to save prompt */
1682 g_signal_connect (G_OBJECT (plugin
->shell
), "save-prompt",
1683 G_CALLBACK (on_save_prompt
), plugin
);
1685 editor_plugin
->project_watch_id
=
1686 anjuta_plugin_add_watch (plugin
, "project_root_uri",
1687 value_added_project_root_uri
,
1688 value_removed_project_root_uri
, NULL
);
1689 editor_plugin
->project_name
= NULL
;
1697 deactivate_plugin (AnjutaPlugin
*plugin
)
1699 // GtkIconFactory *icon_factory;
1700 DocmanPlugin
*eplugin
;
1702 AnjutaStatus
*status
;
1705 DEBUG_PRINT ("DocmanPlugin: Dectivating Editor plugin...");
1707 eplugin
= ANJUTA_PLUGIN_DOCMAN (plugin
);
1709 prefs_finalize (eplugin
);
1710 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1711 G_CALLBACK (on_session_save
), plugin
);
1712 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1713 G_CALLBACK (on_save_prompt
), plugin
);
1715 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
1716 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
1718 g_signal_handlers_disconnect_by_func (G_OBJECT (status
),
1719 G_CALLBACK (anjuta_docman_set_busy
),
1721 g_signal_handlers_disconnect_by_func (G_OBJECT (eplugin
->docman
),
1722 G_CALLBACK (on_editor_changed
),
1724 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1725 G_CALLBACK (on_window_key_press_event
),
1727 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
1728 G_CALLBACK (on_window_key_release_event
),
1731 on_editor_changed (ANJUTA_DOCMAN (eplugin
->docman
), NULL
, plugin
);
1733 /* Widget is removed from the container when destroyed */
1734 gtk_widget_destroy (eplugin
->docman
);
1735 gtk_widget_destroy (eplugin
->search_box
);
1736 anjuta_ui_unmerge (ui
, eplugin
->uiid
);
1737 node
= eplugin
->action_groups
;
1740 GtkActionGroup
*group
= GTK_ACTION_GROUP (node
->data
);
1741 anjuta_ui_remove_action_group (ui
, group
);
1742 node
= g_list_next (node
);
1744 g_list_free (eplugin
->action_groups
);
1747 /* Unregister stock icons */
1748 /* Unregister preferences */
1750 eplugin
->docman
= NULL
;
1752 eplugin
->action_groups
= NULL
;
1758 dispose (GObject
*obj
)
1760 // DocmanPlugin *eplugin = ANJUTA_PLUGIN_DOCMAN (obj);
1761 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
1765 docman_plugin_instance_init (GObject
*obj
)
1767 DocmanPlugin
*plugin
= ANJUTA_PLUGIN_DOCMAN (obj
);
1769 plugin
->g_tabbing
= FALSE
;
1770 plugin
->gconf_notify_ids
= NULL
;
1771 plugin
->support_plugins
= NULL
;
1775 docman_plugin_class_init (GObjectClass
*klass
)
1777 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
1779 parent_class
= g_type_class_peek_parent (klass
);
1781 plugin_class
->activate
= activate_plugin
;
1782 plugin_class
->deactivate
= deactivate_plugin
;
1783 klass
->dispose
= dispose
;
1786 /* Implement IAnjutaDocumentManager interfaces */
1787 static const gchar
*
1788 ianjuta_docman_get_full_filename (IAnjutaDocumentManager
*plugin
,
1789 const gchar
*file
, GError
**e
)
1791 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1792 return anjuta_docman_get_full_filename (ANJUTA_DOCMAN (docman
), file
);
1795 static IAnjutaDocument
*
1796 ianjuta_docman_find_editor_with_path (IAnjutaDocumentManager
*plugin
,
1797 const gchar
*file_path
, GError
**e
)
1799 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1800 return IANJUTA_DOCUMENT(anjuta_docman_find_editor_with_path
1801 (ANJUTA_DOCMAN (docman
), file_path
));
1804 static IAnjutaDocument
*
1805 ianjuta_docman_get_current_document (IAnjutaDocumentManager
*plugin
, GError
**e
)
1807 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1809 anjuta_docman_get_current_document (ANJUTA_DOCMAN (docman
));
1813 ianjuta_docman_set_current_document (IAnjutaDocumentManager
*plugin
,
1814 IAnjutaDocument
*editor
, GError
**e
)
1816 AnjutaDocman
*docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1817 anjuta_docman_set_current_document (ANJUTA_DOCMAN (docman
),
1822 ianjuta_docman_get_editors (IAnjutaDocumentManager
*plugin
, GError
**e
)
1824 AnjutaDocman
*docman
;
1825 GList
* editors
= NULL
;
1826 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1827 editors
= anjuta_docman_get_all_editors (docman
);
1831 static IAnjutaEditor
*
1832 ianjuta_docman_goto_file_line (IAnjutaDocumentManager
*plugin
,
1833 const gchar
*uri
, gint linenum
, GError
**e
)
1835 AnjutaDocman
*docman
;
1836 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1837 return anjuta_docman_goto_file_line (docman
, uri
, linenum
);
1840 static IAnjutaEditor
*
1841 ianjuta_docman_goto_file_line_mark (IAnjutaDocumentManager
*plugin
,
1842 const gchar
*uri
, gint linenum
, gboolean mark
, GError
**e
)
1844 AnjutaDocman
*docman
;
1845 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1846 return anjuta_docman_goto_file_line_mark (docman
, uri
, linenum
, mark
);
1849 static IAnjutaEditor
*
1850 ianjuta_docman_add_buffer (IAnjutaDocumentManager
*plugin
,
1851 const gchar
*filename
, const gchar
*content
,
1854 AnjutaDocman
*docman
;
1856 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1857 te
= anjuta_docman_add_editor (docman
, NULL
, filename
);
1860 /*if (content && strlen (content) > 0)
1861 aneditor_command (te->editor_id, ANE_INSERTTEXT, -1,
1863 return IANJUTA_EDITOR (te
);
1869 ianjuta_docman_add_document (IAnjutaDocumentManager
*plugin
,
1870 IAnjutaDocument
* document
,
1873 AnjutaDocman
*docman
;
1874 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1876 anjuta_docman_add_document(docman
, document
, NULL
);
1880 ianjuta_docman_remove_document(IAnjutaDocumentManager
*plugin
,
1881 IAnjutaDocument
*editor
,
1882 gboolean save_before
, GError
**e
)
1884 gint ret_val
= TRUE
;
1885 AnjutaDocman
*docman
;
1886 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1890 ret_val
= anjuta_docman_save_document(docman
, IANJUTA_DOCUMENT(editor
),
1891 GTK_WIDGET (ANJUTA_PLUGIN (plugin
)->shell
));
1894 anjuta_docman_remove_document (docman
, IANJUTA_DOCUMENT(editor
));
1900 ianjuta_document_manager_iface_init (IAnjutaDocumentManagerIface
*iface
)
1902 iface
->get_full_filename
= ianjuta_docman_get_full_filename
;
1903 iface
->find_document_with_path
= ianjuta_docman_find_editor_with_path
;
1904 iface
->get_current_document
= ianjuta_docman_get_current_document
;
1905 iface
->set_current_document
= ianjuta_docman_set_current_document
;
1906 iface
->get_documents
= ianjuta_docman_get_editors
;
1907 iface
->goto_file_line
= ianjuta_docman_goto_file_line
;
1908 iface
->goto_file_line_mark
= ianjuta_docman_goto_file_line_mark
;
1909 iface
->add_buffer
= ianjuta_docman_add_buffer
;
1910 iface
->remove_document
= ianjuta_docman_remove_document
;
1911 iface
->add_document
= ianjuta_docman_add_document
;
1914 /* Implement IAnjutaFile interface */
1916 ifile_open (IAnjutaFile
* plugin
, const gchar
* uri
, GError
** e
)
1918 AnjutaDocman
*docman
;
1920 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1921 anjuta_docman_goto_file_line_mark (docman
, uri
, -1, FALSE
);
1925 ifile_get_uri (IAnjutaFile
* plugin
, GError
** e
)
1927 AnjutaDocman
*docman
;
1928 IAnjutaDocument
* editor
;
1929 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1930 editor
= anjuta_docman_get_current_document (docman
);
1932 return ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1933 else if (ianjuta_document_get_filename(editor
, NULL
))
1934 return gnome_vfs_get_uri_from_local_path (ianjuta_document_get_filename(editor
, NULL
));
1940 ifile_iface_init (IAnjutaFileIface
*iface
)
1942 iface
->open
= ifile_open
;
1943 iface
->get_uri
= ifile_get_uri
;
1946 /* Implement IAnjutaFileSavable interface */
1948 isaveable_save (IAnjutaFileSavable
* plugin
, GError
** e
)
1950 /* Save all editors */
1951 AnjutaDocman
*docman
;
1952 IAnjutaDocument
* editor
;
1954 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1955 editors
= anjuta_docman_get_all_editors(docman
);
1959 editor
= IANJUTA_DOCUMENT(editors
->data
);
1960 uri
= ianjuta_file_get_uri(IANJUTA_FILE(editor
), NULL
);
1962 ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1964 ianjuta_file_savable_save(IANJUTA_FILE_SAVABLE(editor
), NULL
);
1967 editors
= g_list_next(editors
);
1969 g_list_free(editors
);
1973 isavable_save_as (IAnjutaFileSavable
* plugin
, const gchar
* uri
, GError
** e
)
1975 DEBUG_PRINT("save_as: Not implemented in DocmanPlugin");
1979 isavable_is_dirty(IAnjutaFileSavable
* plugin
, GError
** e
)
1981 /* Is any editor unsaved */
1982 AnjutaDocman
*docman
;
1983 IAnjutaDocument
* editor
;
1985 gboolean retval
= FALSE
;
1986 docman
= ANJUTA_DOCMAN ((ANJUTA_PLUGIN_DOCMAN (plugin
)->docman
));
1987 editors
= anjuta_docman_get_all_editors(docman
);
1990 editor
= IANJUTA_DOCUMENT(editors
->data
);
1991 if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(editor
), NULL
))
1996 editors
= g_list_next(editors
);
1998 g_list_free(editors
);
2003 isavable_set_dirty(IAnjutaFileSavable
* plugin
, gboolean dirty
, GError
** e
)
2005 DEBUG_PRINT("set_dirty: Not implemented in DocmanPlugin");
2009 isavable_iface_init (IAnjutaFileSavableIface
*iface
)
2011 iface
->save
= isaveable_save
;
2012 iface
->save_as
= isavable_save_as
;
2013 iface
->set_dirty
= isavable_set_dirty
;
2014 iface
->is_dirty
= isavable_is_dirty
;
2018 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
2021 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN(ipref
);
2023 /* Add preferences */
2024 gxml
= glade_xml_new (PREFS_GLADE
, "preferences_dialog", NULL
);
2026 anjuta_preferences_add_page (prefs
,
2027 gxml
, "Documents", _("Documents"), ICON_FILE
);
2028 anjuta_encodings_init (prefs
, gxml
);
2030 prefs_init(ANJUTA_PLUGIN_DOCMAN (plugin
));
2031 g_object_unref (G_OBJECT (gxml
));
2035 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
2037 DocmanPlugin
* plugin
= ANJUTA_PLUGIN_DOCMAN (ipref
);
2038 prefs_finalize(plugin
);
2039 anjuta_preferences_remove_page(prefs
, _("Documents"));
2043 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
2045 iface
->merge
= ipreferences_merge
;
2046 iface
->unmerge
= ipreferences_unmerge
;
2049 ANJUTA_PLUGIN_BEGIN (DocmanPlugin
, docman_plugin
);
2050 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_document_manager
, IANJUTA_TYPE_DOCUMENT_MANAGER
);
2051 ANJUTA_PLUGIN_ADD_INTERFACE(ifile
, IANJUTA_TYPE_FILE
);
2052 ANJUTA_PLUGIN_ADD_INTERFACE(isavable
, IANJUTA_TYPE_FILE_SAVABLE
);
2053 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
2056 ANJUTA_SIMPLE_PLUGIN (DocmanPlugin
, docman_plugin
);