# HG changeset patch # User Rik # Date 1589988407 25200 # Node ID 391a9d85e59d0e6aa6a9ad9585e07db5c11f3de6 # Parent 6c2366242767f28925eddb78a1429362afab58cf __add_default_menu__.m: Clean-up code. * __add_default_menu__.m: Remove extra newline in docstring. Add ';' to end of return statement. entries to indicate a new dialog will appear. __add_default_menu__.m (open_cb): Don't assign to temporary variable tmphf which is never used. Delete function inputs "(h, e)" which are not used. __add_default_menu__.m (save_cb): Change second input to '~' since it is not used. __add_default_menu__.m (__save_as__): Don't use ifelse() for performance since second branch is not a simple constant or variable. Re-order input file filter for clarity. Use strcmp rather than ismember for performance. Rename "filterindex" variable to "filteridx". __add_default_menu__.m (close_cb): Delete function inputs "(h, e)" which are not used. __add_default_menu__.m (autoscale_cb, guimode_cb): Delete function input "e" which is not used. __add_default_menu__.m (mouse_tools_cb): Change second input to '~' since it is unused. Add parentheses around condition in switch statement per Octave coding conventions. Delete extra spaces in set() statements. diff -r 6c2366242767 -r 391a9d85e59d scripts/plot/util/private/__add_default_menu__.m --- a/scripts/plot/util/private/__add_default_menu__.m Wed May 20 08:18:09 2020 -0700 +++ b/scripts/plot/util/private/__add_default_menu__.m Wed May 20 08:26:47 2020 -0700 @@ -28,7 +28,6 @@ ## @deftypefnx {} {} __add_default_menu__ (@var{hfig}, @var{hmenu}) ## Add default menu and listeners to figure. ## -## ## All uimenu handles have their @qcode{"HandleVisibility"} property set to ## @qcode{"off"}. ## @end deftypefn @@ -37,7 +36,7 @@ ## Gnuplot doesn't handle uimenu and uitoolbar objects if (strcmp (graphics_toolkit (), "gnuplot")) - return + return; endif ## Create @@ -173,16 +172,16 @@ set (htb, "visible", toolbar_state); endfunction -function open_cb (h, e) +function open_cb () [filename, filedir] = uigetfile ({"*.ofig;*.fig", "Figure Files"}, ... "Open Figure"); if (filename != 0) fname = fullfile (filedir, filename); - tmphf = openfig (fname); + openfig (fname); endif endfunction -function save_cb (h, e, action) +function save_cb (h, ~, action) hfig = gcbf (); fname = get (hfig, "filename"); @@ -198,27 +197,31 @@ endfunction function __save_as__ (hf, fname = "") - def = ifelse (! isempty (fname), fname, fullfile (pwd (), "untitled.ofig")); + if (! isempty (fname)) + def = fname; + else + def = fullfile (pwd (), "untitled.ofig"); + endif filter = {"*.ofig", "Octave Figure"; - "*.eps", "Encapsulated PostScript"; - "*.pdf", "Portable Document Format"; - "*.svg", "Scalable Vector Graphics"; - "*.ps", "PostScript"; - "*.gif", "GIF Image"; - "*.jpg", "JPEG Image"; - "*.png", "Portable Network Graphics Image"; + "*.eps", "Encapsulated PostScript"; + "*.pdf", "Portable Document Format"; + "*.ps", "PostScript"; + "*.svg", "Scalable Vector Graphics"; + "*.gif", "GIF Image"; + "*.jpg", "JPEG Image"; + "*.png", "Portable Network Graphics Image"; "*.tiff", "TIFF Image"}; ## Reorder filters to have current first [~, ~, ext] = fileparts (def); - idx = ismember (filter(:,1), ["*" tolower(ext)]) - filter = [filter(idx,:); filter(~idx,:)]; + idx = strcmp (filter(:,1), ["*" tolower(ext)]); + filter = [filter(idx,:); filter(! idx,:)]; - [filename, filedir, filterindex] = uiputfile (filter, "Save Figure", def); + [filename, filedir, filteridx] = uiputfile (filter, "Save Figure", def); if (filename != 0) fname = fullfile (filedir, filename); - [~, ~, ext] = fileparts(fname); - if (filterindex > size (filter, 1)) + [~, ~, ext] = fileparts (fname); + if (filteridx > rows (filter)) ## "All Files" option if (isempty (ext)) fmt = ""; @@ -226,7 +229,7 @@ fmt = ext(2:end); endif else - fmt = filter{filterindex,1}(3:end); + fmt = filter{filteridx,1}(3:end); if (isempty (ext)) fname = [fname "." fmt]; endif @@ -236,7 +239,7 @@ endif endfunction -function close_cb (h, e) +function close_cb () close (gcbf ()); endfunction @@ -248,7 +251,7 @@ hax = findobj (fig, "type", "axes", "-not", "tag", "legend"); endfunction -function autoscale_cb (h, e) +function autoscale_cb (h) hax = __get_axes__ (h); arrayfun (@(h) axis (h, "auto"), hax); drawnow (); @@ -267,7 +270,7 @@ "FigureHandle", hf)); endfunction -function guimode_cb (h, e) +function guimode_cb (h) [hax, fig] = __get_axes__ (h); id = get (h, "tag"); switch (id) @@ -289,7 +292,7 @@ endswitch endfunction -function mouse_tools_cb (h, ev, htools, typ = "") +function mouse_tools_cb (h, ~, htools, typ = "") persistent recursion = false; @@ -304,7 +307,7 @@ mode = get (hf, "__mouse_mode__"); state = "on"; - switch mode + switch (mode) case "zoom" zm = get (hf, "__zoom_mode__"); if (strcmp (zm.Direction, "in")) @@ -332,7 +335,7 @@ ## Update the mouse mode according to the button state state = get (h, "state"); - switch typ + switch (typ) case {"zoomin", "zoomout"} prop = "__zoom_mode__"; val = get (hf, prop); @@ -343,7 +346,7 @@ else val.Direction = "out"; endif - set (hf, "__mouse_mode__" , "zoom"); + set (hf, "__mouse_mode__", "zoom"); endif val.Enable = state; set (hf, prop, val); @@ -352,21 +355,21 @@ prop = ["__", typ, "_mode__"]; val = get (hf, prop); if (strcmp (state, "on")) - set (hf, "__mouse_mode__" , typ); + set (hf, "__mouse_mode__", typ); endif val.Enable = state; set (hf, prop, val); case {"text", "select"} if (strcmp (state, "on")) - set (hf, "__mouse_mode__" , typ); + set (hf, "__mouse_mode__", typ); endif endswitch if (strcmp (state, "on")) set (htools(htools != h), "state", "off"); elseif (! any (strcmp (get (htools, "state"), "on"))) - set (hf, "__mouse_mode__" , "none"); + set (hf, "__mouse_mode__", "none"); endif endif