how to program BACK button in a file explorer? - c#

Im developing a small file explorer, how do i set Back button.
i have:
txtAddress.Text which is the address bar of the explorer.
string currAddress which has the current address.
List<string> prevAddress which should hold some previous addresses which had been visited for Back Button
and i use:
Root(); to get My Computer items.
Open(string Address); to get Files/Folder from an address.
Search(string Address, string keyword); to get the search result items.
i need the back button because when i do search in a path, i can't press up button (which go to the parent path) because i need to get back to the path i was searching in, so how do back button works in explorer? and when should i add/remove addresses from it?

Suggest keeping/managing this state yourself in the application.
Each time the user navigates/forces a new/different path in the address bar, then add the new directory to a list/collection in your app.
When the back button is clicked, you can find the 'previous' entry in your list/collection. That's your directory to display.
Key Val
1 D:\
2 D:\Foo
3 D:\Foo\Bar
4 C:\ (here the user may have manually typed into the addr bar)
You may run into issues where the directory no longer exists, is renamed, is unavailable, etc. Perhaps you've already got these cases handled in your code. You could use Directory.Exists before attempting to navigate.

To implement a back button well I would suggest using a stack of some kind which maintains the locations which the user has been. Each time a navigation is performed, push the old location onto the stack. When the back button is pressed, pop the top item on the stack and navigate to that location. If the stack is empty, make the back button unusable, as there is nowhere to go back to.

