emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/pgtk f4920a6 011/100: Add pgtk-read-file-name function


From: Yuuki Harano
Subject: feature/pgtk f4920a6 011/100: Add pgtk-read-file-name function
Date: Tue, 24 Nov 2020 08:02:26 -0500 (EST)

branch: feature/pgtk
commit f4920a68831f769f0a1504c85145589bdb4c3eb9
Author: Yuuki Harano <masm+github@masm11.me>
Commit: Jeff Walsh <fejfighter@gmail.com>

    Add pgtk-read-file-name function
    
    * ../src/pgtkfns.c (read_file_name_closed_cb)
        (Fpgtk_read_file_name, syms_of_pgtkfns): add function
    
    pgtk-read-file-name を作成。
    
    toolbar からよく呼ばれるので…
---
 lisp/term/pgtk-win.el | 55 -------------------------------------------
 src/gtkutil.c         |  4 ++++
 src/pgtkfns.c         | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 56 deletions(-)

diff --git a/lisp/term/pgtk-win.el b/lisp/term/pgtk-win.el
index 203cce4..1cf526b 100644
--- a/lisp/term/pgtk-win.el
+++ b/lisp/term/pgtk-win.el
@@ -43,34 +43,6 @@
 
 ;;;; File handling.
 
-(defun x-file-dialog (prompt dir default_filename mustmatch only_dir_p)
-"Read file name, prompting with PROMPT in directory DIR.
-Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
-selection box, if specified.  If MUSTMATCH is non-nil, the returned file
-or directory must exist.
-
-This function is only defined on PGTK, MS Windows, and X Windows with the
-Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
-Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories."
-  (pgtk-read-file-name prompt dir mustmatch default_filename only_dir_p))
-
-(defun pgtk-open-file-using-panel ()
-  "Pop up open-file panel, and load the result in a buffer."
-  (interactive)
-  ;; Prompt dir defaultName isLoad initial.
-  (setq pgtk-input-file (pgtk-read-file-name "Select File to Load" nil t nil))
-  (if pgtk-input-file
-      (and (setq pgtk-input-file (list pgtk-input-file)) (pgtk-find-file))))
-
-(defun pgtk-write-file-using-panel ()
-  "Pop up save-file panel, and save buffer in resulting name."
-  (interactive)
-  (let (pgtk-output-file)
-    ;; Prompt dir defaultName isLoad initial.
-    (setq pgtk-output-file (pgtk-read-file-name "Save As" nil nil nil))
-    (message pgtk-output-file)
-    (if pgtk-output-file (write-file pgtk-output-file))))
-
 (defcustom pgtk-pop-up-frames 'fresh
   "Non-nil means open files upon request from the Workspace in a new frame.
 If t, always do so.  Any other non-nil value means open a new frame
@@ -83,33 +55,6 @@ unless the current buffer is a scratch buffer."
 
 (declare-function pgtk-hide-emacs "pgtkfns.c" (on))
 
-(defun pgtk-find-file ()
-  "Do a `find-file' with the `pgtk-input-file' as argument."
-  (interactive)
-  (let* ((f (file-truename
-            (expand-file-name (pop pgtk-input-file)
-                              command-line-default-directory)))
-         (file (find-file-noselect f))
-         (bufwin1 (get-buffer-window file 'visible))
-         (bufwin2 (get-buffer-window "*scratch*" 'visible)))
-    (cond
-     (bufwin1
-      (select-frame (window-frame bufwin1))
-      (raise-frame (window-frame bufwin1))
-      (select-window bufwin1))
-     ((and (eq pgtk-pop-up-frames 'fresh) bufwin2)
-      (pgtk-hide-emacs 'activate)
-      (select-frame (window-frame bufwin2))
-      (raise-frame (window-frame bufwin2))
-      (select-window bufwin2)
-      (find-file f))
-     (pgtk-pop-up-frames
-      (pgtk-hide-emacs 'activate)
-      (let ((pop-up-frames t)) (pop-to-buffer file nil)))
-     (t
-      (pgtk-hide-emacs 'activate)
-      (find-file f)))))
-
 
 (defun pgtk-drag-n-drop (event &optional new-frame force-text)
   "Edit the files listed in the drag-n-drop EVENT.
diff --git a/src/gtkutil.c b/src/gtkutil.c
index b7a397b..6c0d421 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1319,6 +1319,7 @@ style_changed_cb (GObject *go,
 
 /* Called when a delete-event occurs on WIDGET.  */
 
+#ifndef HAVE_PGTK
 static gboolean
 delete_cb (GtkWidget *widget,
            GdkEvent  *event,
@@ -1326,6 +1327,7 @@ delete_cb (GtkWidget *widget,
 {
   return TRUE;
 }
+#endif
 
 /* Create and set up the GTK widgets for frame F.
    Return true if creation succeeded.  */
@@ -4738,6 +4740,7 @@ xg_tool_bar_help_callback (GtkWidget *w,
 }
 
 
+#ifndef HAVE_GTK3
 /* This callback is called when a tool bar item shall be redrawn.
    It modifies the expose event so that the GtkImage widget redraws the
    whole image.  This to overcome a bug that makes GtkImage draw the image
@@ -4767,6 +4770,7 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
 
   return FALSE;
 }
+#endif
 
 /* Attach a tool bar to frame F.  */
 
diff --git a/src/pgtkfns.c b/src/pgtkfns.c
index 140f29a..34effd1 100644
--- a/src/pgtkfns.c
+++ b/src/pgtkfns.c
@@ -181,7 +181,7 @@ x_set_background_color (struct frame *f, Lisp_Object arg, 
Lisp_Object oldval)
   PGTK_TRACE("x_set_background_color: col.pixel=%08lx.", col.pixel);
   FRAME_X_OUTPUT(f)->background_color = col.pixel;
   FRAME_BACKGROUND_PIXEL (f) =
-    ARGB_TO_ULONG ((int)(0xff), (int)(col.red>>8), (int)(col.green>>8), 
(int)(col.blue>>8));
+    ARGB_TO_ULONG ((unsigned int)(0xff), (unsigned int)(col.red>>8), (unsigned 
int)(col.green>>8), (unsigned int)(col.blue>>8));
 
   xg_set_background_color(f, col.pixel);
   update_face_from_frame_parameter (f, Qbackground_color, arg);
@@ -2579,6 +2579,67 @@ visible.  */)
   return Qnil;
 }
 
+DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
+       doc: /* Read file name, prompting with PROMPT in directory DIR.
+Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
+selection box, if specified.  If MUSTMATCH is non-nil, the returned file
+or directory must exist.
+
+This function is defined only on PGTK, NS, MS Windows, and X Windows with the
+Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
+Otherwise, if ONLY-DIR-P is non-nil, the user can select only directories.
+On MS Windows 7 and later, the file selection dialog "remembers" the last
+directory where the user selected a file, and will open that directory
+instead of DIR on subsequent invocations of this function with the same
+value of DIR as in previous invocations; this is standard MS Windows behavior. 
 */)
+  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, 
Lisp_Object mustmatch, Lisp_Object only_dir_p)
+{
+  struct frame *f = SELECTED_FRAME ();
+  char *fn;
+  Lisp_Object file = Qnil;
+  Lisp_Object decoded_file;
+  ptrdiff_t count = SPECPDL_INDEX ();
+  char *cdef_file;
+
+  check_window_system (f);
+
+  CHECK_STRING (prompt);
+  CHECK_STRING (dir);
+
+  /* Prevent redisplay.  */
+  specbind (Qinhibit_redisplay, Qt);
+#if 0
+  record_unwind_protect_void (clean_up_dialog);
+#endif
+
+  block_input ();
+
+  if (STRINGP (default_filename))
+    cdef_file = SSDATA (default_filename);
+  else
+    cdef_file = SSDATA (dir);
+
+  fn = xg_get_file_name (f, SSDATA (prompt), cdef_file,
+                         ! NILP (mustmatch),
+                         ! NILP (only_dir_p));
+
+  if (fn)
+    {
+      file = build_string (fn);
+      xfree (fn);
+    }
+
+  unblock_input ();
+
+  /* Make "Cancel" equivalent to C-g.  */
+  if (NILP (file))
+    quit ();
+
+  decoded_file = DECODE_FILE (file);
+
+  return unbind_to (count, decoded_file);
+}
+
 DEFUN ("pgtk-backend-display-class", Fpgtk_backend_display_class, 
Spgtk_backend_display_class,
        0, 1, "",
        doc: /* Returns the name of the Gdk backend display class of the 
TERMINAL.
@@ -2711,6 +2772,8 @@ be used as the image of the icon representing the frame.  
*/);
   defsubr (&Spgtk_print_frames_dialog);
   defsubr (&Spgtk_backend_display_class);
 
+  defsubr (&Sx_file_dialog);
+
   as_status = 0;
   as_script = Qnil;
   as_result = 0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]