Logic behind... Something?
-
Hello all, I have a little problem over here. With my word processor, I'm curerntly implementing a feature that basically automates a whole bunch of tasks that would normally require input of some sort from the user. I'm not too sure how to explain it, and I'm not looking for code. I just need a little help getting the logic behid it right as I keep going 'round and 'round in circles and getting stuck. A little info first: It's a tab-based word processor. Scenario: A user clicks the "Close ALL" menu item. Logic: Foreach control tab in tcontrol.tabpages if selected tab contains textbox and the selected tab's tag property contains a filepath and the text inside the textbox, which is inside the selected tab is not equal to the content of the file inside the selected tab's tag property then save changes to that file. And then close that tab. Then move on to the next tab. And repeat process. If selected tab's tag property does not contain a filepath, and the textbox inside the selected tab has a length greater than 0, then automatically display the SaveFileDialog, and then close that tab once the file has been saved. If the selected tab's tag property contains a filepath, but the file that the filepath refers to nolonger exists, then automatically display SaveFileDialog, and close the selected tab if the document has been saved. And Repeat. I know this might not make any sense at first, come to think of it, after reading what I just wrote, it doesn't really make a whole lot of sense to me but It's very difficult trying to explain exactly what I want to do since there are so many if's and else's etc... Is there an easier way to do something like this of would If/Else/Else If be the best way to go about it. I've been told to use Switch Statements for this but I honestly have more trouble that way. I haven't searched on google or msdn because I have no idea what search terms to use for this. Does anybody have any thoughts/suggestions? thank you
-
Hello all, I have a little problem over here. With my word processor, I'm curerntly implementing a feature that basically automates a whole bunch of tasks that would normally require input of some sort from the user. I'm not too sure how to explain it, and I'm not looking for code. I just need a little help getting the logic behid it right as I keep going 'round and 'round in circles and getting stuck. A little info first: It's a tab-based word processor. Scenario: A user clicks the "Close ALL" menu item. Logic: Foreach control tab in tcontrol.tabpages if selected tab contains textbox and the selected tab's tag property contains a filepath and the text inside the textbox, which is inside the selected tab is not equal to the content of the file inside the selected tab's tag property then save changes to that file. And then close that tab. Then move on to the next tab. And repeat process. If selected tab's tag property does not contain a filepath, and the textbox inside the selected tab has a length greater than 0, then automatically display the SaveFileDialog, and then close that tab once the file has been saved. If the selected tab's tag property contains a filepath, but the file that the filepath refers to nolonger exists, then automatically display SaveFileDialog, and close the selected tab if the document has been saved. And Repeat. I know this might not make any sense at first, come to think of it, after reading what I just wrote, it doesn't really make a whole lot of sense to me but It's very difficult trying to explain exactly what I want to do since there are so many if's and else's etc... Is there an easier way to do something like this of would If/Else/Else If be the best way to go about it. I've been told to use Switch Statements for this but I honestly have more trouble that way. I haven't searched on google or msdn because I have no idea what search terms to use for this. Does anybody have any thoughts/suggestions? thank you
Hi, let me summarize that for you: you have a collection of objects (e,g, tab pages on a form), and these objects may or may not contain "dirty data" i.e. data that still needs to be saved, how to make sure it all gets saved? This is what I do: 1. I give each object a bool dirty flag, which starts at false; gets set true whenever I change something to the object; and gets set false again when the object's content is either read from or written to permanent storage, such as a disk. 2. when I want to close the app, or close all the objects of the GUI, I enumerate the collection of objects, and for each dirty object, I ask the object to persist itself in any way fit; it is the object itself that either knows how to do that (because it holds the file path) or has to ask the user (because it does not know a file path yet). :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hello all, I have a little problem over here. With my word processor, I'm curerntly implementing a feature that basically automates a whole bunch of tasks that would normally require input of some sort from the user. I'm not too sure how to explain it, and I'm not looking for code. I just need a little help getting the logic behid it right as I keep going 'round and 'round in circles and getting stuck. A little info first: It's a tab-based word processor. Scenario: A user clicks the "Close ALL" menu item. Logic: Foreach control tab in tcontrol.tabpages if selected tab contains textbox and the selected tab's tag property contains a filepath and the text inside the textbox, which is inside the selected tab is not equal to the content of the file inside the selected tab's tag property then save changes to that file. And then close that tab. Then move on to the next tab. And repeat process. If selected tab's tag property does not contain a filepath, and the textbox inside the selected tab has a length greater than 0, then automatically display the SaveFileDialog, and then close that tab once the file has been saved. If the selected tab's tag property contains a filepath, but the file that the filepath refers to nolonger exists, then automatically display SaveFileDialog, and close the selected tab if the document has been saved. And Repeat. I know this might not make any sense at first, come to think of it, after reading what I just wrote, it doesn't really make a whole lot of sense to me but It's very difficult trying to explain exactly what I want to do since there are so many if's and else's etc... Is there an easier way to do something like this of would If/Else/Else If be the best way to go about it. I've been told to use Switch Statements for this but I honestly have more trouble that way. I haven't searched on google or msdn because I have no idea what search terms to use for this. Does anybody have any thoughts/suggestions? thank you
From what I can gather you have a number of tab pages that contain basically the same controls but can contain different data. when you close all tabs then you want to check certain data and prompt for a save if need be. Is that correct? What I would do in this instance is create a custom control that will basically be the only control on each of the tab pages. This control will have all your other controls however you choose to lay them out. This custom control should then have a function called ValidateClose() or something that does your tests and prompt the user or whatever. This can then be called in side the foreach loop of each tab when you are closing them all. using a switch block is basically the same as if else if logic, so use which ever you prefer. Hope that makes sense and offers some help
Life goes very fast. Tomorrow, today is already yesterday.
-
Hi, let me summarize that for you: you have a collection of objects (e,g, tab pages on a form), and these objects may or may not contain "dirty data" i.e. data that still needs to be saved, how to make sure it all gets saved? This is what I do: 1. I give each object a bool dirty flag, which starts at false; gets set true whenever I change something to the object; and gets set false again when the object's content is either read from or written to permanent storage, such as a disk. 2. when I want to close the app, or close all the objects of the GUI, I enumerate the collection of objects, and for each dirty object, I ask the object to persist itself in any way fit; it is the object itself that either knows how to do that (because it holds the file path) or has to ask the user (because it does not know a file path yet). :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
From what I can gather you have a number of tab pages that contain basically the same controls but can contain different data. when you close all tabs then you want to check certain data and prompt for a save if need be. Is that correct? What I would do in this instance is create a custom control that will basically be the only control on each of the tab pages. This control will have all your other controls however you choose to lay them out. This custom control should then have a function called ValidateClose() or something that does your tests and prompt the user or whatever. This can then be called in side the foreach loop of each tab when you are closing them all. using a switch block is basically the same as if else if logic, so use which ever you prefer. Hope that makes sense and offers some help
Life goes very fast. Tomorrow, today is already yesterday.
-
Ahh... That was so perfect it was almost peotic. :laugh: Your answers are always spot on. Thanks you very much Luc :) Jase
Just adding to Luc's reply, adding a "Do this for all modified files" checkbox will be a nice option to have. Just imagine 30 open documents and all are 'dirty' when the user chooses exit. Also, a "Save all" button on your toolbar would look cool. :)
It is a crappy thing, but it's life -^ Carlo Pallini
-
Just adding to Luc's reply, adding a "Do this for all modified files" checkbox will be a nice option to have. Just imagine 30 open documents and all are 'dirty' when the user chooses exit. Also, a "Save all" button on your toolbar would look cool. :)
It is a crappy thing, but it's life -^ Carlo Pallini
-
Just adding to Luc's reply, adding a "Do this for all modified files" checkbox will be a nice option to have. Just imagine 30 open documents and all are 'dirty' when the user chooses exit. Also, a "Save all" button on your toolbar would look cool. :)
It is a crappy thing, but it's life -^ Carlo Pallini
Rajesh R Subramanian wrote:
Just imagine 30 open documents and all are 'dirty' when the user chooses exit.
I wouldn't advise you to get yourself into such situation. One medium-sized alpha particle could ruin your day. ;P
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, let me summarize that for you: you have a collection of objects (e,g, tab pages on a form), and these objects may or may not contain "dirty data" i.e. data that still needs to be saved, how to make sure it all gets saved? This is what I do: 1. I give each object a bool dirty flag, which starts at false; gets set true whenever I change something to the object; and gets set false again when the object's content is either read from or written to permanent storage, such as a disk. 2. when I want to close the app, or close all the objects of the GUI, I enumerate the collection of objects, and for each dirty object, I ask the object to persist itself in any way fit; it is the object itself that either knows how to do that (because it holds the file path) or has to ask the user (because it does not know a file path yet). :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
The only thing I add to that is a "changed" event thrown upward - that way the parent can give a visual indication in the tab or whatever (just like VS does with the "*" next to the file name) - and does not have to iterate though all tabs to find any dirty data on closing.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
The only thing I add to that is a "changed" event thrown upward - that way the parent can give a visual indication in the tab or whatever (just like VS does with the "*" next to the file name) - and does not have to iterate though all tabs to find any dirty data on closing.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
No problem, as long as the DirtyChanged event only fires on an actual change of bool dirty. Otherwise every keystroke would set of a whole chain of mostly unnecessary actions. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
No problem, as long as the DirtyChanged event only fires on an actual change of bool dirty. Otherwise every keystroke would set of a whole chain of mostly unnecessary actions. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.