From: RobuLAB on 21 May 2010 06:05 Hi, I'm writing a GUI that has a menu bar in which I have a "save" and a "save as" function. The "save"-function is for when a user loads a file, changes it and wants to save it in the same location under the same name. It is also possible to work with the GUI without loading a file. In that case, when the user presses "save", I want the callback for "save as" to kick in so the user can choose a name and location. I can easily program a switch statement in my "save"-function which would execute the same code as "save as" would do when there hasn't been a file loaded, but that would mean that my program has two times the same code in it. Is there a way to do: (pseudo-code) if (no file loaded) jump to save_as else save (same name and location as the loaded file) end Thanks in advance
From: Royi Avital on 21 May 2010 06:40 Why won't you create a "Flag" for "Image Loaded". The create to functions just as you described. You chose which function to run using the Flag. The Flag default should be a value which runs the "Save As" function. "RobuLAB " <amaury.ampe(a)etu.u-bordeaux1.fr> wrote in message <ht5lsj$87o$1(a)fred.mathworks.com>... > Hi, > I'm writing a GUI that has a menu bar in which I have a "save" and a "save as" function. > The "save"-function is for when a user loads a file, changes it and wants to save it in the same location under the same name. It is also possible to work with the GUI without loading a file. In that case, when the user presses "save", I want the callback for "save as" to kick in so the user can choose a name and location. > I can easily program a switch statement in my "save"-function which would execute the same code as "save as" would do when there hasn't been a file loaded, but that would mean that my program has two times the same code in it. > > Is there a way to do: > (pseudo-code) > if (no file loaded) > jump to save_as > else > save (same name and location as the loaded file) > end > > Thanks in advance
From: Steven Lord on 21 May 2010 09:53 "RobuLAB " <amaury.ampe(a)etu.u-bordeaux1.fr> wrote in message news:ht5lsj$87o$1(a)fred.mathworks.com... > Hi, > I'm writing a GUI that has a menu bar in which I have a "save" and a "save > as" function. > The "save"-function is for when a user loads a file, changes it and wants > to save it in the same location under the same name. It is also possible > to work with the GUI without loading a file. In that case, when the user > presses "save", I want the callback for "save as" to kick in so the user > can choose a name and location. I can easily program a switch statement in > my "save"-function which would execute the same code as "save as" would do > when there hasn't been a file loaded, but that would mean that my program > has two times the same code in it. > > Is there a way to do: > (pseudo-code) > if (no file loaded) > jump to save_as > else save (same name and location as the loaded file) > end > > Thanks in advance You have a callback function for your "Save As" button, right? Just call it. if fileNotLoaded SaveasButton_Callback(...) % fill in the appropriate parameters return end % otherwise continue with the rest of the SAVE callback -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: Vectors on ellipsoid surface Next: 'Perhaps Java not running' error |