Back (and forward) is very close to Undo which is more commonly discussed (i.e. mentioned in the "Design Patterns" book).
Common implementation - state (as pointed by #p.campbell answer) for each operation stored in "current state" and 2 stacks: one for undo/back, another for redo/forward. Whenever user makes a change (i.e. by typing something in or actively navigating somewhere) redo/forward stack is cleared and previous state is pushed to undo/back stack. Back/forward correspondingly put current state into one of the stacks and pop next state from the other one.

Related

Using an array to navigate to ViewControllers

I'm currently working on refining an app I made for (currently only) IOS. In this app, I have 15 different UIViewControllers, each one of them shows different data and uses different objects.
My menus have a hierarchical structure (not binary). I have 4 "parent" ViewControllers. These parent ViewControllers each have 1 or more "child" ViewControllers:
Roster
EventDetails
Directions
MapView
ChangeRequests
NewChangeRequest
ChangeRequestDetails
Contacts
ContactDetails
ProgressReport
NewReportEntry
DoubleChecks
NewDoubleCheck
DoubleCheckDetails
DoubleCheckPhotoDetails
On the parent ViewControllers I use a FlyoutMenu (with datasource) to be able to navigate to other parent ViewControllers. On the child ViewControllers I have a custom back button, with a delegate attached to it, to take me back to the previous menu. Here come the problem.
I've been given the assignment to link some menus to each other, to improve user-friendliness. an example:
I'm currently at the EventDetails menu. In this menu, I want a button to take me to the NewDoubleCheck menu. Both of these menus have a back button, that uses PopViewController to navigate back to the previous menu. If I'd accessed NewDoubleCheck from DoubleChecks, it would take me back to DoubleChecks. But if I'd accessed it from EventDetails, it takes me back to EventDetails, because it's on the top of the stack. This means I end up in an endless loop of EventDetails --> NewDoubleCheck --> EventDetails --> NewDoubleCheck.
Long story short: I want to be able to search the stack of ViewControllers and be able to select the right ViewController to be loaded, using PushViewController.
I was thinking about writing a method at the start of my app (somewhere near the initialisation of my FlyOutMenu, I'd reckon, that would make me an array of Dictionary<string, UIViewController> with ALL of the ViewControllers in my project, so I can search and navigate more easily. Is this possible?
I know this is a long text, but I'd be glad to hear any opinions and solutions for my problem.
Thanks in advance.
Dear regards,
Björn
I encountered the same problem in one of my apps.
Funny thing is that I checked some of the 'famous' apps on the store, and I noticed that they have this 'endless loop' issue.
My solution was:
Before navigating to NewDoubleCheck, I'd search if it already exists in the navigationController stack.
If that's the case, then I pop to that viewController instead of pushing a new one.
Something like this:
if ([self.navigationController.viewControllers[[self.navigationController.viewControllers count]-2] isKindOfClass:[NewDoubleCheck class]]) {
// ViewController already exist, so we need to get back to it
NewDoubleCheck *viewController = (NewDoubleCheck *)self.navigationController.viewControllers[[self.navigationController.viewControllers count]-2];
[self.navigationController popToViewController:viewController animated:YES];
} else {
// Push to NewDoubleCheck
}
Yes you can get all view controllers like this
NSArray *controllerArray = [[self navigationController] viewControllers];
for (UIViewController *controller in controllerArray){
NSLog(#"%#",controller.title);
}

Remove UIAlerts When App Goes to Background

In my app I give a alert, if the user wants to confirm the offer or not.
Now I noticed that if the user hits the home button, the alert stays there & makes my app crash if he would enter anything.
How can I remove the alert (all UIAlerts) when I go to background mode?
Kind regards,
Glenn.
Edit 1:
Basically I a making a offer page. When the user clicks OK, I am showing a UIAlert for extra confirmation.
Now I also have functionality that when a user closes (home button) the app & restarts it, it will go to the overview page (where all the products are) and will ask the server for the data (makes the data up -to-date again.).
Normally there would be no problem with my app going into background mode. But with the functionality of refreshing the data & going to another controller it probaly gives problems. Therefore I need to be able to close all the UIAlerts still active.
You app crashes not because of UIAlerts but because something is going wrong. Even if you put an app in the background while showing a UIAlert, the alert stays there.
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
you can use it with this method in AppDelegate.m:
- (void)applicationDidEnterBackground:(UIApplication *)application
but Nikos M. was right: you should find and fix the source of this problem, but not to disguise it. there is a simplest way to show alert, check it, may be it'll help:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Some message" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];

Is it Possible to Place a Permanent ShellTile on the Start Screen

I'm wondering if it is possible to leave out the Uri QueryString parameter so that when a user pins a tile, it may not link to the application. This would be for design reasons when pinning several ShellTiles onto the Start Screen. The user would of course have the option to delete the tile manually from the Start Screen or from a button within the app itself. It seems when trying this I am still taken to the application but a debug error also occurs.
An example of when I create the ShellTile is as follows
ShellTile.Create(new Uri("/MainPage.xaml?" + Constants.Key + title, UriKind.Relative), LiveTile);
Can this be modified somehow?
Your secondary tile must have unique navigation URI. However you could navigate to some page that would immediately close itself. It is not the best solution but there isn't any better way.
For uniqueness just use Guid. You can close app in code with Application.Current.Terminate() for example.

Running a form for only once in entire Windows form application lifetime

In my project i want to show a user-guide when the user first installs my software.So, for only one time i want to show (at beginning) a window where some direction is given so that a user can understand in first time how to use my software.After the user once watches the window(user guide) this window will not appear further time.
I want to use a form like userguid.cs. this will show in the begging of the mainwindow for one time in the life of the my application.
N:B: For example if user restart his computer and again run the app it will not show the userguide window again as it shows before
How can i do that?? Can anyone give idea how can i do that???
Simply maintain a flag, which will help you store, whether the user guide has been displayed or not.
The flag can be a file, which is stored in your application directory, or if you have a database, you can store the boolean value in a db.
Then call the function to display the user guide, when the form loads, or wherever you require.
public void Form1_Load() {
displayUserGuide();
}
And, in the function displayUserGuide see whether flag has been set or not.
public void displayUserGuide() {
//Return, if the form has already been displayed.
if(File.Exists("UGUID")) return;
userGuide.Show();
File.Create("UGUID");
}
You can simply call the functiondisplayUserGuide() any where you want throughout the Application. The function will make sure the form is displayed only once.
In this way you can display Windows form application once.
Hope this helps!
You can create a dummy file in the application path to make sure whether userguide displayed or not.
For Example,
Before loading UserGuide.cs, check for the following,
if(!File.Exists("UserGuideShown"))
{
UserGuide.Show();
File.Create("UserGuideShown");
}
When next time, the application loads, it will check for the file, it will be exists as it shown already. so it will skip showing up..

Possible to override "Pin" functionality of Windows 7 Jump List Item? Or multiple commands on a single line

I've started adding JumpLists to my programs and know how to "talk back" using a single instance of my program, but I was wondering if it is possible to override the Pin functionality or otherwise add two commands to a single line?
I want to have an "Open location" (main click) or "Remove location" option, and was hoping to be able to override the Pin icon to act as the "remove".
I know I could do it by making twice as many items and having half of them as "remove" and half as "open", but it would really clean up the UI / List if they could be on a single line.
I don't believe this is possible. Looking at both the managed and unmanaged API's it's pretty clear that a JumpList is a collection of JumpItem and a JumpItem (or really, a JumpTask or JumpPath) can only take a single path with additional arguments. To override the JumpItem click handler you'd need access to methods that are not exposed by Windows.
I haven't worked with Win7 jumplists before, but is there an event you can catch if users "unpin" an item? If so, you could catch that event, do the necessary operations, and re-add the item to the jumplist... A bit of a workaround, but it'd do what you want.
Otherwise, just change the text and functionality of a list item once it's clicked (from "Open location" to "Remove location" if the user opened a location and vice versa). You could keep a boolean or something for each item to distinguish the current state.

Categories

Resources