changeset 18971:f084aab05cd9

Move checks for graphics_toolkit GUI functions to own script. * __get_funcname__.m: New function to buid the function name from basename and graphics_toolkit. * uigetdir.m, uigetfile.m, uiputfile.m: Adapt to use __get_funcname__ with basename = mfilename ()
author Andreas Weber <andy.weber.aw@gmail.com>
date Thu, 31 Jul 2014 00:03:56 +0200
parents bb2a03f9ed20
children 19cb2530c16b
files scripts/gui/private/__get_funcname__.m scripts/gui/uigetdir.m scripts/gui/uigetfile.m scripts/gui/uiputfile.m
diffstat 4 files changed, 46 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/gui/private/__get_funcname__.m	Thu Jul 31 00:03:56 2014 +0200
@@ -0,0 +1,42 @@
+## Copyright (C) 2014 Andreas Weber
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{funcname} =} __get_funcname__ (@var{basename})
+## Internal function.
+##
+## Build function name for the current graphics toolkit according to schema
+## __[basename]_[graphics_toolkit]__, use fltk as default.
+## @end deftypefn
+
+## Author: Andreas Weber
+
+function funcname = __get_funcname__ (basename)
+
+  if (! __octave_link_enabled__ ())
+    tk = graphics_toolkit ();
+    funcname = strcat ("__", basename, "_", tk, "__");
+    if ((numel (tk) > 0) && (! strcmp(tk, "fltk")) && (! __is_function__ (funcname)))
+      warning ("%s: no implementation for toolkit '%s', using 'fltk' instead",basename, tk);
+    endif
+    funcname = strcat ("__", basename, "_fltk__");
+  else
+    funcname = "";
+  endif
+
+endfunction
--- a/scripts/gui/uigetdir.m	Wed Jul 30 23:34:14 2014 +0200
+++ b/scripts/gui/uigetdir.m	Thu Jul 31 00:03:56 2014 +0200
@@ -30,14 +30,7 @@
 
 function dirname = uigetdir (init_path = pwd, dialog_name = "Select Directory to Open")
 
-  if (! __octave_link_enabled__ ())
-    tk = graphics_toolkit ();
-    funcname = ["uigetdir", tk, "__"];
-    if (numel (tk) > 0 && ! __is_function__ (funcname))
-      warning ("uigetdir: no implementation for toolkit '%s', using 'fltk' instead", tk);
-    endif
-    funcname = "__uigetdir_fltk__";
-  endif
+  funcname = __get_funcname__ (mfilename ());
 
   if (nargin > 2)
     print_usage ();
--- a/scripts/gui/uigetfile.m	Wed Jul 30 23:34:14 2014 +0200
+++ b/scripts/gui/uigetfile.m	Thu Jul 31 00:03:56 2014 +0200
@@ -66,15 +66,8 @@
 
 function [retfile, retpath, retindex] = uigetfile (varargin)
 
-  if (! __octave_link_enabled__ ())
-    tk = graphics_toolkit ();
-    funcname = ["__uigetfile_", tk, "__"];
-    if (numel (tk) > 0 && ! __is_function__ (funcname))
-      warning ("uigetfile: no implementation for toolkit '%s', using 'fltk' instead", tk);
-    endif
-    funcname = "__uigetfile_fltk__";
-  endif
-  
+  funcname = __get_funcname__ (mfilename ());
+
   if (nargin > 7)
     error ("uigetfile: number of input arguments must be less than eight");
   endif
--- a/scripts/gui/uiputfile.m	Wed Jul 30 23:34:14 2014 +0200
+++ b/scripts/gui/uiputfile.m	Thu Jul 31 00:03:56 2014 +0200
@@ -56,14 +56,7 @@
 
 function [retfile, retpath, retindex] = uiputfile (varargin)
 
-  if (! __octave_link_enabled__ ())
-    tk = graphics_toolkit ();
-    funcname = ["uiputfile", tk, "__"];
-    if (numel (tk) > 0 && ! __is_function__ (funcname))
-      warning ("uiputfile: no implementation for toolkit '%s', using 'fltk' instead", tk);
-    endif
-    funcname = "__uiputfile_fltk__";
-  endif
+  funcname = __get_funcname__ (mfilename ());
 
   if (nargin > 3)
     print_usage ();