-;; ----- Menus --------------------------------------------------------------
-(defun ada-add-ada-menu ()
- "Add some items to the standard Ada mode menu.
-The items are added to the menu called NAME, which should be the same
-name as was passed to `ada-create-menu'."
- (interactive)
- (if ada-xemacs
- (let* ((menu-list '("Ada"))
- (goto-menu '("Ada" "Goto"))
- (edit-menu '("Ada" "Edit"))
- (help-menu '("Ada" "Help"))
- (options-menu (list "Ada" "Options")))
- (funcall (symbol-function 'add-menu-button)
- menu-list ["Check file" ada-check-current
- (string= mode-name "Ada")] "Goto")
- (funcall (symbol-function 'add-menu-button)
- menu-list ["Compile file" ada-compile-current
- (string= mode-name "Ada")] "Goto")
- (funcall (symbol-function 'add-menu-button)
- menu-list ["Build" ada-compile-application t] "Goto")
- (funcall (symbol-function 'add-menu-button)
- menu-list ["Run" ada-run-application t] "Goto")
- (funcall (symbol-function 'add-menu-button)
- menu-list ["Debug" ada-gdb-application t] "Goto")
- (funcall (symbol-function 'add-menu-button)
- menu-list ["--" nil t] "Goto")
- (funcall (symbol-function 'add-submenu)
- menu-list '("Project"
- ["Associate" ada-change-prj t]
- ["Set Default..." ada-set-default-project-file t]
- ["List" ada-buffer-list t])
- "Goto")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["Goto Parent Unit" ada-goto-parent t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["Goto References to any entity"
- ada-find-any-references t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["List References" ada-find-references t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["Goto Declaration Other Frame"
- ada-goto-declaration-other-frame t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["Goto Declaration/Body"
- ada-goto-declaration t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["Goto Previous Reference"
- ada-xref-goto-previous-reference t]
- "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- goto-menu ["--" nil t] "Next compilation error")
- (funcall (symbol-function 'add-menu-button)
- edit-menu ["Complete Identifier"
- ada-complete-identifier t]
- "Indent Line")
- (funcall (symbol-function 'add-menu-button)
- edit-menu ["--------" nil t] "Indent Line")
- (funcall (symbol-function 'add-menu-button)
- help-menu ["Gnat User Guide" (info "gnat_ug")])
- (funcall (symbol-function 'add-menu-button)
- help-menu ["Gnat Reference Manual" (info "gnat_rm")])
- (funcall (symbol-function 'add-menu-button)
- help-menu ["Gcc Documentation" (info "gcc")])
- (funcall (symbol-function 'add-menu-button)
- help-menu ["Gdb Documentation" (info "gdb")])
- (funcall (symbol-function 'add-menu-button)
- help-menu ["Ada95 Reference Manual" (info "arm95")])
- (funcall (symbol-function 'add-menu-button)
- options-menu
- ["Show Cross-References in Other Buffer"
- (setq ada-xref-other-buffer
- (not ada-xref-other-buffer))
- :style toggle :selected ada-xref-other-buffer])
- (funcall (symbol-function 'add-menu-button)
- options-menu
- ["Automatically Recompile for Cross-References"
- (setq ada-xref-create-ali (not ada-xref-create-ali))
- :style toggle :selected ada-xref-create-ali])
- (funcall (symbol-function 'add-menu-button)
- options-menu
- ["Confirm Commands"
- (setq ada-xref-confirm-compile
- (not ada-xref-confirm-compile))
- :style toggle :selected ada-xref-confirm-compile])
- )
-
- ;; for Emacs
- (let* ((menu (lookup-key ada-mode-map [menu-bar Ada]))
- (edit-menu (lookup-key ada-mode-map [menu-bar Ada Edit]))
- (help-menu (lookup-key ada-mode-map [menu-bar Ada Help]))
- (goto-menu (lookup-key ada-mode-map [menu-bar Ada Goto]))
- (options-menu (lookup-key ada-mode-map [menu-bar Ada Options])))
-
- (define-key-after menu [Check] '("Check file" . ada-check-current)
- 'Customize)
- (define-key-after menu [Compile] '("Compile file" . ada-compile-current)
- 'Check)
- (define-key-after menu [Build] '("Build" . ada-compile-application)
- 'Compile)
- (define-key-after menu [Run] '("Run" . ada-run-application) 'Build)
- (define-key-after menu [Debug] '("Debug" . ada-gdb-application) 'Run)
- (define-key-after menu [rem] '("--" . nil) 'Debug)
- (define-key-after menu [Project]
- (cons "Project"
- (funcall (symbol-function 'easy-menu-create-menu)
- "Project"
- '(["Associate..." ada-change-prj t
- :included (string= mode-name "Ada")]
- ["Set Default..." ada-set-default-project-file t]
- ["List" ada-buffer-list t])))
- 'rem)
-
- (define-key help-menu [Gnat_ug]
- '("Gnat User Guide" . (lambda() (interactive) (info "gnat_ug"))))
- (define-key help-menu [Gnat_rm]
- '("Gnat Reference Manual" . (lambda() (interactive) (info "gnat_rm"))))
- (define-key help-menu [Gcc]
- '("Gcc Documentation" . (lambda() (interactive) (info "gcc"))))
- (define-key help-menu [gdb]
- '("Gdb Documentation" . (lambda() (interactive) (info "gdb"))))
- (define-key help-menu [gdb]
- '("Ada95 Reference Manual" . (lambda() (interactive) (info "arm95"))))
-
- (define-key goto-menu [rem] '("----" . nil))
- (define-key goto-menu [Parent] '("Goto Parent Unit"
- . ada-goto-parent))
- (define-key goto-menu [References-any]
- '("Goto References to any entity" . ada-find-any-references))
- (define-key goto-menu [References]
- '("List References" . ada-find-references))
- (define-key goto-menu [Prev]
- '("Goto Previous Reference" . ada-xref-goto-previous-reference))
- (define-key goto-menu [Decl-other]
- '("Goto Declaration Other Frame" . ada-goto-declaration-other-frame))
- (define-key goto-menu [Decl]
- '("Goto Declaration/Body" . ada-goto-declaration))
-
- (define-key edit-menu [rem] '("----" . nil))
- (define-key edit-menu [Complete] '("Complete Identifier"
- . ada-complete-identifier))
-
- (define-key-after options-menu [xrefrecompile]
- '(menu-item "Automatically Recompile for Cross-References"
- (lambda()(interactive)
- (setq ada-xref-create-ali (not ada-xref-create-ali)))
- :button (:toggle . ada-xref-create-ali)) t)
- (define-key-after options-menu [xrefconfirm]
- '(menu-item "Confirm Commands"
- (lambda()(interactive)
- (setq ada-xref-confirm-compile
- (not ada-xref-confirm-compile)))
- :button (:toggle . ada-xref-confirm-compile)) t)
- (define-key-after options-menu [xrefother]
- '(menu-item "Show Cross-References in Other Buffer"
- (lambda()(interactive)
- (setq ada-xref-other-buffer (not ada-xref-other-buffer)))
- :button (:toggle . ada-xref-other-buffer)) t)
- )
- )
- )
+(defun ada-xref-get-src-dir-field ()
+ "Return the full value for src_dir, including the default directories.
+All the directories are returned as absolute directories."
+
+ (let ((build-dir (ada-xref-get-project-field 'build_dir)))
+ (append
+ ;; Add ${build_dir} in front of the path
+ (list build-dir)
+
+ (ada-get-absolute-dir-list (ada-xref-get-project-field 'src_dir)
+ build-dir)
+
+ ;; Add the standard runtime at the end
+ ada-xref-runtime-library-specs-path)))
+
+(defun ada-xref-get-obj-dir-field ()
+ "Return the full value for obj_dir, including the default directories.
+All the directories are returned as absolute directories."
+
+ (let ((build-dir (ada-xref-get-project-field 'build_dir)))
+ (append
+ ;; Add ${build_dir} in front of the path
+ (list build-dir)
+
+ (ada-get-absolute-dir-list (ada-xref-get-project-field 'obj_dir)
+ build-dir)
+
+ ;; Add the standard runtime at the end
+ ada-xref-runtime-library-ali-path)))
+
+(defun ada-xref-update-project-menu ()
+ "Update the menu Ada->Project, with the list of available project files."
+ ;; Create the standard items.
+ (let ((submenu
+ `("Project"
+ ["Load..." ada-set-default-project-file t]
+ ["New..." ada-prj-new t]
+ ["Edit..." ada-prj-edit t]
+ "---"
+ ;; Add the new items
+ ,@(mapcar
+ (lambda (x)
+ (let ((name (or (car x) "<default>"))
+ (command `(lambda ()
+ "Change the active project file."
+ (interactive)
+ (ada-parse-prj-file ,(car x))
+ (set 'ada-prj-default-project-file ,(car x))
+ (ada-xref-update-project-menu))))
+ (vector
+ (if (string= (file-name-extension name)
+ ada-project-file-extension)
+ (file-name-sans-extension
+ (file-name-nondirectory name))
+ (file-name-nondirectory name))
+ command
+ :button (cons
+ :toggle
+ (equal ada-prj-default-project-file
+ (car x))
+ ))))
+
+ ;; Parses all the known project files, and insert at
+ ;; least the default one (in case
+ ;; ada-xref-project-files is nil)
+ (or ada-xref-project-files '(nil))))))
+
+ (easy-menu-add-item ada-mode-menu '() submenu)))
+
+
+;;-------------------------------------------------------------
+;;-- Searching a file anywhere on the source path.
+;;--
+;;-- The following functions provide support for finding a file anywhere
+;;-- on the source path, without providing an explicit directory.
+;;-- They also provide file name completion in the minibuffer.
+;;--
+;;-- Public subprograms: ada-find-file
+;;--
+;;-------------------------------------------------------------
+
+(defun ada-do-file-completion (string predicate flag)
+ "Completion function when reading a file from the minibuffer.
+Completion is attempted in all the directories in the source path, as
+defined in the project file."
+ (let (list
+ (dirs (ada-xref-get-src-dir-field)))
+
+ (while dirs
+ (if (file-directory-p (car dirs))
+ (set 'list (append list (file-name-all-completions string (car dirs)))))
+ (set 'dirs (cdr dirs)))
+ (cond ((equal flag 'lambda)
+ (assoc string list))
+ (flag
+ list)
+ (t
+ (try-completion string
+ (mapcar (lambda (x) (cons x 1)) list)
+ predicate)))))
+
+;;;###autoload
+(defun ada-find-file (filename)
+ "Open a file anywhere in the source path.
+Completion is available."
+ (interactive
+ (list (completing-read "File: " 'ada-do-file-completion)))
+ (let ((file (ada-find-src-file-in-dir filename)))
+ (if file
+ (find-file file)
+ (error (concat filename " not found in src_dir")))))
+